blob: 96190e56792d1c1d419d6b9e335ca30b055e62eb [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"
Vince Harron5275aaa2015-01-15 20:08:35 +000017#include "lldb/Host/StringConvert.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"
Johnny Chen7c575b32011-09-10 00:48:33 +000020#include "lldb/Utility/Utils.h"
Greg Clayton84c39662011-04-27 22:04:39 +000021
Zachary Turner1f0f5b52016-09-22 20:22:55 +000022#include "llvm/ADT/ArrayRef.h"
23
Greg Clayton84c39662011-04-27 22:04:39 +000024using namespace lldb;
25using namespace lldb_private;
26
Kate Stoneb9c1b512016-09-06 20:57:50 +000027OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
28
29OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
30
31static OptionDefinition g_option_table[] = {
32 {LLDB_OPT_SET_1, false, "dynamic-type", 'd',
33 OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0,
34 eArgTypeNone, "Show the object as its full dynamic type, not its static "
35 "type, if available."},
36 {LLDB_OPT_SET_1, false, "synthetic-type", 'S',
37 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
38 "Show the object obeying its synthetic provider, if available."},
39 {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,
40 nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when "
41 "dumping aggregate types (default is "
42 "infinity)."},
43 {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,
44 nullptr, 0, eArgTypeNone, "Display results in a flat format that uses "
45 "expression paths for each variable or member."},
46 {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,
47 nullptr, 0, eArgTypeNone, "Show variable location information."},
48 {LLDB_OPT_SET_1, false, "object-description", 'O',
49 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
50 "Print as an Objective-C object."},
51 {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,
52 nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be "
53 "traversed when dumping values "
54 "(default is zero)."},
55 {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,
56 nullptr, nullptr, 0, eArgTypeNone,
57 "Show variable types when dumping values."},
58 {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',
59 OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount,
60 "Set the depth at which omitting summary information stops (default is "
61 "1)."},
62 {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,
63 nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."},
64 {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,
65 nullptr, nullptr, 0, eArgTypeNone,
66 "Ignore the upper bound on the number of children to show."},
67 {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,
68 nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."},
69 {LLDB_OPT_SET_1, false, "element-count", 'Z',
70 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,
71 "Treat the result of the expression as if its type is an array of this "
Zachary Turner1f0f5b52016-09-22 20:22:55 +000072 "many values."}};
Kate Stoneb9c1b512016-09-06 20:57:50 +000073
Zachary Turner1f0f5b52016-09-22 20:22:55 +000074llvm::ArrayRef<OptionDefinition>
75OptionGroupValueObjectDisplay::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +000076 return llvm::makeArrayRef(g_option_table);
Greg Clayton84c39662011-04-27 22:04:39 +000077}
78
Kate Stoneb9c1b512016-09-06 20:57:50 +000079Error OptionGroupValueObjectDisplay::SetOptionValue(
Zachary Turner8cef4b02016-09-23 17:48:13 +000080 uint32_t option_idx, llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 ExecutionContext *execution_context) {
82 Error error;
83 const int short_option = g_option_table[option_idx].short_option;
84 bool success = false;
Greg Clayton84c39662011-04-27 22:04:39 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 switch (short_option) {
87 case 'd': {
88 int32_t result;
89 result =
90 Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error);
91 if (error.Success())
92 use_dynamic = (lldb::DynamicValueType)result;
93 } break;
94 case 'T':
95 show_types = true;
96 break;
97 case 'L':
98 show_location = true;
99 break;
100 case 'F':
101 flat_output = true;
102 break;
103 case 'O':
104 use_objc = true;
105 break;
106 case 'R':
107 be_raw = true;
108 break;
109 case 'A':
110 ignore_cap = true;
111 break;
112
113 case 'D':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000114 if (option_arg.getAsInteger(0, max_depth)) {
115 max_depth = UINT32_MAX;
116 error.SetErrorStringWithFormat("invalid max depth '%s'",
117 option_arg.str().c_str());
118 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119 break;
120
121 case 'Z':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000122 if (option_arg.getAsInteger(0, elem_count)) {
123 elem_count = UINT32_MAX;
124 error.SetErrorStringWithFormat("invalid element count '%s'",
125 option_arg.str().c_str());
126 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127 break;
128
129 case 'P':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000130 if (option_arg.getAsInteger(0, ptr_depth)) {
131 ptr_depth = 0;
132 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
133 option_arg.str().c_str());
134 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135 break;
136
137 case 'Y':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000138 if (option_arg.getAsInteger(0, no_summary_depth)) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139 no_summary_depth = 1;
Zachary Turner8cef4b02016-09-23 17:48:13 +0000140 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
141 option_arg.str().c_str());
142 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000143 break;
144
145 case 'S':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000146 use_synth = Args::StringToBoolean(option_arg, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000147 if (!success)
Zachary Turner8cef4b02016-09-23 17:48:13 +0000148 error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
149 option_arg.str().c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150 break;
151
152 case 'V':
Zachary Turner8cef4b02016-09-23 17:48:13 +0000153 run_validator = Args::StringToBoolean(option_arg, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154 if (!success)
Zachary Turner8cef4b02016-09-23 17:48:13 +0000155 error.SetErrorStringWithFormat("invalid validate '%s'",
156 option_arg.str().c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157 break;
158
159 default:
160 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
161 break;
162 }
163
164 return error;
Greg Clayton84c39662011-04-27 22:04:39 +0000165}
166
Kate Stoneb9c1b512016-09-06 20:57:50 +0000167void OptionGroupValueObjectDisplay::OptionParsingStarting(
168 ExecutionContext *execution_context) {
169 // If these defaults change, be sure to modify AnyOptionWasSet().
170 show_types = false;
171 no_summary_depth = 0;
172 show_location = false;
173 flat_output = false;
174 use_objc = false;
175 max_depth = UINT32_MAX;
176 ptr_depth = 0;
177 elem_count = 0;
178 use_synth = true;
179 be_raw = false;
180 ignore_cap = false;
181 run_validator = false;
182
183 TargetSP target_sp =
184 execution_context ? execution_context->GetTargetSP() : TargetSP();
185 if (target_sp)
186 use_dynamic = target_sp->GetPreferDynamicValue();
187 else {
188 // If we don't have any targets, then dynamic values won't do us much good.
189 use_dynamic = lldb::eNoDynamicValues;
190 }
Greg Clayton84c39662011-04-27 22:04:39 +0000191}
192
Kate Stoneb9c1b512016-09-06 20:57:50 +0000193DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
194 LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
195 lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
196 DumpValueObjectOptions options;
197 options.SetMaximumPointerDepth(
198 {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
199 if (use_objc)
200 options.SetShowSummary(false);
201 else
202 options.SetOmitSummaryDepth(no_summary_depth);
203 options.SetMaximumDepth(max_depth)
204 .SetShowTypes(show_types)
205 .SetShowLocation(show_location)
206 .SetUseObjectiveC(use_objc)
207 .SetUseDynamicType(use_dynamic)
208 .SetUseSyntheticValue(use_synth)
209 .SetFlatOutput(flat_output)
210 .SetIgnoreCap(ignore_cap)
211 .SetFormat(format)
212 .SetSummary(summary_sp);
Greg Clayton84c39662011-04-27 22:04:39 +0000213
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214 if (lang_descr_verbosity ==
215 eLanguageRuntimeDescriptionDisplayVerbosityCompact)
216 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
217 use_objc);
Greg Clayton84c39662011-04-27 22:04:39 +0000218
Kate Stoneb9c1b512016-09-06 20:57:50 +0000219 if (be_raw)
220 options.SetRawDisplay();
Enrico Granata520a4222016-04-25 00:52:47 +0000221
Kate Stoneb9c1b512016-09-06 20:57:50 +0000222 options.SetRunValidator(run_validator);
Greg Clayton84c39662011-04-27 22:04:39 +0000223
Kate Stoneb9c1b512016-09-06 20:57:50 +0000224 options.SetElementCount(elem_count);
Greg Clayton84c39662011-04-27 22:04:39 +0000225
Kate Stoneb9c1b512016-09-06 20:57:50 +0000226 return options;
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000227}