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,9 @@ } bool SetPrompt(const char *) = delete; - virtual ConstString GetControlSequence(char ch) { return ConstString(); } + virtual llvm::StringRef GetControlSequence(char ch) { + return llvm::StringRef(); + } virtual const char *GetCommandPrefix() { return nullptr; } @@ -271,8 +272,8 @@ return true; } - virtual ConstString IOHandlerGetControlSequence(char ch) { - return ConstString(); + virtual llvm::StringRef IOHandlerGetControlSequence(char ch) { + return llvm::StringRef(); } virtual const char *IOHandlerGetCommandPrefix() { return nullptr; } @@ -298,21 +299,24 @@ IOHandlerDelegateMultiline(const char *end_line, Completion completion = Completion::None) : IOHandlerDelegate(completion), - m_end_line((end_line && end_line[0]) ? end_line : "") {} + m_end_line((end_line && end_line[0]) ? std::string(end_line) + "\n" + : "\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 llvm::StringRef(); } 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 +377,7 @@ void TerminalSizeChanged() override; - ConstString GetControlSequence(char ch) override { + llvm::StringRef GetControlSequence(char ch) override { return m_delegate.IOHandlerGetControlSequence(ch); } @@ -522,8 +526,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 llvm::StringRef(); } 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 @@ -1126,7 +1126,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 llvm::StringRef(); } 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 llvm::StringRef(); } void Run() override {