blob: e5943925e86c4fc3edf7847b7d1817d633637312 [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
22using namespace lldb;
23using namespace lldb_private;
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
26
27OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
28
29static 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
73uint32_t OptionGroupValueObjectDisplay::GetNumDefinitions() {
74 return llvm::array_lengthof(g_option_table);
Greg Clayton84c39662011-04-27 22:04:39 +000075}
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077const OptionDefinition *OptionGroupValueObjectDisplay::GetDefinitions() {
78 return g_option_table;
Greg Clayton84c39662011-04-27 22:04:39 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081Error 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 Clayton84c39662011-04-27 22:04:39 +000087
Zachary Turnerecbb0bb2016-09-19 17:54:06 +000088 auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg);
89
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 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 Turnerecbb0bb2016-09-19 17:54:06 +0000146 use_synth = Args::StringToBoolean(option_strref, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000147 if (!success)
148 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
149 break;
150
151 case 'V':
Zachary Turnerecbb0bb2016-09-19 17:54:06 +0000152 run_validator = Args::StringToBoolean(option_strref, true, &success);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 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 Clayton84c39662011-04-27 22:04:39 +0000163}
164
Kate Stoneb9c1b512016-09-06 20:57:50 +0000165void 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 Clayton84c39662011-04-27 22:04:39 +0000189}
190
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191DumpValueObjectOptions 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 Clayton84c39662011-04-27 22:04:39 +0000211
Kate Stoneb9c1b512016-09-06 20:57:50 +0000212 if (lang_descr_verbosity ==
213 eLanguageRuntimeDescriptionDisplayVerbosityCompact)
214 options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
215 use_objc);
Greg Clayton84c39662011-04-27 22:04:39 +0000216
Kate Stoneb9c1b512016-09-06 20:57:50 +0000217 if (be_raw)
218 options.SetRawDisplay();
Enrico Granata520a4222016-04-25 00:52:47 +0000219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 options.SetRunValidator(run_validator);
Greg Clayton84c39662011-04-27 22:04:39 +0000221
Kate Stoneb9c1b512016-09-06 20:57:50 +0000222 options.SetElementCount(elem_count);
Greg Clayton84c39662011-04-27 22:04:39 +0000223
Kate Stoneb9c1b512016-09-06 20:57:50 +0000224 return options;
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000225}