Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 4bee32e | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 10 | #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 16 | #include "lldb/DataFormatters/ValueObjectPrinter.h" |
Zachary Turner | 3eb2b44 | 2017-03-22 23:33:16 +0000 | [diff] [blame] | 17 | #include "lldb/Host/OptionParser.h" |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandInterpreter.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Target.h" |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 20 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/ArrayRef.h" |
| 22 | |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 " |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 71 | "many values."}}; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 73 | llvm::ArrayRef<OptionDefinition> |
| 74 | OptionGroupValueObjectDisplay::GetDefinitions() { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 75 | return llvm::makeArrayRef(g_option_table); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | Error OptionGroupValueObjectDisplay::SetOptionValue( |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 79 | uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | ExecutionContext *execution_context) { |
| 81 | Error error; |
| 82 | const int short_option = g_option_table[option_idx].short_option; |
| 83 | bool success = false; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 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 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | break; |
| 119 | |
| 120 | case 'Z': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 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 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | break; |
| 127 | |
| 128 | case 'P': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 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 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 134 | break; |
| 135 | |
| 136 | case 'Y': |
Zachary Turner | 2f13958 | 2016-09-23 18:11:03 +0000 | [diff] [blame] | 137 | if (option_arg.empty()) |
| 138 | no_summary_depth = 1; |
| 139 | else if (option_arg.getAsInteger(0, no_summary_depth)) { |
Zachary Turner | 16b3913 | 2016-09-23 18:13:18 +0000 | [diff] [blame] | 140 | no_summary_depth = 0; |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 141 | error.SetErrorStringWithFormat("invalid pointer depth '%s'", |
| 142 | option_arg.str().c_str()); |
| 143 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | break; |
| 145 | |
| 146 | case 'S': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 147 | use_synth = Args::StringToBoolean(option_arg, true, &success); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | if (!success) |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 149 | error.SetErrorStringWithFormat("invalid synthetic-type '%s'", |
| 150 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 151 | break; |
| 152 | |
| 153 | case 'V': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 154 | run_validator = Args::StringToBoolean(option_arg, true, &success); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 155 | if (!success) |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 156 | error.SetErrorStringWithFormat("invalid validate '%s'", |
| 157 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | break; |
| 159 | |
| 160 | default: |
| 161 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 162 | break; |
| 163 | } |
| 164 | |
| 165 | return error; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 | } |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 214 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 215 | if (lang_descr_verbosity == |
| 216 | eLanguageRuntimeDescriptionDisplayVerbosityCompact) |
| 217 | options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue( |
| 218 | use_objc); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | if (be_raw) |
| 221 | options.SetRawDisplay(); |
Enrico Granata | 520a422 | 2016-04-25 00:52:47 +0000 | [diff] [blame] | 222 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 223 | options.SetRunValidator(run_validator); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 224 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 225 | options.SetElementCount(elem_count); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 226 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 227 | return options; |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 228 | } |