blob: b2ca4ae7213c31bc42049032b12f36f3eb9702ec [file] [log] [blame]
Greg Clayton57b3c6b2011-04-27 22:04:39 +00001//===-- 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
Johnny Chena0f34692011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton57b3c6b2011-04-27 22:04:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Jim Ingham10de7d12011-05-04 03:43:18 +000016#include "lldb/Target/Target.h"
17#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton57b3c6b2011-04-27 22:04:39 +000018
19using namespace lldb;
20using namespace lldb_private;
21
22OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay()
23{
24}
25
26OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay ()
27{
28}
29
Greg Clayton56bbdaf2011-04-28 20:55:26 +000030static OptionDefinition
Greg Clayton57b3c6b2011-04-27 22:04:39 +000031g_option_table[] =
32{
Jim Ingham10de7d12011-05-04 03:43:18 +000033 { LLDB_OPT_SET_1, false, "dynamic-type", 'd', required_argument, TargetInstanceSettings::g_dynamic_value_types,
Enrico Granatae4e3e2c2011-07-22 00:16:08 +000034 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."},
Greg Clayton56bbdaf2011-04-28 20:55:26 +000036 { LLDB_OPT_SET_1, false, "depth", 'D', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."},
Greg Clayton57b3c6b2011-04-27 22:04:39 +000037 { 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."},
Greg Clayton56bbdaf2011-04-28 20:55:26 +000039 { 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."},
Enrico Granata7f163b32011-07-16 01:22:04 +000042 { LLDB_OPT_SET_1, false, "no-summary-depth",'Y', optional_argument, NULL, 0, eArgTypeCount, "Set a depth for omitting summary information (default is 1)."},
Greg Clayton57b3c6b2011-04-27 22:04:39 +000043 { 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
44};
45
46const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
47
48uint32_t
49OptionGroupValueObjectDisplay::GetNumDefinitions ()
50{
51 return k_num_file_options;
52}
53
54const OptionDefinition *
55OptionGroupValueObjectDisplay::GetDefinitions ()
56{
57 return g_option_table;
58}
59
60
61Error
62OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
63 uint32_t option_idx,
64 const char *option_arg)
65{
66 Error error;
67 char short_option = (char) g_option_table[option_idx].short_option;
68 bool success = false;
69
70 switch (short_option)
71 {
Jim Ingham10de7d12011-05-04 03:43:18 +000072 case 'd':
73 {
74 bool success;
75 int32_t result;
76 result = Args::StringToOptionEnum (option_arg, TargetInstanceSettings::g_dynamic_value_types, 2, &success);
77 if (!success)
78 error.SetErrorStringWithFormat("Invalid dynamic value setting: \"%s\".\n", option_arg);
79 else
80 use_dynamic = (lldb::DynamicValueType) result;
81 }
82 break;
Greg Clayton56bbdaf2011-04-28 20:55:26 +000083 case 'T': show_types = true; break;
Greg Clayton57b3c6b2011-04-27 22:04:39 +000084 case 'L': show_location= true; break;
85 case 'F': flat_output = true; break;
Greg Clayton56bbdaf2011-04-28 20:55:26 +000086 case 'O': use_objc = true; break;
87 case 'D':
Greg Clayton57b3c6b2011-04-27 22:04:39 +000088 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
89 if (!success)
90 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
91 break;
92
Greg Clayton56bbdaf2011-04-28 20:55:26 +000093 case 'P':
Greg Clayton57b3c6b2011-04-27 22:04:39 +000094 ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
95 if (!success)
96 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
97 break;
98
Enrico Granata7f163b32011-07-16 01:22:04 +000099 case 'Y':
100 if (option_arg)
101 {
102 no_summary_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
103 if (!success)
104 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
105 }
106 else
107 no_summary_depth = 1;
108 break;
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000109
110 case 'S':
111 use_synth = Args::StringToBoolean(option_arg, true, &success);
112 if (!success)
113 error.SetErrorStringWithFormat("Invalid synthetic-type '%s'.\n", option_arg);
114 break;
Greg Clayton57b3c6b2011-04-27 22:04:39 +0000115 default:
116 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
117 break;
118 }
119
120 return error;
121}
122
123void
124OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
125{
Enrico Granata7f163b32011-07-16 01:22:04 +0000126 show_types = false;
127 no_summary_depth = 0;
128 show_location = false;
129 flat_output = false;
130 use_objc = false;
131 max_depth = UINT32_MAX;
132 ptr_depth = 0;
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000133 use_synth = true;
Jim Ingham10de7d12011-05-04 03:43:18 +0000134
135 Target *target = interpreter.GetExecutionContext().target;
136 if (target != NULL)
137 use_dynamic = target->GetPreferDynamicValue();
138 else
139 {
140 // If we don't have any targets, then dynamic values won't do us much good.
141 use_dynamic = lldb::eNoDynamicValues;
142 }
Johnny Chena0f34692011-05-13 20:21:08 +0000143}