blob: 2d734a1babe1f0f0579e098e3901bd1a7e8bebd3 [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"
Johnny Chen4003f572011-09-10 00:48:33 +000018#include "lldb/Utility/Utils.h"
Greg Clayton57b3c6b2011-04-27 22:04:39 +000019
20using namespace lldb;
21using namespace lldb_private;
22
23OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay()
24{
25}
26
27OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay ()
28{
29}
30
Greg Clayton56bbdaf2011-04-28 20:55:26 +000031static OptionDefinition
Greg Clayton57b3c6b2011-04-27 22:04:39 +000032g_option_table[] =
33{
Greg Clayton73844aa2012-08-22 17:17:09 +000034 { LLDB_OPT_SET_1, false, "dynamic-type", 'd', required_argument, g_dynamic_value_types, 0, eArgTypeNone, "Show the object as its full dynamic type, not its static type, if available."},
Enrico Granata018921d2011-08-12 02:00:06 +000035 { 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."},
Enrico Granata0d66ca92012-08-08 01:12:11 +000042 { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', optional_argument, NULL, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is 1)."},
Enrico Granata018921d2011-08-12 02:00:06 +000043 { 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."},
Filipe Cabecinhas5ebd51f2012-09-11 18:11:07 +000045 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Greg Clayton57b3c6b2011-04-27 22:04:39 +000046};
47
Greg Clayton57b3c6b2011-04-27 22:04:39 +000048uint32_t
49OptionGroupValueObjectDisplay::GetNumDefinitions ()
50{
Johnny Chen08af5982012-05-15 23:21:36 +000051 return llvm::array_lengthof(g_option_table);
Greg Clayton57b3c6b2011-04-27 22:04:39 +000052}
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 {
Jim Ingham10de7d12011-05-04 03:43:18 +000074 int32_t result;
Greg Clayton73844aa2012-08-22 17:17:09 +000075 result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error);
Greg Clayton61aca5d2011-10-07 18:58:12 +000076 if (error.Success())
Jim Ingham10de7d12011-05-04 03:43:18 +000077 use_dynamic = (lldb::DynamicValueType) result;
78 }
79 break;
Greg Clayton56bbdaf2011-04-28 20:55:26 +000080 case 'T': show_types = true; break;
Greg Clayton57b3c6b2011-04-27 22:04:39 +000081 case 'L': show_location= true; break;
82 case 'F': flat_output = true; break;
Enrico Granata840eb262011-08-09 23:50:01 +000083 case 'O': use_objc = true; break;
84 case 'R': be_raw = true; break;
Enrico Granata018921d2011-08-12 02:00:06 +000085 case 'A': ignore_cap = true; break;
Enrico Granata840eb262011-08-09 23:50:01 +000086
Greg Clayton56bbdaf2011-04-28 20:55:26 +000087 case 'D':
Greg Clayton57b3c6b2011-04-27 22:04:39 +000088 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
89 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +000090 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg);
Greg Clayton57b3c6b2011-04-27 22:04:39 +000091 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)
Greg Clayton9c236732011-10-26 00:56:27 +000096 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
Greg Clayton57b3c6b2011-04-27 22:04:39 +000097 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)
Greg Clayton9c236732011-10-26 00:56:27 +0000104 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
Enrico Granata7f163b32011-07-16 01:22:04 +0000105 }
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)
Greg Clayton9c236732011-10-26 00:56:27 +0000113 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000114 break;
Greg Clayton57b3c6b2011-04-27 22:04:39 +0000115 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000116 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Clayton57b3c6b2011-04-27 22:04:39 +0000117 break;
118 }
119
120 return error;
121}
122
123void
124OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
125{
Greg Clayton902b5be2011-10-26 04:32:38 +0000126 // If these defaults change, be sure to modify AnyOptionWasSet().
Enrico Granata7f163b32011-07-16 01:22:04 +0000127 show_types = false;
128 no_summary_depth = 0;
129 show_location = false;
130 flat_output = false;
131 use_objc = false;
132 max_depth = UINT32_MAX;
133 ptr_depth = 0;
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000134 use_synth = true;
Enrico Granata840eb262011-08-09 23:50:01 +0000135 be_raw = false;
Enrico Granata018921d2011-08-12 02:00:06 +0000136 ignore_cap = false;
Jim Ingham10de7d12011-05-04 03:43:18 +0000137
Greg Clayton567e7f32011-09-22 04:58:26 +0000138 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Jim Ingham10de7d12011-05-04 03:43:18 +0000139 if (target != NULL)
140 use_dynamic = target->GetPreferDynamicValue();
141 else
142 {
143 // If we don't have any targets, then dynamic values won't do us much good.
144 use_dynamic = lldb::eNoDynamicValues;
145 }
Johnny Chena0f34692011-05-13 20:21:08 +0000146}