On Fri, Dec 2, 2011 at 10:48 PM, Tom Tromey wrote: > > >>>>> "Kevin" == Kevin Pouget writes: > > Sorry about the delay on this. > I got kind of distracted this week. > > Kevin> I noticed a bug in the previous version of the patch, which led to > Kevin> `out_of_scope' callback being triggered when it was not supposed to be > Kevin> (namely, when the breakpoint was hit, the execution continued, and > Kevin> then the callback was triggered before the temporary breakpoint could > Kevin> be deleted. > > Looking close now. > > Kevin> +      if (ret) > Kevin> +        self_finishbp->return_value = value_to_value_object (ret); > > If this fails then the error is never cleared or handled. > > I think checking == NULL and then calling gdbpy_print_stack is appropriate. you're right, fixed > > Kevin> +                  /* Ignore Python errors at this stage.  */ > Kevin> +                  self_bpfinish->return_type = type_to_type_object (ret_type); > Kevin> +                  PyErr_Clear (); > Kevin> +                  self_bpfinish->function_type = > Kevin> +                      type_to_type_object (SYMBOL_TYPE (function)); > Kevin> +                  PyErr_Clear (); > > This looked a little weird, but I verified from the docs that it is ok. > > I think this still needs a NEWS entry. nop, it was in the patch :) diff --git a/gdb/NEWS b/gdb/NEWS index f13caf8..7b3f7f2 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -51,6 +51,10 @@ ** The "gdb.breakpoint" function has been deprecated in favor of "gdb.breakpoints". + ** A new class "gdb.FinishBreakpoint" is provided to catch the return + of a function. This class is based on the "finish" command + available in the CLI. + ** Type objects for struct and union types now allow access to the fields using standard Python dictionary (mapping) methods. For example, "some_type['myfield']" now works, as does it was also reviewed by Eli in : http://sourceware.org/ml/gdb-patches/2011-10/msg00645.html Thanks for your review, cordially, Kevin (no regression against current git source tree) -- 2011-12-05 Kevin Pouget Introduce gdb.FinishBreakpoint in Python * Makefile.in (SUBDIR_PYTHON_OBS): Add py-finishbreakpoint.o. (SUBDIR_PYTHON_SRCS): Add python/py-finishbreakpoint.c. Add build rule for this file. * infcmd.c (print_return_value): Split to create get_return_value. (get_return_value): New function based on print_return_value. Handle case where stop_registers are not set. * inferior.h (get_return_value): New prototype. * python/py-breakpoint.c (bppy_pending_object): Make non-static. (gdbpy_breakpoint_created): Set is_py_finish_bp is necessary. (struct breakpoint_object): Move to python-internal.h (BPPY_REQUIRE_VALID): Likewise. (BPPY_SET_REQUIRE_VALID): Likewise. (gdbpy_breakpoint_created): Initialize is_finish_bp. (gdbpy_should_stop): Add pre/post hooks before/after calling stop method. * python/python-internal.h (breakpoint_object_type): Add as extern. (bppy_pending_object): Likewise. (typedef struct breakpoint_object) Removed. (struct breakpoint_object): Moved from py-breakpoint.c. Add field is_finish_bp. (BPPY_REQUIRE_VALID): Moved from py-breakpoint.c. (BPPY_SET_REQUIRE_VALID): Likewise. (frame_object_to_frame_info): New prototype. (gdbpy_initialize_finishbreakpoints): New prototype. (bpfinishpy_is_finish_bp): Likewise. (bpfinishpy_pre_stop_hook): Likewise. (bpfinishpy_post_stop_hook): Likewise. * python/py-finishbreakpoint.c: New file. * python/py-frame.c(frame_object_to_frame_info): Make non-static and accept PyObject instead of frame_object. (frapy_is_valid): Don't cast to frame_object. (frapy_name): Likewise. (frapy_type): Likewise. (frapy_unwind_stop_reason): Likewise. (frapy_pc): Likewise. (frapy_block): Likewise. (frapy_function): Likewise. (frapy_older): Likewise. (frapy_newer): Likewise. (frapy_find_sal): Likewise. (frapy_read_var): Likewise. (frapy_select): Likewise. * python/python.c (gdbpy_is_stopped_at_finish_bp): New noop function. (_initialize_python): Add gdbpy_initialize_finishbreakpoints. * python/python.h: Include breakpoint.h (gdbpy_is_stopped_at_finish_bp): New prototype. doc/ * gdb.texinfo (Finish Breakpoints in Python): New subsection. (Python API): Add menu entry for Finish Breakpoints. testsuite/ * gdb.python/py-breakpoint.exp (mult_line): Define and use variable instead of line number. * gdb.python/py-finish-breakpoint.c: New file. * gdb.python/py-finish-breakpoint.exp: New file. * gdb.python/py-finish-breakpoint.py: New file. * gdb.python/py-finish-breakpoint2.cc: New file. * gdb.python/py-finish-breakpoint2.exp: New file. * gdb.python/py-finish-breakpoint2.py: New file.