From a69bbe02a2352271e8b14542073f177e24c499c1 Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Tue, 29 Oct 2019 13:42:38 -0700 Subject: [LLDB][breakpoints] ArgInfo::count -> ArgInfo::max_positional_args Summary: Move breakpoints from the old, bad ArgInfo::count to the new, better ArgInfo::max_positional_args. Soon ArgInfo::count will be no more. It looks like this functionality is already well tested by `TestBreakpointCommandsFromPython.py`, so there's no need to write additional tests for it. Reviewers: labath, jingham, JDevlieghere Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69468 --- lldb/scripts/Python/python-wrapper.swig | 42 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'lldb/scripts/Python') diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index 5e9a2ba..71a958a 100644 --- a/lldb/scripts/Python/python-wrapper.swig +++ b/lldb/scripts/Python/python-wrapper.swig @@ -39,7 +39,7 @@ private: // This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...) // and is used when a script command is attached to a breakpoint for execution. -SWIGEXPORT bool +SWIGEXPORT llvm::Expected LLDBSwigPythonBreakpointCallbackFunction ( const char *python_function_name, @@ -49,38 +49,40 @@ LLDBSwigPythonBreakpointCallbackFunction lldb_private::StructuredDataImpl *args_impl ) { + using namespace llvm; + lldb::SBFrame sb_frame (frame_sp); lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp); - bool stop_at_breakpoint = true; - PyErr_Cleaner py_err_cleaner(true); auto dict = PythonModule::MainModule().ResolveName(session_dictionary_name); auto pfunc = PythonObject::ResolveNameWithDictionary(python_function_name, dict); - if (!pfunc.IsAllocated()) - return stop_at_breakpoint; + unsigned max_positional_args; + if (auto arg_info = pfunc.GetArgInfo()) + max_positional_args = arg_info.get().max_positional_args; + else + return arg_info.takeError(); PythonObject frame_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_frame)); PythonObject bp_loc_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_bp_loc)); - PythonObject result; - // If the called function doesn't take extra_args, drop them here: - auto arg_info = pfunc.GetNumArguments(); - if (arg_info.count == 3) - result = pfunc(frame_arg, bp_loc_arg, dict); - else if (arg_info.count == 4) { - lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); - PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); - result = pfunc(frame_arg, bp_loc_arg, args_arg, dict); - } else { - return stop_at_breakpoint; - } + auto result = [&] () -> Expected { + // If the called function doesn't take extra_args, drop them here: + if (max_positional_args < 4) { + return pfunc.Call(frame_arg, bp_loc_arg, dict); + } else { + lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl); + PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value)); + return pfunc.Call(frame_arg, bp_loc_arg, args_arg, dict); + } + } (); - if (result.get() == Py_False) - stop_at_breakpoint = false; + if (!result) + return result.takeError(); - return stop_at_breakpoint; + // Only False counts as false! + return result.get().get() != Py_False; } // This function is called by lldb_private::ScriptInterpreterPython::WatchpointCallbackFunction(...) -- cgit v1.1