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/Interpreter/CommandInterpreter.h" 19 #include "lldb/Target/Target.h" 20 #include "lldb/Utility/Utils.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {} 26 27 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {} 28 29 static OptionDefinition g_option_table[] = { 30 {LLDB_OPT_SET_1, false, "dynamic-type", 'd', 31 OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0, 32 eArgTypeNone, "Show the object as its full dynamic type, not its static " 33 "type, if available."}, 34 {LLDB_OPT_SET_1, false, "synthetic-type", 'S', 35 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, 36 "Show the object obeying its synthetic provider, if available."}, 37 {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, 38 nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when " 39 "dumping aggregate types (default is " 40 "infinity)."}, 41 {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr, 42 nullptr, 0, eArgTypeNone, "Display results in a flat format that uses " 43 "expression paths for each variable or member."}, 44 {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, 45 nullptr, 0, eArgTypeNone, "Show variable location information."}, 46 {LLDB_OPT_SET_1, false, "object-description", 'O', 47 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 48 "Print as an Objective-C object."}, 49 {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, 50 nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be " 51 "traversed when dumping values " 52 "(default is zero)."}, 53 {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, 54 nullptr, nullptr, 0, eArgTypeNone, 55 "Show variable types when dumping values."}, 56 {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', 57 OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount, 58 "Set the depth at which omitting summary information stops (default is " 59 "1)."}, 60 {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, 61 nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."}, 62 {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, 63 nullptr, nullptr, 0, eArgTypeNone, 64 "Ignore the upper bound on the number of children to show."}, 65 {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, 66 nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."}, 67 {LLDB_OPT_SET_1, false, "element-count", 'Z', 68 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, 69 "Treat the result of the expression as if its type is an array of this " 70 "many values."}, 71 {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; 72 73 uint32_t OptionGroupValueObjectDisplay::GetNumDefinitions() { 74 return llvm::array_lengthof(g_option_table); 75 } 76 77 const OptionDefinition *OptionGroupValueObjectDisplay::GetDefinitions() { 78 return g_option_table; 79 } 80 81 Error OptionGroupValueObjectDisplay::SetOptionValue( 82 uint32_t option_idx, const char *option_arg, 83 ExecutionContext *execution_context) { 84 Error error; 85 const int short_option = g_option_table[option_idx].short_option; 86 bool success = false; 87 88 switch (short_option) { 89 case 'd': { 90 int32_t result; 91 result = 92 Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error); 93 if (error.Success()) 94 use_dynamic = (lldb::DynamicValueType)result; 95 } break; 96 case 'T': 97 show_types = true; 98 break; 99 case 'L': 100 show_location = true; 101 break; 102 case 'F': 103 flat_output = true; 104 break; 105 case 'O': 106 use_objc = true; 107 break; 108 case 'R': 109 be_raw = true; 110 break; 111 case 'A': 112 ignore_cap = true; 113 break; 114 115 case 'D': 116 max_depth = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success); 117 if (!success) 118 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg); 119 break; 120 121 case 'Z': 122 elem_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success); 123 if (!success) 124 error.SetErrorStringWithFormat("invalid element count '%s'", option_arg); 125 break; 126 127 case 'P': 128 ptr_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success); 129 if (!success) 130 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 131 break; 132 133 case 'Y': 134 if (option_arg) { 135 no_summary_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success); 136 if (!success) 137 error.SetErrorStringWithFormat("invalid pointer depth '%s'", 138 option_arg); 139 } else 140 no_summary_depth = 1; 141 break; 142 143 case 'S': 144 use_synth = Args::StringToBoolean(option_arg, true, &success); 145 if (!success) 146 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); 147 break; 148 149 case 'V': 150 run_validator = Args::StringToBoolean(option_arg, true, &success); 151 if (!success) 152 error.SetErrorStringWithFormat("invalid validate '%s'", option_arg); 153 break; 154 155 default: 156 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); 157 break; 158 } 159 160 return error; 161 } 162 163 void OptionGroupValueObjectDisplay::OptionParsingStarting( 164 ExecutionContext *execution_context) { 165 // If these defaults change, be sure to modify AnyOptionWasSet(). 166 show_types = false; 167 no_summary_depth = 0; 168 show_location = false; 169 flat_output = false; 170 use_objc = false; 171 max_depth = UINT32_MAX; 172 ptr_depth = 0; 173 elem_count = 0; 174 use_synth = true; 175 be_raw = false; 176 ignore_cap = false; 177 run_validator = false; 178 179 TargetSP target_sp = 180 execution_context ? execution_context->GetTargetSP() : TargetSP(); 181 if (target_sp) 182 use_dynamic = target_sp->GetPreferDynamicValue(); 183 else { 184 // If we don't have any targets, then dynamic values won't do us much good. 185 use_dynamic = lldb::eNoDynamicValues; 186 } 187 } 188 189 DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions( 190 LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, 191 lldb::Format format, lldb::TypeSummaryImplSP summary_sp) { 192 DumpValueObjectOptions options; 193 options.SetMaximumPointerDepth( 194 {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth}); 195 if (use_objc) 196 options.SetShowSummary(false); 197 else 198 options.SetOmitSummaryDepth(no_summary_depth); 199 options.SetMaximumDepth(max_depth) 200 .SetShowTypes(show_types) 201 .SetShowLocation(show_location) 202 .SetUseObjectiveC(use_objc) 203 .SetUseDynamicType(use_dynamic) 204 .SetUseSyntheticValue(use_synth) 205 .SetFlatOutput(flat_output) 206 .SetIgnoreCap(ignore_cap) 207 .SetFormat(format) 208 .SetSummary(summary_sp); 209 210 if (lang_descr_verbosity == 211 eLanguageRuntimeDescriptionDisplayVerbosityCompact) 212 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue( 213 use_objc); 214 215 if (be_raw) 216 options.SetRawDisplay(); 217 218 options.SetRunValidator(run_validator); 219 220 options.SetElementCount(elem_count); 221 222 return options; 223 } 224