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/Target/Target.h" |
| 19 | #include "lldb/Interpreter/CommandInterpreter.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 | |
| 25 | OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay () |
| 30 | { |
| 31 | } |
| 32 | |
Greg Clayton | 68ebae6 | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 33 | static OptionDefinition |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 34 | g_option_table[] = |
| 35 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 36 | { LLDB_OPT_SET_1, false, "dynamic-type", 'd', OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0, eArgTypeNone, "Show the object as its full dynamic type, not its static type, if available."}, |
| 37 | { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, |
| 38 | { LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."}, |
| 39 | { LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."}, |
| 40 | { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable location information."}, |
| 41 | { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print as an Objective-C object."}, |
| 42 | { LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."}, |
| 43 | { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable types when dumping values."}, |
| 44 | { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is 1)."}, |
| 45 | { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."}, |
| 46 | { LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Ignore the upper bound on the number of children to show."}, |
Enrico Granata | 0f883ff | 2014-09-06 02:20:19 +0000 | [diff] [blame] | 47 | { LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."}, |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 48 | { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 51 | uint32_t |
| 52 | OptionGroupValueObjectDisplay::GetNumDefinitions () |
| 53 | { |
Johnny Chen | 6ebc8c45 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 54 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | const OptionDefinition * |
| 58 | OptionGroupValueObjectDisplay::GetDefinitions () |
| 59 | { |
| 60 | return g_option_table; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | Error |
| 65 | OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter, |
| 66 | uint32_t option_idx, |
| 67 | const char *option_arg) |
| 68 | { |
| 69 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 70 | const int short_option = g_option_table[option_idx].short_option; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 71 | bool success = false; |
| 72 | |
| 73 | switch (short_option) |
| 74 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 75 | case 'd': |
| 76 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 77 | int32_t result; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 78 | result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error); |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 79 | if (error.Success()) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 80 | use_dynamic = (lldb::DynamicValueType) result; |
| 81 | } |
| 82 | break; |
Greg Clayton | 68ebae6 | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 83 | case 'T': show_types = true; break; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 84 | case 'L': show_location= true; break; |
| 85 | case 'F': flat_output = true; break; |
Enrico Granata | ce68b02 | 2011-08-09 23:50:01 +0000 | [diff] [blame] | 86 | case 'O': use_objc = true; break; |
| 87 | case 'R': be_raw = true; break; |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 88 | case 'A': ignore_cap = true; break; |
Enrico Granata | ce68b02 | 2011-08-09 23:50:01 +0000 | [diff] [blame] | 89 | |
Greg Clayton | 68ebae6 | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 90 | case 'D': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 91 | max_depth = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0, &success); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 92 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 93 | error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 94 | break; |
| 95 | |
Greg Clayton | 68ebae6 | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 96 | case 'P': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 97 | ptr_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 98 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 99 | error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 100 | break; |
| 101 | |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 102 | case 'Y': |
| 103 | if (option_arg) |
| 104 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 105 | no_summary_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success); |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 106 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 107 | error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 108 | } |
| 109 | else |
| 110 | no_summary_depth = 1; |
| 111 | break; |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 112 | |
| 113 | case 'S': |
| 114 | use_synth = Args::StringToBoolean(option_arg, true, &success); |
| 115 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 116 | error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 117 | break; |
Enrico Granata | 0f883ff | 2014-09-06 02:20:19 +0000 | [diff] [blame] | 118 | |
| 119 | case 'V': |
| 120 | run_validator = Args::StringToBoolean(option_arg, true, &success); |
| 121 | if (!success) |
| 122 | error.SetErrorStringWithFormat("invalid validate '%s'", option_arg); |
| 123 | break; |
| 124 | |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 125 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 126 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 127 | break; |
| 128 | } |
| 129 | |
| 130 | return error; |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter) |
| 135 | { |
Greg Clayton | 82f4cf4 | 2011-10-26 04:32:38 +0000 | [diff] [blame] | 136 | // If these defaults change, be sure to modify AnyOptionWasSet(). |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 137 | show_types = false; |
| 138 | no_summary_depth = 0; |
| 139 | show_location = false; |
| 140 | flat_output = false; |
| 141 | use_objc = false; |
| 142 | max_depth = UINT32_MAX; |
| 143 | ptr_depth = 0; |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 144 | use_synth = true; |
Enrico Granata | ce68b02 | 2011-08-09 23:50:01 +0000 | [diff] [blame] | 145 | be_raw = false; |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 146 | ignore_cap = false; |
Enrico Granata | 0f883ff | 2014-09-06 02:20:19 +0000 | [diff] [blame] | 147 | run_validator = false; |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 148 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 149 | Target *target = interpreter.GetExecutionContext().GetTargetPtr(); |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 150 | if (target != nullptr) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 151 | use_dynamic = target->GetPreferDynamicValue(); |
| 152 | else |
| 153 | { |
| 154 | // If we don't have any targets, then dynamic values won't do us much good. |
| 155 | use_dynamic = lldb::eNoDynamicValues; |
| 156 | } |
Johnny Chen | 4bee32e | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 157 | } |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 158 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 159 | DumpValueObjectOptions |
| 160 | OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 161 | lldb::Format format, |
| 162 | lldb::TypeSummaryImplSP summary_sp) |
| 163 | { |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 164 | DumpValueObjectOptions options; |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 165 | options.SetMaximumPointerDepth( {DumpValueObjectOptions::PointerDepth::Mode::Always,ptr_depth} ); |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 166 | if (use_objc) |
| 167 | options.SetShowSummary(false); |
| 168 | else |
| 169 | options.SetOmitSummaryDepth(no_summary_depth); |
| 170 | options.SetMaximumDepth(max_depth) |
| 171 | .SetShowTypes(show_types) |
| 172 | .SetShowLocation(show_location) |
| 173 | .SetUseObjectiveC(use_objc) |
| 174 | .SetUseDynamicType(use_dynamic) |
| 175 | .SetUseSyntheticValue(use_synth) |
| 176 | .SetFlatOutput(flat_output) |
| 177 | .SetIgnoreCap(ignore_cap) |
| 178 | .SetFormat(format) |
| 179 | .SetSummary(summary_sp); |
| 180 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 181 | if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 182 | options.SetHideRootType(use_objc) |
| 183 | .SetHideName(use_objc) |
| 184 | .SetHideValue(use_objc); |
| 185 | |
| 186 | if (be_raw) |
Enrico Granata | a126e46 | 2014-11-21 18:47:26 +0000 | [diff] [blame] | 187 | options.SetRawDisplay(); |
Enrico Granata | 0f883ff | 2014-09-06 02:20:19 +0000 | [diff] [blame] | 188 | |
| 189 | options.SetRunValidator(run_validator); |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 190 | |
| 191 | return options; |
| 192 | } |