Added the ability to specify dumping options (show types, show location,
depth control, pointer depth, and more) when dumping memory and viewing as
a type.
llvm-svn: 130436
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index e7dd536..95183a0 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -876,7 +876,8 @@
Args::StringToFormat
(
const char *s,
- lldb::Format &format
+ lldb::Format &format,
+ uint32_t *byte_size_ptr
)
{
format = eFormatInvalid;
@@ -884,29 +885,51 @@
if (s && s[0])
{
- switch (s[0])
+ if (byte_size_ptr)
{
- case 'y': format = eFormatBytes; break;
- case 'Y': format = eFormatBytesWithASCII; break;
- case 'b': format = eFormatBinary; break;
- case 'B': format = eFormatBoolean; break;
- case 'c': format = eFormatChar; break;
- case 'C': format = eFormatCharPrintable; break;
- case 'o': format = eFormatOctal; break;
- case 'O': format = eFormatOSType; break;
- case 'i':
- case 'd': format = eFormatDecimal; break;
- case 'I': format = eFormatComplexInteger; break;
- case 'u': format = eFormatUnsigned; break;
- case 'x': format = eFormatHex; break;
- case 'X': format = eFormatComplex; break;
- case 'f':
- case 'e':
- case 'g': format = eFormatFloat; break;
- case 'p': format = eFormatPointer; break;
- case 's': format = eFormatCString; break;
- default:
- error.SetErrorStringWithFormat("Invalid format character '%c'. Valid values are:\n"
+ if (isdigit (s[0]))
+ {
+ char *format_char = NULL;
+ unsigned long byte_size = ::strtoul (s, &format_char, 0);
+ if (byte_size != ULONG_MAX)
+ *byte_size_ptr = byte_size;
+ s = format_char;
+ }
+ else
+ *byte_size_ptr = 0;
+ }
+
+ bool success = s[1] == '\0';
+ if (success)
+ {
+ switch (s[0])
+ {
+ case 'y': format = eFormatBytes; break;
+ case 'Y': format = eFormatBytesWithASCII; break;
+ case 'b': format = eFormatBinary; break;
+ case 'B': format = eFormatBoolean; break;
+ case 'c': format = eFormatChar; break;
+ case 'C': format = eFormatCharPrintable; break;
+ case 'o': format = eFormatOctal; break;
+ case 'O': format = eFormatOSType; break;
+ case 'i':
+ case 'd': format = eFormatDecimal; break;
+ case 'I': format = eFormatComplexInteger; break;
+ case 'u': format = eFormatUnsigned; break;
+ case 'x': format = eFormatHex; break;
+ case 'X': format = eFormatComplex; break;
+ case 'f':
+ case 'e':
+ case 'g': format = eFormatFloat; break;
+ case 'p': format = eFormatPointer; break;
+ case 's': format = eFormatCString; break;
+ default:
+ success = false;
+ break;
+ }
+ }
+ if (!success)
+ error.SetErrorStringWithFormat ("Invalid format specification '%s'. Valid values are:\n"
" b - binary\n"
" B - boolean\n"
" c - char\n"
@@ -925,9 +948,10 @@
" x - hex\n"
" X - complex float\n"
" y - bytes\n"
- " Y - bytes with ASCII\n", s[0]);
- break;
- }
+ " Y - bytes with ASCII\n%s",
+ s,
+ byte_size_ptr ? "An optional byte size can precede the format character.\n" : "");
+
if (error.Fail())
return error;
diff --git a/lldb/source/Interpreter/NamedOptionValue.cpp b/lldb/source/Interpreter/NamedOptionValue.cpp
index 04306e2..6ccc8d0 100644
--- a/lldb/source/Interpreter/NamedOptionValue.cpp
+++ b/lldb/source/Interpreter/NamedOptionValue.cpp
@@ -318,11 +318,14 @@
OptionValueFormat::SetValueFromCString (const char *value_cstr)
{
Format new_format;
- Error error (Args::StringToFormat(value_cstr, new_format));
+ uint32_t new_byte_size = UINT32_MAX;
+ Error error (Args::StringToFormat(value_cstr, new_format, m_byte_size_prefix_ok ? &new_byte_size : NULL));
if (error.Success())
{
m_value_was_set = true;
m_current_value = new_format;
+ if (new_byte_size != UINT32_MAX)
+ m_current_byte_size = new_byte_size;
}
return error;
}
diff --git a/lldb/source/Interpreter/OptionGroupFormat.cpp b/lldb/source/Interpreter/OptionGroupFormat.cpp
index 0bc29ee..213255e 100644
--- a/lldb/source/Interpreter/OptionGroupFormat.cpp
+++ b/lldb/source/Interpreter/OptionGroupFormat.cpp
@@ -17,8 +17,14 @@
using namespace lldb;
using namespace lldb_private;
-OptionGroupFormat::OptionGroupFormat(lldb::Format default_format) :
- m_format (default_format, default_format)
+OptionGroupFormat::OptionGroupFormat(lldb::Format default_format,
+ uint32_t default_byte_size,
+ bool byte_size_prefix_ok) :
+ m_format (default_format,
+ default_format,
+ default_byte_size,
+ default_byte_size,
+ byte_size_prefix_ok)
{
}
@@ -47,8 +53,8 @@
Error
OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter,
- uint32_t option_idx,
- const char *option_arg)
+ uint32_t option_idx,
+ const char *option_arg)
{
Error error;
char short_option = (char) g_option_table[option_idx].short_option;
diff --git a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
index af52a7c..dac44b1 100644
--- a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
+++ b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
@@ -25,17 +25,16 @@
{
}
-OptionDefinition
+static OptionDefinition
g_option_table[] =
{
- { LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
- { LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat,"Specify the format that the variable output should use."},
+ { LLDB_OPT_SET_1, false, "depth", 'D', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
{ LLDB_OPT_SET_1, false, "flat", 'F', no_argument, NULL, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."},
{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."},
- { LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, eArgTypeNone, "Print as an Objective-C object."},
- { LLDB_OPT_SET_1, false, "ptr-depth", 'p', required_argument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."},
- { LLDB_OPT_SET_1, false, "show-types", 't', no_argument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."},
- { LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
+ { LLDB_OPT_SET_1, false, "objc", 'O', no_argument, NULL, 0, eArgTypeNone, "Print as an Objective-C object."},
+ { LLDB_OPT_SET_1, false, "ptr-depth", 'P', required_argument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."},
+ { LLDB_OPT_SET_1, false, "show-types", 'T', no_argument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."},
+ { LLDB_OPT_SET_1, false, "no-summary", 'Y', no_argument, NULL, 0, eArgTypeNone, "Omit summary information."},
{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
};
@@ -65,19 +64,18 @@
switch (short_option)
{
- case 't': show_types = true; break;
- case 'y': show_summary = false; break;
+ case 'T': show_types = true; break;
+ case 'Y': show_summary = false; break;
case 'L': show_location= true; break;
case 'F': flat_output = true; break;
- case 'f': error = Args::StringToFormat(option_arg, format); break;
- case 'o': use_objc = true; break;
- case 'd':
+ case 'O': use_objc = true; break;
+ case 'D':
max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
if (!success)
error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
break;
- case 'p':
+ case 'P':
ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
if (!success)
error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
@@ -101,6 +99,5 @@
use_objc = false;
max_depth = UINT32_MAX;
ptr_depth = 0;
- format = eFormatDefault;
}