blob: 52d05658831a410bd7989379351382b0dc2ba83a [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(
80 uint32_t option_idx, const char *option_arg,
81 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
Zachary Turnerecbb0bb2016-09-19 17:54:06 +000086 auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg);
87
Kate Stoneb9c1b512016-09-06 20:57:50 +000088 switch (short_option) {
89 case 'd': {
90 int32_t result;
91 result =
92 Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error);
93 if (error.Success())
94 use_dynamic = (lldb::DynamicValueType)result;
95 } break;
96 case 'T':
97 show_types = true;
98 break;
99 case 'L':
100 show_location = true;
101 break;
102 case 'F':
103 flat_output = true;
104 break;
105 case 'O':
106 use_objc = true;
107 break;
108 case 'R':
109 be_raw = true;
110 break;
111 case 'A':
112 ignore_cap = true;
113 break;
114
115 case 'D':
116 max_depth = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success);
117 if (!success)
118 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg);
119 break;
120
121 case 'Z':
122 elem_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0, &success);
123 if (!success)
124 error.SetErrorStringWithFormat("invalid element count '%s'", option_arg);
125 break;
126
127 case 'P':
128 ptr_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success);
129 if (!success)
130 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
131 break;
132
133 case 'Y':
134 if (option_arg) {
135 no_summary_depth = StringConvert::ToUInt32(option_arg, 0, 0, &success);
136 if (!success)
137 error.SetErrorStringWithFormat("invalid pointer depth '%s'",
138 option_arg);
139 } else
140 no_summary_depth = 1;
141 break;
142
143 case 'S':
Zachary Turnerecbb0bb2016-09-19 17:54:06 +0000144 use_synth = Args::StringToBoolean(option_strref, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000145 if (!success)
146 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
147 break;
148
149 case 'V':
Zachary Turnerecbb0bb2016-09-19 17:54:06 +0000150 run_validator = Args::StringToBoolean(option_strref, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151 if (!success)
152 error.SetErrorStringWithFormat("invalid validate '%s'", option_arg);
153 break;
154
155 default:
156 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
157 break;
158 }
159
160 return error;
Greg Clayton84c39662011-04-27 22:04:39 +0000161}
162
Kate Stoneb9c1b512016-09-06 20:57:50 +0000163void OptionGroupValueObjectDisplay::OptionParsingStarting(
164 ExecutionContext *execution_context) {
165 // If these defaults change, be sure to modify AnyOptionWasSet().
166 show_types = false;
167 no_summary_depth = 0;
168 show_location = false;
169 flat_output = false;
170 use_objc = false;
171 max_depth = UINT32_MAX;
172 ptr_depth = 0;
173 elem_count = 0;
174 use_synth = true;
175 be_raw = false;
176 ignore_cap = false;
177 run_validator = false;
178
179 TargetSP target_sp =
180 execution_context ? execution_context->GetTargetSP() : TargetSP();
181 if (target_sp)
182 use_dynamic = target_sp->GetPreferDynamicValue();
183 else {
184 // If we don't have any targets, then dynamic values won't do us much good.
185 use_dynamic = lldb::eNoDynamicValues;
186 }
Greg Clayton84c39662011-04-27 22:04:39 +0000187}
188
Kate Stoneb9c1b512016-09-06 20:57:50 +0000189DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
190 LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
191 lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
192 DumpValueObjectOptions options;
193 options.SetMaximumPointerDepth(
194 {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
195 if (use_objc)
196 options.SetShowSummary(false);
197 else
198 options.SetOmitSummaryDepth(no_summary_depth);
199 options.SetMaximumDepth(max_depth)
200 .SetShowTypes(show_types)
201 .SetShowLocation(show_location)
202 .SetUseObjectiveC(use_objc)
203 .SetUseDynamicType(use_dynamic)
204 .SetUseSyntheticValue(use_synth)
205 .SetFlatOutput(flat_output)
206 .SetIgnoreCap(ignore_cap)
207 .SetFormat(format)
208 .SetSummary(summary_sp);
Greg Clayton84c39662011-04-27 22:04:39 +0000209
Kate Stoneb9c1b512016-09-06 20:57:50 +0000210 if (lang_descr_verbosity ==
211 eLanguageRuntimeDescriptionDisplayVerbosityCompact)
212 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
213 use_objc);
Greg Clayton84c39662011-04-27 22:04:39 +0000214
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215 if (be_raw)
216 options.SetRawDisplay();
Enrico Granata520a4222016-04-25 00:52:47 +0000217
Kate Stoneb9c1b512016-09-06 20:57:50 +0000218 options.SetRunValidator(run_validator);
Greg Clayton84c39662011-04-27 22:04:39 +0000219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 options.SetElementCount(elem_count);
Greg Clayton84c39662011-04-27 22:04:39 +0000221
Kate Stoneb9c1b512016-09-06 20:57:50 +0000222 return options;
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000223}