]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
MFV ntp 4.2.8p2 (r281348)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionGroupValueObjectDisplay.cpp
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
26 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay()
27 {
28 }
29
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, nullptr, 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, nullptr, nullptr, 0, eArgTypeBoolean,   "Show the object obeying its synthetic provider, if available."},
39     { LLDB_OPT_SET_1, false, "depth",              'D', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,     "Set the max recurse depth when dumping aggregate types (default is infinity)."},
40     { LLDB_OPT_SET_1, false, "flat",               'F', OptionParser::eNoArgument,       nullptr, nullptr, 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,       nullptr, nullptr, 0, eArgTypeNone,      "Show variable location information."},
42     { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,      "Print as an Objective-C object."},
43     { LLDB_OPT_SET_1, false, "ptr-depth",          'P', OptionParser::eRequiredArgument, nullptr, nullptr, 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,       nullptr, nullptr, 0, eArgTypeNone,      "Show variable types when dumping values."},
45     { LLDB_OPT_SET_1, false, "no-summary-depth",   'Y', OptionParser::eOptionalArgument, nullptr, nullptr, 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,       nullptr, nullptr, 0, eArgTypeNone,      "Don't use formatting options."},
47     { LLDB_OPT_SET_1, false, "show-all-children",  'A', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,      "Ignore the upper bound on the number of children to show."},
48     { LLDB_OPT_SET_1, false, "validate",           'V',  OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,   "Show results of type validators."},
49     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
50 };
51
52 uint32_t
53 OptionGroupValueObjectDisplay::GetNumDefinitions ()
54 {
55     return llvm::array_lengthof(g_option_table);
56 }
57
58 const OptionDefinition *
59 OptionGroupValueObjectDisplay::GetDefinitions ()
60 {
61     return g_option_table;
62 }
63
64
65 Error
66 OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
67                                                uint32_t option_idx,
68                                                const char *option_arg)
69 {
70     Error error;
71     const int short_option = g_option_table[option_idx].short_option;
72     bool success = false;
73
74     switch (short_option)
75     {
76         case 'd':
77             {
78                 int32_t result;
79                 result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error);
80                 if (error.Success())
81                     use_dynamic = (lldb::DynamicValueType) result;
82             }
83             break;
84         case 'T':   show_types   = true;  break;
85         case 'L':   show_location= true;  break;
86         case 'F':   flat_output  = true;  break;
87         case 'O':   use_objc     = true;  break;
88         case 'R':   be_raw       = true;  break;
89         case 'A':   ignore_cap   = true;  break;
90             
91         case 'D':
92             max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
93             if (!success)
94                 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg);
95             break;
96             
97         case 'P':
98             ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
99             if (!success)
100                 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
101             break;
102             
103         case 'Y':
104             if (option_arg)
105             {
106                 no_summary_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
107                 if (!success)
108                     error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
109             }
110             else
111                 no_summary_depth = 1;
112             break;
113             
114         case 'S':
115             use_synth = Args::StringToBoolean(option_arg, true, &success);
116             if (!success)
117                 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
118             break;
119             
120         case 'V':
121             run_validator = Args::StringToBoolean(option_arg, true, &success);
122             if (!success)
123                 error.SetErrorStringWithFormat("invalid validate '%s'", option_arg);
124             break;
125             
126         default:
127             error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
128             break;
129     }
130
131     return error;
132 }
133
134 void
135 OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
136 {
137     // If these defaults change, be sure to modify AnyOptionWasSet().
138     show_types        = false;
139     no_summary_depth  = 0;
140     show_location     = false;
141     flat_output       = false;
142     use_objc          = false;
143     max_depth         = UINT32_MAX;
144     ptr_depth         = 0;
145     use_synth         = true;
146     be_raw            = false;
147     ignore_cap        = false;
148     run_validator     = false;
149     
150     Target *target = interpreter.GetExecutionContext().GetTargetPtr();
151     if (target != nullptr)
152         use_dynamic = target->GetPreferDynamicValue();
153     else
154     {
155         // If we don't have any targets, then dynamic values won't do us much good.
156         use_dynamic = lldb::eNoDynamicValues;
157     }
158 }
159
160 DumpValueObjectOptions
161 OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
162                                                  lldb::Format format,
163                                                  lldb::TypeSummaryImplSP summary_sp)
164 {
165     DumpValueObjectOptions options;
166     options.SetMaximumPointerDepth(ptr_depth);
167     if (use_objc)
168         options.SetShowSummary(false);
169     else
170         options.SetOmitSummaryDepth(no_summary_depth);
171     options.SetMaximumDepth(max_depth)
172     .SetShowTypes(show_types)
173     .SetShowLocation(show_location)
174     .SetUseObjectiveC(use_objc)
175     .SetUseDynamicType(use_dynamic)
176     .SetUseSyntheticValue(use_synth)
177     .SetFlatOutput(flat_output)
178     .SetIgnoreCap(ignore_cap)
179     .SetFormat(format)
180     .SetSummary(summary_sp);
181     
182     if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact)
183         options.SetHideRootType(use_objc)
184         .SetHideName(use_objc)
185         .SetHideValue(use_objc);
186     
187     if (be_raw)
188         options.SetRawDisplay();
189     
190     options.SetRunValidator(run_validator);
191
192     return options;
193 }