Path: blob/main/contrib/llvm-project/lldb/source/Interpreter/OptionGroupVariable.cpp
39587 views
//===-- OptionGroupVariable.cpp -------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Interpreter/OptionGroupVariable.h"910#include "lldb/DataFormatters/DataVisualization.h"11#include "lldb/Host/OptionParser.h"12#include "lldb/Interpreter/CommandInterpreter.h"13#include "lldb/Target/Target.h"14#include "lldb/Utility/Status.h"1516using namespace lldb;17using namespace lldb_private;1819// if you add any options here, remember to update the counters in20// OptionGroupVariable::GetNumDefinitions()21static constexpr OptionDefinition g_variable_options[] = {22{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a',23OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,24"Omit function arguments."},25{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-recognized-args", 't',26OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,27"Omit recognized function arguments."},28{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l',29OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,30"Omit local variables."},31{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g',32OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,33"Show the current frame source file global and static variables."},34{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c',35OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,36"Show variable declaration information (source file and line where the "37"variable was declared)."},38{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r',39OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeRegularExpression,40"The <variable-name> argument for name lookups are regular expressions."},41{LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's',42OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,43"Show variable scope (argument, local, global, static)."},44{LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument,45nullptr, {}, 0, eArgTypeName,46"Specify the summary that the variable output should use."},47{LLDB_OPT_SET_2, false, "summary-string", 'z',48OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName,49"Specify a summary string to use to format the variable output."},50};5152static constexpr auto g_num_frame_options = 4;53static const auto g_variable_options_noframe =54llvm::ArrayRef<OptionDefinition>(g_variable_options)55.drop_front(g_num_frame_options);5657static Status ValidateNamedSummary(const char *str, void *) {58if (!str || !str[0])59return Status("must specify a valid named summary");60TypeSummaryImplSP summary_sp;61if (!DataVisualization::NamedSummaryFormats::GetSummaryFormat(62ConstString(str), summary_sp))63return Status("must specify a valid named summary");64return Status();65}6667static Status ValidateSummaryString(const char *str, void *) {68if (!str || !str[0])69return Status("must specify a non-empty summary string");70return Status();71}7273OptionGroupVariable::OptionGroupVariable(bool show_frame_options)74: include_frame_options(show_frame_options), show_args(false),75show_recognized_args(false), show_locals(false), show_globals(false),76use_regex(false), show_scope(false), show_decl(false),77summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}7879Status80OptionGroupVariable::SetOptionValue(uint32_t option_idx,81llvm::StringRef option_arg,82ExecutionContext *execution_context) {83Status error;84llvm::ArrayRef<OptionDefinition> variable_options =85include_frame_options ? g_variable_options : g_variable_options_noframe;86const int short_option = variable_options[option_idx].short_option;87switch (short_option) {88case 'r':89use_regex = true;90break;91case 'a':92show_args = false;93break;94case 'l':95show_locals = false;96break;97case 'g':98show_globals = true;99break;100case 'c':101show_decl = true;102break;103case 's':104show_scope = true;105break;106case 't':107show_recognized_args = false;108break;109case 'y':110error = summary.SetCurrentValue(option_arg);111break;112case 'z':113error = summary_string.SetCurrentValue(option_arg);114break;115default:116llvm_unreachable("Unimplemented option");117}118119return error;120}121122void OptionGroupVariable::OptionParsingStarting(123ExecutionContext *execution_context) {124show_args = true; // Frame option only125show_recognized_args = true; // Frame option only126show_locals = true; // Frame option only127show_globals = false; // Frame option only128show_decl = false;129use_regex = false;130show_scope = false;131summary.Clear();132summary_string.Clear();133}134135llvm::ArrayRef<OptionDefinition> OptionGroupVariable::GetDefinitions() {136// Show the "--no-args", "--no-recognized-args", "--no-locals" and137// "--show-globals" options if we are showing frame specific options138return include_frame_options ? g_variable_options139: g_variable_options_noframe;140}141142143