184c39663SGreg Clayton //===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===// 284c39663SGreg Clayton // 384c39663SGreg Clayton // The LLVM Compiler Infrastructure 484c39663SGreg Clayton // 584c39663SGreg Clayton // This file is distributed under the University of Illinois Open Source 684c39663SGreg Clayton // License. See LICENSE.TXT for details. 784c39663SGreg Clayton // 884c39663SGreg Clayton //===----------------------------------------------------------------------===// 984c39663SGreg Clayton 104bee32e5SJohnny Chen #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" 1184c39663SGreg Clayton 1284c39663SGreg Clayton // C Includes 1384c39663SGreg Clayton // C++ Includes 1484c39663SGreg Clayton // Other libraries and framework includes 1584c39663SGreg Clayton // Project includes 164d93b8cdSEnrico Granata #include "lldb/DataFormatters/ValueObjectPrinter.h" 175275aaa0SVince Harron #include "lldb/Host/StringConvert.h" 182837b766SJim Ingham #include "lldb/Target/Target.h" 192837b766SJim Ingham #include "lldb/Interpreter/CommandInterpreter.h" 207c575b3bSJohnny Chen #include "lldb/Utility/Utils.h" 2184c39663SGreg Clayton 2284c39663SGreg Clayton using namespace lldb; 2384c39663SGreg Clayton using namespace lldb_private; 2484c39663SGreg Clayton 2584c39663SGreg Clayton OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() 2684c39663SGreg Clayton { 2784c39663SGreg Clayton } 2884c39663SGreg Clayton 2984c39663SGreg Clayton OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay () 3084c39663SGreg Clayton { 3184c39663SGreg Clayton } 3284c39663SGreg Clayton 3368ebae61SGreg Clayton static OptionDefinition 3484c39663SGreg Clayton g_option_table[] = 3584c39663SGreg Clayton { 36d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "dynamic-type", 'd', OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0, eArgTypeNone, "Show the object as its full dynamic type, not its static type, if available."}, 37d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, 38d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."}, 39d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."}, 40d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable location information."}, 41d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print as an Objective-C object."}, 42d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."}, 43d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable types when dumping values."}, 44d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is 1)."}, 45d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."}, 46d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Ignore the upper bound on the number of children to show."}, 470f883ffbSEnrico Granata { LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."}, 48d37221dcSZachary Turner { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 4984c39663SGreg Clayton }; 5084c39663SGreg Clayton 5184c39663SGreg Clayton uint32_t 5284c39663SGreg Clayton OptionGroupValueObjectDisplay::GetNumDefinitions () 5384c39663SGreg Clayton { 546ebc8c45SJohnny Chen return llvm::array_lengthof(g_option_table); 5584c39663SGreg Clayton } 5684c39663SGreg Clayton 5784c39663SGreg Clayton const OptionDefinition * 5884c39663SGreg Clayton OptionGroupValueObjectDisplay::GetDefinitions () 5984c39663SGreg Clayton { 6084c39663SGreg Clayton return g_option_table; 6184c39663SGreg Clayton } 6284c39663SGreg Clayton 6384c39663SGreg Clayton 6484c39663SGreg Clayton Error 6584c39663SGreg Clayton OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter, 6684c39663SGreg Clayton uint32_t option_idx, 6784c39663SGreg Clayton const char *option_arg) 6884c39663SGreg Clayton { 6984c39663SGreg Clayton Error error; 703bcdfc0eSGreg Clayton const int short_option = g_option_table[option_idx].short_option; 7184c39663SGreg Clayton bool success = false; 7284c39663SGreg Clayton 7384c39663SGreg Clayton switch (short_option) 7484c39663SGreg Clayton { 752837b766SJim Ingham case 'd': 762837b766SJim Ingham { 772837b766SJim Ingham int32_t result; 7867cc0636SGreg Clayton result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error); 79cf0e4f0dSGreg Clayton if (error.Success()) 802837b766SJim Ingham use_dynamic = (lldb::DynamicValueType) result; 812837b766SJim Ingham } 822837b766SJim Ingham break; 8368ebae61SGreg Clayton case 'T': show_types = true; break; 8484c39663SGreg Clayton case 'L': show_location= true; break; 8584c39663SGreg Clayton case 'F': flat_output = true; break; 8668ebae61SGreg Clayton case 'O': use_objc = true; break; 87ce68b02cSEnrico Granata case 'R': be_raw = true; break; 8822c55d18SEnrico Granata case 'A': ignore_cap = true; break; 89ce68b02cSEnrico Granata 9068ebae61SGreg Clayton case 'D': 915275aaa0SVince Harron max_depth = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0, &success); 9284c39663SGreg Clayton if (!success) 9386edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg); 9484c39663SGreg Clayton break; 9584c39663SGreg Clayton 9668ebae61SGreg Clayton case 'P': 975275aaa0SVince Harron ptr_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success); 9884c39663SGreg Clayton if (!success) 9986edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 10084c39663SGreg Clayton break; 10184c39663SGreg Clayton 1020c5ef693SEnrico Granata case 'Y': 1030c5ef693SEnrico Granata if (option_arg) 1040c5ef693SEnrico Granata { 1055275aaa0SVince Harron no_summary_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success); 1060c5ef693SEnrico Granata if (!success) 10786edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 1080c5ef693SEnrico Granata } 1090c5ef693SEnrico Granata else 1100c5ef693SEnrico Granata no_summary_depth = 1; 1110c5ef693SEnrico Granata break; 1120c5ef693SEnrico Granata 113d55546b2SEnrico Granata case 'S': 114d55546b2SEnrico Granata use_synth = Args::StringToBoolean(option_arg, true, &success); 115d55546b2SEnrico Granata if (!success) 11686edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); 117d55546b2SEnrico Granata break; 1180f883ffbSEnrico Granata 1190f883ffbSEnrico Granata case 'V': 1200f883ffbSEnrico Granata run_validator = Args::StringToBoolean(option_arg, true, &success); 1210f883ffbSEnrico Granata if (!success) 1220f883ffbSEnrico Granata error.SetErrorStringWithFormat("invalid validate '%s'", option_arg); 1230f883ffbSEnrico Granata break; 1240f883ffbSEnrico Granata 12584c39663SGreg Clayton default: 12686edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 12784c39663SGreg Clayton break; 12884c39663SGreg Clayton } 12984c39663SGreg Clayton 13084c39663SGreg Clayton return error; 13184c39663SGreg Clayton } 13284c39663SGreg Clayton 13384c39663SGreg Clayton void 13484c39663SGreg Clayton OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter) 13584c39663SGreg Clayton { 13682f4cf46SGreg Clayton // If these defaults change, be sure to modify AnyOptionWasSet(). 13784c39663SGreg Clayton show_types = false; 1380c5ef693SEnrico Granata no_summary_depth = 0; 13984c39663SGreg Clayton show_location = false; 14084c39663SGreg Clayton flat_output = false; 14184c39663SGreg Clayton use_objc = false; 14284c39663SGreg Clayton max_depth = UINT32_MAX; 14384c39663SGreg Clayton ptr_depth = 0; 144d55546b2SEnrico Granata use_synth = true; 145ce68b02cSEnrico Granata be_raw = false; 14622c55d18SEnrico Granata ignore_cap = false; 1470f883ffbSEnrico Granata run_validator = false; 14884c39663SGreg Clayton 149c14ee32dSGreg Clayton Target *target = interpreter.GetExecutionContext().GetTargetPtr(); 150d78c9576SEd Maste if (target != nullptr) 1512837b766SJim Ingham use_dynamic = target->GetPreferDynamicValue(); 1522837b766SJim Ingham else 1532837b766SJim Ingham { 1542837b766SJim Ingham // If we don't have any targets, then dynamic values won't do us much good. 1552837b766SJim Ingham use_dynamic = lldb::eNoDynamicValues; 1562837b766SJim Ingham } 1572837b766SJim Ingham } 1589fb5ab55SEnrico Granata 1594d93b8cdSEnrico Granata DumpValueObjectOptions 1604d93b8cdSEnrico Granata OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, 1619fb5ab55SEnrico Granata lldb::Format format, 1629fb5ab55SEnrico Granata lldb::TypeSummaryImplSP summary_sp) 1639fb5ab55SEnrico Granata { 1644d93b8cdSEnrico Granata DumpValueObjectOptions options; 165*c1b7c09aSEnrico Granata options.SetMaximumPointerDepth( {DumpValueObjectOptions::PointerDepth::Mode::Always,ptr_depth} ); 1669fb5ab55SEnrico Granata if (use_objc) 1679fb5ab55SEnrico Granata options.SetShowSummary(false); 1689fb5ab55SEnrico Granata else 1699fb5ab55SEnrico Granata options.SetOmitSummaryDepth(no_summary_depth); 1709fb5ab55SEnrico Granata options.SetMaximumDepth(max_depth) 1719fb5ab55SEnrico Granata .SetShowTypes(show_types) 1729fb5ab55SEnrico Granata .SetShowLocation(show_location) 1739fb5ab55SEnrico Granata .SetUseObjectiveC(use_objc) 1749fb5ab55SEnrico Granata .SetUseDynamicType(use_dynamic) 1759fb5ab55SEnrico Granata .SetUseSyntheticValue(use_synth) 1769fb5ab55SEnrico Granata .SetFlatOutput(flat_output) 1779fb5ab55SEnrico Granata .SetIgnoreCap(ignore_cap) 1789fb5ab55SEnrico Granata .SetFormat(format) 1799fb5ab55SEnrico Granata .SetSummary(summary_sp); 1809fb5ab55SEnrico Granata 1814d93b8cdSEnrico Granata if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) 1829fb5ab55SEnrico Granata options.SetHideRootType(use_objc) 1839fb5ab55SEnrico Granata .SetHideName(use_objc) 1849fb5ab55SEnrico Granata .SetHideValue(use_objc); 1859fb5ab55SEnrico Granata 1869fb5ab55SEnrico Granata if (be_raw) 187a126e462SEnrico Granata options.SetRawDisplay(); 1889fb5ab55SEnrico Granata 1890f883ffbSEnrico Granata options.SetRunValidator(run_validator); 1900f883ffbSEnrico Granata 1919fb5ab55SEnrico Granata return options; 1929fb5ab55SEnrico Granata } 193