blob: 89acf3f0d3f92721d972a26e9e53cb0fdf226593 [file] [log] [blame]
Greg Clayton84c39662011-04-27 22:04:39 +00001//===-- 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 Chen4bee32e2011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton84c39662011-04-27 22:04:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Enrico Granata4d93b8c2013-09-30 19:11:51 +000016#include "lldb/DataFormatters/ValueObjectPrinter.h"
Zachary Turner3eb2b442017-03-22 23:33:16 +000017#include "lldb/Host/OptionParser.h"
Jim Ingham2837b762011-05-04 03:43:18 +000018#include "lldb/Interpreter/CommandInterpreter.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000019#include "lldb/Target/Target.h"
Greg Clayton84c39662011-04-27 22:04:39 +000020
Zachary Turner1f0f5b52016-09-22 20:22:55 +000021#include "llvm/ADT/ArrayRef.h"
22
Greg Clayton84c39662011-04-27 22:04:39 +000023using namespace lldb;
24using namespace lldb_private;
25
Kate Stoneb9c1b512016-09-06 20:57:50 +000026OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
27
28OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
29
30static 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 Turner1f0f5b52016-09-22 20:22:55 +000071 "many values."}};
Kate Stoneb9c1b512016-09-06 20:57:50 +000072
Zachary Turner1f0f5b52016-09-22 20:22:55 +000073llvm::ArrayRef<OptionDefinition>
74OptionGroupValueObjectDisplay::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +000075 return llvm::makeArrayRef(g_option_table);
Greg Clayton84c39662011-04-27 22:04:39 +000076}
77
Kate Stoneb9c1b512016-09-06 20:57:50 +000078Error OptionGroupValueObjectDisplay::SetOptionValue(
Zachary Turner8cef4b02016-09-23 17:48:13 +000079 uint32_t option_idx, llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 ExecutionContext *execution_context) {
81 Error error;
82 const int short_option = g_option_table[option_idx].short_option;
83 bool success = false;
Greg Clayton84c39662011-04-27 22:04:39 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 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 Turner8cef4b02016-09-23 17:48:13 +0000113 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 Stoneb9c1b512016-09-06 20:57:50 +0000118 break;
119
120 case 'Z':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000121 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 Stoneb9c1b512016-09-06 20:57:50 +0000126 break;
127
128 case 'P':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000129 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 Stoneb9c1b512016-09-06 20:57:50 +0000134 break;
135
136 case 'Y':
Zachary Turner2f139582016-09-23 18:11:03 +0000137 if (option_arg.empty())
138 no_summary_depth = 1;
139 else if (option_arg.getAsInteger(0, no_summary_depth)) {
Zachary Turner16b39132016-09-23 18:13:18 +0000140 no_summary_depth = 0;
Zachary Turner8cef4b02016-09-23 17:48:13 +0000141 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
142 option_arg.str().c_str());
143 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144 break;
145
146 case 'S':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000147 use_synth = Args::StringToBoolean(option_arg, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148 if (!success)
Zachary Turner8cef4b02016-09-23 17:48:13 +0000149 error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
150 option_arg.str().c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151 break;
152
153 case 'V':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000154 run_validator = Args::StringToBoolean(option_arg, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155 if (!success)
Zachary Turner8cef4b02016-09-23 17:48:13 +0000156 error.SetErrorStringWithFormat("invalid validate '%s'",
157 option_arg.str().c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158 break;
159
160 default:
161 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
162 break;
163 }
164
165 return error;
Greg Clayton84c39662011-04-27 22:04:39 +0000166}
167
Kate Stoneb9c1b512016-09-06 20:57:50 +0000168void 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 Clayton84c39662011-04-27 22:04:39 +0000192}
193
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194DumpValueObjectOptions 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 Clayton84c39662011-04-27 22:04:39 +0000214
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215 if (lang_descr_verbosity ==
216 eLanguageRuntimeDescriptionDisplayVerbosityCompact)
217 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
218 use_objc);
Greg Clayton84c39662011-04-27 22:04:39 +0000219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 if (be_raw)
221 options.SetRawDisplay();
Enrico Granata520a4222016-04-25 00:52:47 +0000222
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223 options.SetRunValidator(run_validator);
Greg Clayton84c39662011-04-27 22:04:39 +0000224
Kate Stoneb9c1b512016-09-06 20:57:50 +0000225 options.SetElementCount(elem_count);
Greg Clayton84c39662011-04-27 22:04:39 +0000226
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227 return options;
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000228}