1 //===-- 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
10 #include "lldb/lldb-python.h"
11
12 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
13
14 // C Includes
15 // C++ Includes
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/DataFormatters/ValueObjectPrinter.h"
19 #include "lldb/Target/Target.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
21 #include "lldb/Utility/Utils.h"
22
23 using namespace lldb;
24 using namespace lldb_private;
25
OptionGroupValueObjectDisplay()26 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay()
27 {
28 }
29
~OptionGroupValueObjectDisplay()30 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay ()
31 {
32 }
33
34 static OptionDefinition
35 g_option_table[] =
36 {
37 { LLDB_OPT_SET_1, false, "dynamic-type", 'd', OptionParser::eRequiredArgument, g_dynamic_value_types, 0, eArgTypeNone, "Show the object as its full dynamic type, not its static type, if available."},
38 { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."},
39 { LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
40 { LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."},
41 { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable location information."},
42 { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Print as an Objective-C object."},
43 { LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."},
44 { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."},
45 { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', OptionParser::eOptionalArgument, NULL, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is 1)."},
46 { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use formatting options."},
47 { LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Ignore the upper bound on the number of children to show."},
48 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
49 };
50
51 uint32_t
GetNumDefinitions()52 OptionGroupValueObjectDisplay::GetNumDefinitions ()
53 {
54 return llvm::array_lengthof(g_option_table);
55 }
56
57 const OptionDefinition *
GetDefinitions()58 OptionGroupValueObjectDisplay::GetDefinitions ()
59 {
60 return g_option_table;
61 }
62
63
64 Error
SetOptionValue(CommandInterpreter & interpreter,uint32_t option_idx,const char * option_arg)65 OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
66 uint32_t option_idx,
67 const char *option_arg)
68 {
69 Error error;
70 const int short_option = g_option_table[option_idx].short_option;
71 bool success = false;
72
73 switch (short_option)
74 {
75 case 'd':
76 {
77 int32_t result;
78 result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error);
79 if (error.Success())
80 use_dynamic = (lldb::DynamicValueType) result;
81 }
82 break;
83 case 'T': show_types = true; break;
84 case 'L': show_location= true; break;
85 case 'F': flat_output = true; break;
86 case 'O': use_objc = true; break;
87 case 'R': be_raw = true; break;
88 case 'A': ignore_cap = true; break;
89
90 case 'D':
91 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
92 if (!success)
93 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg);
94 break;
95
96 case 'P':
97 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
98 if (!success)
99 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
100 break;
101
102 case 'Y':
103 if (option_arg)
104 {
105 no_summary_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
106 if (!success)
107 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
108 }
109 else
110 no_summary_depth = 1;
111 break;
112
113 case 'S':
114 use_synth = Args::StringToBoolean(option_arg, true, &success);
115 if (!success)
116 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
117 break;
118 default:
119 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
120 break;
121 }
122
123 return error;
124 }
125
126 void
OptionParsingStarting(CommandInterpreter & interpreter)127 OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
128 {
129 // If these defaults change, be sure to modify AnyOptionWasSet().
130 show_types = false;
131 no_summary_depth = 0;
132 show_location = false;
133 flat_output = false;
134 use_objc = false;
135 max_depth = UINT32_MAX;
136 ptr_depth = 0;
137 use_synth = true;
138 be_raw = false;
139 ignore_cap = false;
140
141 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
142 if (target != NULL)
143 use_dynamic = target->GetPreferDynamicValue();
144 else
145 {
146 // If we don't have any targets, then dynamic values won't do us much good.
147 use_dynamic = lldb::eNoDynamicValues;
148 }
149 }
150
151 DumpValueObjectOptions
GetAsDumpOptions(LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,lldb::Format format,lldb::TypeSummaryImplSP summary_sp)152 OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
153 lldb::Format format,
154 lldb::TypeSummaryImplSP summary_sp)
155 {
156 DumpValueObjectOptions options;
157 options.SetMaximumPointerDepth(ptr_depth);
158 if (use_objc)
159 options.SetShowSummary(false);
160 else
161 options.SetOmitSummaryDepth(no_summary_depth);
162 options.SetMaximumDepth(max_depth)
163 .SetShowTypes(show_types)
164 .SetShowLocation(show_location)
165 .SetUseObjectiveC(use_objc)
166 .SetUseDynamicType(use_dynamic)
167 .SetUseSyntheticValue(use_synth)
168 .SetFlatOutput(flat_output)
169 .SetIgnoreCap(ignore_cap)
170 .SetFormat(format)
171 .SetSummary(summary_sp);
172
173 if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact)
174 options.SetHideRootType(use_objc)
175 .SetHideName(use_objc)
176 .SetHideValue(use_objc);
177
178 if (be_raw)
179 options.SetRawDisplay(true);
180
181 return options;
182 }
183