blob: 760563071d7dcd4a202628777587672d5078d4fd [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 Turnerbf9a7732017-02-02 21:39:50 +000020#include "lldb/Utility/Error.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()
Zachary Turner1f0f5b52016-09-22 20:22:55 +000027static OptionDefinition g_variable_options[] = {
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
29 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
30 "Omit function arguments."},
31 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
32 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
33 "Omit local variables."},
34 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
35 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
36 "Show the current frame source file global and static variables."},
37 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
38 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
39 "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',
42 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
43 "The <variable-name> argument for name lookups are regular expressions."},
44 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
45 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
46 "Show variable scope (argument, local, global, static)."},
47 {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,
48 nullptr, nullptr, 0, eArgTypeName,
49 "Specify the summary that the variable output should use."},
50 {LLDB_OPT_SET_2, false, "summary-string", 'z',
51 OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName,
52 "Specify a summary string to use to format the variable output."},
Greg Clayton715c2362011-07-07 04:38:25 +000053};
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055static Error ValidateNamedSummary(const char *str, void *) {
56 if (!str || !str[0])
57 return Error("must specify a valid named summary");
58 TypeSummaryImplSP summary_sp;
59 if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(
60 ConstString(str), summary_sp) == false)
61 return Error("must specify a valid named summary");
Mehdi Aminic1edf562016-11-11 04:29:25 +000062 return Error();
Enrico Granataef6b06d2013-01-17 20:24:11 +000063}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065static Error ValidateSummaryString(const char *str, void *) {
66 if (!str || !str[0])
67 return Error("must specify a non-empty summary string");
Mehdi Aminic1edf562016-11-11 04:29:25 +000068 return Error();
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
77Error OptionGroupVariable::SetOptionValue(uint32_t option_idx,
Zachary Turner8cef4b02016-09-23 17:48:13 +000078 llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 ExecutionContext *execution_context) {
80 Error error;
81 if (!include_frame_options)
82 option_idx += 3;
Zachary Turner1f0f5b52016-09-22 20:22:55 +000083 const int short_option = g_variable_options[option_idx].short_option;
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 switch (short_option) {
85 case 'r':
86 use_regex = true;
87 break;
88 case 'a':
89 show_args = false;
90 break;
91 case 'l':
92 show_locals = false;
93 break;
94 case 'g':
95 show_globals = true;
96 break;
97 case 'c':
98 show_decl = true;
99 break;
100 case 's':
101 show_scope = true;
102 break;
103 case 'y':
104 error = summary.SetCurrentValue(option_arg);
105 break;
106 case 'z':
107 error = summary_string.SetCurrentValue(option_arg);
108 break;
109 default:
110 error.SetErrorStringWithFormat("unrecognized short option '%c'",
111 short_option);
112 break;
113 }
114
115 return error;
Greg Clayton715c2362011-07-07 04:38:25 +0000116}
117
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118void OptionGroupVariable::OptionParsingStarting(
119 ExecutionContext *execution_context) {
120 show_args = true; // Frame option only
121 show_locals = true; // Frame option only
122 show_globals = false; // Frame option only
123 show_decl = false;
124 use_regex = false;
125 show_scope = false;
126 summary.Clear();
127 summary_string.Clear();
Greg Clayton715c2362011-07-07 04:38:25 +0000128}
129
Johnny Chen0a57b232011-09-10 01:19:01 +0000130#define NUM_FRAME_OPTS 3
Greg Clayton715c2362011-07-07 04:38:25 +0000131
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000132llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +0000133 auto result = llvm::makeArrayRef(g_variable_options);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134 // Show the "--no-args", "--no-locals" and "--show-globals"
135 // options if we are showing frame specific options
136 if (include_frame_options)
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000137 return result;
Greg Clayton715c2362011-07-07 04:38:25 +0000138
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139 // Skip the "--no-args", "--no-locals" and "--show-globals"
140 // options if we are not showing frame specific options (globals only)
Zachary Turner1f0f5b52016-09-22 20:22:55 +0000141 return result.drop_front(NUM_FRAME_OPTS);
Greg Clayton715c2362011-07-07 04:38:25 +0000142}