[Lldb-commits] [lldb] r148615 - in /lldb/trunk: source/Commands/CommandObjectSettings.cpp source/Commands/CommandObjectSettings.h test/functionalities/completion/TestCompletion.py test/settings/TestSettings.py
Johnny Chen
johnny.chen at apple.com
Fri Jan 20 17:45:18 PST 2012
Author: johnny
Date: Fri Jan 20 19:45:18 2012
New Revision: 148615
URL: http://llvm.org/viewvc/llvm-project?rev=148615&view=rev
Log:
Followup check in for http://llvm.org/viewvc/llvm-project?rev=148491&view=rev,
where we changed the CommandObjectSettingsSet object impl to require raw command string.
Do the same for CommandObjectSettingsReplace class and add two test cases; one for
the "settings replace" command and the other to ensure that completion for variable
name still works.
Modified:
lldb/trunk/source/Commands/CommandObjectSettings.cpp
lldb/trunk/source/Commands/CommandObjectSettings.h
lldb/trunk/test/functionalities/completion/TestCompletion.py
lldb/trunk/test/settings/TestSettings.py
Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=148615&r1=148614&r2=148615&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Fri Jan 20 19:45:18 2012
@@ -690,11 +690,12 @@
}
bool
-CommandObjectSettingsReplace::Execute (Args& command, CommandReturnObject &result)
+CommandObjectSettingsReplace::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result)
{
UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ());
- const int argc = command.GetArgumentCount ();
+ Args cmd_args(raw_command);
+ const int argc = cmd_args.GetArgumentCount ();
if (argc < 3)
{
@@ -703,7 +704,7 @@
return false;
}
- const char *var_name = command.GetArgumentAtIndex (0);
+ const char *var_name = cmd_args.GetArgumentAtIndex (0);
std::string var_name_string;
if ((var_name == NULL) || (var_name[0] == '\0'))
{
@@ -713,9 +714,9 @@
}
var_name_string = var_name;
- command.Shift();
+ cmd_args.Shift();
- const char *index_value = command.GetArgumentAtIndex (0);
+ const char *index_value = cmd_args.GetArgumentAtIndex (0);
std::string index_value_string;
if ((index_value == NULL) || (index_value[0] == '\0'))
{
@@ -725,15 +726,15 @@
}
index_value_string = index_value;
- command.Shift();
-
- const char *var_value;
- std::string value_string;
+ cmd_args.Shift();
- command.GetQuotedCommandString (value_string);
- var_value = value_string.c_str();
+ // Split the raw command into var_name, index_value, and value triple.
+ llvm::StringRef raw_str(raw_command);
+ llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second;
+ StripLeadingSpaces(var_value_str);
+ std::string var_value_string = var_value_str.str();
- if ((var_value == NULL) || (var_value[0] == '\0'))
+ if (var_value_string.empty())
{
result.AppendError ("'settings replace' command requires a valid variable value; no value supplied");
result.SetStatus (eReturnStatusFailed);
@@ -741,7 +742,7 @@
else
{
Error err = usc_sp->SetVariable (var_name_string.c_str(),
- var_value,
+ var_value_string.c_str(),
eVarSetOperationReplace,
true,
m_interpreter.GetDebugger().GetInstanceName().AsCString(),
Modified: lldb/trunk/source/Commands/CommandObjectSettings.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.h?rev=148615&r1=148614&r2=148615&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.h (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.h Fri Jan 20 19:45:18 2012
@@ -212,7 +212,19 @@
virtual bool
Execute (Args& command,
- CommandReturnObject &result);
+ CommandReturnObject &result)
+ { return false; }
+
+ virtual bool
+ WantsRawCommandString() { return true; }
+
+ // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
+ virtual bool
+ WantsCompletion() { return true; }
+
+ virtual bool
+ ExecuteRawCommandString (const char *raw_command,
+ CommandReturnObject &result);
virtual int
HandleArgumentCompletion (Args &input,
Modified: lldb/trunk/test/functionalities/completion/TestCompletion.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/completion/TestCompletion.py?rev=148615&r1=148614&r2=148615&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/completion/TestCompletion.py (original)
+++ lldb/trunk/test/functionalities/completion/TestCompletion.py Fri Jan 20 19:45:18 2012
@@ -18,6 +18,10 @@
system(["/bin/sh", "-c", "rm -f child_send.txt"])
system(["/bin/sh", "-c", "rm -f child_read.txt"])
+ def test_settings_replace_target_ru(self):
+ """Test that 'settings replace target.ru' completes to 'settings replace target.run-args'."""
+ self.complete_from_to('settings replace target.ru', 'settings replace target.run-args')
+
def test_settings_s(self):
"""Test that 'settings s' completes to ['Available completions:', 'set', 'show']."""
self.complete_from_to('settings s', ['Available completions:', 'set', 'show'])
Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=148615&r1=148614&r2=148615&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Fri Jan 20 19:45:18 2012
@@ -27,6 +27,23 @@
"environment variables",
"executable's environment"])
+ def test_replace_target_run_args(self):
+ """Test that 'replace target.run-args' works."""
+ # Set the run-args and then replace the index-0 element.
+ self.runCmd('settings set target.run-args a b c')
+ # And add hooks to restore the settings during tearDown().
+ self.addTearDownHook(
+ lambda: self.runCmd("settings set -r target.run-args"))
+
+ # Now replace the index-0 element with 'A', instead.
+ self.runCmd('settings replace target.run-args 0 A')
+ # Check it immediately!
+ self.expect('settings show target.run-args',
+ substrs = ['target.run-args (array) = ',
+ '[0]: "A"',
+ '[1]: "b"',
+ '[2]: "c"'])
+
def test_set_prompt(self):
"""Test that 'set prompt' actually changes the prompt."""
More information about the lldb-commits
mailing list