1 //===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
11 #include "lldb/DataFormatters/ValueObjectPrinter.h"
12 #include "lldb/Host/OptionParser.h"
13 #include "lldb/Interpreter/CommandInterpreter.h"
14 #include "lldb/Interpreter/OptionArgParser.h"
15 #include "lldb/Target/Target.h"
17 #include "llvm/ADT/ArrayRef.h"
20 using namespace lldb_private;
22 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
24 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
26 static const OptionDefinition g_option_table[] = {
27 {LLDB_OPT_SET_1, false, "dynamic-type", 'd',
28 OptionParser::eRequiredArgument, nullptr, GetDynamicValueTypes(), 0,
29 eArgTypeNone, "Show the object as its full dynamic type, not its static "
30 "type, if available."},
31 {LLDB_OPT_SET_1, false, "synthetic-type", 'S',
32 OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean,
33 "Show the object obeying its synthetic provider, if available."},
34 {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,
35 nullptr, {}, 0, eArgTypeCount, "Set the max recurse depth when dumping "
36 "aggregate types (default is infinity)."},
37 {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,
38 {}, 0, eArgTypeNone, "Display results in a flat format that uses "
39 "expression paths for each variable or member."},
40 {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,
41 {}, 0, eArgTypeNone, "Show variable location information."},
42 {LLDB_OPT_SET_1, false, "object-description", 'O',
43 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
44 "Display using a language-specific description API, if possible."},
45 {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,
46 nullptr, {}, 0, eArgTypeCount, "The number of pointers to be traversed "
47 "when dumping values (default is zero)."},
48 {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,
49 nullptr, {}, 0, eArgTypeNone,
50 "Show variable types when dumping values."},
51 {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',
52 OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeCount,
53 "Set the depth at which omitting summary information stops (default is "
55 {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,
56 nullptr, {}, 0, eArgTypeNone, "Don't use formatting options."},
57 {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,
58 nullptr, {}, 0, eArgTypeNone,
59 "Ignore the upper bound on the number of children to show."},
60 {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,
61 nullptr, {}, 0, eArgTypeBoolean, "Show results of type validators."},
62 {LLDB_OPT_SET_1, false, "element-count", 'Z',
63 OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount,
64 "Treat the result of the expression as if its type is an array of this "
67 llvm::ArrayRef<OptionDefinition>
68 OptionGroupValueObjectDisplay::GetDefinitions() {
69 return llvm::makeArrayRef(g_option_table);
72 Status OptionGroupValueObjectDisplay::SetOptionValue(
73 uint32_t option_idx, llvm::StringRef option_arg,
74 ExecutionContext *execution_context) {
76 const int short_option = g_option_table[option_idx].short_option;
79 switch (short_option) {
82 result = OptionArgParser::ToOptionEnum(option_arg, GetDynamicValueTypes(),
85 use_dynamic = (lldb::DynamicValueType)result;
107 if (option_arg.getAsInteger(0, max_depth)) {
108 max_depth = UINT32_MAX;
109 error.SetErrorStringWithFormat("invalid max depth '%s'",
110 option_arg.str().c_str());
115 if (option_arg.getAsInteger(0, elem_count)) {
116 elem_count = UINT32_MAX;
117 error.SetErrorStringWithFormat("invalid element count '%s'",
118 option_arg.str().c_str());
123 if (option_arg.getAsInteger(0, ptr_depth)) {
125 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
126 option_arg.str().c_str());
131 if (option_arg.empty())
132 no_summary_depth = 1;
133 else if (option_arg.getAsInteger(0, no_summary_depth)) {
134 no_summary_depth = 0;
135 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
136 option_arg.str().c_str());
141 use_synth = OptionArgParser::ToBoolean(option_arg, true, &success);
143 error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
144 option_arg.str().c_str());
148 run_validator = OptionArgParser::ToBoolean(option_arg, true, &success);
150 error.SetErrorStringWithFormat("invalid validate '%s'",
151 option_arg.str().c_str());
155 llvm_unreachable("Unimplemented option");
161 void OptionGroupValueObjectDisplay::OptionParsingStarting(
162 ExecutionContext *execution_context) {
163 // If these defaults change, be sure to modify AnyOptionWasSet().
165 no_summary_depth = 0;
166 show_location = false;
169 max_depth = UINT32_MAX;
175 run_validator = false;
178 execution_context ? execution_context->GetTargetSP() : TargetSP();
180 use_dynamic = target_sp->GetPreferDynamicValue();
182 // If we don't have any targets, then dynamic values won't do us much good.
183 use_dynamic = lldb::eNoDynamicValues;
187 DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
188 LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
189 lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
190 DumpValueObjectOptions options;
191 options.SetMaximumPointerDepth(
192 {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
194 options.SetShowSummary(false);
196 options.SetOmitSummaryDepth(no_summary_depth);
197 options.SetMaximumDepth(max_depth)
198 .SetShowTypes(show_types)
199 .SetShowLocation(show_location)
200 .SetUseObjectiveC(use_objc)
201 .SetUseDynamicType(use_dynamic)
202 .SetUseSyntheticValue(use_synth)
203 .SetFlatOutput(flat_output)
204 .SetIgnoreCap(ignore_cap)
206 .SetSummary(summary_sp);
208 if (lang_descr_verbosity ==
209 eLanguageRuntimeDescriptionDisplayVerbosityCompact)
210 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
214 options.SetRawDisplay();
216 options.SetRunValidator(run_validator);
218 options.SetElementCount(elem_count);