diff options
author | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-10-29 13:42:38 -0700 |
---|---|---|
committer | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-10-29 15:03:02 -0700 |
commit | a69bbe02a2352271e8b14542073f177e24c499c1 (patch) | |
tree | 35235c75e8d75a9a9b0c52719b150ca4f9435e2d /lldb/scripts | |
parent | 98286b569d01a461d75c9fd133cbf52c0c92e32a (diff) | |
download | llvm-a69bbe02a2352271e8b14542073f177e24c499c1.tar.gz |
[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
Diffstat (limited to 'lldb/scripts')
-rw-r--r-- | lldb/scripts/Python/python-wrapper.swig | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index 5e9a2ba1367c..71a958acb72c 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<bool> 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<PythonDictionary>(session_dictionary_name); auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(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<PythonObject> { + // 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(...) |