Path: blob/main/contrib/llvm-project/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
39587 views
//===-- OptionGroupValueObjectDisplay.cpp ---------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"910#include "lldb/DataFormatters/ValueObjectPrinter.h"11#include "lldb/Host/OptionParser.h"12#include "lldb/Interpreter/CommandInterpreter.h"13#include "lldb/Interpreter/OptionArgParser.h"14#include "lldb/Target/Target.h"1516#include "llvm/ADT/ArrayRef.h"1718using namespace lldb;19using namespace lldb_private;2021static const OptionDefinition g_option_table[] = {22{LLDB_OPT_SET_1, false, "dynamic-type", 'd',23OptionParser::eRequiredArgument, nullptr, GetDynamicValueTypes(), 0,24eArgTypeNone, "Show the object as its full dynamic type, not its static "25"type, if available."},26{LLDB_OPT_SET_1, false, "synthetic-type", 'S',27OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean,28"Show the object obeying its synthetic provider, if available."},29{LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,30nullptr, {}, 0, eArgTypeCount, "Set the max recurse depth when dumping "31"aggregate types (default is infinity)."},32{LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,33{}, 0, eArgTypeNone, "Display results in a flat format that uses "34"expression paths for each variable or member."},35{LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,36{}, 0, eArgTypeNone, "Show variable location information."},37{LLDB_OPT_SET_1, false, "object-description", 'O',38OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,39"Display using a language-specific description API, if possible."},40{LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,41nullptr, {}, 0, eArgTypeCount, "The number of pointers to be traversed "42"when dumping values (default is zero)."},43{LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,44nullptr, {}, 0, eArgTypeNone,45"Show variable types when dumping values."},46{LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',47OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeCount,48"Set the depth at which omitting summary information stops (default is "49"1)."},50{LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,51nullptr, {}, 0, eArgTypeNone, "Don't use formatting options."},52{LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,53nullptr, {}, 0, eArgTypeNone,54"Ignore the upper bound on the number of children to show."},55{LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,56nullptr, {}, 0, eArgTypeBoolean, "Show results of type validators."},57{LLDB_OPT_SET_1, false, "element-count", 'Z',58OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount,59"Treat the result of the expression as if its type is an array of this "60"many values."}};6162llvm::ArrayRef<OptionDefinition>63OptionGroupValueObjectDisplay::GetDefinitions() {64return llvm::ArrayRef(g_option_table);65}6667Status OptionGroupValueObjectDisplay::SetOptionValue(68uint32_t option_idx, llvm::StringRef option_arg,69ExecutionContext *execution_context) {70Status error;71const int short_option = g_option_table[option_idx].short_option;72bool success = false;7374switch (short_option) {75case 'd': {76int32_t result;77result = OptionArgParser::ToOptionEnum(option_arg, GetDynamicValueTypes(),782, error);79if (error.Success())80use_dynamic = (lldb::DynamicValueType)result;81} break;82case 'T':83show_types = true;84break;85case 'L':86show_location = true;87break;88case 'F':89flat_output = true;90break;91case 'O':92use_objc = true;93break;94case 'R':95be_raw = true;96break;97case 'A':98ignore_cap = true;99break;100101case 'D':102if (option_arg.getAsInteger(0, max_depth)) {103max_depth = UINT32_MAX;104error.SetErrorStringWithFormat("invalid max depth '%s'",105option_arg.str().c_str());106} else {107max_depth_is_default = false;108}109break;110111case 'Z':112if (option_arg.getAsInteger(0, elem_count)) {113elem_count = UINT32_MAX;114error.SetErrorStringWithFormat("invalid element count '%s'",115option_arg.str().c_str());116}117break;118119case 'P':120if (option_arg.getAsInteger(0, ptr_depth)) {121ptr_depth = 0;122error.SetErrorStringWithFormat("invalid pointer depth '%s'",123option_arg.str().c_str());124}125break;126127case 'Y':128if (option_arg.empty())129no_summary_depth = 1;130else if (option_arg.getAsInteger(0, no_summary_depth)) {131no_summary_depth = 0;132error.SetErrorStringWithFormat("invalid pointer depth '%s'",133option_arg.str().c_str());134}135break;136137case 'S':138use_synth = OptionArgParser::ToBoolean(option_arg, true, &success);139if (!success)140error.SetErrorStringWithFormat("invalid synthetic-type '%s'",141option_arg.str().c_str());142break;143144case 'V':145run_validator = OptionArgParser::ToBoolean(option_arg, true, &success);146if (!success)147error.SetErrorStringWithFormat("invalid validate '%s'",148option_arg.str().c_str());149break;150151default:152llvm_unreachable("Unimplemented option");153}154155return error;156}157158void OptionGroupValueObjectDisplay::OptionParsingStarting(159ExecutionContext *execution_context) {160// If these defaults change, be sure to modify AnyOptionWasSet().161show_types = false;162no_summary_depth = 0;163show_location = false;164flat_output = false;165use_objc = false;166max_depth = UINT32_MAX;167max_depth_is_default = true;168ptr_depth = 0;169elem_count = 0;170use_synth = true;171be_raw = false;172ignore_cap = false;173run_validator = false;174175TargetSP target_sp =176execution_context ? execution_context->GetTargetSP() : TargetSP();177if (target_sp) {178use_dynamic = target_sp->GetPreferDynamicValue();179auto max_depth_config = target_sp->GetMaximumDepthOfChildrenToDisplay();180max_depth = std::get<uint32_t>(max_depth_config);181max_depth_is_default = std::get<bool>(max_depth_config);182} else {183// If we don't have any targets, then dynamic values won't do us much good.184use_dynamic = lldb::eNoDynamicValues;185}186}187188DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(189LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,190lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {191DumpValueObjectOptions options;192options.SetMaximumPointerDepth(193{DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});194if (use_objc)195options.SetShowSummary(false);196else197options.SetOmitSummaryDepth(no_summary_depth);198options.SetMaximumDepth(max_depth, max_depth_is_default)199.SetShowTypes(show_types)200.SetShowLocation(show_location)201.SetUseObjectiveC(use_objc)202.SetUseDynamicType(use_dynamic)203.SetUseSyntheticValue(use_synth)204.SetFlatOutput(flat_output)205.SetIgnoreCap(ignore_cap)206.SetFormat(format)207.SetSummary(summary_sp);208209if (lang_descr_verbosity ==210eLanguageRuntimeDescriptionDisplayVerbosityCompact)211options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(212use_objc);213214if (be_raw)215options.SetRawDisplay();216217options.SetRunValidator(run_validator);218219options.SetElementCount(elem_count);220221return options;222}223224225