LLDB  mainline
OptionGroupValueObjectDisplay.cpp
Go to the documentation of this file.
1 //===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
12 #include "lldb/Host/OptionParser.h"
15 #include "lldb/Target/Target.h"
16 
17 #include "llvm/ADT/ArrayRef.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {}
23 
24 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {}
25 
26 static const OptionDefinition g_option_table[] = {
27  {LLDB_OPT_SET_1, false, "dynamic-type", 'd',
28  OptionParser::eRequiredArgument, nullptr, GetDynamicValueTypes(), 0,
29  eArgTypeNone, "Show the object as its full dynamic type, not its static "
30  "type, if available."},
31  {LLDB_OPT_SET_1, false, "synthetic-type", 'S',
32  OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean,
33  "Show the object obeying its synthetic provider, if available."},
34  {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument,
35  nullptr, {}, 0, eArgTypeCount, "Set the max recurse depth when dumping "
36  "aggregate types (default is infinity)."},
37  {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr,
38  {}, 0, eArgTypeNone, "Display results in a flat format that uses "
39  "expression paths for each variable or member."},
40  {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr,
41  {}, 0, eArgTypeNone, "Show variable location information."},
42  {LLDB_OPT_SET_1, false, "object-description", 'O',
43  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
44  "Print as an Objective-C object."},
45  {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument,
46  nullptr, {}, 0, eArgTypeCount, "The number of pointers to be traversed "
47  "when dumping values (default is zero)."},
48  {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument,
49  nullptr, {}, 0, eArgTypeNone,
50  "Show variable types when dumping values."},
51  {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y',
52  OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeCount,
53  "Set the depth at which omitting summary information stops (default is "
54  "1)."},
55  {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument,
56  nullptr, {}, 0, eArgTypeNone, "Don't use formatting options."},
57  {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument,
58  nullptr, {}, 0, eArgTypeNone,
59  "Ignore the upper bound on the number of children to show."},
60  {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument,
61  nullptr, {}, 0, eArgTypeBoolean, "Show results of type validators."},
62  {LLDB_OPT_SET_1, false, "element-count", 'Z',
63  OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount,
64  "Treat the result of the expression as if its type is an array of this "
65  "many values."}};
66 
67 llvm::ArrayRef<OptionDefinition>
68 OptionGroupValueObjectDisplay::GetDefinitions() {
69  return llvm::makeArrayRef(g_option_table);
70 }
71 
72 Status OptionGroupValueObjectDisplay::SetOptionValue(
73  uint32_t option_idx, llvm::StringRef option_arg,
74  ExecutionContext *execution_context) {
75  Status error;
76  const int short_option = g_option_table[option_idx].short_option;
77  bool success = false;
78 
79  switch (short_option) {
80  case 'd': {
81  int32_t result;
82  result = OptionArgParser::ToOptionEnum(option_arg, GetDynamicValueTypes(),
83  2, error);
84  if (error.Success())
85  use_dynamic = (lldb::DynamicValueType)result;
86  } break;
87  case 'T':
88  show_types = true;
89  break;
90  case 'L':
91  show_location = true;
92  break;
93  case 'F':
94  flat_output = true;
95  break;
96  case 'O':
97  use_objc = true;
98  break;
99  case 'R':
100  be_raw = true;
101  break;
102  case 'A':
103  ignore_cap = true;
104  break;
105 
106  case 'D':
107  if (option_arg.getAsInteger(0, max_depth)) {
108  max_depth = UINT32_MAX;
109  error.SetErrorStringWithFormat("invalid max depth '%s'",
110  option_arg.str().c_str());
111  }
112  break;
113 
114  case 'Z':
115  if (option_arg.getAsInteger(0, elem_count)) {
116  elem_count = UINT32_MAX;
117  error.SetErrorStringWithFormat("invalid element count '%s'",
118  option_arg.str().c_str());
119  }
120  break;
121 
122  case 'P':
123  if (option_arg.getAsInteger(0, ptr_depth)) {
124  ptr_depth = 0;
125  error.SetErrorStringWithFormat("invalid pointer depth '%s'",
126  option_arg.str().c_str());
127  }
128  break;
129 
130  case 'Y':
131  if (option_arg.empty())
132  no_summary_depth = 1;
133  else if (option_arg.getAsInteger(0, no_summary_depth)) {
134  no_summary_depth = 0;
135  error.SetErrorStringWithFormat("invalid pointer depth '%s'",
136  option_arg.str().c_str());
137  }
138  break;
139 
140  case 'S':
141  use_synth = OptionArgParser::ToBoolean(option_arg, true, &success);
142  if (!success)
143  error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
144  option_arg.str().c_str());
145  break;
146 
147  case 'V':
148  run_validator = OptionArgParser::ToBoolean(option_arg, true, &success);
149  if (!success)
150  error.SetErrorStringWithFormat("invalid validate '%s'",
151  option_arg.str().c_str());
152  break;
153 
154  default:
155  error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
156  break;
157  }
158 
159  return error;
160 }
161 
162 void OptionGroupValueObjectDisplay::OptionParsingStarting(
163  ExecutionContext *execution_context) {
164  // If these defaults change, be sure to modify AnyOptionWasSet().
165  show_types = false;
166  no_summary_depth = 0;
167  show_location = false;
168  flat_output = false;
169  use_objc = false;
170  max_depth = UINT32_MAX;
171  ptr_depth = 0;
172  elem_count = 0;
173  use_synth = true;
174  be_raw = false;
175  ignore_cap = false;
176  run_validator = false;
177 
178  TargetSP target_sp =
179  execution_context ? execution_context->GetTargetSP() : TargetSP();
180  if (target_sp)
181  use_dynamic = target_sp->GetPreferDynamicValue();
182  else {
183  // If we don't have any targets, then dynamic values won't do us much good.
184  use_dynamic = lldb::eNoDynamicValues;
185  }
186 }
187 
188 DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
189  LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
190  lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
191  DumpValueObjectOptions options;
192  options.SetMaximumPointerDepth(
193  {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
194  if (use_objc)
195  options.SetShowSummary(false);
196  else
197  options.SetOmitSummaryDepth(no_summary_depth);
198  options.SetMaximumDepth(max_depth)
199  .SetShowTypes(show_types)
200  .SetShowLocation(show_location)
201  .SetUseObjectiveC(use_objc)
202  .SetUseDynamicType(use_dynamic)
203  .SetUseSyntheticValue(use_synth)
204  .SetFlatOutput(flat_output)
205  .SetIgnoreCap(ignore_cap)
206  .SetFormat(format)
207  .SetSummary(summary_sp);
208 
209  if (lang_descr_verbosity ==
211  options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
212  use_objc);
213 
214  if (be_raw)
215  options.SetRawDisplay();
216 
217  options.SetRunValidator(run_validator);
218 
219  options.SetElementCount(elem_count);
220 
221  return options;
222 }
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
DumpValueObjectOptions & SetMaximumDepth(uint32_t depth=0)
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
DumpValueObjectOptions & SetHideValue(bool hide_value=false)
DumpValueObjectOptions & SetSummary(lldb::TypeSummaryImplSP summary=lldb::TypeSummaryImplSP())
DumpValueObjectOptions & SetHideName(bool hide_name=false)
DumpValueObjectOptions & SetShowLocation(bool show=false)
DumpValueObjectOptions & SetElementCount(uint32_t element_count=0)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
DumpValueObjectOptions & SetUseObjectiveC(bool use=false)
DumpValueObjectOptions & SetShowSummary(bool show=true)
DumpValueObjectOptions & SetRunValidator(bool run=true)
#define UINT32_MAX
Definition: lldb-defines.h:31
DumpValueObjectOptions & SetUseDynamicType(lldb::DynamicValueType dyn=lldb::eNoDynamicValues)
DumpValueObjectOptions & SetShowTypes(bool show=false)
DumpValueObjectOptions & SetIgnoreCap(bool ignore=false)
DumpValueObjectOptions & SetHideRootType(bool hide_root_type=false)
bool Success() const
Test for success condition.
Definition: Status.cpp:287
DumpValueObjectOptions & SetMaximumPointerDepth(PointerDepth depth={PointerDepth::Mode::Never, 0})
Definition: SBAddress.h:15
DumpValueObjectOptions & SetUseSyntheticValue(bool use_synthetic=true)
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
OptionEnumValues GetDynamicValueTypes()
Definition: Target.cpp:3237
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:111
DumpValueObjectOptions & SetFlatOutput(bool flat=false)
DumpValueObjectOptions & SetFormat(lldb::Format format=lldb::eFormatDefault)
DumpValueObjectOptions & SetOmitSummaryDepth(uint32_t depth=0)
static const OptionDefinition g_option_table[]
An error handling class.
Definition: Status.h:44