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/Interpreter/OptionGroupValueObjectDisplay.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Target/Target.h"
17 #include "lldb/Interpreter/CommandInterpreter.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay()
23 {
24 }
25 
26 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay ()
27 {
28 }
29 
30 static OptionDefinition
31 g_option_table[] =
32 {
33     { LLDB_OPT_SET_1, false, "dynamic-type",     'd', required_argument, TargetInstanceSettings::g_dynamic_value_types,
34                                                                               0, eArgTypeNone,      "Show the object as its full dynamic type, not its static type, if available."},
35     { LLDB_OPT_SET_1, false, "synthetic-type",   'S', required_argument, NULL, 0, eArgTypeBoolean,   "Show the object obeying its synthetic provider, if available."},
36     { LLDB_OPT_SET_1, false, "depth",            'D', required_argument, NULL, 0, eArgTypeCount,     "Set the max recurse depth when dumping aggregate types (default is infinity)."},
37     { LLDB_OPT_SET_1, false, "flat",             'F', no_argument,       NULL, 0, eArgTypeNone,      "Display results in a flat format that uses expression paths for each variable or member."},
38     { LLDB_OPT_SET_1, false, "location",         'L', no_argument,       NULL, 0, eArgTypeNone,      "Show variable location information."},
39     { LLDB_OPT_SET_1, false, "objc",             'O', no_argument,       NULL, 0, eArgTypeNone,      "Print as an Objective-C object."},
40     { LLDB_OPT_SET_1, false, "ptr-depth",        'P', required_argument, NULL, 0, eArgTypeCount,     "The number of pointers to be traversed when dumping values (default is zero)."},
41     { LLDB_OPT_SET_1, false, "show-types",       'T', no_argument,       NULL, 0, eArgTypeNone,      "Show variable types when dumping values."},
42     { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', optional_argument, NULL, 0, eArgTypeCount,     "Set a depth for omitting summary information (default is 1)."},
43     { LLDB_OPT_SET_1, false, "raw-output",       'R', no_argument,       NULL, 0, eArgTypeNone,      "Don't use formatting options."},
44     { LLDB_OPT_SET_1, false, "show-all-children",'A', no_argument,       NULL, 0, eArgTypeNone,      "Ignore the upper bound on the number of children to show."},
45     { 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
46 };
47 
48 const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
49 
50 uint32_t
51 OptionGroupValueObjectDisplay::GetNumDefinitions ()
52 {
53     return k_num_file_options;
54 }
55 
56 const OptionDefinition *
57 OptionGroupValueObjectDisplay::GetDefinitions ()
58 {
59     return g_option_table;
60 }
61 
62 
63 Error
64 OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
65                                                uint32_t option_idx,
66                                                const char *option_arg)
67 {
68     Error error;
69     char short_option = (char) g_option_table[option_idx].short_option;
70     bool success = false;
71 
72     switch (short_option)
73     {
74         case 'd':
75             {
76                 bool success;
77                 int32_t result;
78                 result = Args::StringToOptionEnum (option_arg, TargetInstanceSettings::g_dynamic_value_types, 2, &success);
79                 if (!success)
80                     error.SetErrorStringWithFormat("Invalid dynamic value setting: \"%s\".\n", option_arg);
81                 else
82                     use_dynamic = (lldb::DynamicValueType) result;
83             }
84             break;
85         case 'T':   show_types   = true;  break;
86         case 'L':   show_location= true;  break;
87         case 'F':   flat_output  = true;  break;
88         case 'O':   use_objc     = true;  break;
89         case 'R':   be_raw       = true;  break;
90         case 'A':   ignore_cap   = true;  break;
91 
92         case 'D':
93             max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
94             if (!success)
95                 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
96             break;
97 
98         case 'P':
99             ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
100             if (!success)
101                 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
102             break;
103 
104         case 'Y':
105             if (option_arg)
106             {
107                 no_summary_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
108                 if (!success)
109                     error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
110             }
111             else
112                 no_summary_depth = 1;
113             break;
114 
115         case 'S':
116             use_synth = Args::StringToBoolean(option_arg, true, &success);
117             if (!success)
118                 error.SetErrorStringWithFormat("Invalid synthetic-type '%s'.\n", option_arg);
119             break;
120         default:
121             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
122             break;
123     }
124 
125     return error;
126 }
127 
128 void
129 OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
130 {
131     show_types        = false;
132     no_summary_depth  = 0;
133     show_location     = false;
134     flat_output       = false;
135     use_objc          = false;
136     max_depth         = UINT32_MAX;
137     ptr_depth         = 0;
138     use_synth         = true;
139     be_raw            = false;
140     ignore_cap        = false;
141 
142     Target *target = interpreter.GetExecutionContext().target;
143     if (target != NULL)
144         use_dynamic = target->GetPreferDynamicValue();
145     else
146     {
147         // If we don't have any targets, then dynamic values won't do us much good.
148         use_dynamic = lldb::eNoDynamicValues;
149     }
150 }
151