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 #include "lldb/DataFormatters/ValueObjectPrinter.h" 13 #include "lldb/Host/OptionParser.h" 14 #include "lldb/Interpreter/CommandInterpreter.h" 15 #include "lldb/Interpreter/OptionArgParser.h" 16 #include "lldb/Target/Target.h" 17 18 #include "llvm/ADT/ArrayRef.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {} 24 25 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {} 26 27 static const OptionDefinition g_option_table[] = { 28 {LLDB_OPT_SET_1, false, "dynamic-type", 'd', 29 OptionParser::eRequiredArgument, nullptr, GetDynamicValueTypes(), 0, 30 eArgTypeNone, "Show the object as its full dynamic type, not its static " 31 "type, if available."}, 32 {LLDB_OPT_SET_1, false, "synthetic-type", 'S', 33 OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, 34 "Show the object obeying its synthetic provider, if available."}, 35 {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, 36 nullptr, {}, 0, eArgTypeCount, "Set the max recurse depth when dumping " 37 "aggregate types (default is infinity)."}, 38 {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr, 39 {}, 0, eArgTypeNone, "Display results in a flat format that uses " 40 "expression paths for each variable or member."}, 41 {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, 42 {}, 0, eArgTypeNone, "Show variable location information."}, 43 {LLDB_OPT_SET_1, false, "object-description", 'O', 44 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, 45 "Print as an Objective-C object."}, 46 {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, 47 nullptr, {}, 0, eArgTypeCount, "The number of pointers to be traversed " 48 "when dumping values (default is zero)."}, 49 {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, 50 nullptr, {}, 0, eArgTypeNone, 51 "Show variable types when dumping values."}, 52 {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', 53 OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeCount, 54 "Set the depth at which omitting summary information stops (default is " 55 "1)."}, 56 {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, 57 nullptr, {}, 0, eArgTypeNone, "Don't use formatting options."}, 58 {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, 59 nullptr, {}, 0, eArgTypeNone, 60 "Ignore the upper bound on the number of children to show."}, 61 {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, 62 nullptr, {}, 0, eArgTypeBoolean, "Show results of type validators."}, 63 {LLDB_OPT_SET_1, false, "element-count", 'Z', 64 OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount, 65 "Treat the result of the expression as if its type is an array of this " 66 "many values."}}; 67 68 llvm::ArrayRef<OptionDefinition> 69 OptionGroupValueObjectDisplay::GetDefinitions() { 70 return llvm::makeArrayRef(g_option_table); 71 } 72 73 Status OptionGroupValueObjectDisplay::SetOptionValue( 74 uint32_t option_idx, llvm::StringRef option_arg, 75 ExecutionContext *execution_context) { 76 Status error; 77 const int short_option = g_option_table[option_idx].short_option; 78 bool success = false; 79 80 switch (short_option) { 81 case 'd': { 82 int32_t result; 83 result = OptionArgParser::ToOptionEnum(option_arg, GetDynamicValueTypes(), 84 2, error); 85 if (error.Success()) 86 use_dynamic = (lldb::DynamicValueType)result; 87 } break; 88 case 'T': 89 show_types = true; 90 break; 91 case 'L': 92 show_location = true; 93 break; 94 case 'F': 95 flat_output = true; 96 break; 97 case 'O': 98 use_objc = true; 99 break; 100 case 'R': 101 be_raw = true; 102 break; 103 case 'A': 104 ignore_cap = true; 105 break; 106 107 case 'D': 108 if (option_arg.getAsInteger(0, max_depth)) { 109 max_depth = UINT32_MAX; 110 error.SetErrorStringWithFormat("invalid max depth '%s'", 111 option_arg.str().c_str()); 112 } 113 break; 114 115 case 'Z': 116 if (option_arg.getAsInteger(0, elem_count)) { 117 elem_count = UINT32_MAX; 118 error.SetErrorStringWithFormat("invalid element count '%s'", 119 option_arg.str().c_str()); 120 } 121 break; 122 123 case 'P': 124 if (option_arg.getAsInteger(0, ptr_depth)) { 125 ptr_depth = 0; 126 error.SetErrorStringWithFormat("invalid pointer depth '%s'", 127 option_arg.str().c_str()); 128 } 129 break; 130 131 case 'Y': 132 if (option_arg.empty()) 133 no_summary_depth = 1; 134 else if (option_arg.getAsInteger(0, no_summary_depth)) { 135 no_summary_depth = 0; 136 error.SetErrorStringWithFormat("invalid pointer depth '%s'", 137 option_arg.str().c_str()); 138 } 139 break; 140 141 case 'S': 142 use_synth = OptionArgParser::ToBoolean(option_arg, true, &success); 143 if (!success) 144 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", 145 option_arg.str().c_str()); 146 break; 147 148 case 'V': 149 run_validator = OptionArgParser::ToBoolean(option_arg, true, &success); 150 if (!success) 151 error.SetErrorStringWithFormat("invalid validate '%s'", 152 option_arg.str().c_str()); 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