diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectFrame.cpp')
| -rw-r--r-- | contrib/llvm-project/lldb/source/Commands/CommandObjectFrame.cpp | 209 |
1 files changed, 89 insertions, 120 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectFrame.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectFrame.cpp index ab6a07952f19..50d5c751de5c 100644 --- a/contrib/llvm-project/lldb/source/Commands/CommandObjectFrame.cpp +++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectFrame.cpp @@ -7,14 +7,10 @@ //===----------------------------------------------------------------------===// #include "CommandObjectFrame.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/StreamFile.h" -#include "lldb/Core/Value.h" #include "lldb/Core/ValueObject.h" -#include "lldb/Core/ValueObjectVariable.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/ValueObjectPrinter.h" -#include "lldb/Host/Host.h" +#include "lldb/Host/Config.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -23,24 +19,16 @@ #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" #include "lldb/Interpreter/OptionGroupVariable.h" #include "lldb/Interpreter/Options.h" -#include "lldb/Symbol/ClangASTContext.h" -#include "lldb/Symbol/CompilerType.h" #include "lldb/Symbol/Function.h" -#include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolContext.h" -#include "lldb/Symbol/Type.h" #include "lldb/Symbol/Variable.h" #include "lldb/Symbol/VariableList.h" -#include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/StackFrameRecognizer.h" #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/Args.h" -#include "lldb/Utility/LLDBAssert.h" -#include "lldb/Utility/StreamString.h" -#include "lldb/Utility/Timer.h" #include <memory> #include <string> @@ -54,13 +42,8 @@ using namespace lldb_private; // CommandObjectFrameDiagnose -static constexpr OptionDefinition g_frame_diag_options[] = { - // clang-format off - { LLDB_OPT_SET_1, false, "register", 'r', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeRegisterName, "A register to diagnose." }, - { LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeAddress, "An address to diagnose." }, - { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeOffset, "An optional offset. Requires --register." } - // clang-format on -}; +#define LLDB_OPTIONS_frame_diag +#include "CommandOptions.inc" class CommandObjectFrameDiagnose : public CommandObjectParsed { public: @@ -98,9 +81,7 @@ public: } break; default: - error.SetErrorStringWithFormat("invalid short option character '%c'", - short_option); - break; + llvm_unreachable("Unimplemented option"); } return error; @@ -185,10 +166,10 @@ protected: return false; } - - DumpValueObjectOptions::DeclPrintingHelper helper = [&valobj_sp]( - ConstString type, ConstString var, const DumpValueObjectOptions &opts, - Stream &stream) -> bool { + DumpValueObjectOptions::DeclPrintingHelper helper = + [&valobj_sp](ConstString type, ConstString var, + const DumpValueObjectOptions &opts, + Stream &stream) -> bool { const ValueObject::GetExpressionPathFormat format = ValueObject:: GetExpressionPathFormat::eGetExpressionPathFormatHonorPointers; const bool qualify_cxx_base_classes = false; @@ -217,12 +198,13 @@ protected: class CommandObjectFrameInfo : public CommandObjectParsed { public: CommandObjectFrameInfo(CommandInterpreter &interpreter) - : CommandObjectParsed( - interpreter, "frame info", "List information about the current " - "stack frame in the current thread.", - "frame info", - eCommandRequiresFrame | eCommandTryTargetAPILock | - eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {} + : CommandObjectParsed(interpreter, "frame info", + "List information about the current " + "stack frame in the current thread.", + "frame info", + eCommandRequiresFrame | eCommandTryTargetAPILock | + eCommandProcessMustBeLaunched | + eCommandProcessMustBePaused) {} ~CommandObjectFrameInfo() override = default; @@ -238,11 +220,8 @@ protected: // CommandObjectFrameSelect -static OptionDefinition g_frame_select_options[] = { - // clang-format off - { LLDB_OPT_SET_1, false, "relative", 'r', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeOffset, "A relative frame index offset from the current frame index." }, - // clang-format on -}; +#define LLDB_OPTIONS_frame_select +#include "CommandOptions.inc" class CommandObjectFrameSelect : public CommandObjectParsed { public: @@ -257,42 +236,43 @@ public: Status error; const int short_option = m_getopt_table[option_idx].val; switch (short_option) { - case 'r': - if (option_arg.getAsInteger(0, relative_frame_offset)) { - relative_frame_offset = INT32_MIN; + case 'r': { + int32_t offset = 0; + if (option_arg.getAsInteger(0, offset) || offset == INT32_MIN) { error.SetErrorStringWithFormat("invalid frame offset argument '%s'", option_arg.str().c_str()); - } + } else + relative_frame_offset = offset; break; + } default: - error.SetErrorStringWithFormat("invalid short option character '%c'", - short_option); - break; + llvm_unreachable("Unimplemented option"); } return error; } void OptionParsingStarting(ExecutionContext *execution_context) override { - relative_frame_offset = INT32_MIN; + relative_frame_offset.reset(); } llvm::ArrayRef<OptionDefinition> GetDefinitions() override { return llvm::makeArrayRef(g_frame_select_options); } - int32_t relative_frame_offset; + llvm::Optional<int32_t> relative_frame_offset; }; CommandObjectFrameSelect(CommandInterpreter &interpreter) - : CommandObjectParsed( - interpreter, "frame select", "Select the current stack frame by " - "index from within the current thread " - "(see 'thread backtrace'.)", - nullptr, - eCommandRequiresThread | eCommandTryTargetAPILock | - eCommandProcessMustBeLaunched | eCommandProcessMustBePaused), + : CommandObjectParsed(interpreter, "frame select", + "Select the current stack frame by " + "index from within the current thread " + "(see 'thread backtrace'.)", + nullptr, + eCommandRequiresThread | eCommandTryTargetAPILock | + eCommandProcessMustBeLaunched | + eCommandProcessMustBePaused), m_options() { CommandArgumentEntry arg; CommandArgumentData index_arg; @@ -320,15 +300,16 @@ protected: Thread *thread = m_exe_ctx.GetThreadPtr(); uint32_t frame_idx = UINT32_MAX; - if (m_options.relative_frame_offset != INT32_MIN) { + if (m_options.relative_frame_offset.hasValue()) { // The one and only argument is a signed relative frame index frame_idx = thread->GetSelectedFrameIndex(); if (frame_idx == UINT32_MAX) frame_idx = 0; - if (m_options.relative_frame_offset < 0) { - if (static_cast<int32_t>(frame_idx) >= -m_options.relative_frame_offset) - frame_idx += m_options.relative_frame_offset; + if (*m_options.relative_frame_offset < 0) { + if (static_cast<int32_t>(frame_idx) >= + -*m_options.relative_frame_offset) + frame_idx += *m_options.relative_frame_offset; else { if (frame_idx == 0) { // If you are already at the bottom of the stack, then just warn @@ -339,15 +320,15 @@ protected: } else frame_idx = 0; } - } else if (m_options.relative_frame_offset > 0) { + } else if (*m_options.relative_frame_offset > 0) { // I don't want "up 20" where "20" takes you past the top of the stack // to produce // an error, but rather to just go to the top. So I have to count the // stack here... const uint32_t num_frames = thread->GetStackFrameCount(); if (static_cast<int32_t>(num_frames - frame_idx) > - m_options.relative_frame_offset) - frame_idx += m_options.relative_frame_offset; + *m_options.relative_frame_offset) + frame_idx += *m_options.relative_frame_offset; else { if (frame_idx == num_frames - 1) { // If we are already at the top of the stack, just warn and don't @@ -371,7 +352,7 @@ protected: } if (command.GetArgumentCount() == 1) { - if (command[0].ref.getAsInteger(0, frame_idx)) { + if (command[0].ref().getAsInteger(0, frame_idx)) { result.AppendErrorWithFormat("invalid frame index argument '%s'.", command[0].c_str()); result.SetStatus(eReturnStatusFailed); @@ -425,14 +406,14 @@ public: "uses debug information and memory reads directly, rather than " "parsing and evaluating an expression, which may even involve " "JITing and running code in the target program.", - nullptr, eCommandRequiresFrame | eCommandTryTargetAPILock | - eCommandProcessMustBeLaunched | - eCommandProcessMustBePaused | eCommandRequiresProcess), + nullptr, + eCommandRequiresFrame | eCommandTryTargetAPILock | + eCommandProcessMustBeLaunched | eCommandProcessMustBePaused | + eCommandRequiresProcess), m_option_group(), m_option_variable( true), // Include the frame specific options by passing "true" - m_option_format(eFormatDefault), - m_varobj_options() { + m_option_format(eFormatDefault), m_varobj_options() { CommandArgumentEntry arg; CommandArgumentData var_name_arg; @@ -460,14 +441,13 @@ public: Options *GetOptions() override { return &m_option_group; } - int HandleArgumentCompletion( - CompletionRequest &request, - OptionElementVector &opt_element_vector) override { + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { // Arguments are the standard source file completer. CommandCompletions::InvokeCommonCompletionCallbacks( GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion, request, nullptr); - return request.GetNumberOfMatches(); } protected: @@ -541,9 +521,9 @@ protected: for (auto &entry : command) { if (m_option_variable.use_regex) { const size_t regex_start_index = regex_var_list.GetSize(); - llvm::StringRef name_str = entry.ref; + llvm::StringRef name_str = entry.ref(); RegularExpression regex(name_str); - if (regex.Compile(name_str)) { + if (regex.IsValid()) { size_t num_matches = 0; const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex, regex_var_list, @@ -582,9 +562,9 @@ protected: entry.c_str()); } } else { - char regex_error[1024]; - if (regex.GetErrorAsCString(regex_error, sizeof(regex_error))) - result.GetErrorStream().Printf("error: %s\n", regex_error); + if (llvm::Error err = regex.GetError()) + result.GetErrorStream().Printf( + "error: %s\n", llvm::toString(std::move(err)).c_str()); else result.GetErrorStream().Printf( "error: unknown regex error when compiling '%s'\n", @@ -600,7 +580,7 @@ protected: StackFrame::eExpressionPathOptionsInspectAnonymousUnions; lldb::VariableSP var_sp; valobj_sp = frame->GetValueForVariableExpressionPath( - entry.ref, m_varobj_options.use_dynamic, expr_path_options, + entry.ref(), m_varobj_options.use_dynamic, expr_path_options, var_sp, error); if (valobj_sp) { std::string scope_string; @@ -727,11 +707,11 @@ protected: // Increment statistics. bool res = result.Succeeded(); - Target *target = GetSelectedOrDummyTarget(); + Target &target = GetSelectedOrDummyTarget(); if (res) - target->IncrementStats(StatisticKind::FrameVarSuccess); + target.IncrementStats(StatisticKind::FrameVarSuccess); else - target->IncrementStats(StatisticKind::FrameVarFailure); + target.IncrementStats(StatisticKind::FrameVarFailure); return res; } @@ -744,14 +724,8 @@ protected: #pragma mark CommandObjectFrameRecognizer -static OptionDefinition g_frame_recognizer_add_options[] = { - // clang-format off - { LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Name of the module or shared library that this recognizer applies to." }, - { LLDB_OPT_SET_ALL, false, "function", 'n', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSymbolCompletion, eArgTypeName, "Name of the function that this recognizer applies to." }, - { LLDB_OPT_SET_2, false, "python-class", 'l', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePythonClass, "Give the name of a Python class to use for this frame recognizer." }, - { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Function name and module name are actually regular expressions." } - // clang-format on -}; +#define LLDB_OPTIONS_frame_recognizer_add +#include "CommandOptions.inc" class CommandObjectFrameRecognizerAdd : public CommandObjectParsed { private: @@ -779,9 +753,7 @@ private: m_regex = true; break; default: - error.SetErrorStringWithFormat("unrecognized option '%c'", - short_option); - break; + llvm_unreachable("Unimplemented option"); } return error; @@ -868,7 +840,7 @@ Process 1234 stopped bool CommandObjectFrameRecognizerAdd::DoExecute(Args &command, CommandReturnObject &result) { -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON if (m_options.m_class_name.empty()) { result.AppendErrorWithFormat( "%s needs a Python class name (-l argument).\n", m_cmd_name.c_str()); @@ -894,9 +866,8 @@ bool CommandObjectFrameRecognizerAdd::DoExecute(Args &command, if (interpreter && !interpreter->CheckObjectExists(m_options.m_class_name.c_str())) { - result.AppendWarning( - "The provided class does not exist - please define it " - "before attempting to use this frame recognizer"); + result.AppendWarning("The provided class does not exist - please define it " + "before attempting to use this frame recognizer"); } StackFrameRecognizerSP recognizer_sp = @@ -923,7 +894,7 @@ class CommandObjectFrameRecognizerClear : public CommandObjectParsed { public: CommandObjectFrameRecognizerClear(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "frame recognizer clear", - "Delete all frame recognizers.", nullptr) {} + "Delete all frame recognizers.", nullptr) {} ~CommandObjectFrameRecognizerClear() override = default; @@ -936,14 +907,14 @@ protected: }; class CommandObjectFrameRecognizerDelete : public CommandObjectParsed { - public: +public: CommandObjectFrameRecognizerDelete(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "frame recognizer delete", "Delete an existing frame recognizer.", nullptr) {} ~CommandObjectFrameRecognizerDelete() override = default; - protected: +protected: bool DoExecute(Args &command, CommandReturnObject &result) override { if (command.GetArgumentCount() == 0) { if (!m_interpreter.Confirm( @@ -976,7 +947,7 @@ class CommandObjectFrameRecognizerDelete : public CommandObjectParsed { }; class CommandObjectFrameRecognizerList : public CommandObjectParsed { - public: +public: CommandObjectFrameRecognizerList(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "frame recognizer list", "Show a list of active frame recognizers.", @@ -984,14 +955,15 @@ class CommandObjectFrameRecognizerList : public CommandObjectParsed { ~CommandObjectFrameRecognizerList() override = default; - protected: +protected: bool DoExecute(Args &command, CommandReturnObject &result) override { bool any_printed = false; StackFrameRecognizerManager::ForEach( [&result, &any_printed](uint32_t recognizer_id, std::string name, std::string function, std::string symbol, bool regexp) { - if (name == "") name = "(internal)"; + if (name == "") + name = "(internal)"; result.GetOutputStream().Printf( "%d: %s, module %s, function %s%s\n", recognizer_id, name.c_str(), function.c_str(), symbol.c_str(), regexp ? " (regexp)" : ""); @@ -1009,7 +981,7 @@ class CommandObjectFrameRecognizerList : public CommandObjectParsed { }; class CommandObjectFrameRecognizerInfo : public CommandObjectParsed { - public: +public: CommandObjectFrameRecognizerInfo(CommandInterpreter &interpreter) : CommandObjectParsed( interpreter, "frame recognizer info", @@ -1032,7 +1004,7 @@ class CommandObjectFrameRecognizerInfo : public CommandObjectParsed { ~CommandObjectFrameRecognizerInfo() override = default; - protected: +protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Process *process = m_exe_ctx.GetProcessPtr(); if (process == nullptr) { @@ -1080,27 +1052,24 @@ class CommandObjectFrameRecognizerInfo : public CommandObjectParsed { }; class CommandObjectFrameRecognizer : public CommandObjectMultiword { - public: +public: CommandObjectFrameRecognizer(CommandInterpreter &interpreter) : CommandObjectMultiword( interpreter, "frame recognizer", "Commands for editing and viewing frame recognizers.", "frame recognizer [<sub-command-options>] ") { - LoadSubCommand( - "add", - CommandObjectSP(new CommandObjectFrameRecognizerAdd(interpreter))); + LoadSubCommand("add", CommandObjectSP(new CommandObjectFrameRecognizerAdd( + interpreter))); LoadSubCommand( "clear", CommandObjectSP(new CommandObjectFrameRecognizerClear(interpreter))); LoadSubCommand( "delete", CommandObjectSP(new CommandObjectFrameRecognizerDelete(interpreter))); - LoadSubCommand( - "list", - CommandObjectSP(new CommandObjectFrameRecognizerList(interpreter))); - LoadSubCommand( - "info", - CommandObjectSP(new CommandObjectFrameRecognizerInfo(interpreter))); + LoadSubCommand("list", CommandObjectSP(new CommandObjectFrameRecognizerList( + interpreter))); + LoadSubCommand("info", CommandObjectSP(new CommandObjectFrameRecognizerInfo( + interpreter))); } ~CommandObjectFrameRecognizer() override = default; @@ -1112,9 +1081,10 @@ class CommandObjectFrameRecognizer : public CommandObjectMultiword { CommandObjectMultiwordFrame::CommandObjectMultiwordFrame( CommandInterpreter &interpreter) - : CommandObjectMultiword(interpreter, "frame", "Commands for selecting and " - "examing the current " - "thread's stack frames.", + : CommandObjectMultiword(interpreter, "frame", + "Commands for selecting and " + "examing the current " + "thread's stack frames.", "frame <subcommand> [<subcommand-options>]") { LoadSubCommand("diagnose", CommandObjectSP(new CommandObjectFrameDiagnose(interpreter))); @@ -1124,10 +1094,9 @@ CommandObjectMultiwordFrame::CommandObjectMultiwordFrame( CommandObjectSP(new CommandObjectFrameSelect(interpreter))); LoadSubCommand("variable", CommandObjectSP(new CommandObjectFrameVariable(interpreter))); -#ifndef LLDB_DISABLE_PYTHON - LoadSubCommand( - "recognizer", - CommandObjectSP(new CommandObjectFrameRecognizer(interpreter))); +#if LLDB_ENABLE_PYTHON + LoadSubCommand("recognizer", CommandObjectSP(new CommandObjectFrameRecognizer( + interpreter))); #endif } |
