LLDB mainline
ScriptedFramePythonInterface.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/Host/Config.h"
11#include "lldb/Utility/Log.h"
13
14#if LLDB_ENABLE_PYTHON
15
16// LLDB Python header must be included first
17#include "../lldb-python.h"
18
19#include "../SWIGPythonBridge.h"
22#include <optional>
23
24using namespace lldb;
25using namespace lldb_private;
26using namespace lldb_private::python;
27using Locker = ScriptInterpreterPythonImpl::Locker;
28
29ScriptedFramePythonInterface::ScriptedFramePythonInterface(
30 ScriptInterpreterPythonImpl &interpreter)
31 : ScriptedFrameInterface(), ScriptedPythonInterface(interpreter) {}
32
33llvm::Expected<StructuredData::GenericSP>
34ScriptedFramePythonInterface::CreatePluginObject(
35 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
37 ExecutionContextRefSP exe_ctx_ref_sp =
38 std::make_shared<ExecutionContextRef>(exe_ctx);
39 StructuredDataImpl sd_impl(args_sp);
40 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
41 exe_ctx_ref_sp, sd_impl);
42}
43
44lldb::user_id_t ScriptedFramePythonInterface::GetID() {
46 StructuredData::ObjectSP obj = Dispatch("get_id", error);
47
48 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
49 error))
51
52 return obj->GetUnsignedIntegerValue(LLDB_INVALID_FRAME_ID);
53}
54
55lldb::addr_t ScriptedFramePythonInterface::GetPC() {
57 StructuredData::ObjectSP obj = Dispatch("get_pc", error);
58
59 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
60 error))
62
63 return obj->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);
64}
65
66std::optional<SymbolContext> ScriptedFramePythonInterface::GetSymbolContext() {
68 auto sym_ctx = Dispatch<SymbolContext>("get_symbol_context", error);
69
70 if (error.Fail()) {
71 return ErrorWithMessage<SymbolContext>(LLVM_PRETTY_FUNCTION,
72 error.AsCString(), error);
73 }
74
75 return sym_ctx;
76}
77
78std::optional<std::string> ScriptedFramePythonInterface::GetFunctionName() {
80 StructuredData::ObjectSP obj = Dispatch("get_function_name", error);
81
82 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
83 error))
84 return {};
85
86 return obj->GetStringValue().str();
87}
88
89std::optional<std::string>
90ScriptedFramePythonInterface::GetDisplayFunctionName() {
92 StructuredData::ObjectSP obj = Dispatch("get_display_function_name", error);
93
94 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
95 error))
96 return {};
97
98 return obj->GetStringValue().str();
99}
100
101bool ScriptedFramePythonInterface::IsInlined() {
103 StructuredData::ObjectSP obj = Dispatch("is_inlined", error);
104
105 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
106 error))
107 return false;
108
109 return obj->GetBooleanValue();
110}
111
112bool ScriptedFramePythonInterface::IsArtificial() {
114 StructuredData::ObjectSP obj = Dispatch("is_artificial", error);
115
116 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
117 error))
118 return false;
119
120 return obj->GetBooleanValue();
121}
122
123bool ScriptedFramePythonInterface::IsHidden() {
125 StructuredData::ObjectSP obj = Dispatch("is_hidden", error);
126
127 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
128 error))
129 return false;
130
131 return obj->GetBooleanValue();
132}
133
134StructuredData::DictionarySP ScriptedFramePythonInterface::GetRegisterInfo() {
137 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
138
139 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
140 error))
141 return {};
142
143 return dict;
144}
145
146std::optional<std::string> ScriptedFramePythonInterface::GetRegisterContext() {
148 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
149
150 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
151 error))
152 return {};
153
154 return obj->GetAsString()->GetValue().str();
155}
156
157#endif
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_FRAME_ID
A class that represents a running process on the host machine.
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP