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