5 SBTypeToSWIGWrapper (T* item);
10 PyErr_Cleaner(bool print=false) :
19 if(m_print && !PyErr_ExceptionMatches(PyExc_SystemExit))
33 // resolve a dotted Python name in the form
34 // foo.bar.baz.Foobar to an actual Python object
35 // if pmodule is NULL, the __main__ module will be used
36 // as the starting point for the search
39 // This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...)
40 // and is used when a script command is attached to a breakpoint for execution.
42 SWIGEXPORT llvm::Expected<bool>
43 LLDBSwigPythonBreakpointCallbackFunction
45 const char *python_function_name,
46 const char *session_dictionary_name,
47 const lldb::StackFrameSP& frame_sp,
48 const lldb::BreakpointLocationSP& bp_loc_sp,
49 lldb_private::StructuredDataImpl *args_impl
54 lldb::SBFrame sb_frame (frame_sp);
55 lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
57 PyErr_Cleaner py_err_cleaner(true);
58 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
59 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
61 unsigned max_positional_args;
62 if (auto arg_info = pfunc.GetArgInfo())
63 max_positional_args = arg_info.get().max_positional_args;
65 return arg_info.takeError();
67 PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_frame));
68 PythonObject bp_loc_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_bp_loc));
70 auto result = [&] () -> Expected<PythonObject> {
71 // If the called function doesn't take extra_args, drop them here:
72 if (max_positional_args < 4) {
73 return pfunc.Call(frame_arg, bp_loc_arg, dict);
75 lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
76 PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
77 return pfunc.Call(frame_arg, bp_loc_arg, args_arg, dict);
82 return result.takeError();
84 // Only False counts as false!
85 return result.get().get() != Py_False;
88 // This function is called by lldb_private::ScriptInterpreterPython::WatchpointCallbackFunction(...)
89 // and is used when a script command is attached to a watchpoint for execution.
92 LLDBSwigPythonWatchpointCallbackFunction
94 const char *python_function_name,
95 const char *session_dictionary_name,
96 const lldb::StackFrameSP& frame_sp,
97 const lldb::WatchpointSP& wp_sp
100 lldb::SBFrame sb_frame (frame_sp);
101 lldb::SBWatchpoint sb_wp(wp_sp);
103 bool stop_at_watchpoint = true;
105 PyErr_Cleaner py_err_cleaner(true);
107 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
108 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
110 if (!pfunc.IsAllocated())
111 return stop_at_watchpoint;
113 PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_frame));
114 PythonObject wp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_wp));
115 PythonObject result = pfunc(frame_arg, wp_arg, dict);
117 if (result.get() == Py_False)
118 stop_at_watchpoint = false;
120 return stop_at_watchpoint;
124 LLDBSwigPythonCallTypeScript
126 const char *python_function_name,
127 const void *session_dictionary,
128 const lldb::ValueObjectSP& valobj_sp,
129 void** pyfunct_wrapper,
130 const lldb::TypeSummaryOptionsSP& options_sp,
134 lldb::SBValue sb_value (valobj_sp);
135 lldb::SBTypeSummaryOptions sb_options(options_sp.get());
139 if (!python_function_name || !session_dictionary)
142 PyObject *pfunc_impl = nullptr;
144 if (pyfunct_wrapper && *pyfunct_wrapper && PyFunction_Check (*pyfunct_wrapper))
146 pfunc_impl = (PyObject*)(*pyfunct_wrapper);
147 if (pfunc_impl->ob_refcnt == 1)
149 Py_XDECREF(pfunc_impl);
154 PyObject *py_dict = (PyObject*)session_dictionary;
155 if (!PythonDictionary::Check(py_dict))
158 PythonDictionary dict(PyRefType::Borrowed, py_dict);
160 PyErr_Cleaner pyerr_cleanup(true); // show Python errors
162 PythonCallable pfunc(PyRefType::Borrowed, pfunc_impl);
164 if (!pfunc.IsAllocated())
166 pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
167 if (!pfunc.IsAllocated())
172 *pyfunct_wrapper = pfunc.get();
173 Py_XINCREF(pfunc.get());
178 auto argc = pfunc.GetArgInfo();
180 llvm::consumeError(argc.takeError());
184 PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value));
185 PythonObject options_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_options));
187 if (argc.get().max_positional_args < 3)
188 result = pfunc(value_arg,dict);
190 result = pfunc(value_arg,dict,options_arg);
192 retval = result.Str().GetString().str();
198 LLDBSwigPythonCreateSyntheticProvider
200 const char *python_class_name,
201 const char *session_dictionary_name,
202 const lldb::ValueObjectSP& valobj_sp
205 if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
208 PyErr_Cleaner py_err_cleaner(true);
210 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
211 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name,dict);
213 if (!pfunc.IsAllocated())
216 // I do not want the SBValue to be deallocated when going out of scope because python
217 // has ownership of it and will manage memory for this object by itself
218 lldb::SBValue *sb_value = new lldb::SBValue(valobj_sp);
219 sb_value->SetPreferSyntheticValue(false);
221 PythonObject val_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value));
222 if (!val_arg.IsAllocated())
225 PythonObject result = pfunc(val_arg, dict);
227 if (result.IsAllocated())
228 return result.release();
234 LLDBSwigPythonCreateCommandObject
236 const char *python_class_name,
237 const char *session_dictionary_name,
238 const lldb::DebuggerSP debugger_sp
241 if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
244 PyErr_Cleaner py_err_cleaner(true);
245 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
246 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict);
248 if (!pfunc.IsAllocated())
251 lldb::SBDebugger debugger_sb(debugger_sp);
252 PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb));
253 PythonObject result = pfunc(debugger_arg, dict);
255 if (result.IsAllocated())
256 return result.release();
262 LLDBSwigPythonCreateScriptedThreadPlan
264 const char *python_class_name,
265 const char *session_dictionary_name,
266 lldb_private::StructuredDataImpl *args_impl,
267 std::string &error_string,
268 const lldb::ThreadPlanSP& thread_plan_sp
271 if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
274 // I do not want the SBThreadPlan to be deallocated when going out of scope because python
275 // has ownership of it and will manage memory for this object by itself
276 lldb::SBThreadPlan *tp_value = new lldb::SBThreadPlan(thread_plan_sp);
278 PyErr_Cleaner py_err_cleaner(true);
280 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
281 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict);
283 if (!pfunc.IsAllocated()) {
284 error_string.append("could not find script class: ");
285 error_string.append(python_class_name);
289 PythonObject tp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(tp_value));
291 if (!tp_arg.IsAllocated())
294 llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
296 llvm::handleAllErrors(
297 arg_info.takeError(),
298 [&](PythonException &E) {
299 error_string.append(E.ReadBacktrace());
301 [&](const llvm::ErrorInfoBase &E) {
302 error_string.append(E.message());
307 PythonObject result = {};
308 if (arg_info.get().max_positional_args == 2) {
309 if (args_impl != nullptr) {
310 error_string.assign("args passed, but __init__ does not take an args dictionary");
313 result = pfunc(tp_arg, dict);
314 } else if (arg_info.get().max_positional_args >= 3) {
315 lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
316 PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
317 result = pfunc(tp_arg, args_arg, dict);
319 error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)");
323 // FIXME: At this point we should check that the class we found supports all the methods
326 if (result.IsAllocated())
327 return result.release();
332 LLDBSWIGPythonCallThreadPlan
335 const char *method_name,
336 lldb_private::Event *event,
342 PyErr_Cleaner py_err_cleaner(false);
343 PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor));
344 auto pfunc = self.ResolveName<PythonCallable>(method_name);
346 if (!pfunc.IsAllocated())
350 if (event != nullptr)
352 lldb::SBEvent sb_event(event);
353 PythonObject event_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_event));
354 result = pfunc(event_arg);
359 if (PyErr_Occurred())
362 printf ("Return value was neither false nor true for call to %s.\n", method_name);
367 if (result.get() == Py_True)
369 else if (result.get() == Py_False)
372 // Somebody returned the wrong thing...
374 printf ("Wrong return value type for call to %s.\n", method_name);
379 LLDBSwigPythonCreateScriptedBreakpointResolver
381 const char *python_class_name,
382 const char *session_dictionary_name,
383 lldb_private::StructuredDataImpl *args_impl,
384 lldb::BreakpointSP &breakpoint_sp
387 if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
390 PyErr_Cleaner py_err_cleaner(true);
392 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
393 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict);
395 if (!pfunc.IsAllocated())
398 lldb::SBBreakpoint *bkpt_value = new lldb::SBBreakpoint(breakpoint_sp);
400 PythonObject bkpt_arg(PyRefType::Owned, SBTypeToSWIGWrapper(bkpt_value));
402 lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
403 PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
405 PythonObject result = pfunc(bkpt_arg, args_arg, dict);
406 // FIXME: At this point we should check that the class we found supports all the methods
409 if (result.IsAllocated())
411 // Check that __callback__ is defined:
412 auto callback_func = result.ResolveName<PythonCallable>("__callback__");
413 if (callback_func.IsAllocated())
414 return result.release();
421 SWIGEXPORT unsigned int
422 LLDBSwigPythonCallBreakpointResolver
425 const char *method_name,
426 lldb_private::SymbolContext *sym_ctx
429 PyErr_Cleaner py_err_cleaner(false);
430 PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor));
431 auto pfunc = self.ResolveName<PythonCallable>(method_name);
433 if (!pfunc.IsAllocated())
437 if (sym_ctx != nullptr) {
438 lldb::SBSymbolContext sb_sym_ctx(sym_ctx);
439 PythonObject sym_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_sym_ctx));
440 result = pfunc(sym_ctx_arg);
444 if (PyErr_Occurred())
450 // The callback will return a bool, but we're need to also return ints
451 // so we're squirrelling the bool through as an int... And if you return
452 // nothing, we'll continue.
453 if (strcmp(method_name, "__callback__") == 0) {
454 if (result.get() == Py_False)
460 PythonInteger int_result = result.AsType<PythonInteger>();
461 if (!int_result.IsAllocated())
464 unsigned int ret_val = int_result.GetInteger();
469 // wrapper that calls an optional instance member of an object taking no arguments
471 LLDBSwigPython_CallOptionalMember
473 PyObject* implementor,
475 PyObject* ret_if_not_found = Py_None,
476 bool* was_found = NULL
479 PyErr_Cleaner py_err_cleaner(false);
481 PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor));
482 auto pfunc = self.ResolveName<PythonCallable>(callee_name);
484 if (!pfunc.IsAllocated())
488 Py_XINCREF(ret_if_not_found);
489 return ret_if_not_found;
495 PythonObject result = pfunc();
496 return result.release();
500 LLDBSwigPython_CalculateNumChildren
502 PyObject *implementor,
506 PythonObject self(PyRefType::Borrowed, implementor);
507 auto pfunc = self.ResolveName<PythonCallable>("num_children");
509 if (!pfunc.IsAllocated())
512 auto arg_info = pfunc.GetArgInfo();
514 llvm::consumeError(arg_info.takeError());
520 if (arg_info.get().max_positional_args < 1)
523 result = pfunc(PythonInteger(max));
525 if (!result.IsAllocated())
528 PythonInteger int_result = result.AsType<PythonInteger>();
529 if (!int_result.IsAllocated())
532 size_t ret_val = int_result.GetInteger();
534 if (PyErr_Occurred()) //FIXME use Expected to catch python exceptions
540 if (arg_info.get().max_positional_args < 1)
541 ret_val = std::min(ret_val, static_cast<size_t>(max));
547 LLDBSwigPython_GetChildAtIndex
549 PyObject *implementor,
553 PyErr_Cleaner py_err_cleaner(true);
555 PythonObject self(PyRefType::Borrowed, implementor);
556 auto pfunc = self.ResolveName<PythonCallable>("get_child_at_index");
558 if (!pfunc.IsAllocated())
561 PythonObject result = pfunc(PythonInteger(idx));
563 if (!result.IsAllocated())
566 lldb::SBValue* sbvalue_ptr = nullptr;
567 if (SWIG_ConvertPtr(result.get(), (void**)&sbvalue_ptr, SWIGTYPE_p_lldb__SBValue, 0) == -1)
570 if (sbvalue_ptr == nullptr)
573 return result.release();
577 LLDBSwigPython_GetIndexOfChildWithName
579 PyObject *implementor,
580 const char* child_name
583 PyErr_Cleaner py_err_cleaner(true);
585 PythonObject self(PyRefType::Borrowed, implementor);
586 auto pfunc = self.ResolveName<PythonCallable>("get_child_index");
588 if (!pfunc.IsAllocated())
591 PythonObject result = pfunc(PythonString(child_name));
593 if (!result.IsAllocated())
596 PythonInteger int_result = result.AsType<PythonInteger>();
597 if (!int_result.IsAllocated())
600 int64_t retval = int_result.GetInteger();
602 return (uint32_t)retval;
608 LLDBSwigPython_UpdateSynthProviderInstance
610 PyObject *implementor
613 bool ret_val = false;
615 static char callee_name[] = "update";
617 PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name);
619 if (py_return == Py_True)
622 Py_XDECREF(py_return);
628 LLDBSwigPython_MightHaveChildrenSynthProviderInstance
630 PyObject *implementor
633 bool ret_val = false;
635 static char callee_name[] = "has_children";
637 PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, Py_True);
639 if (py_return == Py_True)
642 Py_XDECREF(py_return);
648 LLDBSwigPython_GetValueSynthProviderInstance
650 PyObject *implementor
653 PyObject* ret_val = nullptr;
655 static char callee_name[] = "get_value";
657 PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, Py_None);
659 if (py_return == Py_None || py_return == nullptr)
662 lldb::SBValue* sbvalue_ptr = NULL;
664 if (SWIG_ConvertPtr(py_return, (void**)&sbvalue_ptr, SWIGTYPE_p_lldb__SBValue, 0) == -1)
666 else if (sbvalue_ptr == NULL)
671 Py_XDECREF(py_return);
676 LLDBSWIGPython_CastPyObjectToSBValue
681 lldb::SBValue* sb_ptr = NULL;
683 int valid_cast = SWIG_ConvertPtr(data, (void**)&sb_ptr, SWIGTYPE_p_lldb__SBValue, 0);
685 if (valid_cast == -1)
692 LLDBSwigPythonCallCommand
694 const char *python_function_name,
695 const char *session_dictionary_name,
696 lldb::DebuggerSP& debugger,
698 lldb_private::CommandReturnObject& cmd_retobj,
699 lldb::ExecutionContextRefSP exe_ctx_ref_sp
702 lldb::SBCommandReturnObject cmd_retobj_sb(cmd_retobj);
703 lldb::SBDebugger debugger_sb(debugger);
704 lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp);
706 PyErr_Cleaner py_err_cleaner(true);
707 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
708 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
710 if (!pfunc.IsAllocated())
713 // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
714 // see comment above for SBCommandReturnObjectReleaser for further details
715 auto argc = pfunc.GetArgInfo();
717 llvm::consumeError(argc.takeError());
720 PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb));
721 PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb));
722 PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb));
724 if (argc.get().max_positional_args < 5u)
725 pfunc(debugger_arg, PythonString(args), cmd_retobj_arg, dict);
727 pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg, dict);
733 LLDBSwigPythonCallCommandObject
735 PyObject *implementor,
736 lldb::DebuggerSP& debugger,
738 lldb_private::CommandReturnObject& cmd_retobj,
739 lldb::ExecutionContextRefSP exe_ctx_ref_sp
742 lldb::SBCommandReturnObject cmd_retobj_sb(cmd_retobj);
743 lldb::SBDebugger debugger_sb(debugger);
744 lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp);
746 PyErr_Cleaner py_err_cleaner(true);
748 PythonObject self(PyRefType::Borrowed, implementor);
749 auto pfunc = self.ResolveName<PythonCallable>("__call__");
751 if (!pfunc.IsAllocated())
754 // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
755 // see comment above for SBCommandReturnObjectReleaser for further details
756 PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb));
757 PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb));
758 PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb));
760 pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg);
766 LLDBSWIGPythonCreateOSPlugin
768 const char *python_class_name,
769 const char *session_dictionary_name,
770 const lldb::ProcessSP& process_sp
773 if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
776 PyErr_Cleaner py_err_cleaner(true);
778 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
779 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict);
781 if (!pfunc.IsAllocated())
784 // I do not want the SBProcess to be deallocated when going out of scope because python
785 // has ownership of it and will manage memory for this object by itself
786 lldb::SBProcess *process_sb = new lldb::SBProcess(process_sp);
787 PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb));
788 if (!process_arg.IsAllocated())
791 auto result = pfunc(process_arg);
793 if (result.IsAllocated())
794 return result.release();
800 LLDBSWIGPython_CreateFrameRecognizer
802 const char *python_class_name,
803 const char *session_dictionary_name
806 if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
809 PyErr_Cleaner py_err_cleaner(true);
811 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
812 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict);
814 if (!pfunc.IsAllocated())
817 auto result = pfunc();
819 if (result.IsAllocated())
820 return result.release();
826 LLDBSwigPython_GetRecognizedArguments
828 PyObject *implementor,
829 const lldb::StackFrameSP& frame_sp
832 static char callee_name[] = "get_recognized_arguments";
834 lldb::SBFrame frame_sb(frame_sp);
835 PyObject *arg = SBTypeToSWIGWrapper(frame_sb);
837 PythonString str(callee_name);
838 PyObject* result = PyObject_CallMethodObjArgs(implementor, str.get(), arg,
844 LLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, const lldb::TargetSP& target_sp)
846 if (!module || !setting)
849 PyErr_Cleaner py_err_cleaner(true);
850 PythonObject py_module(PyRefType::Borrowed, (PyObject *)module);
851 auto pfunc = py_module.ResolveName<PythonCallable>("get_dynamic_setting");
853 if (!pfunc.IsAllocated())
856 lldb::SBTarget target_sb(target_sp);
857 PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb));
858 auto result = pfunc(target_arg, PythonString(setting));
860 return result.release();
864 LLDBSWIGPythonRunScriptKeywordProcess
865 (const char* python_function_name,
866 const char* session_dictionary_name,
867 lldb::ProcessSP& process,
871 if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
874 PyErr_Cleaner py_err_cleaner(true);
876 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
877 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
879 if (!pfunc.IsAllocated())
882 lldb::SBProcess process_sb(process);
883 PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb));
884 auto result = pfunc(process_arg, dict);
886 output = result.Str().GetString().str();
892 LLDBSWIGPythonRunScriptKeywordThread
893 (const char* python_function_name,
894 const char* session_dictionary_name,
895 lldb::ThreadSP& thread,
899 if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
902 PyErr_Cleaner py_err_cleaner(true);
904 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
905 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
907 if (!pfunc.IsAllocated())
910 lldb::SBThread thread_sb(thread);
911 PythonObject thread_arg(PyRefType::Owned, SBTypeToSWIGWrapper(thread_sb));
912 auto result = pfunc(thread_arg, dict);
914 output = result.Str().GetString().str();
920 LLDBSWIGPythonRunScriptKeywordTarget
921 (const char* python_function_name,
922 const char* session_dictionary_name,
923 lldb::TargetSP& target,
927 if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
930 PyErr_Cleaner py_err_cleaner(true);
932 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
933 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name,dict);
935 if (!pfunc.IsAllocated())
938 lldb::SBTarget target_sb(target);
939 PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb));
940 auto result = pfunc(target_arg, dict);
942 output = result.Str().GetString().str();
948 LLDBSWIGPythonRunScriptKeywordFrame
949 (const char* python_function_name,
950 const char* session_dictionary_name,
951 lldb::StackFrameSP& frame,
955 if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
958 PyErr_Cleaner py_err_cleaner(true);
960 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
961 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name,dict);
963 if (!pfunc.IsAllocated())
966 lldb::SBFrame frame_sb(frame);
967 PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(frame_sb));
968 auto result = pfunc(frame_arg, dict);
970 output = result.Str().GetString().str();
976 LLDBSWIGPythonRunScriptKeywordValue
977 (const char* python_function_name,
978 const char* session_dictionary_name,
979 lldb::ValueObjectSP& value,
983 if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
986 PyErr_Cleaner py_err_cleaner(true);
988 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
989 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
991 if (!pfunc.IsAllocated())
994 lldb::SBValue value_sb(value);
995 PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(value_sb));
996 auto result = pfunc(value_arg, dict);
998 output = result.Str().GetString().str();
1004 LLDBSwigPythonCallModuleInit
1006 const char *python_module_name,
1007 const char *session_dictionary_name,
1008 lldb::DebuggerSP& debugger
1011 std::string python_function_name_string = python_module_name;
1012 python_function_name_string += ".__lldb_init_module";
1013 const char* python_function_name = python_function_name_string.c_str();
1015 PyErr_Cleaner py_err_cleaner(true);
1017 auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
1018 auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_function_name, dict);
1020 // This method is optional and need not exist. So if we don't find it,
1021 // it's actually a success, not a failure.
1022 if (!pfunc.IsAllocated())
1025 lldb::SBDebugger debugger_sb(debugger);
1026 PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb));
1027 pfunc(debugger_arg, dict);
1035 // Forward declaration to be inserted at the start of LLDBWrapPython.h
1036 #include "lldb/API/SBDebugger.h"
1037 #include "lldb/API/SBValue.h"
1039 SWIGEXPORT lldb::ValueObjectSP
1040 LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data)
1042 lldb::ValueObjectSP valobj_sp;
1045 lldb::SBValue* sb_ptr = (lldb::SBValue *)data;
1046 valobj_sp = sb_ptr->GetSP();
1055 void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton);
1065 // For the LogOutputCallback functions
1066 void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton) {
1067 if (baton != Py_None) {
1068 SWIG_PYTHON_THREAD_BEGIN_BLOCK;
1069 PyObject *result = PyObject_CallFunction(reinterpret_cast<PyObject*>(baton), const_cast<char*>("s"), str);
1071 SWIG_PYTHON_THREAD_END_BLOCK;