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 1093a64300SDaniel Malea #include "lldb/lldb-python.h" 1193a64300SDaniel Malea 124bee32e5SJohnny Chen #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" 1384c39663SGreg Clayton 1484c39663SGreg Clayton // C Includes 1584c39663SGreg Clayton // C++ Includes 1684c39663SGreg Clayton // Other libraries and framework includes 1784c39663SGreg Clayton // Project includes 184d93b8cdSEnrico Granata #include "lldb/DataFormatters/ValueObjectPrinter.h" 192837b766SJim Ingham #include "lldb/Target/Target.h" 202837b766SJim Ingham #include "lldb/Interpreter/CommandInterpreter.h" 217c575b3bSJohnny Chen #include "lldb/Utility/Utils.h" 2284c39663SGreg Clayton 2384c39663SGreg Clayton using namespace lldb; 2484c39663SGreg Clayton using namespace lldb_private; 2584c39663SGreg Clayton 2684c39663SGreg Clayton OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() 2784c39663SGreg Clayton { 2884c39663SGreg Clayton } 2984c39663SGreg Clayton 3084c39663SGreg Clayton OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay () 3184c39663SGreg Clayton { 3284c39663SGreg Clayton } 3384c39663SGreg Clayton 3468ebae61SGreg Clayton static OptionDefinition 3584c39663SGreg Clayton g_option_table[] = 3684c39663SGreg Clayton { 37d37221dcSZachary 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."}, 38d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, 39d37221dcSZachary 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)."}, 40d37221dcSZachary 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."}, 41d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable location information."}, 42d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print as an Objective-C object."}, 43d37221dcSZachary 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)."}, 44d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable types when dumping values."}, 45d37221dcSZachary 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)."}, 46d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."}, 47d37221dcSZachary 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."}, 48*0f883ffbSEnrico Granata { LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."}, 49d37221dcSZachary Turner { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 5084c39663SGreg Clayton }; 5184c39663SGreg Clayton 5284c39663SGreg Clayton uint32_t 5384c39663SGreg Clayton OptionGroupValueObjectDisplay::GetNumDefinitions () 5484c39663SGreg Clayton { 556ebc8c45SJohnny Chen return llvm::array_lengthof(g_option_table); 5684c39663SGreg Clayton } 5784c39663SGreg Clayton 5884c39663SGreg Clayton const OptionDefinition * 5984c39663SGreg Clayton OptionGroupValueObjectDisplay::GetDefinitions () 6084c39663SGreg Clayton { 6184c39663SGreg Clayton return g_option_table; 6284c39663SGreg Clayton } 6384c39663SGreg Clayton 6484c39663SGreg Clayton 6584c39663SGreg Clayton Error 6684c39663SGreg Clayton OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter, 6784c39663SGreg Clayton uint32_t option_idx, 6884c39663SGreg Clayton const char *option_arg) 6984c39663SGreg Clayton { 7084c39663SGreg Clayton Error error; 713bcdfc0eSGreg Clayton const int short_option = g_option_table[option_idx].short_option; 7284c39663SGreg Clayton bool success = false; 7384c39663SGreg Clayton 7484c39663SGreg Clayton switch (short_option) 7584c39663SGreg Clayton { 762837b766SJim Ingham case 'd': 772837b766SJim Ingham { 782837b766SJim Ingham int32_t result; 7967cc0636SGreg Clayton result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error); 80cf0e4f0dSGreg Clayton if (error.Success()) 812837b766SJim Ingham use_dynamic = (lldb::DynamicValueType) result; 822837b766SJim Ingham } 832837b766SJim Ingham break; 8468ebae61SGreg Clayton case 'T': show_types = true; break; 8584c39663SGreg Clayton case 'L': show_location= true; break; 8684c39663SGreg Clayton case 'F': flat_output = true; break; 8768ebae61SGreg Clayton case 'O': use_objc = true; break; 88ce68b02cSEnrico Granata case 'R': be_raw = true; break; 8922c55d18SEnrico Granata case 'A': ignore_cap = true; break; 90ce68b02cSEnrico Granata 9168ebae61SGreg Clayton case 'D': 9284c39663SGreg Clayton max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success); 9384c39663SGreg Clayton if (!success) 9486edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg); 9584c39663SGreg Clayton break; 9684c39663SGreg Clayton 9768ebae61SGreg Clayton case 'P': 9884c39663SGreg Clayton ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success); 9984c39663SGreg Clayton if (!success) 10086edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 10184c39663SGreg Clayton break; 10284c39663SGreg Clayton 1030c5ef693SEnrico Granata case 'Y': 1040c5ef693SEnrico Granata if (option_arg) 1050c5ef693SEnrico Granata { 1060c5ef693SEnrico Granata no_summary_depth = Args::StringToUInt32 (option_arg, 0, 0, &success); 1070c5ef693SEnrico Granata if (!success) 10886edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 1090c5ef693SEnrico Granata } 1100c5ef693SEnrico Granata else 1110c5ef693SEnrico Granata no_summary_depth = 1; 1120c5ef693SEnrico Granata break; 1130c5ef693SEnrico Granata 114d55546b2SEnrico Granata case 'S': 115d55546b2SEnrico Granata use_synth = Args::StringToBoolean(option_arg, true, &success); 116d55546b2SEnrico Granata if (!success) 11786edbf41SGreg Clayton error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); 118d55546b2SEnrico Granata break; 119*0f883ffbSEnrico Granata 120*0f883ffbSEnrico Granata case 'V': 121*0f883ffbSEnrico Granata run_validator = Args::StringToBoolean(option_arg, true, &success); 122*0f883ffbSEnrico Granata if (!success) 123*0f883ffbSEnrico Granata error.SetErrorStringWithFormat("invalid validate '%s'", option_arg); 124*0f883ffbSEnrico Granata break; 125*0f883ffbSEnrico Granata 12684c39663SGreg Clayton default: 12786edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 12884c39663SGreg Clayton break; 12984c39663SGreg Clayton } 13084c39663SGreg Clayton 13184c39663SGreg Clayton return error; 13284c39663SGreg Clayton } 13384c39663SGreg Clayton 13484c39663SGreg Clayton void 13584c39663SGreg Clayton OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter) 13684c39663SGreg Clayton { 13782f4cf46SGreg Clayton // If these defaults change, be sure to modify AnyOptionWasSet(). 13884c39663SGreg Clayton show_types = false; 1390c5ef693SEnrico Granata no_summary_depth = 0; 14084c39663SGreg Clayton show_location = false; 14184c39663SGreg Clayton flat_output = false; 14284c39663SGreg Clayton use_objc = false; 14384c39663SGreg Clayton max_depth = UINT32_MAX; 14484c39663SGreg Clayton ptr_depth = 0; 145d55546b2SEnrico Granata use_synth = true; 146ce68b02cSEnrico Granata be_raw = false; 14722c55d18SEnrico Granata ignore_cap = false; 148*0f883ffbSEnrico Granata run_validator = false; 14984c39663SGreg Clayton 150c14ee32dSGreg Clayton Target *target = interpreter.GetExecutionContext().GetTargetPtr(); 151d78c9576SEd Maste if (target != nullptr) 1522837b766SJim Ingham use_dynamic = target->GetPreferDynamicValue(); 1532837b766SJim Ingham else 1542837b766SJim Ingham { 1552837b766SJim Ingham // If we don't have any targets, then dynamic values won't do us much good. 1562837b766SJim Ingham use_dynamic = lldb::eNoDynamicValues; 1572837b766SJim Ingham } 1582837b766SJim Ingham } 1599fb5ab55SEnrico Granata 1604d93b8cdSEnrico Granata DumpValueObjectOptions 1614d93b8cdSEnrico Granata OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, 1629fb5ab55SEnrico Granata lldb::Format format, 1639fb5ab55SEnrico Granata lldb::TypeSummaryImplSP summary_sp) 1649fb5ab55SEnrico Granata { 1654d93b8cdSEnrico Granata DumpValueObjectOptions options; 1669fb5ab55SEnrico Granata options.SetMaximumPointerDepth(ptr_depth); 1679fb5ab55SEnrico Granata if (use_objc) 1689fb5ab55SEnrico Granata options.SetShowSummary(false); 1699fb5ab55SEnrico Granata else 1709fb5ab55SEnrico Granata options.SetOmitSummaryDepth(no_summary_depth); 1719fb5ab55SEnrico Granata options.SetMaximumDepth(max_depth) 1729fb5ab55SEnrico Granata .SetShowTypes(show_types) 1739fb5ab55SEnrico Granata .SetShowLocation(show_location) 1749fb5ab55SEnrico Granata .SetUseObjectiveC(use_objc) 1759fb5ab55SEnrico Granata .SetUseDynamicType(use_dynamic) 1769fb5ab55SEnrico Granata .SetUseSyntheticValue(use_synth) 1779fb5ab55SEnrico Granata .SetFlatOutput(flat_output) 1789fb5ab55SEnrico Granata .SetIgnoreCap(ignore_cap) 1799fb5ab55SEnrico Granata .SetFormat(format) 1809fb5ab55SEnrico Granata .SetSummary(summary_sp); 1819fb5ab55SEnrico Granata 1824d93b8cdSEnrico Granata if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) 1839fb5ab55SEnrico Granata options.SetHideRootType(use_objc) 1849fb5ab55SEnrico Granata .SetHideName(use_objc) 1859fb5ab55SEnrico Granata .SetHideValue(use_objc); 1869fb5ab55SEnrico Granata 1879fb5ab55SEnrico Granata if (be_raw) 1889fb5ab55SEnrico Granata options.SetRawDisplay(true); 1899fb5ab55SEnrico Granata 190*0f883ffbSEnrico Granata options.SetRunValidator(run_validator); 191*0f883ffbSEnrico Granata 1929fb5ab55SEnrico Granata return options; 1939fb5ab55SEnrico Granata } 194