tberghammer created this revision.
tberghammer added reviewers: labath, clayborg.
tberghammer added a subscriber: lldb-commits.
Fix tab completion for command arguments containing spaces
If a command argument contains a space then it have to be escaped with
backslash signs so the argument parsing logic can parse it properly. This CL
fixes the tab completion code for the arguments to create completions with
correctly escaped strings.
http://reviews.llvm.org/D12531
Files:
source/Interpreter/Options.cpp
test/functionalities/completion/Makefile
test/functionalities/completion/TestCompletion.py
test/functionalities/completion/main.cpp
Index: test/functionalities/completion/main.cpp
===================================================================
--- /dev/null
+++ test/functionalities/completion/main.cpp
@@ -0,0 +1,14 @@
+class Foo
+{
+public:
+ int Bar(int x, int y)
+ {
+ return x + y;
+ }
+};
+
+int main()
+{
+ Foo f;
+ f.Bar(1, 2);
+}
Index: test/functionalities/completion/TestCompletion.py
===================================================================
--- test/functionalities/completion/TestCompletion.py
+++ test/functionalities/completion/TestCompletion.py
@@ -219,6 +219,23 @@
"""Test that 'target va' completes to 'target variable '."""
self.complete_from_to('target va', 'target variable ')
+ @skipUnlessDarwin
+ @dsym_test
+ def test_symbol_name_dsym(self):
+ self.buildDsym()
+ self.complete_from_to('''file a.out
+ breakpoint set -n Fo''',
+ 'breakpoint set -n Foo::Bar(int,\\ int)',
+ turn_off_re_match=True)
+
+ @dwarf_test
+ def test_symbol_name_dwarf(self):
+ self.buildDwarf()
+ self.complete_from_to('''file a.out
+ breakpoint set -n Fo''',
+ 'breakpoint set -n Foo::Bar(int,\\ int)',
+ turn_off_re_match=True)
+
def complete_from_to(self, str_input, patterns, turn_off_re_match=False):
"""Test that the completion mechanism completes str_input to patterns,
where patterns could be a pattern-string or a list of pattern-strings"""
Index: test/functionalities/completion/Makefile
===================================================================
--- /dev/null
+++ test/functionalities/completion/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
Index: source/Interpreter/Options.cpp
===================================================================
--- source/Interpreter/Options.cpp
+++ source/Interpreter/Options.cpp
@@ -975,15 +975,31 @@
}
}
- return CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
- completion_mask,
- input.GetArgumentAtIndex (opt_arg_pos),
- match_start_point,
- max_return_elements,
- filter_ap.get(),
- word_complete,
- matches);
-
+ bool ret = CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
+ completion_mask,
+ input.GetArgumentAtIndex (opt_arg_pos),
+ match_start_point,
+ max_return_elements,
+ filter_ap.get(),
+ word_complete,
+ matches);
+
+ // Escape spaces and backslashes in the matches list as the arguments shouldn't contain any of
+ // these characters without escaping.
+ for (size_t i = 0; i < matches.GetSize(); ++i)
+ {
+ std::string s;
+ s.reserve(matches[i].size());
+
+ for (char c : matches[i])
+ {
+ if (c == ' ' || c == '\\')
+ s.push_back('\\');
+ s.push_back(c);
+ }
+ matches[i] = s;
+ }
+ return ret;
}
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits