1 //===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/DataFormatters/ValueObjectPrinter.h" 17 #include "lldb/Host/StringConvert.h" 18 #include "lldb/Target/Target.h" 19 #include "lldb/Interpreter/CommandInterpreter.h" 20 #include "lldb/Utility/Utils.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() 26 { 27 } 28 29 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay () 30 { 31 } 32 33 static OptionDefinition 34 g_option_table[] = 35 { 36 { 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."}, 37 { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, 38 { 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)."}, 39 { 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."}, 40 { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable location information."}, 41 { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print as an Objective-C object."}, 42 { 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)."}, 43 { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable types when dumping values."}, 44 { 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)."}, 45 { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."}, 46 { 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."}, 47 { LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."}, 48 { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 49 }; 50 51 uint32_t 52 OptionGroupValueObjectDisplay::GetNumDefinitions () 53 { 54 return llvm::array_lengthof(g_option_table); 55 } 56 57 const OptionDefinition * 58 OptionGroupValueObjectDisplay::GetDefinitions () 59 { 60 return g_option_table; 61 } 62 63 64 Error 65 OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter, 66 uint32_t option_idx, 67 const char *option_arg) 68 { 69 Error error; 70 const int short_option = g_option_table[option_idx].short_option; 71 bool success = false; 72 73 switch (short_option) 74 { 75 case 'd': 76 { 77 int32_t result; 78 result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error); 79 if (error.Success()) 80 use_dynamic = (lldb::DynamicValueType) result; 81 } 82 break; 83 case 'T': show_types = true; break; 84 case 'L': show_location= true; break; 85 case 'F': flat_output = true; break; 86 case 'O': use_objc = true; break; 87 case 'R': be_raw = true; break; 88 case 'A': ignore_cap = true; break; 89 90 case 'D': 91 max_depth = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0, &success); 92 if (!success) 93 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg); 94 break; 95 96 case 'P': 97 ptr_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success); 98 if (!success) 99 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 100 break; 101 102 case 'Y': 103 if (option_arg) 104 { 105 no_summary_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success); 106 if (!success) 107 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 108 } 109 else 110 no_summary_depth = 1; 111 break; 112 113 case 'S': 114 use_synth = Args::StringToBoolean(option_arg, true, &success); 115 if (!success) 116 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); 117 break; 118 119 case 'V': 120 run_validator = Args::StringToBoolean(option_arg, true, &success); 121 if (!success) 122 error.SetErrorStringWithFormat("invalid validate '%s'", option_arg); 123 break; 124 125 default: 126 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 127 break; 128 } 129 130 return error; 131 } 132 133 void 134 OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter) 135 { 136 // If these defaults change, be sure to modify AnyOptionWasSet(). 137 show_types = false; 138 no_summary_depth = 0; 139 show_location = false; 140 flat_output = false; 141 use_objc = false; 142 max_depth = UINT32_MAX; 143 ptr_depth = 0; 144 use_synth = true; 145 be_raw = false; 146 ignore_cap = false; 147 run_validator = false; 148 149 Target *target = interpreter.GetExecutionContext().GetTargetPtr(); 150 if (target != nullptr) 151 use_dynamic = target->GetPreferDynamicValue(); 152 else 153 { 154 // If we don't have any targets, then dynamic values won't do us much good. 155 use_dynamic = lldb::eNoDynamicValues; 156 } 157 } 158 159 DumpValueObjectOptions 160 OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, 161 lldb::Format format, 162 lldb::TypeSummaryImplSP summary_sp) 163 { 164 DumpValueObjectOptions options; 165 options.SetMaximumPointerDepth( {DumpValueObjectOptions::PointerDepth::Mode::Always,ptr_depth} ); 166 if (use_objc) 167 options.SetShowSummary(false); 168 else 169 options.SetOmitSummaryDepth(no_summary_depth); 170 options.SetMaximumDepth(max_depth) 171 .SetShowTypes(show_types) 172 .SetShowLocation(show_location) 173 .SetUseObjectiveC(use_objc) 174 .SetUseDynamicType(use_dynamic) 175 .SetUseSyntheticValue(use_synth) 176 .SetFlatOutput(flat_output) 177 .SetIgnoreCap(ignore_cap) 178 .SetFormat(format) 179 .SetSummary(summary_sp); 180 181 if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) 182 options.SetHideRootType(use_objc) 183 .SetHideName(use_objc) 184 .SetHideValue(use_objc); 185 186 if (be_raw) 187 options.SetRawDisplay(); 188 189 options.SetRunValidator(run_validator); 190 191 return options; 192 } 193