LLDB mainline
OptionGroupVariable.cpp
Go to the documentation of this file.
1//===-- OptionGroupVariable.cpp -------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
14#include "lldb/Target/Target.h"
15#include "lldb/Utility/Status.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20// if you add any options here, remember to update the counters in
21// OptionGroupVariable::GetNumDefinitions()
23 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
25 "Omit function arguments."},
26 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-recognized-args", 't',
28 "Omit recognized function arguments."},
29 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
31 "Omit local variables."},
32 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
34 "Show the current frame source file global and static variables."},
35 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
37 "Show variable declaration information (source file and line where the "
38 "variable was declared)."},
39 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r',
41 "The <variable-name> argument for name lookups are regular expressions."},
42 {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
44 "Show variable scope (argument, local, global, static)."},
45 {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,
46 nullptr, {}, 0, eArgTypeName,
47 "Specify the summary that the variable output should use."},
48 {LLDB_OPT_SET_2, false, "summary-string", 'z',
50 "Specify a summary string to use to format the variable output."},
51};
52
53static constexpr auto g_num_frame_options = 4;
54static const auto g_variable_options_noframe =
55 llvm::ArrayRef<OptionDefinition>(g_variable_options)
56 .drop_front(g_num_frame_options);
57
58static Status ValidateNamedSummary(const char *str, void *) {
59 if (!str || !str[0])
60 return Status("must specify a valid named summary");
61 TypeSummaryImplSP summary_sp;
63 ConstString(str), summary_sp))
64 return Status("must specify a valid named summary");
65 return Status();
66}
67
68static Status ValidateSummaryString(const char *str, void *) {
69 if (!str || !str[0])
70 return Status("must specify a non-empty summary string");
71 return Status();
72}
73
75 : include_frame_options(show_frame_options), show_args(false),
76 show_recognized_args(false), show_locals(false), show_globals(false),
77 use_regex(false), show_scope(false), show_decl(false),
78 summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
79
82 llvm::StringRef option_arg,
83 ExecutionContext *execution_context) {
85 llvm::ArrayRef<OptionDefinition> variable_options =
87 const int short_option = variable_options[option_idx].short_option;
88 switch (short_option) {
89 case 'r':
90 use_regex = true;
91 break;
92 case 'a':
93 show_args = false;
94 break;
95 case 'l':
96 show_locals = false;
97 break;
98 case 'g':
99 show_globals = true;
100 break;
101 case 'c':
102 show_decl = true;
103 break;
104 case 's':
105 show_scope = true;
106 break;
107 case 't':
108 show_recognized_args = false;
109 break;
110 case 'y':
111 error = summary.SetCurrentValue(option_arg);
112 break;
113 case 'z':
115 break;
116 default:
117 llvm_unreachable("Unimplemented option");
118 }
119
120 return error;
121}
122
124 ExecutionContext *execution_context) {
125 show_args = true; // Frame option only
126 show_recognized_args = true; // Frame option only
127 show_locals = true; // Frame option only
128 show_globals = false; // Frame option only
129 show_decl = false;
130 use_regex = false;
131 show_scope = false;
132 summary.Clear();
134}
135
136llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {
137 // Show the "--no-args", "--no-recognized-args", "--no-locals" and
138 // "--show-globals" options if we are showing frame specific options
141}
static llvm::raw_ostream & error(Stream &strm)
static Status ValidateSummaryString(const char *str, void *)
static Status ValidateNamedSummary(const char *str, void *)
static const auto g_variable_options_noframe
static constexpr OptionDefinition g_variable_options[]
static constexpr auto g_num_frame_options
A uniqued constant string class.
Definition: ConstString.h:40
static bool GetSummaryFormat(ConstString type, lldb::TypeSummaryImplSP &entry)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
OptionGroupVariable(bool show_frame_options)
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetCurrentValue(llvm::StringRef value)
An error handling class.
Definition: Status.h:44
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:111
#define LLDB_OPT_SET_2
Definition: lldb-defines.h:112
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:463
@ eArgTypeRegularExpression