LLDB mainline
ScriptedStackFrameRecognizerPythonInterface.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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-python.h"
10
17
18#include "../SWIGPythonBridge.h"
21
22using namespace lldb;
23using namespace lldb_private;
24using namespace lldb_private::python;
25
31
32llvm::Expected<StructuredData::GenericSP>
38
46
48 lldb::StackFrameSP frame_sp) {
50 StructuredData::ObjectSP obj = Dispatch("should_hide", error, frame_sp);
51
52 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
53 error))
54 return false;
55
56 return obj->GetBooleanValue();
57}
58
66
72
74 lldb::StackFrameSP frame_sp) {
77 Dispatch("get_stop_description", error, frame_sp);
78 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
79 error))
80 return "";
81 return obj->GetStringValue().str();
82}
83
86 lldb::ThreadSP thread_sp) {
89 "get_step_through_plan", error, thread_sp);
90 if (error.Fail())
91 return {};
92
93 // The return value is an StructuredData::Dictionary with the class name and
94 // the extra args for the call:
95 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION,
96 dict_sp, error))
97 return {};
98
99 StructuredData::ObjectSP obj = dict_sp->GetValueForKey("class_name");
100 if (!obj)
101 return {};
102
103 llvm::StringRef class_string = obj->GetStringValue();
104 if (class_string.empty())
105 return {};
106
107 // Look for extra args, this is optional:
108 StructuredData::Dictionary *extra_args_ptr = nullptr;
109 StructuredData::DictionarySP extra_args_sp;
110 if (dict_sp->GetValueForKeyAsDictionary("extra_args", extra_args_ptr))
111 extra_args_sp = std::static_pointer_cast<StructuredData::Dictionary>(
112 extra_args_ptr->shared_from_this());
113
114 // Now make a new thread plan for stepping using the provided class name and
115 // extra args.
116 ScriptedMetadata plan_metadata(class_string, extra_args_sp);
117 ThreadPlanSP step_through_plan_sp(
118 new ScriptedThreadPlan(*thread_sp.get(), plan_metadata));
119 step_through_plan_sp->SetStopOthers(true);
120
121 return step_through_plan_sp;
122}
123
125 const std::vector<llvm::StringRef> ci_usages = {
126 "frame recognizer add -l <script-name> [-s <shlib> ...] "
127 "[-n <symbol> ... | -x <symbol-regex>] [-f false] "
128 "[--mangled-name-preference <mode>]"};
131 "Recognize a stack frame and provide extra information about it "
132 "(recognized arguments, exception object, stop description, "
133 "hidden/most-relevant frame).",
135 eScriptLanguagePython, {ci_usages, {}});
136}
137
static llvm::raw_ostream & error(Stream &strm)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
lldb::StackFrameSP SelectMostRelevantFrame(lldb::StackFrameSP frame_sp) override
lldb::ValueObjectSP GetException(lldb::StackFrameSP frame_sp) override
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata) override
lldb::ValueObjectListSP GetRecognizedArguments(lldb::StackFrameSP frame_sp) override
An error handling class.
Definition Status.h:118
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
@ eScriptLanguagePython
@ eScriptedExtensionScriptedStackFrameRecognizer
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ValueObjectList > ValueObjectListSP