@@ -229,6 +229,133 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateCommandObject
229
229
return pfunc(SWIGBridge::ToSWIGWrapper(std::move(debugger_sp)), dict);
230
230
}
231
231
232
+ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedThreadPlan(
233
+ const char *python_class_name, const char *session_dictionary_name,
234
+ const lldb_private::StructuredDataImpl &args_impl,
235
+ std::string &error_string, const lldb::ThreadPlanSP &thread_plan_sp) {
236
+ if (python_class_name == NULL || python_class_name[0] == '\0' ||
237
+ !session_dictionary_name)
238
+ return PythonObject();
239
+
240
+ PyErr_Cleaner py_err_cleaner(true);
241
+
242
+ auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
243
+ session_dictionary_name);
244
+ auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(
245
+ python_class_name, dict);
246
+
247
+ if (!pfunc.IsAllocated()) {
248
+ error_string.append("could not find script class: ");
249
+ error_string.append(python_class_name);
250
+ return PythonObject();
251
+ }
252
+
253
+ PythonObject tp_arg = SWIGBridge::ToSWIGWrapper(thread_plan_sp);
254
+
255
+ llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
256
+ if (!arg_info) {
257
+ llvm::handleAllErrors(
258
+ arg_info.takeError(),
259
+ [&](PythonException &E) { error_string.append(E.ReadBacktrace()); },
260
+ [&](const llvm::ErrorInfoBase &E) {
261
+ error_string.append(E.message());
262
+ });
263
+ return PythonObject();
264
+ }
265
+
266
+ PythonObject result = {};
267
+ auto args_sb = std::unique_ptr<lldb::SBStructuredData>(new lldb::SBStructuredData(args_impl));
268
+ if (arg_info.get().max_positional_args == 2) {
269
+ if (args_sb->IsValid()) {
270
+ error_string.assign(
271
+ "args passed, but __init__ does not take an args dictionary");
272
+ return PythonObject();
273
+ }
274
+ result = pfunc(tp_arg, dict);
275
+ } else if (arg_info.get().max_positional_args >= 3) {
276
+ result = pfunc(tp_arg, SWIGBridge::ToSWIGWrapper(std::move(args_sb)), dict);
277
+ } else {
278
+ error_string.assign("wrong number of arguments in __init__, should be 2 or "
279
+ "3 (not including self)");
280
+ return PythonObject();
281
+ }
282
+
283
+ // FIXME: At this point we should check that the class we found supports all
284
+ // the methods that we need.
285
+
286
+ return result;
287
+ }
288
+
289
+ bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan(
290
+ void *implementor, const char *method_name, lldb_private::Event *event,
291
+ bool &got_error) {
292
+ got_error = false;
293
+
294
+ PyErr_Cleaner py_err_cleaner(false);
295
+ PythonObject self(PyRefType::Borrowed, static_cast<PyObject *>(implementor));
296
+ auto pfunc = self.ResolveName<PythonCallable>(method_name);
297
+
298
+ if (!pfunc.IsAllocated())
299
+ return false;
300
+
301
+ PythonObject result;
302
+ if (event != nullptr) {
303
+ ScopedPythonObject<SBEvent> event_arg = SWIGBridge::ToSWIGWrapper(event);
304
+ result = pfunc(event_arg.obj());
305
+ } else
306
+ result = pfunc();
307
+
308
+ if (PyErr_Occurred()) {
309
+ got_error = true;
310
+ printf("Return value was neither false nor true for call to %s.\n",
311
+ method_name);
312
+ PyErr_Print();
313
+ return false;
314
+ }
315
+
316
+ if (result.get() == Py_True)
317
+ return true;
318
+ else if (result.get() == Py_False)
319
+ return false;
320
+
321
+ // Somebody returned the wrong thing...
322
+ got_error = true;
323
+ printf("Wrong return value type for call to %s.\n", method_name);
324
+ return false;
325
+ }
326
+
327
+ bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan(
328
+ void *implementor, const char *method_name, lldb_private::Stream *stream,
329
+ bool &got_error) {
330
+ got_error = false;
331
+
332
+ PyErr_Cleaner py_err_cleaner(false);
333
+ PythonObject self(PyRefType::Borrowed, static_cast<PyObject *>(implementor));
334
+ auto pfunc = self.ResolveName<PythonCallable>(method_name);
335
+
336
+ if (!pfunc.IsAllocated())
337
+ return false;
338
+
339
+ auto *sb_stream = new lldb::SBStream();
340
+ PythonObject sb_stream_arg =
341
+ SWIGBridge::ToSWIGWrapper(std::unique_ptr<lldb::SBStream>(sb_stream));
342
+
343
+ PythonObject result;
344
+ result = pfunc(sb_stream_arg);
345
+
346
+ if (PyErr_Occurred()) {
347
+ printf("Error occured for call to %s.\n",
348
+ method_name);
349
+ PyErr_Print();
350
+ got_error = true;
351
+ return false;
352
+ }
353
+ if (stream)
354
+ stream->PutCString(sb_stream->GetData());
355
+ return true;
356
+
357
+ }
358
+
232
359
PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedBreakpointResolver(
233
360
const char *python_class_name, const char *session_dictionary_name,
234
361
const StructuredDataImpl &args_impl,
@@ -375,7 +502,7 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonStopHookCallHandleStop(
375
502
376
503
auto *sb_stream = new lldb::SBStream();
377
504
PythonObject sb_stream_arg =
378
- SWIGBridge::ToSWIGWrapper(stream.get( ));
505
+ SWIGBridge::ToSWIGWrapper(std::unique_ptr<lldb::SBStream>(sb_stream ));
379
506
PythonObject result =
380
507
pfunc(SWIGBridge::ToSWIGWrapper(std::move(exc_ctx_sp)), sb_stream_arg);
381
508
@@ -626,30 +753,6 @@ void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBError(PyObject * data
626
753
return sb_ptr;
627
754
}
628
755
629
- void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBEvent(PyObject * data) {
630
- lldb::SBEvent *sb_ptr = nullptr;
631
-
632
- int valid_cast =
633
- SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBEvent, 0);
634
-
635
- if (valid_cast == -1)
636
- return NULL;
637
-
638
- return sb_ptr;
639
- }
640
-
641
- void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBStream(PyObject * data) {
642
- lldb::SBStream *sb_ptr = nullptr;
643
-
644
- int valid_cast =
645
- SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBStream, 0);
646
-
647
- if (valid_cast == -1)
648
- return NULL;
649
-
650
- return sb_ptr;
651
- }
652
-
653
756
void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject * data) {
654
757
lldb::SBValue *sb_ptr = NULL;
655
758
0 commit comments