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
41 lldb::StackFrameSP frame_sp) {
42 return LogAndDefault(
43 Dispatch<lldb::ValueObjectListSP>("get_recognized_arguments", frame_sp),
44 LLVM_PRETTY_FUNCTION);
45}
46
48 lldb::StackFrameSP frame_sp) {
50 LogAndDefault(Dispatch("should_hide", frame_sp), LLVM_PRETTY_FUNCTION);
51 if (!obj)
52 return false;
53
54 return obj->GetBooleanValue();
55}
56
59 lldb::StackFrameSP frame_sp) {
60 return LogAndDefault(
61 Dispatch<lldb::StackFrameSP>("select_most_relevant_frame", frame_sp),
62 LLVM_PRETTY_FUNCTION);
63}
64
70
72 lldb::StackFrameSP frame_sp) {
74 Dispatch("get_stop_description", frame_sp), LLVM_PRETTY_FUNCTION);
75 if (!obj)
76 return "";
77
78 return obj->GetStringValue().str();
79}
80
83 lldb::ThreadSP thread_sp) {
86 "get_step_through_plan", thread_sp),
87 LLVM_PRETTY_FUNCTION);
88
89 // The return value is an StructuredData::Dictionary with the class name and
90 // the extra args for the call:
91 if (!dict_sp || !dict_sp->IsValid())
92 return {};
93
94 StructuredData::ObjectSP obj = dict_sp->GetValueForKey("class_name");
95 if (!obj)
96 return {};
97
98 llvm::StringRef class_string = obj->GetStringValue();
99 if (class_string.empty())
100 return {};
101
102 // Look for extra args, this is optional:
103 StructuredData::Dictionary *extra_args_ptr = nullptr;
104 StructuredData::DictionarySP extra_args_sp;
105 if (dict_sp->GetValueForKeyAsDictionary("extra_args", extra_args_ptr))
106 extra_args_sp = std::static_pointer_cast<StructuredData::Dictionary>(
107 extra_args_ptr->shared_from_this());
108
109 // Now make a new thread plan for stepping using the provided class name and
110 // extra args.
111 ScriptedMetadata plan_metadata(class_string, extra_args_sp);
112 ThreadPlanSP step_through_plan_sp(
113 new ScriptedThreadPlan(*thread_sp.get(), plan_metadata));
114 step_through_plan_sp->SetStopOthers(true);
115
116 return step_through_plan_sp;
117}
118
120 const std::vector<llvm::StringRef> ci_usages = {
121 "frame recognizer add -l <script-name> [-s <shlib> ...] "
122 "[-n <symbol> ... | -x <symbol-regex>] [-f false] "
123 "[--mangled-name-preference <mode>]"};
126 "Recognize a stack frame and provide extra information about it "
127 "(recognized arguments, exception object, stop description, "
128 "hidden/most-relevant frame).",
130 eScriptLanguagePython, {ci_usages, {}});
131}
132
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
static T LogAndDefault(llvm::Expected< T > value_or_err, llvm::StringRef caller)
Log the failure in value_or_err and fall back to a default-constructed T.
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Expected< T > Dispatch(llvm::StringRef method_name, Args &&...args)
Call method_name on the scripted object.
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
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