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" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 17 | #include "lldb/Host/StringConvert.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" |
Johnny Chen | 7c575b3 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 20 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace lldb; |
| 23 | using namespace lldb_private; |
| 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | const OptionDefinition *OptionGroupValueObjectDisplay::GetDefinitions() { |
| 78 | return g_option_table; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 87 | |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame^] | 88 | auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); |
| 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | switch (short_option) { |
| 91 | case 'd': { |
| 92 | int32_t result; |
| 93 | result = |
| 94 | Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error); |
| 95 | if (error.Success()) |
| 96 | use_dynamic = (lldb::DynamicValueType)result; |
| 97 | } break; |
| 98 | case 'T': |
| 99 | show_types = true; |
| 100 | break; |
| 101 | case 'L': |
| 102 | show_location = true; |
| 103 | break; |
| 104 | case 'F': |
| 105 | flat_output = true; |
| 106 | break; |
| 107 | case 'O': |
| 108 | use_objc = true; |
| 109 | break; |
| 110 | case 'R': |
| 111 | be_raw = true; |
| 112 | break; |
| 113 | case 'A': |
| 114 | ignore_cap = true; |
| 115 | break; |
| 116 | |
| 117 | case 'D': |
| 118 | max_depth = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success); |
| 119 | if (!success) |
| 120 | error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg); |
| 121 | break; |
| 122 | |
| 123 | case 'Z': |
| 124 | elem_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success); |
| 125 | if (!success) |
| 126 | error.SetErrorStringWithFormat("invalid element count '%s'", option_arg); |
| 127 | break; |
| 128 | |
| 129 | case 'P': |
| 130 | ptr_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success); |
| 131 | if (!success) |
| 132 | error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); |
| 133 | break; |
| 134 | |
| 135 | case 'Y': |
| 136 | if (option_arg) { |
| 137 | no_summary_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success); |
| 138 | if (!success) |
| 139 | error.SetErrorStringWithFormat("invalid pointer depth '%s'", |
| 140 | option_arg); |
| 141 | } else |
| 142 | no_summary_depth = 1; |
| 143 | break; |
| 144 | |
| 145 | case 'S': |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame^] | 146 | use_synth = Args::StringToBoolean(option_strref, true, &success); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 147 | if (!success) |
| 148 | error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); |
| 149 | break; |
| 150 | |
| 151 | case 'V': |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame^] | 152 | run_validator = Args::StringToBoolean(option_strref, true, &success); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | if (!success) |
| 154 | error.SetErrorStringWithFormat("invalid validate '%s'", option_arg); |
| 155 | break; |
| 156 | |
| 157 | default: |
| 158 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | return error; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | void OptionGroupValueObjectDisplay::OptionParsingStarting( |
| 166 | ExecutionContext *execution_context) { |
| 167 | // If these defaults change, be sure to modify AnyOptionWasSet(). |
| 168 | show_types = false; |
| 169 | no_summary_depth = 0; |
| 170 | show_location = false; |
| 171 | flat_output = false; |
| 172 | use_objc = false; |
| 173 | max_depth = UINT32_MAX; |
| 174 | ptr_depth = 0; |
| 175 | elem_count = 0; |
| 176 | use_synth = true; |
| 177 | be_raw = false; |
| 178 | ignore_cap = false; |
| 179 | run_validator = false; |
| 180 | |
| 181 | TargetSP target_sp = |
| 182 | execution_context ? execution_context->GetTargetSP() : TargetSP(); |
| 183 | if (target_sp) |
| 184 | use_dynamic = target_sp->GetPreferDynamicValue(); |
| 185 | else { |
| 186 | // If we don't have any targets, then dynamic values won't do us much good. |
| 187 | use_dynamic = lldb::eNoDynamicValues; |
| 188 | } |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 191 | DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions( |
| 192 | LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, |
| 193 | lldb::Format format, lldb::TypeSummaryImplSP summary_sp) { |
| 194 | DumpValueObjectOptions options; |
| 195 | options.SetMaximumPointerDepth( |
| 196 | {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth}); |
| 197 | if (use_objc) |
| 198 | options.SetShowSummary(false); |
| 199 | else |
| 200 | options.SetOmitSummaryDepth(no_summary_depth); |
| 201 | options.SetMaximumDepth(max_depth) |
| 202 | .SetShowTypes(show_types) |
| 203 | .SetShowLocation(show_location) |
| 204 | .SetUseObjectiveC(use_objc) |
| 205 | .SetUseDynamicType(use_dynamic) |
| 206 | .SetUseSyntheticValue(use_synth) |
| 207 | .SetFlatOutput(flat_output) |
| 208 | .SetIgnoreCap(ignore_cap) |
| 209 | .SetFormat(format) |
| 210 | .SetSummary(summary_sp); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 211 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 212 | if (lang_descr_verbosity == |
| 213 | eLanguageRuntimeDescriptionDisplayVerbosityCompact) |
| 214 | options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue( |
| 215 | use_objc); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 216 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 217 | if (be_raw) |
| 218 | options.SetRawDisplay(); |
Enrico Granata | 520a422 | 2016-04-25 00:52:47 +0000 | [diff] [blame] | 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | options.SetRunValidator(run_validator); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 221 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 222 | options.SetElementCount(elem_count); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 223 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 224 | return options; |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 225 | } |