blob: fd3935181c7fd51651f860b2038b06fa2277a2fa [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"
Greg Clayton715c2362011-07-07 04:38:25 +000017#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000018#include "lldb/Target/Target.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000019#include "lldb/Utility/Error.h"
Greg Clayton715c2362011-07-07 04:38:25 +000020
21using namespace lldb;
22using namespace lldb_private;
23
Kate Stoneb9c1b512016-09-06 20:57:50 +000024// if you add any options here, remember to update the counters in
25// OptionGroupVariable::GetNumDefinitions()
Zachary Turner1f0f5b52016-09-22 20:22:55 +000026static OptionDefinition g_variable_options[] = {
Kate Stoneb9c1b512016-09-06 20:57:50 +000027 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
28 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
29 "Omit function arguments."},
30 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
31 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
32 "Omit local variables."},
33 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
34 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
35 "Show the current frame source file global and static variables."},
36 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
37 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
38 "Show variable declaration information (source file and line where the "
39 "variable was declared)."},
40 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r',
41 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
42 "The <variable-name> argument for name lookups are regular expressions."},
43 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
44 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
45 "Show variable scope (argument, local, global, static)."},
46 {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,
47 nullptr, nullptr, 0, eArgTypeName,
48 "Specify the summary that the variable output should use."},
49 {LLDB_OPT_SET_2, false, "summary-string", 'z',
50 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName,
51 "Specify a summary string to use to format the variable output."},
Greg Clayton715c2362011-07-07 04:38:25 +000052};
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054static Error ValidateNamedSummary(const char *str, void *) {
55 if (!str || !str[0])
56 return Error("must specify a valid named summary");
57 TypeSummaryImplSP summary_sp;
58 if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(
59 ConstString(str), summary_sp) == false)
60 return Error("must specify a valid named summary");
Mehdi Aminic1edf562016-11-11 04:29:25 +000061 return Error();
Enrico Granataef6b06d2013-01-17 20:24:11 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064static Error ValidateSummaryString(const char *str, void *) {
65 if (!str || !str[0])
66 return Error("must specify a non-empty summary string");
Mehdi Aminic1edf562016-11-11 04:29:25 +000067 return Error();
Enrico Granataef6b06d2013-01-17 20:24:11 +000068}
Greg Clayton715c2362011-07-07 04:38:25 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
71 : OptionGroup(), include_frame_options(show_frame_options),
72 summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
73
74OptionGroupVariable::~OptionGroupVariable() {}
75
76Error OptionGroupVariable::SetOptionValue(uint32_t option_idx,
Zachary Turner8cef4b02016-09-23 17:48:13 +000077 llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 ExecutionContext *execution_context) {
79 Error error;
80 if (!include_frame_options)
81 option_idx += 3;
Zachary Turner1f0f5b52016-09-22 20:22:55 +000082 const int short_option = g_variable_options[option_idx].short_option;
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 switch (short_option) {
84 case 'r':
85 use_regex = true;
86 break;
87 case 'a':
88 show_args = false;
89 break;
90 case 'l':
91 show_locals = false;
92 break;
93 case 'g':
94 show_globals = true;
95 break;
96 case 'c':
97 show_decl = true;
98 break;
99 case 's':
100 show_scope = true;
101 break;
102 case 'y':
103 error = summary.SetCurrentValue(option_arg);
104 break;
105 case 'z':
106 error = summary_string.SetCurrentValue(option_arg);
107 break;
108 default:
109 error.SetErrorStringWithFormat("unrecognized short option '%c'",
110 short_option);
111 break;
112 }
113
114 return error;
Greg Clayton715c2362011-07-07 04:38:25 +0000115}
116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117void OptionGroupVariable::OptionParsingStarting(
118 ExecutionContext *execution_context) {
119 show_args = true; // Frame option only
120 show_locals = true; // Frame option only
121 show_globals = false; // Frame option only
122 show_decl = false;
123 use_regex = false;
124 show_scope = false;
125 summary.Clear();
126 summary_string.Clear();
Greg Clayton715c2362011-07-07 04:38:25 +0000127}
128
Johnny Chen0a57b232011-09-10 01:19:01 +0000129#define NUM_FRAME_OPTS 3
Greg Clayton715c2362011-07-07 04:38:25 +0000130
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000131llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +0000132 auto result = llvm::makeArrayRef(g_variable_options);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 // Show the "--no-args", "--no-locals" and "--show-globals"
134 // options if we are showing frame specific options
135 if (include_frame_options)
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000136 return result;
Greg Clayton715c2362011-07-07 04:38:25 +0000137
Kate Stoneb9c1b512016-09-06 20:57:50 +0000138 // Skip the "--no-args", "--no-locals" and "--show-globals"
139 // options if we are not showing frame specific options (globals only)
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000140 return result.drop_front(NUM_FRAME_OPTS);
Greg Clayton715c2362011-07-07 04:38:25 +0000141}