Various fixes mostly relating to the User Settings stuff:

- Added new utility function to Arg, GetQuotedCommandString, which re-assembles
the args into a string, replacing quotes that were originally there.

- Modified user settings stuff to always show individual elements when printing out
arrays and dictionaries.

- Added more extensive help to 'settings set', explaining more about dictionaries
and arrays (including current dictionary syntax).

- Fixed bug in user settings  where quotes were being stripped and lost, so that
sometimes array or dictionary elements that ought to have been a single element
were being split up.

llvm-svn: 121438
This commit is contained in:
Caroline Tice
2010-12-10 00:26:54 +00:00
parent 957373fc84
commit 2d5289d621
4 changed files with 79 additions and 13 deletions

View File

@@ -122,6 +122,9 @@ public:
bool
GetCommandString (std::string &command);
bool
GetQuotedCommandString (std::string &command);
//------------------------------------------------------------------
/// Gets the number of arguments left in this command object.
///

View File

@@ -90,6 +90,29 @@ CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpre
// Push the data for the first argument into the m_arguments vector.
m_arguments.push_back (arg1);
m_arguments.push_back (arg2);
SetHelpLong (
"When setting a dictionary or array variable, you can set multiple entries \n\
at once by giving the values to the set command. For example: \n\
\n\
(lldb) settings set target.process.run-args value1 value2 value3 \n\
(lldb) settings set target.process.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\
\n\
(lldb) settings show target.process.run-args \n\
[0]: 'value1' \n\
[1]: 'value2' \n\
[3]: 'value3' \n\
(lldb) settings show target.process.env-vars \n\
'MYPATH=~/.:/usr/bin'\n\
'SOME_ENV_VAR=12345' \n\
\n\
Note the special syntax for setting a dictionary element: [\"<key>\"]=<value> \n\
\n\
Warning: The 'set' command re-sets the entire array or dictionary. If you \n\
just want to add, remove or update individual values (or add something to \n\
the end), use one of the other settings sub-commands: append, replace, \n\
insert-before or insert-after.\n");
}
CommandObjectSettingsSet::~CommandObjectSettingsSet()
@@ -126,7 +149,7 @@ CommandObjectSettingsSet::Execute (Args& command, CommandReturnObject &result)
const char *var_value;
std::string value_string;
command.GetCommandString (value_string);
command.GetQuotedCommandString (value_string);
var_value = value_string.c_str();
if (!m_options.m_reset
@@ -342,14 +365,17 @@ CommandObjectSettingsShow::Execute (Args& command,
if (value.GetSize() == 0)
result.AppendMessageWithFormat ("%s%s = ''\n", variable_name, type_name);
else if (value.GetSize() == 1)
else if ((var_type != lldb::eSetVarTypeArray) && (var_type != lldb::eSetVarTypeDictionary))
result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0));
else
{
result.AppendMessageWithFormat ("%s%s:\n", variable_name, type_name);
for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
{
result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
if (var_type == lldb::eSetVarTypeArray)
result.AppendMessageWithFormat (" [%d]: '%s'\n", i, value.GetStringAtIndex (i));
else if (var_type == lldb::eSetVarTypeDictionary)
result.AppendMessageWithFormat (" '%s'\n", value.GetStringAtIndex (i));
}
}
result.SetStatus (eReturnStatusSuccessFinishNoResult);
@@ -727,7 +753,7 @@ CommandObjectSettingsReplace::Execute ( Args& command,
const char *var_value;
std::string value_string;
command.GetCommandString (value_string);
command.GetQuotedCommandString (value_string);
var_value = value_string.c_str();
if ((var_value == NULL) || (var_value[0] == '\0'))
@@ -872,7 +898,7 @@ CommandObjectSettingsInsertBefore::Execute ( Args&
const char *var_value;
std::string value_string;
command.GetCommandString (value_string);
command.GetQuotedCommandString (value_string);
var_value = value_string.c_str();
if ((var_value == NULL) || (var_value[0] == '\0'))
@@ -1019,7 +1045,7 @@ CommandObjectSettingsInsertAfter::Execute ( Args& co
const char *var_value;
std::string value_string;
command.GetCommandString (value_string);
command.GetQuotedCommandString (value_string);
var_value = value_string.c_str();
if ((var_value == NULL) || (var_value[0] == '\0'))
@@ -1144,7 +1170,7 @@ CommandObjectSettingsAppend::Execute (Args& command,
const char *var_value;
std::string value_string;
command.GetCommandString (value_string);
command.GetQuotedCommandString (value_string);
var_value = value_string.c_str();
if ((var_value == NULL) || (var_value[0] == '\0'))

View File

@@ -780,18 +780,31 @@ UserSettingsController::GetAllDefaultSettingValues (StreamString &result_stream)
m_default_settings->GetInstanceSettingsValue (entry, var_name, tmp_value, NULL);
StreamString value_string;
bool multi_value = false;
if (tmp_value.GetSize() == 1)
value_string.Printf ("%s", tmp_value.GetStringAtIndex (0));
else
{
for (int j = 0; j < tmp_value.GetSize(); ++j)
value_string.Printf ("%s ", tmp_value.GetStringAtIndex (j));
{
if (entry.var_type == lldb::eSetVarTypeArray)
value_string.Printf ("\n [%d]: '%s'", j, tmp_value.GetStringAtIndex (j));
else if (entry.var_type == lldb::eSetVarTypeDictionary)
value_string.Printf ("\n '%s'", tmp_value.GetStringAtIndex (j));
}
multi_value = true;
}
if (! parent_prefix.empty())
result_stream.Printf ("%s.%s (%s) = '%s'\n", prefix, var_name.AsCString(),
UserSettingsController::GetTypeString (entry.var_type), value_string.GetData());
{
if (multi_value)
result_stream.Printf ("%s.%s (%s):%s\n", prefix, var_name.AsCString(),
UserSettingsController::GetTypeString (entry.var_type), value_string.GetData());
else
result_stream.Printf ("%s.%s (%s) = '%s'\n", prefix, var_name.AsCString(),
UserSettingsController::GetTypeString (entry.var_type), value_string.GetData());
}
}
}
@@ -1366,10 +1379,12 @@ UserSettingsController::GetAllVariableValues (CommandInterpreter &interpreter,
value.GetStringAtIndex (0));
else
{
description.Printf ("%s (%s) = '", full_var_name.GetData(), GetTypeString (entry.var_type));
description.Printf ("%s (%s):\n", full_var_name.GetData(), GetTypeString (entry.var_type));
for (int j = 0; j < value.GetSize(); ++j)
description.Printf ("%s ", value.GetStringAtIndex (j));
description.Printf ("'");
if (entry.var_type == lldb::eSetVarTypeArray)
description.Printf (" [%d]: '%s'\n", j, value.GetStringAtIndex (j));
else if (entry.var_type == lldb::eSetVarTypeDictionary)
description.Printf (" '%s'\n", value.GetStringAtIndex (j));
}
result_stream.Printf ("%s\n", description.GetData());

View File

@@ -93,6 +93,28 @@ Args::GetCommandString (std::string &command)
return argc > 0;
}
bool
Args::GetQuotedCommandString (std::string &command)
{
command.clear ();
int argc = GetArgumentCount ();
for (int i = 0; i < argc; ++i)
{
if (i > 0)
command += ' ';
char quote_char = m_args_quote_char[i];
if (quote_char != '\0')
{
command += quote_char;
command += m_argv[i];
command += quote_char;
}
else
command += m_argv[i];
}
return argc > 0;
}
void
Args::SetCommandString (const char *command, size_t len)
{