2011-04-28 06:04:39 +08:00
|
|
|
//===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-05-14 04:21:08 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
|
|
|
#include "lldb/DataFormatters/ValueObjectPrinter.h"
|
2015-01-16 04:08:35 +08:00
|
|
|
#include "lldb/Host/StringConvert.h"
|
2011-05-04 11:43:18 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2011-09-10 08:48:33 +08:00
|
|
|
#include "lldb/Utility/Utils.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
|
|
|
|
|
|
|
|
OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
|
|
|
|
|
|
|
|
static OptionDefinition g_option_table[] = {
|
|
|
|
{LLDB_OPT_SET_1, false, "dynamic-type", 'd',
|
|
|
|
OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0,
|
|
|
|
eArgTypeNone, "Show the object as its full dynamic type, not its static "
|
|
|
|
"type, if available."},
|
|
|
|
{LLDB_OPT_SET_1, false, "synthetic-type", 'S',
|
|
|
|
OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
|
|
|
|
"Show the object obeying its synthetic provider, if available."},
|
|
|
|
{LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,
|
|
|
|
nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when "
|
|
|
|
"dumping aggregate types (default is "
|
|
|
|
"infinity)."},
|
|
|
|
{LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,
|
|
|
|
nullptr, 0, eArgTypeNone, "Display results in a flat format that uses "
|
|
|
|
"expression paths for each variable or member."},
|
|
|
|
{LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,
|
|
|
|
nullptr, 0, eArgTypeNone, "Show variable location information."},
|
|
|
|
{LLDB_OPT_SET_1, false, "object-description", 'O',
|
|
|
|
OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
|
|
|
|
"Print as an Objective-C object."},
|
|
|
|
{LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,
|
|
|
|
nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be "
|
|
|
|
"traversed when dumping values "
|
|
|
|
"(default is zero)."},
|
|
|
|
{LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,
|
|
|
|
nullptr, nullptr, 0, eArgTypeNone,
|
|
|
|
"Show variable types when dumping values."},
|
|
|
|
{LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',
|
|
|
|
OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount,
|
|
|
|
"Set the depth at which omitting summary information stops (default is "
|
|
|
|
"1)."},
|
|
|
|
{LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,
|
|
|
|
nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."},
|
|
|
|
{LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,
|
|
|
|
nullptr, nullptr, 0, eArgTypeNone,
|
|
|
|
"Ignore the upper bound on the number of children to show."},
|
|
|
|
{LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,
|
|
|
|
nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."},
|
|
|
|
{LLDB_OPT_SET_1, false, "element-count", 'Z',
|
|
|
|
OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,
|
|
|
|
"Treat the result of the expression as if its type is an array of this "
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
"many values."}};
|
2011-04-28 06:04:39 +08:00
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition>
|
|
|
|
OptionGroupValueObjectDisplay::GetDefinitions() {
|
2016-09-07 04:57:50 +08:00
|
|
|
return g_option_table;
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Error OptionGroupValueObjectDisplay::SetOptionValue(
|
|
|
|
uint32_t option_idx, const char *option_arg,
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
Error error;
|
|
|
|
const int short_option = g_option_table[option_idx].short_option;
|
|
|
|
bool success = false;
|
|
|
|
|
2016-09-20 01:54:06 +08:00
|
|
|
auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
switch (short_option) {
|
|
|
|
case 'd': {
|
|
|
|
int32_t result;
|
|
|
|
result =
|
|
|
|
Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error);
|
|
|
|
if (error.Success())
|
|
|
|
use_dynamic = (lldb::DynamicValueType)result;
|
|
|
|
} break;
|
|
|
|
case 'T':
|
|
|
|
show_types = true;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
show_location = true;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
flat_output = true;
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
use_objc = true;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
be_raw = true;
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
ignore_cap = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
max_depth = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success);
|
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
elem_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success);
|
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("invalid element count '%s'", option_arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
ptr_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success);
|
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Y':
|
|
|
|
if (option_arg) {
|
|
|
|
no_summary_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success);
|
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("invalid pointer depth '%s'",
|
|
|
|
option_arg);
|
|
|
|
} else
|
|
|
|
no_summary_depth = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
2016-09-20 01:54:06 +08:00
|
|
|
use_synth = Args::StringToBoolean(option_strref, true, &success);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
2016-09-20 01:54:06 +08:00
|
|
|
run_validator = Args::StringToBoolean(option_strref, true, &success);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("invalid validate '%s'", option_arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void OptionGroupValueObjectDisplay::OptionParsingStarting(
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
// If these defaults change, be sure to modify AnyOptionWasSet().
|
|
|
|
show_types = false;
|
|
|
|
no_summary_depth = 0;
|
|
|
|
show_location = false;
|
|
|
|
flat_output = false;
|
|
|
|
use_objc = false;
|
|
|
|
max_depth = UINT32_MAX;
|
|
|
|
ptr_depth = 0;
|
|
|
|
elem_count = 0;
|
|
|
|
use_synth = true;
|
|
|
|
be_raw = false;
|
|
|
|
ignore_cap = false;
|
|
|
|
run_validator = false;
|
|
|
|
|
|
|
|
TargetSP target_sp =
|
|
|
|
execution_context ? execution_context->GetTargetSP() : TargetSP();
|
|
|
|
if (target_sp)
|
|
|
|
use_dynamic = target_sp->GetPreferDynamicValue();
|
|
|
|
else {
|
|
|
|
// If we don't have any targets, then dynamic values won't do us much good.
|
|
|
|
use_dynamic = lldb::eNoDynamicValues;
|
|
|
|
}
|
2011-05-14 04:21:08 +08:00
|
|
|
}
|
2013-03-27 02:04:53 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
|
|
|
|
LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
|
|
|
|
lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
|
|
|
|
DumpValueObjectOptions options;
|
|
|
|
options.SetMaximumPointerDepth(
|
|
|
|
{DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
|
|
|
|
if (use_objc)
|
|
|
|
options.SetShowSummary(false);
|
|
|
|
else
|
|
|
|
options.SetOmitSummaryDepth(no_summary_depth);
|
|
|
|
options.SetMaximumDepth(max_depth)
|
|
|
|
.SetShowTypes(show_types)
|
|
|
|
.SetShowLocation(show_location)
|
|
|
|
.SetUseObjectiveC(use_objc)
|
|
|
|
.SetUseDynamicType(use_dynamic)
|
|
|
|
.SetUseSyntheticValue(use_synth)
|
|
|
|
.SetFlatOutput(flat_output)
|
|
|
|
.SetIgnoreCap(ignore_cap)
|
|
|
|
.SetFormat(format)
|
|
|
|
.SetSummary(summary_sp);
|
|
|
|
|
|
|
|
if (lang_descr_verbosity ==
|
|
|
|
eLanguageRuntimeDescriptionDisplayVerbosityCompact)
|
|
|
|
options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
|
|
|
|
use_objc);
|
|
|
|
|
|
|
|
if (be_raw)
|
|
|
|
options.SetRawDisplay();
|
|
|
|
|
|
|
|
options.SetRunValidator(run_validator);
|
|
|
|
|
|
|
|
options.SetElementCount(elem_count);
|
|
|
|
|
|
|
|
return options;
|
2013-03-27 02:04:53 +08:00
|
|
|
}
|