1 namespace lldb_private {
4 PythonObject ToSWIGHelper(void *obj, swig_type_info *info) {
5 return {PyRefType::Owned, SWIG_NewPointerObj(obj, info, SWIG_POINTER_OWN)};
8 /// A class that automatically clears an SB object when it goes out of scope.
9 /// Use for cases where the SB object points to a temporary/unowned entity.
10 template <typename T> class ScopedPythonObject : PythonObject {
12 ScopedPythonObject(T *sb, swig_type_info *info)
13 : PythonObject(ToSWIGHelper(sb, info)), m_sb(sb) {}
14 ~ScopedPythonObject() {
18 ScopedPythonObject(ScopedPythonObject &&rhs)
19 : PythonObject(std::move(rhs)), m_sb(std::exchange(rhs.m_sb, nullptr)) {}
20 ScopedPythonObject(const ScopedPythonObject &) = delete;
21 ScopedPythonObject &operator=(const ScopedPythonObject &) = delete;
22 ScopedPythonObject &operator=(ScopedPythonObject &&) = delete;
24 const PythonObject &obj() const { return *this; }
30 PythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBValue> value_sb) {
31 return ToSWIGHelper(value_sb.release(), SWIGTYPE_p_lldb__SBValue);
34 PythonObject ToSWIGWrapper(lldb::ValueObjectSP value_sp) {
35 return ToSWIGWrapper(std::make_unique<lldb::SBValue>(std::move(value_sp)));
38 PythonObject ToSWIGWrapper(lldb::TargetSP target_sp) {
39 return ToSWIGHelper(new lldb::SBTarget(std::move(target_sp)),
40 SWIGTYPE_p_lldb__SBTarget);
43 PythonObject ToSWIGWrapper(lldb::ProcessSP process_sp) {
44 return ToSWIGHelper(new lldb::SBProcess(std::move(process_sp)),
45 SWIGTYPE_p_lldb__SBProcess);
48 PythonObject ToSWIGWrapper(lldb::ThreadPlanSP thread_plan_sp) {
49 return ToSWIGHelper(new lldb::SBThreadPlan(std::move(thread_plan_sp)),
50 SWIGTYPE_p_lldb__SBThreadPlan);
53 PythonObject ToSWIGWrapper(lldb::BreakpointSP breakpoint_sp) {
54 return ToSWIGHelper(new lldb::SBBreakpoint(std::move(breakpoint_sp)),
55 SWIGTYPE_p_lldb__SBBreakpoint);
58 PythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStream> stream_sb) {
59 return ToSWIGHelper(stream_sb.release(), SWIGTYPE_p_lldb__SBStream);
62 PythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStructuredData> data_sb) {
63 return ToSWIGHelper(data_sb.release(), SWIGTYPE_p_lldb__SBStructuredData);
66 PythonObject ToSWIGWrapper(const StructuredDataImpl &data_impl) {
67 return ToSWIGWrapper(std::make_unique<lldb::SBStructuredData>(data_impl));
70 PythonObject ToSWIGWrapper(lldb::ThreadSP thread_sp) {
71 return ToSWIGHelper(new lldb::SBThread(std::move(thread_sp)),
72 SWIGTYPE_p_lldb__SBThread);
75 PythonObject ToSWIGWrapper(lldb::StackFrameSP frame_sp) {
76 return ToSWIGHelper(new lldb::SBFrame(std::move(frame_sp)),
77 SWIGTYPE_p_lldb__SBFrame);
80 PythonObject ToSWIGWrapper(lldb::DebuggerSP debugger_sp) {
81 return ToSWIGHelper(new lldb::SBDebugger(std::move(debugger_sp)),
82 SWIGTYPE_p_lldb__SBDebugger);
85 PythonObject ToSWIGWrapper(lldb::WatchpointSP watchpoint_sp) {
86 return ToSWIGHelper(new lldb::SBWatchpoint(std::move(watchpoint_sp)),
87 SWIGTYPE_p_lldb__SBWatchpoint);
90 PythonObject ToSWIGWrapper(lldb::BreakpointLocationSP bp_loc_sp) {
91 return ToSWIGHelper(new lldb::SBBreakpointLocation(std::move(bp_loc_sp)),
92 SWIGTYPE_p_lldb__SBBreakpointLocation);
95 PythonObject ToSWIGWrapper(lldb::ExecutionContextRefSP ctx_sp) {
96 return ToSWIGHelper(new lldb::SBExecutionContext(std::move(ctx_sp)),
97 SWIGTYPE_p_lldb__SBExecutionContext);
100 PythonObject ToSWIGWrapper(const TypeSummaryOptions &summary_options) {
101 return ToSWIGHelper(new lldb::SBTypeSummaryOptions(summary_options),
102 SWIGTYPE_p_lldb__SBTypeSummaryOptions);
105 PythonObject ToSWIGWrapper(const SymbolContext &sym_ctx) {
106 return ToSWIGHelper(new lldb::SBSymbolContext(sym_ctx),
107 SWIGTYPE_p_lldb__SBSymbolContext);
110 ScopedPythonObject<lldb::SBCommandReturnObject>
111 ToSWIGWrapper(CommandReturnObject &cmd_retobj) {
112 return ScopedPythonObject<lldb::SBCommandReturnObject>(
113 new lldb::SBCommandReturnObject(cmd_retobj),
114 SWIGTYPE_p_lldb__SBCommandReturnObject);
117 ScopedPythonObject<lldb::SBEvent> ToSWIGWrapper(Event *event) {
118 return ScopedPythonObject<lldb::SBEvent>(new lldb::SBEvent(event),
119 SWIGTYPE_p_lldb__SBEvent);
122 } // namespace python
123 } // namespace lldb_private