blob: bbd966859c343e5893b29b01f6c42326167b317e [file] [log] [blame]
Greg Clayton84c39662011-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 Chen4bee32e2011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton84c39662011-04-27 22:04:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Enrico Granata4d93b8c2013-09-30 19:11:51 +000016#include "lldb/DataFormatters/ValueObjectPrinter.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000017#include "lldb/Host/StringConvert.h"
Jim Ingham2837b762011-05-04 03:43:18 +000018#include "lldb/Target/Target.h"
19#include "lldb/Interpreter/CommandInterpreter.h"
Johnny Chen7c575b32011-09-10 00:48:33 +000020#include "lldb/Utility/Utils.h"
Greg Clayton84c39662011-04-27 22:04:39 +000021
22using namespace lldb;
23using namespace lldb_private;
24
25OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay()
26{
27}
28
29OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay ()
30{
31}
32
Greg Clayton68ebae62011-04-28 20:55:26 +000033static OptionDefinition
Greg Clayton84c39662011-04-27 22:04:39 +000034g_option_table[] =
35{
Zachary Turnerd37221d2014-07-09 16:31:49 +000036 { 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."},
37 { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."},
38 { 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)."},
39 { 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."},
40 { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable location information."},
41 { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print as an Objective-C object."},
42 { 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)."},
43 { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show variable types when dumping values."},
44 { 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)."},
45 { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."},
46 { 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."},
Enrico Granata0f883ff2014-09-06 02:20:19 +000047 { LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."},
Zachary Turnerd37221d2014-07-09 16:31:49 +000048 { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Greg Clayton84c39662011-04-27 22:04:39 +000049};
50
Greg Clayton84c39662011-04-27 22:04:39 +000051uint32_t
52OptionGroupValueObjectDisplay::GetNumDefinitions ()
53{
Johnny Chen6ebc8c452012-05-15 23:21:36 +000054 return llvm::array_lengthof(g_option_table);
Greg Clayton84c39662011-04-27 22:04:39 +000055}
56
57const OptionDefinition *
58OptionGroupValueObjectDisplay::GetDefinitions ()
59{
60 return g_option_table;
61}
62
63
64Error
65OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
66 uint32_t option_idx,
67 const char *option_arg)
68{
69 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +000070 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton84c39662011-04-27 22:04:39 +000071 bool success = false;
72
73 switch (short_option)
74 {
Jim Ingham2837b762011-05-04 03:43:18 +000075 case 'd':
76 {
Jim Ingham2837b762011-05-04 03:43:18 +000077 int32_t result;
Greg Clayton67cc0632012-08-22 17:17:09 +000078 result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error);
Greg Claytoncf0e4f02011-10-07 18:58:12 +000079 if (error.Success())
Jim Ingham2837b762011-05-04 03:43:18 +000080 use_dynamic = (lldb::DynamicValueType) result;
81 }
82 break;
Greg Clayton68ebae62011-04-28 20:55:26 +000083 case 'T': show_types = true; break;
Greg Clayton84c39662011-04-27 22:04:39 +000084 case 'L': show_location= true; break;
85 case 'F': flat_output = true; break;
Enrico Granatace68b022011-08-09 23:50:01 +000086 case 'O': use_objc = true; break;
87 case 'R': be_raw = true; break;
Enrico Granata22c55d12011-08-12 02:00:06 +000088 case 'A': ignore_cap = true; break;
Enrico Granatace68b022011-08-09 23:50:01 +000089
Greg Clayton68ebae62011-04-28 20:55:26 +000090 case 'D':
Vince Harron5275aaa2015-01-15 20:08:35 +000091 max_depth = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0, &success);
Greg Clayton84c39662011-04-27 22:04:39 +000092 if (!success)
Greg Clayton86edbf42011-10-26 00:56:27 +000093 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg);
Greg Clayton84c39662011-04-27 22:04:39 +000094 break;
95
Greg Clayton68ebae62011-04-28 20:55:26 +000096 case 'P':
Vince Harron5275aaa2015-01-15 20:08:35 +000097 ptr_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
Greg Clayton84c39662011-04-27 22:04:39 +000098 if (!success)
Greg Clayton86edbf42011-10-26 00:56:27 +000099 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
Greg Clayton84c39662011-04-27 22:04:39 +0000100 break;
101
Enrico Granata0c5ef692011-07-16 01:22:04 +0000102 case 'Y':
103 if (option_arg)
104 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000105 no_summary_depth = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
Enrico Granata0c5ef692011-07-16 01:22:04 +0000106 if (!success)
Greg Clayton86edbf42011-10-26 00:56:27 +0000107 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
Enrico Granata0c5ef692011-07-16 01:22:04 +0000108 }
109 else
110 no_summary_depth = 1;
111 break;
Enrico Granatad55546b2011-07-22 00:16:08 +0000112
113 case 'S':
114 use_synth = Args::StringToBoolean(option_arg, true, &success);
115 if (!success)
Greg Clayton86edbf42011-10-26 00:56:27 +0000116 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
Enrico Granatad55546b2011-07-22 00:16:08 +0000117 break;
Enrico Granata0f883ff2014-09-06 02:20:19 +0000118
119 case 'V':
120 run_validator = Args::StringToBoolean(option_arg, true, &success);
121 if (!success)
122 error.SetErrorStringWithFormat("invalid validate '%s'", option_arg);
123 break;
124
Greg Clayton84c39662011-04-27 22:04:39 +0000125 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000126 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Clayton84c39662011-04-27 22:04:39 +0000127 break;
128 }
129
130 return error;
131}
132
133void
134OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
135{
Greg Clayton82f4cf42011-10-26 04:32:38 +0000136 // If these defaults change, be sure to modify AnyOptionWasSet().
Enrico Granata0c5ef692011-07-16 01:22:04 +0000137 show_types = false;
138 no_summary_depth = 0;
139 show_location = false;
140 flat_output = false;
141 use_objc = false;
142 max_depth = UINT32_MAX;
143 ptr_depth = 0;
Enrico Granatad55546b2011-07-22 00:16:08 +0000144 use_synth = true;
Enrico Granatace68b022011-08-09 23:50:01 +0000145 be_raw = false;
Enrico Granata22c55d12011-08-12 02:00:06 +0000146 ignore_cap = false;
Enrico Granata0f883ff2014-09-06 02:20:19 +0000147 run_validator = false;
Jim Ingham2837b762011-05-04 03:43:18 +0000148
Greg Claytonc14ee322011-09-22 04:58:26 +0000149 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Ed Masted78c9572014-04-20 00:31:37 +0000150 if (target != nullptr)
Jim Ingham2837b762011-05-04 03:43:18 +0000151 use_dynamic = target->GetPreferDynamicValue();
152 else
153 {
154 // If we don't have any targets, then dynamic values won't do us much good.
155 use_dynamic = lldb::eNoDynamicValues;
156 }
Johnny Chen4bee32e2011-05-13 20:21:08 +0000157}
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000158
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000159DumpValueObjectOptions
160OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000161 lldb::Format format,
162 lldb::TypeSummaryImplSP summary_sp)
163{
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000164 DumpValueObjectOptions options;
Enrico Granatac1b7c092015-07-27 18:34:14 +0000165 options.SetMaximumPointerDepth( {DumpValueObjectOptions::PointerDepth::Mode::Always,ptr_depth} );
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000166 if (use_objc)
167 options.SetShowSummary(false);
168 else
169 options.SetOmitSummaryDepth(no_summary_depth);
170 options.SetMaximumDepth(max_depth)
171 .SetShowTypes(show_types)
172 .SetShowLocation(show_location)
173 .SetUseObjectiveC(use_objc)
174 .SetUseDynamicType(use_dynamic)
175 .SetUseSyntheticValue(use_synth)
176 .SetFlatOutput(flat_output)
177 .SetIgnoreCap(ignore_cap)
178 .SetFormat(format)
179 .SetSummary(summary_sp);
180
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000181 if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact)
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000182 options.SetHideRootType(use_objc)
183 .SetHideName(use_objc)
184 .SetHideValue(use_objc);
185
186 if (be_raw)
Enrico Granataa126e462014-11-21 18:47:26 +0000187 options.SetRawDisplay();
Enrico Granata0f883ff2014-09-06 02:20:19 +0000188
189 options.SetRunValidator(run_validator);
Enrico Granata9fb5ab52013-03-26 18:04:53 +0000190
191 return options;
192}