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 { 37*d37221dcSZachary 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."}, 38*d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, 39*d37221dcSZachary 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)."}, 40*d37221dcSZachary 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."}, 41*d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable location information."}, 42*d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print as an Objective-C object."}, 43*d37221dcSZachary 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)."}, 44*d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable types when dumping values."}, 45*d37221dcSZachary 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)."}, 46*d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."}, 47*d37221dcSZachary 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*d37221dcSZachary 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': 9184c39663SGreg Clayton max_depth = Args::StringToUInt32 (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': 9784c39663SGreg Clayton ptr_depth = Args::StringToUInt32 (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 { 1050c5ef693SEnrico Granata no_summary_depth = Args::StringToUInt32 (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; 11884c39663SGreg Clayton default: 11986edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 12084c39663SGreg Clayton break; 12184c39663SGreg Clayton } 12284c39663SGreg Clayton 12384c39663SGreg Clayton return error; 12484c39663SGreg Clayton } 12584c39663SGreg Clayton 12684c39663SGreg Clayton void 12784c39663SGreg Clayton OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter) 12884c39663SGreg Clayton { 12982f4cf46SGreg Clayton // If these defaults change, be sure to modify AnyOptionWasSet(). 13084c39663SGreg Clayton show_types = false; 1310c5ef693SEnrico Granata no_summary_depth = 0; 13284c39663SGreg Clayton show_location = false; 13384c39663SGreg Clayton flat_output = false; 13484c39663SGreg Clayton use_objc = false; 13584c39663SGreg Clayton max_depth = UINT32_MAX; 13684c39663SGreg Clayton ptr_depth = 0; 137d55546b2SEnrico Granata use_synth = true; 138ce68b02cSEnrico Granata be_raw = false; 13922c55d18SEnrico Granata ignore_cap = false; 14084c39663SGreg Clayton 141c14ee32dSGreg Clayton Target *target = interpreter.GetExecutionContext().GetTargetPtr(); 142d78c9576SEd Maste if (target != nullptr) 1432837b766SJim Ingham use_dynamic = target->GetPreferDynamicValue(); 1442837b766SJim Ingham else 1452837b766SJim Ingham { 1462837b766SJim Ingham // If we don't have any targets, then dynamic values won't do us much good. 1472837b766SJim Ingham use_dynamic = lldb::eNoDynamicValues; 1482837b766SJim Ingham } 1492837b766SJim Ingham } 1509fb5ab55SEnrico Granata 1514d93b8cdSEnrico Granata DumpValueObjectOptions 1524d93b8cdSEnrico Granata OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, 1539fb5ab55SEnrico Granata lldb::Format format, 1549fb5ab55SEnrico Granata lldb::TypeSummaryImplSP summary_sp) 1559fb5ab55SEnrico Granata { 1564d93b8cdSEnrico Granata DumpValueObjectOptions options; 1579fb5ab55SEnrico Granata options.SetMaximumPointerDepth(ptr_depth); 1589fb5ab55SEnrico Granata if (use_objc) 1599fb5ab55SEnrico Granata options.SetShowSummary(false); 1609fb5ab55SEnrico Granata else 1619fb5ab55SEnrico Granata options.SetOmitSummaryDepth(no_summary_depth); 1629fb5ab55SEnrico Granata options.SetMaximumDepth(max_depth) 1639fb5ab55SEnrico Granata .SetShowTypes(show_types) 1649fb5ab55SEnrico Granata .SetShowLocation(show_location) 1659fb5ab55SEnrico Granata .SetUseObjectiveC(use_objc) 1669fb5ab55SEnrico Granata .SetUseDynamicType(use_dynamic) 1679fb5ab55SEnrico Granata .SetUseSyntheticValue(use_synth) 1689fb5ab55SEnrico Granata .SetFlatOutput(flat_output) 1699fb5ab55SEnrico Granata .SetIgnoreCap(ignore_cap) 1709fb5ab55SEnrico Granata .SetFormat(format) 1719fb5ab55SEnrico Granata .SetSummary(summary_sp); 1729fb5ab55SEnrico Granata 1734d93b8cdSEnrico Granata if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) 1749fb5ab55SEnrico Granata options.SetHideRootType(use_objc) 1759fb5ab55SEnrico Granata .SetHideName(use_objc) 1769fb5ab55SEnrico Granata .SetHideValue(use_objc); 1779fb5ab55SEnrico Granata 1789fb5ab55SEnrico Granata if (be_raw) 1799fb5ab55SEnrico Granata options.SetRawDisplay(true); 1809fb5ab55SEnrico Granata 1819fb5ab55SEnrico Granata return options; 1829fb5ab55SEnrico Granata } 183