llvm-project
141 строка · 5.2 Кб
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
9#include "lldb/Interpreter/OptionGroupVariable.h"10
11#include "lldb/DataFormatters/DataVisualization.h"12#include "lldb/Host/OptionParser.h"13#include "lldb/Interpreter/CommandInterpreter.h"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()
22static constexpr OptionDefinition g_variable_options[] = {23{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',24OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,25"Omit function arguments."},26{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-recognized-args", 't',27OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,28"Omit recognized function arguments."},29{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',30OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,31"Omit local variables."},32{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',33OptionParser::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',36OptionParser::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',40OptionParser::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',43OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,44"Show variable scope (argument, local, global, static)."},45{LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,46nullptr, {}, 0, eArgTypeName,47"Specify the summary that the variable output should use."},48{LLDB_OPT_SET_2, false, "summary-string", 'z',49OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName,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 =55llvm::ArrayRef<OptionDefinition>(g_variable_options)56.drop_front(g_num_frame_options);57
58static Status ValidateNamedSummary(const char *str, void *) {59if (!str || !str[0])60return Status("must specify a valid named summary");61TypeSummaryImplSP summary_sp;62if (!DataVisualization::NamedSummaryFormats::GetSummaryFormat(63ConstString(str), summary_sp))64return Status("must specify a valid named summary");65return Status();66}
67
68static Status ValidateSummaryString(const char *str, void *) {69if (!str || !str[0])70return Status("must specify a non-empty summary string");71return Status();72}
73
74OptionGroupVariable::OptionGroupVariable(bool show_frame_options)75: include_frame_options(show_frame_options), show_args(false),76show_recognized_args(false), show_locals(false), show_globals(false),77use_regex(false), show_scope(false), show_decl(false),78summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}79
80Status
81OptionGroupVariable::SetOptionValue(uint32_t option_idx,82llvm::StringRef option_arg,83ExecutionContext *execution_context) {84Status error;85llvm::ArrayRef<OptionDefinition> variable_options =86include_frame_options ? g_variable_options : g_variable_options_noframe;87const int short_option = variable_options[option_idx].short_option;88switch (short_option) {89case 'r':90use_regex = true;91break;92case 'a':93show_args = false;94break;95case 'l':96show_locals = false;97break;98case 'g':99show_globals = true;100break;101case 'c':102show_decl = true;103break;104case 's':105show_scope = true;106break;107case 't':108show_recognized_args = false;109break;110case 'y':111error = summary.SetCurrentValue(option_arg);112break;113case 'z':114error = summary_string.SetCurrentValue(option_arg);115break;116default:117llvm_unreachable("Unimplemented option");118}119
120return error;121}
122
123void OptionGroupVariable::OptionParsingStarting(124ExecutionContext *execution_context) {125show_args = true; // Frame option only126show_recognized_args = true; // Frame option only127show_locals = true; // Frame option only128show_globals = false; // Frame option only129show_decl = false;130use_regex = false;131show_scope = false;132summary.Clear();133summary_string.Clear();134}
135
136llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {137// Show the "--no-args", "--no-recognized-args", "--no-locals" and138// "--show-globals" options if we are showing frame specific options139return include_frame_options ? g_variable_options140: g_variable_options_noframe;141}
142