1 //===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
14 // Other libraries and framework includes
16 #include "lldb/DataFormatters/ValueObjectPrinter.h"
17 #include "lldb/Host/OptionParser.h"
18 #include "lldb/Interpreter/CommandInterpreter.h"
19 #include "lldb/Target/Target.h"
21 #include "llvm/ADT/ArrayRef.h"
24 using namespace lldb_private;
26 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
28 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
30 static OptionDefinition g_option_table[] = {
31 {LLDB_OPT_SET_1, false, "dynamic-type", 'd',
32 OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0,
33 eArgTypeNone, "Show the object as its full dynamic type, not its static "
34 "type, if available."},
35 {LLDB_OPT_SET_1, false, "synthetic-type", 'S',
36 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
37 "Show the object obeying its synthetic provider, if available."},
38 {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,
39 nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when "
40 "dumping aggregate types (default is "
42 {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,
43 nullptr, 0, eArgTypeNone, "Display results in a flat format that uses "
44 "expression paths for each variable or member."},
45 {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,
46 nullptr, 0, eArgTypeNone, "Show variable location information."},
47 {LLDB_OPT_SET_1, false, "object-description", 'O',
48 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
49 "Print as an Objective-C object."},
50 {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,
51 nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be "
52 "traversed when dumping values "
53 "(default is zero)."},
54 {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,
55 nullptr, nullptr, 0, eArgTypeNone,
56 "Show variable types when dumping values."},
57 {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',
58 OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount,
59 "Set the depth at which omitting summary information stops (default is "
61 {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,
62 nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."},
63 {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,
64 nullptr, nullptr, 0, eArgTypeNone,
65 "Ignore the upper bound on the number of children to show."},
66 {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,
67 nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."},
68 {LLDB_OPT_SET_1, false, "element-count", 'Z',
69 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,
70 "Treat the result of the expression as if its type is an array of this "
73 llvm::ArrayRef<OptionDefinition>
74 OptionGroupValueObjectDisplay::GetDefinitions() {
75 return llvm::makeArrayRef(g_option_table);
78 Status OptionGroupValueObjectDisplay::SetOptionValue(
79 uint32_t option_idx, llvm::StringRef option_arg,
80 ExecutionContext *execution_context) {
82 const int short_option = g_option_table[option_idx].short_option;
85 switch (short_option) {
89 Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error);
91 use_dynamic = (lldb::DynamicValueType)result;
113 if (option_arg.getAsInteger(0, max_depth)) {
114 max_depth = UINT32_MAX;
115 error.SetErrorStringWithFormat("invalid max depth '%s'",
116 option_arg.str().c_str());
121 if (option_arg.getAsInteger(0, elem_count)) {
122 elem_count = UINT32_MAX;
123 error.SetErrorStringWithFormat("invalid element count '%s'",
124 option_arg.str().c_str());
129 if (option_arg.getAsInteger(0, ptr_depth)) {
131 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
132 option_arg.str().c_str());
137 if (option_arg.empty())
138 no_summary_depth = 1;
139 else if (option_arg.getAsInteger(0, no_summary_depth)) {
140 no_summary_depth = 0;
141 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
142 option_arg.str().c_str());
147 use_synth = Args::StringToBoolean(option_arg, true, &success);
149 error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
150 option_arg.str().c_str());
154 run_validator = Args::StringToBoolean(option_arg, true, &success);
156 error.SetErrorStringWithFormat("invalid validate '%s'",
157 option_arg.str().c_str());
161 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
168 void OptionGroupValueObjectDisplay::OptionParsingStarting(
169 ExecutionContext *execution_context) {
170 // If these defaults change, be sure to modify AnyOptionWasSet().
172 no_summary_depth = 0;
173 show_location = false;
176 max_depth = UINT32_MAX;
182 run_validator = false;
185 execution_context ? execution_context->GetTargetSP() : TargetSP();
187 use_dynamic = target_sp->GetPreferDynamicValue();
189 // If we don't have any targets, then dynamic values won't do us much good.
190 use_dynamic = lldb::eNoDynamicValues;
194 DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
195 LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
196 lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
197 DumpValueObjectOptions options;
198 options.SetMaximumPointerDepth(
199 {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
201 options.SetShowSummary(false);
203 options.SetOmitSummaryDepth(no_summary_depth);
204 options.SetMaximumDepth(max_depth)
205 .SetShowTypes(show_types)
206 .SetShowLocation(show_location)
207 .SetUseObjectiveC(use_objc)
208 .SetUseDynamicType(use_dynamic)
209 .SetUseSyntheticValue(use_synth)
210 .SetFlatOutput(flat_output)
211 .SetIgnoreCap(ignore_cap)
213 .SetSummary(summary_sp);
215 if (lang_descr_verbosity ==
216 eLanguageRuntimeDescriptionDisplayVerbosityCompact)
217 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
221 options.SetRawDisplay();
223 options.SetRunValidator(run_validator);
225 options.SetElementCount(elem_count);