diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -229,7 +229,7 @@ void PrintAsync(const char *s, size_t len, bool is_stdout); - ConstString GetTopIOHandlerControlSequence(char ch); + llvm::StringRef GetTopIOHandlerControlSequence(char ch); const char *GetIOHandlerCommandPrefix(); diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -12,7 +12,6 @@ #include "lldb/Core/ValueObjectList.h" #include "lldb/Host/Config.h" #include "lldb/Utility/CompletionRequest.h" -#include "lldb/Utility/ConstString.h" #include "lldb/Utility/Flags.h" #include "lldb/Utility/Predicate.h" #include "lldb/Utility/Stream.h" @@ -107,7 +106,7 @@ } bool SetPrompt(const char *) = delete; - virtual ConstString GetControlSequence(char ch) { return ConstString(); } + virtual llvm::StringRef GetControlSequence(char ch) { return {}; } virtual const char *GetCommandPrefix() { return nullptr; } @@ -271,9 +270,7 @@ return true; } - virtual ConstString IOHandlerGetControlSequence(char ch) { - return ConstString(); - } + virtual llvm::StringRef IOHandlerGetControlSequence(char ch) { return {}; } virtual const char *IOHandlerGetCommandPrefix() { return nullptr; } @@ -295,24 +292,25 @@ // the last line is equal to "end_line" which is specified in the constructor. class IOHandlerDelegateMultiline : public IOHandlerDelegate { public: - IOHandlerDelegateMultiline(const char *end_line, + IOHandlerDelegateMultiline(llvm::StringRef end_line, Completion completion = Completion::None) - : IOHandlerDelegate(completion), - m_end_line((end_line && end_line[0]) ? end_line : "") {} + : IOHandlerDelegate(completion), m_end_line(end_line.str() + "\n") {} ~IOHandlerDelegateMultiline() override = default; - ConstString IOHandlerGetControlSequence(char ch) override { + llvm::StringRef IOHandlerGetControlSequence(char ch) override { if (ch == 'd') - return ConstString(m_end_line + "\n"); - return ConstString(); + return m_end_line; + return {}; } bool IOHandlerIsInputComplete(IOHandler &io_handler, StringList &lines) override { // Determine whether the end of input signal has been entered const size_t num_lines = lines.GetSize(); - if (num_lines > 0 && lines[num_lines - 1] == m_end_line) { + const llvm::StringRef end_line = + llvm::StringRef(m_end_line).drop_back(1); // Drop '\n' + if (num_lines > 0 && llvm::StringRef(lines[num_lines - 1]) == end_line) { // Remove the terminal line from "lines" so it doesn't appear in the // resulting input and return true to indicate we are done getting lines lines.PopBack(); @@ -373,7 +371,7 @@ void TerminalSizeChanged() override; - ConstString GetControlSequence(char ch) override { + llvm::StringRef GetControlSequence(char ch) override { return m_delegate.IOHandlerGetControlSequence(ch); } @@ -522,8 +520,9 @@ m_stack[num_io_handlers - 2]->GetType() == second_top_type); } - ConstString GetTopIOHandlerControlSequence(char ch) { - return ((m_top != nullptr) ? m_top->GetControlSequence(ch) : ConstString()); + llvm::StringRef GetTopIOHandlerControlSequence(char ch) { + return ((m_top != nullptr) ? m_top->GetControlSequence(ch) + : llvm::StringRef()); } const char *GetTopIOHandlerCommandPrefix() { diff --git a/lldb/include/lldb/Expression/REPL.h b/lldb/include/lldb/Expression/REPL.h --- a/lldb/include/lldb/Expression/REPL.h +++ b/lldb/include/lldb/Expression/REPL.h @@ -88,7 +88,7 @@ const char *IOHandlerGetFixIndentationCharacters() override; - ConstString IOHandlerGetControlSequence(char ch) override; + llvm::StringRef IOHandlerGetControlSequence(char ch) override; const char *IOHandlerGetCommandPrefix() override; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -652,10 +652,11 @@ void IOHandlerInputComplete(IOHandler &io_handler, std::string &line) override; - ConstString IOHandlerGetControlSequence(char ch) override { + llvm::StringRef IOHandlerGetControlSequence(char ch) override { + static constexpr llvm::StringLiteral control_sequence("quit\n"); if (ch == 'd') - return ConstString("quit\n"); - return ConstString(); + return control_sequence; + return {}; } void GetProcessOutput(); diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -155,11 +155,12 @@ const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) { LLDB_INSTRUMENT_VA(this, ch); - return (IsValid() - ? m_opaque_ptr->GetDebugger() - .GetTopIOHandlerControlSequence(ch) - .GetCString() - : nullptr); + if (!IsValid()) + return nullptr; + + return ConstString( + m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence(ch)) + .GetCString(); } lldb::ReturnStatus diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1127,7 +1127,7 @@ } } -ConstString Debugger::GetTopIOHandlerControlSequence(char ch) { +llvm::StringRef Debugger::GetTopIOHandlerControlSequence(char ch) { return m_io_handler_stack.GetTopIOHandlerControlSequence(ch); } diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -117,10 +117,11 @@ return (m_enable_auto_indent ? GetAutoIndentCharacters() : nullptr); } -ConstString REPL::IOHandlerGetControlSequence(char ch) { +llvm::StringRef REPL::IOHandlerGetControlSequence(char ch) { + static constexpr llvm::StringLiteral control_sequence(":quit\n"); if (ch == 'd') - return ConstString(":quit\n"); - return ConstString(); + return control_sequence; + return {}; } const char *REPL::IOHandlerGetCommandPrefix() { return ":"; } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -434,10 +434,11 @@ ~IOHandlerPythonInterpreter() override = default; - ConstString GetControlSequence(char ch) override { + llvm::StringRef GetControlSequence(char ch) override { + static constexpr llvm::StringLiteral control_sequence("quit()\n"); if (ch == 'd') - return ConstString("quit()\n"); - return ConstString(); + return control_sequence; + return {}; } void Run() override {