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/StringConvert.h"
18 #include "lldb/Interpreter/CommandInterpreter.h"
19 #include "lldb/Target/Target.h"
20 #include "lldb/Utility/Utils.h"
22 #include "llvm/ADT/ArrayRef.h"
25 using namespace lldb_private;
27 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
29 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
31 static OptionDefinition g_option_table[] = {
32 {LLDB_OPT_SET_1, false, "dynamic-type", 'd',
33 OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0,
34 eArgTypeNone, "Show the object as its full dynamic type, not its static "
35 "type, if available."},
36 {LLDB_OPT_SET_1, false, "synthetic-type", 'S',
37 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
38 "Show the object obeying its synthetic provider, if available."},
39 {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,
40 nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when "
41 "dumping aggregate types (default is "
43 {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,
44 nullptr, 0, eArgTypeNone, "Display results in a flat format that uses "
45 "expression paths for each variable or member."},
46 {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,
47 nullptr, 0, eArgTypeNone, "Show variable location information."},
48 {LLDB_OPT_SET_1, false, "object-description", 'O',
49 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
50 "Print as an Objective-C object."},
51 {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,
52 nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be "
53 "traversed when dumping values "
54 "(default is zero)."},
55 {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,
56 nullptr, nullptr, 0, eArgTypeNone,
57 "Show variable types when dumping values."},
58 {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',
59 OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount,
60 "Set the depth at which omitting summary information stops (default is "
62 {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,
63 nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."},
64 {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,
65 nullptr, nullptr, 0, eArgTypeNone,
66 "Ignore the upper bound on the number of children to show."},
67 {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,
68 nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."},
69 {LLDB_OPT_SET_1, false, "element-count", 'Z',
70 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,
71 "Treat the result of the expression as if its type is an array of this "
74 llvm::ArrayRef<OptionDefinition>
75 OptionGroupValueObjectDisplay::GetDefinitions() {
76 return llvm::makeArrayRef(g_option_table);
79 Error OptionGroupValueObjectDisplay::SetOptionValue(
80 uint32_t option_idx, llvm::StringRef option_arg,
81 ExecutionContext *execution_context) {
83 const int short_option = g_option_table[option_idx].short_option;
86 switch (short_option) {
90 Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error);
92 use_dynamic = (lldb::DynamicValueType)result;
114 if (option_arg.getAsInteger(0, max_depth)) {
115 max_depth = UINT32_MAX;
116 error.SetErrorStringWithFormat("invalid max depth '%s'",
117 option_arg.str().c_str());
122 if (option_arg.getAsInteger(0, elem_count)) {
123 elem_count = UINT32_MAX;
124 error.SetErrorStringWithFormat("invalid element count '%s'",
125 option_arg.str().c_str());
130 if (option_arg.getAsInteger(0, ptr_depth)) {
132 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
133 option_arg.str().c_str());
138 if (option_arg.empty())
139 no_summary_depth = 1;
140 else if (option_arg.getAsInteger(0, no_summary_depth)) {
141 no_summary_depth = 0;
142 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
143 option_arg.str().c_str());
148 use_synth = Args::StringToBoolean(option_arg, true, &success);
150 error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
151 option_arg.str().c_str());
155 run_validator = Args::StringToBoolean(option_arg, true, &success);
157 error.SetErrorStringWithFormat("invalid validate '%s'",
158 option_arg.str().c_str());
162 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
169 void OptionGroupValueObjectDisplay::OptionParsingStarting(
170 ExecutionContext *execution_context) {
171 // If these defaults change, be sure to modify AnyOptionWasSet().
173 no_summary_depth = 0;
174 show_location = false;
177 max_depth = UINT32_MAX;
183 run_validator = false;
186 execution_context ? execution_context->GetTargetSP() : TargetSP();
188 use_dynamic = target_sp->GetPreferDynamicValue();
190 // If we don't have any targets, then dynamic values won't do us much good.
191 use_dynamic = lldb::eNoDynamicValues;
195 DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
196 LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
197 lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
198 DumpValueObjectOptions options;
199 options.SetMaximumPointerDepth(
200 {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
202 options.SetShowSummary(false);
204 options.SetOmitSummaryDepth(no_summary_depth);
205 options.SetMaximumDepth(max_depth)
206 .SetShowTypes(show_types)
207 .SetShowLocation(show_location)
208 .SetUseObjectiveC(use_objc)
209 .SetUseDynamicType(use_dynamic)
210 .SetUseSyntheticValue(use_synth)
211 .SetFlatOutput(flat_output)
212 .SetIgnoreCap(ignore_cap)
214 .SetSummary(summary_sp);
216 if (lang_descr_verbosity ==
217 eLanguageRuntimeDescriptionDisplayVerbosityCompact)
218 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
222 options.SetRawDisplay();
224 options.SetRunValidator(run_validator);
226 options.SetElementCount(elem_count);