9#include "lldb/Host/Config.h"
16#include "../lldb-python.h"
18#include "../ScriptInterpreterPythonImpl.h"
25ScriptedPythonInterface::ScriptedPythonInterface(
26 ScriptInterpreterPythonImpl &interpreter)
31ScriptedPythonInterface::ExtractValueFromPythonObject<StructuredData::ArraySP>(
33 python::PythonList result_list(python::PyRefType::Borrowed, p.get());
34 return result_list.CreateStructuredArray();
39ScriptedPythonInterface::ExtractValueFromPythonObject<
41 python::PythonDictionary result_dict(python::PyRefType::Borrowed, p.get());
42 return result_dict.CreateStructuredDictionary();
46Status ScriptedPythonInterface::ExtractValueFromPythonObject<Status>(
49 python::LLDBSWIGPython_CastPyObjectToSBError(p.get())))
50 return m_interpreter.GetStatusFromSBError(*sb_error);
52 Status::FromErrorString(
"Couldn't cast lldb::SBError to lldb::Status.");
58Event *ScriptedPythonInterface::ExtractValueFromPythonObject<Event *>(
61 python::LLDBSWIGPython_CastPyObjectToSBEvent(p.get())))
62 return m_interpreter.GetOpaqueTypeFromSBEvent(*sb_event);
63 error = Status::FromErrorString(
64 "Couldn't cast lldb::SBEvent to lldb_private::Event.");
71ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StreamSP>(
74 python::LLDBSWIGPython_CastPyObjectToSBStream(p.get())))
75 return m_interpreter.GetOpaqueTypeFromSBStream(*sb_stream);
76 error = Status::FromErrorString(
77 "Couldn't cast lldb::SBStream to lldb_private::Stream.");
84ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::DataExtractorSP>(
87 python::LLDBSWIGPython_CastPyObjectToSBData(p.get()));
90 error = Status::FromErrorStringWithFormat(
91 "Couldn't cast lldb::SBData to lldb::DataExtractorSP.");
95 return m_interpreter.GetDataExtractorFromSBData(*sb_data);
100ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::BreakpointSP>(
103 python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(p.get()));
105 if (!sb_breakpoint) {
106 error = Status::FromErrorStringWithFormat(
107 "Couldn't cast lldb::SBBreakpoint to lldb::BreakpointSP.");
111 return m_interpreter.GetOpaqueTypeFromSBBreakpoint(*sb_breakpoint);
118 python::LLDBSWIGPython_CastPyObjectToSBAttachInfo(p.get()));
120 if (!sb_attach_info) {
121 error = Status::FromErrorStringWithFormat(
122 "Couldn't cast lldb::SBAttachInfo to lldb::ProcessAttachInfoSP.");
126 return m_interpreter.GetOpaqueTypeFromSBAttachInfo(*sb_attach_info);
133 python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(p.get()));
135 if (!sb_launch_info) {
136 error = Status::FromErrorStringWithFormat(
137 "Couldn't cast lldb::SBLaunchInfo to lldb::ProcessLaunchInfoSP.");
141 return m_interpreter.GetOpaqueTypeFromSBLaunchInfo(*sb_launch_info);
145std::optional<MemoryRegionInfo>
146ScriptedPythonInterface::ExtractValueFromPythonObject<
147 std::optional<MemoryRegionInfo>>(python::PythonObject &p,
Status &
error) {
151 python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(p.get()));
153 if (!sb_mem_reg_info) {
154 error = Status::FromErrorStringWithFormat(
155 "Couldn't cast lldb::SBMemoryRegionInfo to lldb::MemoryRegionInfoSP.");
159 return m_interpreter.GetOpaqueTypeFromSBMemoryRegionInfo(*sb_mem_reg_info);
164ScriptedPythonInterface::ExtractValueFromPythonObject<
169 python::LLDBSWIGPython_CastPyObjectToSBExecutionContext(p.get()));
172 error = Status::FromErrorStringWithFormat(
173 "Couldn't cast lldb::SBExecutionContext to "
174 "lldb::ExecutionContextRefSP.");
178 return m_interpreter.GetOpaqueTypeFromSBExecutionContext(*sb_exe_ctx);
static llvm::raw_ostream & error(Stream &strm)
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Array > ArraySP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ProcessAttachInfo > ProcessAttachInfoSP
std::shared_ptr< lldb_private::Stream > StreamSP
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::ProcessLaunchInfo > ProcessLaunchInfoSP
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP