<rdar://problem/11578397> Adding a new --summary-string option for the frame variable command which allows the user to provide a summary string with which he wants to display the variables without having to make a named summary first

llvm-svn: 161623
This commit is contained in:
Enrico Granata 2012-08-09 22:02:51 +00:00
parent d82f647dee
commit 17b1174911
5 changed files with 42 additions and 19 deletions

View File

@ -522,11 +522,23 @@ namespace lldb_private {
return m_current_value.c_str();
}
bool
IsCurrentValueEmpty () const
{
return m_current_value.empty();
}
const char *
GetDefaultValue() const
{
return m_default_value.c_str();
}
bool
IsDefaultValueEmpty () const
{
return m_default_value.empty();
}
void
SetCurrentValue (const char *value)

View File

@ -14,6 +14,7 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Interpreter/NamedOptionValue.h"
#include "lldb/Interpreter/Options.h"
namespace lldb_private {
@ -52,7 +53,8 @@ namespace lldb_private {
use_regex:1,
show_scope:1,
show_decl:1;
std::string summary;
OptionValueString summary; // the name of a named summary
OptionValueString summary_string; // a summary string
private:
DISALLOW_COPY_AND_ASSIGN(OptionGroupVariable);

View File

@ -394,8 +394,10 @@ protected:
size_t idx;
TypeSummaryImplSP summary_format_sp;
if (!m_option_variable.summary.empty())
DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
if (!m_option_variable.summary.IsCurrentValueEmpty())
DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp);
else if (!m_option_variable.summary_string.IsCurrentValueEmpty())
summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue()));
ValueObject::DumpValueObjectOptions options;

View File

@ -24,13 +24,14 @@ using namespace lldb_private;
static OptionDefinition
g_option_table[] =
{
{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
{ LLDB_OPT_SET_1, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
{ LLDB_OPT_SET_1, false, "show-declaration",'c', no_argument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."},
{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."},
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."},
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."},
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration",'c', no_argument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."},
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."},
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."},
{ LLDB_OPT_SET_1, false, "summary", 'y', required_argument, NULL, 0, eArgTypeName, "Specify the summary that the variable output should use."},
{ LLDB_OPT_SET_2, false, "summary-string", 'z', required_argument, NULL, 0, eArgTypeName, "Specify a summary string to use to format the variable output."},
};
@ -64,7 +65,10 @@ OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter,
show_scope = true;
break;
case 'y':
summary = std::string(option_arg);
summary.SetCurrentValue(option_arg);
break;
case 'z':
summary_string.SetCurrentValue(option_arg);
break;
default:
error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
@ -83,7 +87,8 @@ OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter)
show_decl = false;
use_regex = false;
show_scope = false;
summary = "";
summary.Clear();
summary_string.Clear();
}
#define NUM_FRAME_OPTS 3

View File

@ -119,9 +119,7 @@ class AdvDataFormatterTestCase(TestBase):
substrs = ['low bits are',
'tgt is 6'])
self.runCmd("type summary add --summary-string \"${*var[0-1]}\" -x \"int \[[0-9]\]\"")
self.expect("frame variable int_array",
self.expect("frame variable int_array --summary-string \"${*var[0-1]}\"",
substrs = ['3'])
self.runCmd("type summary clear")
@ -162,21 +160,25 @@ class AdvDataFormatterTestCase(TestBase):
self.runCmd("type summary clear")
self.runCmd("type summary add --summary-string \"${var[0][0-2]%hex}\" -x \"int \[[0-9]\]\"")
self.expect("frame variable int_array",
self.expect("frame variable int_array --summary-string \"${var[0][0-2]%hex}\"",
substrs = ['0x',
'7'])
self.runCmd("type summary clear")
self.runCmd("type summary add --summary-string \"${*var[].x[0-3]%hex} is a bitfield on a set of integers\" -x \"SimpleWithPointers \[[0-9]\]\"")
self.runCmd("type summary add --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\" Couple")
self.expect("frame variable couple",
self.expect("frame variable couple --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\"",
substrs = ['1 are low bits of integer 9.',
'If I pretend it is an array I get [9,'])
# if the summary has an error, we still display the value
self.expect("frame variable couple --summary-string \"${*var.sp.foo[0-2]\"",
substrs = ['(Couple) couple = {','sp = {','z =','"X"'])
self.runCmd("type summary add --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\" Couple")
self.expect("frame variable sparray",
substrs = ['[0x0000000f,0x0000000c,0x00000009]'])