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     { 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
45 };
46 
47 const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
48 
49 uint32_t
50 OptionGroupValueObjectDisplay::GetNumDefinitions ()
51 {
52     return k_num_file_options;
53 }
54 
55 const OptionDefinition *
56 OptionGroupValueObjectDisplay::GetDefinitions ()
57 {
58     return g_option_table;
59 }
60 
61 
62 Error
63 OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
64                                                uint32_t option_idx,
65                                                const char *option_arg)
66 {
67     Error error;
68     char short_option = (char) g_option_table[option_idx].short_option;
69     bool success = false;
70 
71     switch (short_option)
72     {
73         case 'd':
74             {
75                 bool success;
76                 int32_t result;
77                 result = Args::StringToOptionEnum (option_arg, TargetInstanceSettings::g_dynamic_value_types, 2, &success);
78                 if (!success)
79                     error.SetErrorStringWithFormat("Invalid dynamic value setting: \"%s\".\n", option_arg);
80                 else
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 
90         case 'D':
91             max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
92             if (!success)
93                 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", 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'.\n", 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'.\n", 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'.\n", option_arg);
117             break;
118         default:
119             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
120             break;
121     }
122 
123     return error;
124 }
125 
126 void
127 OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
128 {
129     show_types        = false;
130     no_summary_depth  = 0;
131     show_location     = false;
132     flat_output       = false;
133     use_objc          = false;
134     max_depth         = UINT32_MAX;
135     ptr_depth         = 0;
136     use_synth         = true;
137     be_raw            = false;
138 
139     Target *target = interpreter.GetExecutionContext().target;
140     if (target != NULL)
141         use_dynamic = target->GetPreferDynamicValue();
142     else
143     {
144         // If we don't have any targets, then dynamic values won't do us much good.
145         use_dynamic = lldb::eNoDynamicValues;
146     }
147 }
148