From 97f5b66d2b2fc6cb9b1f0229b281cf8d40976d80 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 20 Dec 2019 15:11:49 +0100 Subject: [PATCH 1/3] [lldb/pexpect] Force-set the TERM environment variable In some environments (typically, buildbots), this variable may not be available. This can cause tests to behave differently. Explicitly set the variable to "vt100" to ensure consistent test behavior. It should not matter that we do not inherit the process TERM variable, as the child process runs in a new virtual terminal anyway. --- lldb/packages/Python/lldbsuite/test/lldbpexpect.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py index 402148a9534fd..29a04ea947d2d 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py +++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py @@ -2,6 +2,7 @@ from __future__ import absolute_import # System modules +import os import sys # Third-party modules @@ -30,6 +31,7 @@ def expect_prompt(self): def launch(self, executable=None, extra_args=None, timeout=30, dimensions=None): logfile = getattr(sys.stdout, 'buffer', sys.stdout) if self.TraceOn() else None + args = ['--no-lldbinit', '--no-use-colors'] for cmd in self.setUpCommands(): args += ['-O', cmd] @@ -37,9 +39,13 @@ def launch(self, executable=None, extra_args=None, timeout=30, dimensions=None): args += ['--file', executable] if extra_args is not None: args.extend(extra_args) + + env = dict(os.environ) + env["TERM"]="vt100" + self.child = pexpect.spawn( lldbtest_config.lldbExec, args=args, logfile=logfile, - timeout=timeout, dimensions=dimensions) + timeout=timeout, dimensions=dimensions, env=env) self.expect_prompt() for cmd in self.setUpCommands(): self.child.expect_exact(cmd) From 88be0a0ac20536e4a150e7feabb9c1e11017605c Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 27 Jan 2020 21:19:33 +0100 Subject: [PATCH 2/3] [lldb] Fix that CompletionRequestGetRawLineUntilCursor returns the wrong result By using m_cursor_index and not m_raw_cursor_pos in this function we return the characters until the argument index (not the character index). This means that for "foo" (cursor at the end of the string) this returns "" instead of "foo" (as the argument index is 0 for the first argument and not 4 which is the character index at the end). This lead to a crash in the REPL completion where it would cause that we would complete the string "ABC" to " " as we think the line is actually empty and we want to provide the indentation string. Note that the function has already been deleted upstream so this bug doesn't exist there. --- lldb/include/lldb/Utility/CompletionRequest.h | 2 +- lldb/unittests/Utility/CompletionRequestTest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Utility/CompletionRequest.h b/lldb/include/lldb/Utility/CompletionRequest.h index 28ac78a875659..ca045139946e0 100644 --- a/lldb/include/lldb/Utility/CompletionRequest.h +++ b/lldb/include/lldb/Utility/CompletionRequest.h @@ -104,7 +104,7 @@ class CompletionRequest { llvm::StringRef GetRawLine() const { return m_command; } llvm::StringRef GetRawLineUntilCursor() const { - return m_command.substr(0, m_cursor_index); + return m_command.substr(0, m_raw_cursor_pos); } unsigned GetRawCursorPos() const { return m_raw_cursor_pos; } diff --git a/lldb/unittests/Utility/CompletionRequestTest.cpp b/lldb/unittests/Utility/CompletionRequestTest.cpp index 54bd342992194..afeba875f40f4 100644 --- a/lldb/unittests/Utility/CompletionRequestTest.cpp +++ b/lldb/unittests/Utility/CompletionRequestTest.cpp @@ -26,6 +26,7 @@ TEST(CompletionRequest, Constructor) { EXPECT_EQ(request.GetRawCursorPos(), cursor_pos); EXPECT_EQ(request.GetCursorIndex(), arg_index); EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos); + EXPECT_EQ(request.GetRawLineUntilCursor(), "a b"); EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u); EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b"); From 43978f8fccb1f2d04a129be9b40a25db741beaa2 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 27 Jan 2020 21:24:39 +0100 Subject: [PATCH 3/3] [lldb] Use CompletionRequest in REPL::CompleteCode and remove translation code to old API Any REPL client should just move to CompletionRequest instead of relying on the translation code from the old API, so let's remove that translation code. --- lldb/include/lldb/Expression/REPL.h | 4 ++-- lldb/source/Expression/REPL.cpp | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lldb/include/lldb/Expression/REPL.h b/lldb/include/lldb/Expression/REPL.h index d34a792f58f1c..ba5655a541130 100644 --- a/lldb/include/lldb/Expression/REPL.h +++ b/lldb/include/lldb/Expression/REPL.h @@ -130,8 +130,8 @@ class REPL : public IOHandlerDelegate { lldb::ValueObjectSP &valobj_sp, ExpressionVariable *var = nullptr) = 0; - virtual int CompleteCode(const std::string ¤t_code, - StringList &matches) = 0; + virtual void CompleteCode(const std::string ¤t_code, + CompletionRequest &request) = 0; OptionGroupFormat m_format_options = OptionGroupFormat(lldb::eFormatDefault); OptionGroupValueObjectDisplay m_varobj_options; diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index 01350f3dd74d1..033ad463f10bd 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -481,14 +481,7 @@ void REPL::IOHandlerComplete(IOHandler &io_handler, current_code.append("\n"); current_code += request.GetRawLineUntilCursor(); - StringList matches; - int result = CompleteCode(current_code, matches); - if (result == -2) { - assert(matches.GetSize() == 1); - request.AddCompletion(matches.GetStringAtIndex(0), "", - CompletionMode::RewriteLine); - } else - request.AddCompletions(matches); + CompleteCode(current_code, request); } bool QuitCommandOverrideCallback(void *baton, const char **argv) {