1cfca06d7SDimitry Andric //===-- OptionGroupValueObjectDisplay.cpp ---------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
10f034231aSEd Maste
11f21a844fSEd Maste #include "lldb/DataFormatters/ValueObjectPrinter.h"
1274a628f7SDimitry Andric #include "lldb/Host/OptionParser.h"
13f034231aSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
14f73363f1SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h"
1514f1b3e8SDimitry Andric #include "lldb/Target/Target.h"
16f034231aSEd Maste
1714f1b3e8SDimitry Andric #include "llvm/ADT/ArrayRef.h"
1814f1b3e8SDimitry Andric
19f034231aSEd Maste using namespace lldb;
20f034231aSEd Maste using namespace lldb_private;
21f034231aSEd Maste
2294994d37SDimitry Andric static const OptionDefinition g_option_table[] = {
2314f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "dynamic-type", 'd',
2494994d37SDimitry Andric OptionParser::eRequiredArgument, nullptr, GetDynamicValueTypes(), 0,
2514f1b3e8SDimitry Andric eArgTypeNone, "Show the object as its full dynamic type, not its static "
2614f1b3e8SDimitry Andric "type, if available."},
2714f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "synthetic-type", 'S',
2894994d37SDimitry Andric OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean,
2914f1b3e8SDimitry Andric "Show the object obeying its synthetic provider, if available."},
3014f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,
3194994d37SDimitry Andric nullptr, {}, 0, eArgTypeCount, "Set the max recurse depth when dumping "
3294994d37SDimitry Andric "aggregate types (default is infinity)."},
3314f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,
3494994d37SDimitry Andric {}, 0, eArgTypeNone, "Display results in a flat format that uses "
3514f1b3e8SDimitry Andric "expression paths for each variable or member."},
3614f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,
3794994d37SDimitry Andric {}, 0, eArgTypeNone, "Show variable location information."},
3814f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "object-description", 'O',
3994994d37SDimitry Andric OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
40706b4fc4SDimitry Andric "Display using a language-specific description API, if possible."},
4114f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,
4294994d37SDimitry Andric nullptr, {}, 0, eArgTypeCount, "The number of pointers to be traversed "
4394994d37SDimitry Andric "when dumping values (default is zero)."},
4414f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,
4594994d37SDimitry Andric nullptr, {}, 0, eArgTypeNone,
4614f1b3e8SDimitry Andric "Show variable types when dumping values."},
4714f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',
4894994d37SDimitry Andric OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeCount,
4914f1b3e8SDimitry Andric "Set the depth at which omitting summary information stops (default is "
5014f1b3e8SDimitry Andric "1)."},
5114f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,
5294994d37SDimitry Andric nullptr, {}, 0, eArgTypeNone, "Don't use formatting options."},
5314f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,
5494994d37SDimitry Andric nullptr, {}, 0, eArgTypeNone,
5514f1b3e8SDimitry Andric "Ignore the upper bound on the number of children to show."},
5614f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,
5794994d37SDimitry Andric nullptr, {}, 0, eArgTypeBoolean, "Show results of type validators."},
5814f1b3e8SDimitry Andric {LLDB_OPT_SET_1, false, "element-count", 'Z',
5994994d37SDimitry Andric OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount,
6014f1b3e8SDimitry Andric "Treat the result of the expression as if its type is an array of this "
6114f1b3e8SDimitry Andric "many values."}};
6214f1b3e8SDimitry Andric
6314f1b3e8SDimitry Andric llvm::ArrayRef<OptionDefinition>
GetDefinitions()6414f1b3e8SDimitry Andric OptionGroupValueObjectDisplay::GetDefinitions() {
65e3b55780SDimitry Andric return llvm::ArrayRef(g_option_table);
66f034231aSEd Maste }
67f034231aSEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)68b76161e4SDimitry Andric Status OptionGroupValueObjectDisplay::SetOptionValue(
6914f1b3e8SDimitry Andric uint32_t option_idx, llvm::StringRef option_arg,
7014f1b3e8SDimitry Andric ExecutionContext *execution_context) {
71b76161e4SDimitry Andric Status error;
72f034231aSEd Maste const int short_option = g_option_table[option_idx].short_option;
73f034231aSEd Maste bool success = false;
74f034231aSEd Maste
7514f1b3e8SDimitry Andric switch (short_option) {
7614f1b3e8SDimitry Andric case 'd': {
77f034231aSEd Maste int32_t result;
7894994d37SDimitry Andric result = OptionArgParser::ToOptionEnum(option_arg, GetDynamicValueTypes(),
7994994d37SDimitry Andric 2, error);
80f034231aSEd Maste if (error.Success())
81f034231aSEd Maste use_dynamic = (lldb::DynamicValueType)result;
8214f1b3e8SDimitry Andric } break;
8314f1b3e8SDimitry Andric case 'T':
8414f1b3e8SDimitry Andric show_types = true;
85f034231aSEd Maste break;
8614f1b3e8SDimitry Andric case 'L':
8714f1b3e8SDimitry Andric show_location = true;
8814f1b3e8SDimitry Andric break;
8914f1b3e8SDimitry Andric case 'F':
9014f1b3e8SDimitry Andric flat_output = true;
9114f1b3e8SDimitry Andric break;
9214f1b3e8SDimitry Andric case 'O':
9314f1b3e8SDimitry Andric use_objc = true;
9414f1b3e8SDimitry Andric break;
9514f1b3e8SDimitry Andric case 'R':
9614f1b3e8SDimitry Andric be_raw = true;
9714f1b3e8SDimitry Andric break;
9814f1b3e8SDimitry Andric case 'A':
9914f1b3e8SDimitry Andric ignore_cap = true;
10014f1b3e8SDimitry Andric break;
101f034231aSEd Maste
102f034231aSEd Maste case 'D':
10314f1b3e8SDimitry Andric if (option_arg.getAsInteger(0, max_depth)) {
10414f1b3e8SDimitry Andric max_depth = UINT32_MAX;
10514f1b3e8SDimitry Andric error.SetErrorStringWithFormat("invalid max depth '%s'",
10614f1b3e8SDimitry Andric option_arg.str().c_str());
107145449b1SDimitry Andric } else {
108145449b1SDimitry Andric max_depth_is_default = false;
10914f1b3e8SDimitry Andric }
110f034231aSEd Maste break;
111f034231aSEd Maste
112f3fbd1c0SDimitry Andric case 'Z':
11314f1b3e8SDimitry Andric if (option_arg.getAsInteger(0, elem_count)) {
11414f1b3e8SDimitry Andric elem_count = UINT32_MAX;
11514f1b3e8SDimitry Andric error.SetErrorStringWithFormat("invalid element count '%s'",
11614f1b3e8SDimitry Andric option_arg.str().c_str());
11714f1b3e8SDimitry Andric }
118f3fbd1c0SDimitry Andric break;
119f3fbd1c0SDimitry Andric
120f034231aSEd Maste case 'P':
12114f1b3e8SDimitry Andric if (option_arg.getAsInteger(0, ptr_depth)) {
12214f1b3e8SDimitry Andric ptr_depth = 0;
12314f1b3e8SDimitry Andric error.SetErrorStringWithFormat("invalid pointer depth '%s'",
12414f1b3e8SDimitry Andric option_arg.str().c_str());
12514f1b3e8SDimitry Andric }
126f034231aSEd Maste break;
127f034231aSEd Maste
128f034231aSEd Maste case 'Y':
12914f1b3e8SDimitry Andric if (option_arg.empty())
130f034231aSEd Maste no_summary_depth = 1;
13114f1b3e8SDimitry Andric else if (option_arg.getAsInteger(0, no_summary_depth)) {
13214f1b3e8SDimitry Andric no_summary_depth = 0;
13314f1b3e8SDimitry Andric error.SetErrorStringWithFormat("invalid pointer depth '%s'",
13414f1b3e8SDimitry Andric option_arg.str().c_str());
13514f1b3e8SDimitry Andric }
136f034231aSEd Maste break;
137f034231aSEd Maste
138f034231aSEd Maste case 'S':
139f73363f1SDimitry Andric use_synth = OptionArgParser::ToBoolean(option_arg, true, &success);
140f034231aSEd Maste if (!success)
14114f1b3e8SDimitry Andric error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
14214f1b3e8SDimitry Andric option_arg.str().c_str());
143f034231aSEd Maste break;
144205afe67SEd Maste
145205afe67SEd Maste case 'V':
146f73363f1SDimitry Andric run_validator = OptionArgParser::ToBoolean(option_arg, true, &success);
147205afe67SEd Maste if (!success)
14814f1b3e8SDimitry Andric error.SetErrorStringWithFormat("invalid validate '%s'",
14914f1b3e8SDimitry Andric option_arg.str().c_str());
150205afe67SEd Maste break;
151205afe67SEd Maste
152f034231aSEd Maste default:
153ead24645SDimitry Andric llvm_unreachable("Unimplemented option");
154f034231aSEd Maste }
155f034231aSEd Maste
156f034231aSEd Maste return error;
157f034231aSEd Maste }
158f034231aSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)15914f1b3e8SDimitry Andric void OptionGroupValueObjectDisplay::OptionParsingStarting(
16014f1b3e8SDimitry Andric ExecutionContext *execution_context) {
161f034231aSEd Maste // If these defaults change, be sure to modify AnyOptionWasSet().
162f034231aSEd Maste show_types = false;
163f034231aSEd Maste no_summary_depth = 0;
164f034231aSEd Maste show_location = false;
165f034231aSEd Maste flat_output = false;
166f034231aSEd Maste use_objc = false;
167f034231aSEd Maste max_depth = UINT32_MAX;
168145449b1SDimitry Andric max_depth_is_default = true;
169f034231aSEd Maste ptr_depth = 0;
170f3fbd1c0SDimitry Andric elem_count = 0;
171f034231aSEd Maste use_synth = true;
172f034231aSEd Maste be_raw = false;
173f034231aSEd Maste ignore_cap = false;
174205afe67SEd Maste run_validator = false;
175f034231aSEd Maste
17614f1b3e8SDimitry Andric TargetSP target_sp =
17714f1b3e8SDimitry Andric execution_context ? execution_context->GetTargetSP() : TargetSP();
178145449b1SDimitry Andric if (target_sp) {
17914f1b3e8SDimitry Andric use_dynamic = target_sp->GetPreferDynamicValue();
180145449b1SDimitry Andric auto max_depth_config = target_sp->GetMaximumDepthOfChildrenToDisplay();
181145449b1SDimitry Andric max_depth = std::get<uint32_t>(max_depth_config);
182145449b1SDimitry Andric max_depth_is_default = std::get<bool>(max_depth_config);
183145449b1SDimitry Andric } else {
184f034231aSEd Maste // If we don't have any targets, then dynamic values won't do us much good.
185f034231aSEd Maste use_dynamic = lldb::eNoDynamicValues;
186f034231aSEd Maste }
187f034231aSEd Maste }
188f034231aSEd Maste
GetAsDumpOptions(LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,lldb::Format format,lldb::TypeSummaryImplSP summary_sp)18914f1b3e8SDimitry Andric DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
19014f1b3e8SDimitry Andric LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
19114f1b3e8SDimitry Andric lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
192f21a844fSEd Maste DumpValueObjectOptions options;
19314f1b3e8SDimitry Andric options.SetMaximumPointerDepth(
19414f1b3e8SDimitry Andric {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
195f034231aSEd Maste if (use_objc)
196f034231aSEd Maste options.SetShowSummary(false);
197f034231aSEd Maste else
198f034231aSEd Maste options.SetOmitSummaryDepth(no_summary_depth);
199145449b1SDimitry Andric options.SetMaximumDepth(max_depth, max_depth_is_default)
200f034231aSEd Maste .SetShowTypes(show_types)
201f034231aSEd Maste .SetShowLocation(show_location)
202f034231aSEd Maste .SetUseObjectiveC(use_objc)
203f034231aSEd Maste .SetUseDynamicType(use_dynamic)
204f034231aSEd Maste .SetUseSyntheticValue(use_synth)
205f034231aSEd Maste .SetFlatOutput(flat_output)
206f034231aSEd Maste .SetIgnoreCap(ignore_cap)
207f034231aSEd Maste .SetFormat(format)
208f034231aSEd Maste .SetSummary(summary_sp);
209f034231aSEd Maste
21014f1b3e8SDimitry Andric if (lang_descr_verbosity ==
21114f1b3e8SDimitry Andric eLanguageRuntimeDescriptionDisplayVerbosityCompact)
21214f1b3e8SDimitry Andric options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
21314f1b3e8SDimitry Andric use_objc);
214f034231aSEd Maste
215f034231aSEd Maste if (be_raw)
216205afe67SEd Maste options.SetRawDisplay();
217205afe67SEd Maste
218205afe67SEd Maste options.SetRunValidator(run_validator);
219f034231aSEd Maste
220f3fbd1c0SDimitry Andric options.SetElementCount(elem_count);
221f3fbd1c0SDimitry Andric
222f034231aSEd Maste return options;
223f034231aSEd Maste }
224