xref: /freebsd/contrib/llvm-project/lldb/bindings/python/python-swigsafecast.swig (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
14824e7fdSDimitry Andricnamespace lldb_private {
24824e7fdSDimitry Andricnamespace python {
34824e7fdSDimitry Andric
44824e7fdSDimitry AndricPythonObject ToSWIGHelper(void *obj, swig_type_info *info) {
54824e7fdSDimitry Andric  return {PyRefType::Owned, SWIG_NewPointerObj(obj, info, SWIG_POINTER_OWN)};
64824e7fdSDimitry Andric}
74824e7fdSDimitry Andric
8*04eeddc0SDimitry Andric/// A class that automatically clears an SB object when it goes out of scope.
9*04eeddc0SDimitry Andric/// Use for cases where the SB object points to a temporary/unowned entity.
10*04eeddc0SDimitry Andrictemplate <typename T> class ScopedPythonObject : PythonObject {
11*04eeddc0SDimitry Andricpublic:
12*04eeddc0SDimitry Andric  ScopedPythonObject(T *sb, swig_type_info *info)
13*04eeddc0SDimitry Andric      : PythonObject(ToSWIGHelper(sb, info)), m_sb(sb) {}
14*04eeddc0SDimitry Andric  ~ScopedPythonObject() {
15*04eeddc0SDimitry Andric    if (m_sb)
16*04eeddc0SDimitry Andric      *m_sb = T();
17*04eeddc0SDimitry Andric  }
18*04eeddc0SDimitry Andric  ScopedPythonObject(ScopedPythonObject &&rhs)
19*04eeddc0SDimitry Andric      : PythonObject(std::move(rhs)), m_sb(std::exchange(rhs.m_sb, nullptr)) {}
20*04eeddc0SDimitry Andric  ScopedPythonObject(const ScopedPythonObject &) = delete;
21*04eeddc0SDimitry Andric  ScopedPythonObject &operator=(const ScopedPythonObject &) = delete;
22*04eeddc0SDimitry Andric  ScopedPythonObject &operator=(ScopedPythonObject &&) = delete;
23*04eeddc0SDimitry Andric
24*04eeddc0SDimitry Andric  const PythonObject &obj() const { return *this; }
25*04eeddc0SDimitry Andric
26*04eeddc0SDimitry Andricprivate:
27*04eeddc0SDimitry Andric  T *m_sb;
28*04eeddc0SDimitry Andric};
29*04eeddc0SDimitry Andric
304824e7fdSDimitry AndricPythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBValue> value_sb) {
314824e7fdSDimitry Andric  return ToSWIGHelper(value_sb.release(), SWIGTYPE_p_lldb__SBValue);
324824e7fdSDimitry Andric}
334824e7fdSDimitry Andric
344824e7fdSDimitry AndricPythonObject ToSWIGWrapper(lldb::ValueObjectSP value_sp) {
354824e7fdSDimitry Andric  return ToSWIGWrapper(std::make_unique<lldb::SBValue>(std::move(value_sp)));
364824e7fdSDimitry Andric}
374824e7fdSDimitry Andric
384824e7fdSDimitry AndricPythonObject ToSWIGWrapper(lldb::TargetSP target_sp) {
394824e7fdSDimitry Andric  return ToSWIGHelper(new lldb::SBTarget(std::move(target_sp)),
404824e7fdSDimitry Andric                      SWIGTYPE_p_lldb__SBTarget);
414824e7fdSDimitry Andric}
424824e7fdSDimitry Andric
434824e7fdSDimitry AndricPythonObject ToSWIGWrapper(lldb::ProcessSP process_sp) {
444824e7fdSDimitry Andric  return ToSWIGHelper(new lldb::SBProcess(std::move(process_sp)),
454824e7fdSDimitry Andric                      SWIGTYPE_p_lldb__SBProcess);
464824e7fdSDimitry Andric}
474824e7fdSDimitry Andric
484824e7fdSDimitry AndricPythonObject ToSWIGWrapper(lldb::ThreadPlanSP thread_plan_sp) {
494824e7fdSDimitry Andric  return ToSWIGHelper(new lldb::SBThreadPlan(std::move(thread_plan_sp)),
504824e7fdSDimitry Andric                      SWIGTYPE_p_lldb__SBThreadPlan);
514824e7fdSDimitry Andric}
524824e7fdSDimitry Andric
534824e7fdSDimitry AndricPythonObject ToSWIGWrapper(lldb::BreakpointSP breakpoint_sp) {
544824e7fdSDimitry Andric  return ToSWIGHelper(new lldb::SBBreakpoint(std::move(breakpoint_sp)),
554824e7fdSDimitry Andric                      SWIGTYPE_p_lldb__SBBreakpoint);
564824e7fdSDimitry Andric}
574824e7fdSDimitry Andric
580eae32dcSDimitry AndricPythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStream> stream_sb) {
590eae32dcSDimitry Andric  return ToSWIGHelper(stream_sb.release(), SWIGTYPE_p_lldb__SBStream);
600eae32dcSDimitry Andric}
610eae32dcSDimitry Andric
620eae32dcSDimitry AndricPythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStructuredData> data_sb) {
630eae32dcSDimitry Andric  return ToSWIGHelper(data_sb.release(), SWIGTYPE_p_lldb__SBStructuredData);
640eae32dcSDimitry Andric}
650eae32dcSDimitry Andric
660eae32dcSDimitry AndricPythonObject ToSWIGWrapper(const StructuredDataImpl &data_impl) {
670eae32dcSDimitry Andric  return ToSWIGWrapper(std::make_unique<lldb::SBStructuredData>(data_impl));
680eae32dcSDimitry Andric}
690eae32dcSDimitry Andric
700eae32dcSDimitry AndricPythonObject ToSWIGWrapper(lldb::ThreadSP thread_sp) {
710eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBThread(std::move(thread_sp)),
720eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBThread);
730eae32dcSDimitry Andric}
740eae32dcSDimitry Andric
750eae32dcSDimitry AndricPythonObject ToSWIGWrapper(lldb::StackFrameSP frame_sp) {
760eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBFrame(std::move(frame_sp)),
770eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBFrame);
780eae32dcSDimitry Andric}
790eae32dcSDimitry Andric
800eae32dcSDimitry AndricPythonObject ToSWIGWrapper(lldb::DebuggerSP debugger_sp) {
810eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBDebugger(std::move(debugger_sp)),
820eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBDebugger);
830eae32dcSDimitry Andric}
840eae32dcSDimitry Andric
850eae32dcSDimitry AndricPythonObject ToSWIGWrapper(lldb::WatchpointSP watchpoint_sp) {
860eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBWatchpoint(std::move(watchpoint_sp)),
870eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBWatchpoint);
880eae32dcSDimitry Andric}
890eae32dcSDimitry Andric
900eae32dcSDimitry AndricPythonObject ToSWIGWrapper(lldb::BreakpointLocationSP bp_loc_sp) {
910eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBBreakpointLocation(std::move(bp_loc_sp)),
920eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBBreakpointLocation);
930eae32dcSDimitry Andric}
940eae32dcSDimitry Andric
950eae32dcSDimitry AndricPythonObject ToSWIGWrapper(lldb::ExecutionContextRefSP ctx_sp) {
960eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBExecutionContext(std::move(ctx_sp)),
970eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBExecutionContext);
980eae32dcSDimitry Andric}
990eae32dcSDimitry Andric
1000eae32dcSDimitry AndricPythonObject ToSWIGWrapper(const TypeSummaryOptions &summary_options) {
1010eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBTypeSummaryOptions(summary_options),
1020eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBTypeSummaryOptions);
1030eae32dcSDimitry Andric}
1040eae32dcSDimitry Andric
1050eae32dcSDimitry AndricPythonObject ToSWIGWrapper(const SymbolContext &sym_ctx) {
1060eae32dcSDimitry Andric  return ToSWIGHelper(new lldb::SBSymbolContext(sym_ctx),
1070eae32dcSDimitry Andric                      SWIGTYPE_p_lldb__SBSymbolContext);
1080eae32dcSDimitry Andric}
1090eae32dcSDimitry Andric
110*04eeddc0SDimitry AndricScopedPythonObject<lldb::SBCommandReturnObject>
111*04eeddc0SDimitry AndricToSWIGWrapper(CommandReturnObject &cmd_retobj) {
112*04eeddc0SDimitry Andric  return ScopedPythonObject<lldb::SBCommandReturnObject>(
113*04eeddc0SDimitry Andric      new lldb::SBCommandReturnObject(cmd_retobj),
114*04eeddc0SDimitry Andric      SWIGTYPE_p_lldb__SBCommandReturnObject);
115*04eeddc0SDimitry Andric}
116*04eeddc0SDimitry Andric
117*04eeddc0SDimitry AndricScopedPythonObject<lldb::SBEvent> ToSWIGWrapper(Event *event) {
118*04eeddc0SDimitry Andric  return ScopedPythonObject<lldb::SBEvent>(new lldb::SBEvent(event),
119*04eeddc0SDimitry Andric                                           SWIGTYPE_p_lldb__SBEvent);
120*04eeddc0SDimitry Andric}
121*04eeddc0SDimitry Andric
1224824e7fdSDimitry Andric} // namespace python
1234824e7fdSDimitry Andric} // namespace lldb_private
124