blob: 1bcddb4b49f7513239b737d0e3a5e9640bdb0706 [file] [log] [blame]
Greg Clayton715c2362011-07-07 04:38:25 +00001//===-- OptionGroupVariable.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/OptionGroupVariable.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Enrico Granata5548cb52013-01-28 23:47:25 +000016#include "lldb/DataFormatters/DataVisualization.h"
Zachary Turner3eb2b442017-03-22 23:33:16 +000017#include "lldb/Host/OptionParser.h"
Greg Clayton715c2362011-07-07 04:38:25 +000018#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000019#include "lldb/Target/Target.h"
Zachary Turner97206d52017-05-12 04:51:55 +000020#include "lldb/Utility/Status.h"
Greg Clayton715c2362011-07-07 04:38:25 +000021
22using namespace lldb;
23using namespace lldb_private;
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025// if you add any options here, remember to update the counters in
26// OptionGroupVariable::GetNumDefinitions()
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000027static constexpr OptionDefinition g_variable_options[] = {
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000029 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
Kate Stoneb9c1b512016-09-06 20:57:50 +000030 "Omit function arguments."},
31 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000032 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 "Omit local variables."},
34 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000035 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 "Show the current frame source file global and static variables."},
37 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000038 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 "Show variable declaration information (source file and line where the "
40 "variable was declared)."},
41 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r',
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000042 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeRegularExpression,
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 "The <variable-name> argument for name lookups are regular expressions."},
44 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000045 OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 "Show variable scope (argument, local, global, static)."},
47 {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000048 nullptr, {}, 0, eArgTypeName,
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 "Specify the summary that the variable output should use."},
50 {LLDB_OPT_SET_2, false, "summary-string", 'z',
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000051 OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName,
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 "Specify a summary string to use to format the variable output."},
Greg Clayton715c2362011-07-07 04:38:25 +000053};
54
Zachary Turner97206d52017-05-12 04:51:55 +000055static Status ValidateNamedSummary(const char *str, void *) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 if (!str || !str[0])
Zachary Turner97206d52017-05-12 04:51:55 +000057 return Status("must specify a valid named summary");
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 TypeSummaryImplSP summary_sp;
59 if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(
60 ConstString(str), summary_sp) == false)
Zachary Turner97206d52017-05-12 04:51:55 +000061 return Status("must specify a valid named summary");
62 return Status();
Enrico Granataef6b06d2013-01-17 20:24:11 +000063}
64
Zachary Turner97206d52017-05-12 04:51:55 +000065static Status ValidateSummaryString(const char *str, void *) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 if (!str || !str[0])
Zachary Turner97206d52017-05-12 04:51:55 +000067 return Status("must specify a non-empty summary string");
68 return Status();
Enrico Granataef6b06d2013-01-17 20:24:11 +000069}
Greg Clayton715c2362011-07-07 04:38:25 +000070
Kate Stoneb9c1b512016-09-06 20:57:50 +000071OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
72 : OptionGroup(), include_frame_options(show_frame_options),
73 summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
74
75OptionGroupVariable::~OptionGroupVariable() {}
76
Zachary Turner97206d52017-05-12 04:51:55 +000077Status
78OptionGroupVariable::SetOptionValue(uint32_t option_idx,
79 llvm::StringRef option_arg,
80 ExecutionContext *execution_context) {
81 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 if (!include_frame_options)
83 option_idx += 3;
Zachary Turner1f0f5b52016-09-22 20:22:55 +000084 const int short_option = g_variable_options[option_idx].short_option;
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 switch (short_option) {
86 case 'r':
87 use_regex = true;
88 break;
89 case 'a':
90 show_args = false;
91 break;
92 case 'l':
93 show_locals = false;
94 break;
95 case 'g':
96 show_globals = true;
97 break;
98 case 'c':
99 show_decl = true;
100 break;
101 case 's':
102 show_scope = true;
103 break;
104 case 'y':
105 error = summary.SetCurrentValue(option_arg);
106 break;
107 case 'z':
108 error = summary_string.SetCurrentValue(option_arg);
109 break;
110 default:
111 error.SetErrorStringWithFormat("unrecognized short option '%c'",
112 short_option);
113 break;
114 }
115
116 return error;
Greg Clayton715c2362011-07-07 04:38:25 +0000117}
118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119void OptionGroupVariable::OptionParsingStarting(
120 ExecutionContext *execution_context) {
121 show_args = true; // Frame option only
122 show_locals = true; // Frame option only
123 show_globals = false; // Frame option only
124 show_decl = false;
125 use_regex = false;
126 show_scope = false;
127 summary.Clear();
128 summary_string.Clear();
Greg Clayton715c2362011-07-07 04:38:25 +0000129}
130
Johnny Chen0a57b232011-09-10 01:19:01 +0000131#define NUM_FRAME_OPTS 3
Greg Clayton715c2362011-07-07 04:38:25 +0000132
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000133llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +0000134 auto result = llvm::makeArrayRef(g_variable_options);
Adrian Prantl05097242018-04-30 16:49:04 +0000135 // Show the "--no-args", "--no-locals" and "--show-globals" options if we are
136 // showing frame specific options
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137 if (include_frame_options)
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000138 return result;
Greg Clayton715c2362011-07-07 04:38:25 +0000139
Adrian Prantl05097242018-04-30 16:49:04 +0000140 // Skip the "--no-args", "--no-locals" and "--show-globals" options if we are
141 // not showing frame specific options (globals only)
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000142 return result.drop_front(NUM_FRAME_OPTS);
Greg Clayton715c2362011-07-07 04:38:25 +0000143}