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