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 
12 #include "lldb/Host/OptionParser.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Utility/Status.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 // if you add any options here, remember to update the counters in
21 // OptionGroupVariable::GetNumDefinitions()
22 static constexpr OptionDefinition g_variable_options[] = {
23  {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',
24  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
25  "Omit function arguments."},
26  {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-recognized-args", 't',
27  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
28  "Omit recognized function arguments."},
29  {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',
30  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
31  "Omit local variables."},
32  {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',
33  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
34  "Show the current frame source file global and static variables."},
35  {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',
36  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
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',
40  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeRegularExpression,
41  "The <variable-name> argument for name lookups are regular expressions."},
42  {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',
43  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
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',
49  OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName,
50  "Specify a summary string to use to format the variable output."},
51 };
52 
53 static Status ValidateNamedSummary(const char *str, void *) {
54  if (!str || !str[0])
55  return Status("must specify a valid named summary");
56  TypeSummaryImplSP summary_sp;
57  if (!DataVisualization::NamedSummaryFormats::GetSummaryFormat(
58  ConstString(str), summary_sp))
59  return Status("must specify a valid named summary");
60  return Status();
61 }
62 
63 static Status ValidateSummaryString(const char *str, void *) {
64  if (!str || !str[0])
65  return Status("must specify a non-empty summary string");
66  return Status();
67 }
68 
69 OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
70  : include_frame_options(show_frame_options), summary(ValidateNamedSummary),
71  summary_string(ValidateSummaryString) {}
72 
73 Status
75  llvm::StringRef option_arg,
76  ExecutionContext *execution_context) {
77  Status error;
79  option_idx += 3;
80  const int short_option = g_variable_options[option_idx].short_option;
81  switch (short_option) {
82  case 'r':
83  use_regex = true;
84  break;
85  case 'a':
86  show_args = false;
87  break;
88  case 'l':
89  show_locals = false;
90  break;
91  case 'g':
92  show_globals = true;
93  break;
94  case 'c':
95  show_decl = true;
96  break;
97  case 's':
98  show_scope = true;
99  break;
100  case 't':
101  show_recognized_args = false;
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  llvm_unreachable("Unimplemented option");
111  }
112 
113  return error;
114 }
115 
117  ExecutionContext *execution_context) {
118  show_args = true; // Frame option only
119  show_recognized_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();
127 }
128 
129 #define NUM_FRAME_OPTS 3
130 
131 llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {
132  auto result = llvm::makeArrayRef(g_variable_options);
133  // Show the "--no-args", "--no-locals" and "--show-globals" options if we are
134  // showing frame specific options
136  return result;
137 
138  // Skip the "--no-args", "--no-locals" and "--show-globals" options if we are
139  // not showing frame specific options (globals only)
140  return result.drop_front(NUM_FRAME_OPTS);
141 }
lldb_private::OptionGroupVariable::summary_string
OptionValueString summary_string
Definition: OptionGroupVariable.h:40
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::OptionGroupVariable::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: OptionGroupVariable.cpp:131
lldb_private::OptionGroupVariable::summary
OptionValueString summary
Definition: OptionGroupVariable.h:39
g_variable_options
static constexpr OptionDefinition g_variable_options[]
Definition: OptionGroupVariable.cpp:22
lldb_private::OptionGroupVariable::include_frame_options
bool include_frame_options
Definition: OptionGroupVariable.h:32
lldb_private::OptionGroupVariable::show_locals
bool show_locals
Definition: OptionGroupVariable.h:36
Target.h
lldb_private::OptionGroupVariable::show_decl
bool show_decl
Definition: OptionGroupVariable.h:38
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::OptionGroupVariable::show_scope
bool show_scope
Definition: OptionGroupVariable.h:38
ValidateSummaryString
static Status ValidateSummaryString(const char *str, void *)
Definition: OptionGroupVariable.cpp:63
LLDB_OPT_SET_1
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:113
lldb_private::ConstString
Definition: ConstString.h:40
lldb::eArgTypeRegularExpression
@ eArgTypeRegularExpression
Definition: lldb-enumerations.h:569
ValidateNamedSummary
static Status ValidateNamedSummary(const char *str, void *)
Definition: OptionGroupVariable.cpp:53
OptionGroupVariable.h
lldb_private::OptionValueString::Clear
void Clear() override
Definition: OptionValueString.h:76
lldb_private::Status
Definition: Status.h:44
DataVisualization.h
NUM_FRAME_OPTS
#define NUM_FRAME_OPTS
Definition: OptionGroupVariable.cpp:129
uint32_t
lldb_private::OptionGroupVariable::use_regex
bool use_regex
Definition: OptionGroupVariable.h:38
lldb::eArgTypeNone
@ eArgTypeNone
Definition: lldb-enumerations.h:595
lldb::eArgTypeName
@ eArgTypeName
Definition: lldb-enumerations.h:551
lldb_private::OptionValueString::SetCurrentValue
Status SetCurrentValue(llvm::StringRef value)
Definition: OptionValueString.cpp:120
lldb_private::OptionGroupVariable::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: OptionGroupVariable.cpp:116
Status.h
OptionParser.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::OptionGroupVariable::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
Definition: OptionGroupVariable.cpp:74
lldb_private::OptionDefinition
Definition: OptionDefinition.h:20
CommandInterpreter.h
lldb_private::OptionGroupVariable::show_args
bool show_args
Definition: OptionGroupVariable.h:33
lldb_private::OptionGroupVariable::show_globals
bool show_globals
Definition: OptionGroupVariable.h:37
lldb_private::OptionGroupVariable::show_recognized_args
bool show_recognized_args
Definition: OptionGroupVariable.h:34
lldb_private::OptionDefinition::short_option
int short_option
Single character for this option.
Definition: OptionDefinition.h:32
LLDB_OPT_SET_2
#define LLDB_OPT_SET_2
Definition: lldb-defines.h:114
lldb
Definition: SBAddress.h:15