binutils-gdb/gdb/testsuite/gdb.python
Tom de Vries 64760036a8 [gdb/python] Fix gdb.python/py-finish-breakpoint2.exp for -m32
[ Partial resubmission of an earlier submission by Andrew (
https://sourceware.org/pipermail/gdb-patches/2012-September/096347.html ), so
listing him as co-author. ]

With x86_64-linux and target board unix/-m32, we have:
...
(gdb) continue^M
Continuing.^M
Exception #10^M
^M
Breakpoint 3, throw_exception_1 (e=10) at py-finish-breakpoint2.cc:23^M
23        throw new int (e);^M
(gdb) FAIL: gdb.python/py-finish-breakpoint2.exp: \
  check FinishBreakpoint in catch()
...

The following scenario happens:
- set breakpoint in throw_exception_1, a function that throws an exception
- continue
- hit breakpoint, with call stack main.c:38 -> throw_exception_1
- set a finish breakpoint
- continue
- hit the breakpoint again, with call stack main.c:48 -> throw_exception
  -> throw_exception_1

Due to the exception, the function call did not properly terminate, and the
finish breakpoint didn't trigger.  This is expected behaviour.

However, the intention is that gdb detects this situation at the next stop
and calls the out_of_scope callback, which would result here in this test-case
in a rather confusing "exception did not finish" message.  So the problem is
that this message doesn't show up, in other words, the out_of_scope callback
is not called.

[ Note that the fact that the situation is detected only at the next stop
(wherever that happens to be) could be improved upon, and the earlier
submission did that by setting a longjmp breakpoint.  But I'm considering this
problem out-of-scope for this patch. ]

Note that the message does show up later, at thread exit:
...
[Inferior 1 (process 20046) exited with code 0236]^M
exception did not finish ...^M
...

The decision on whether to call the out_of_scope call back is taken in
bpfinishpy_detect_out_scope_cb, and the interesting bit is here:
...
             if (b->pspace == current_inferior ()->pspace
                 && (!target_has_registers ()
                     || frame_find_by_id (b->frame_id) == NULL))
               bpfinishpy_out_of_scope (finish_bp);
...

In the case of the thread exit, the callback triggers because
target_has_registers () == 0.

So why doesn't the callback trigger in the case of the breakpoint?

Well, the b->frame_id is the frame_id of the frame of main (the frame
in which the finish breakpoint is supposed to trigger), so AFAIU
frame_find_by_id (b->frame_id) == NULL will only be true once we've
left main, at which point I guess we don't stop till thread exit.

Fix this by saving the frame in which the finish breakpoint was created, and
using frame_find_by_id () == NULL on that frame instead, such that we have:
...
(gdb) continue^M
Continuing.^M
Exception #10^M
^M
Breakpoint 3, throw_exception_1 (e=10) at py-finish-breakpoint2.cc:23^M
23        throw new int (e);^M
exception did not finish ...^M
(gdb) FAIL: gdb.python/py-finish-breakpoint2.exp: \
  check FinishBreakpoint in catch()
...

Still, the test-case is failing because it's setup to match the behaviour that
we get on x86_64-linux with target board unix/-m64:
...
(gdb) continue^M
Continuing.^M
Exception #10^M
stopped at ExceptionFinishBreakpoint^M
(gdb) PASS: gdb.python/py-finish-breakpoint2.exp: \
  check FinishBreakpoint in catch()
...

So what happens here?  Again, due to the exception, the function call did not
properly terminate, but the finish breakpoint still triggers.  This is somewhat
unexpected.  This happens because it just so happens to be that the frame
return address at which the breakpoint is set, is also the first instruction
after the exception has been handled.  This is a know problem, filed as
PR29909, so KFAIL it, and modify the test-case to expect the out_of_scope
callback.

Also add a breakpoint after setting the finish breakpoint but before throwing
the exception, to check that we don't call the out_of_scope callback too early.

Tested on x86_64-linux, with target boards unix/-m32.

Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
PR python/27247
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27247
2022-12-31 08:51:40 +01:00
..
amd64-py-framefilter-invalidarg.S
compare-enum-type-a.c
compare-enum-type-b.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
compare-enum-type.exp
compare-enum-type.h
flexible-array-member.c
flexible-array-member.exp
lib-types.cc
lib-types.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
libpy-autoloaded-pretty-printers-in-newobjfile-event.so-gdb.py
pretty-print-call-by-hand.c gdb/frame: Add reinflation method for frame_info_ptr 2022-10-10 11:57:10 +02:00
pretty-print-call-by-hand.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
pretty-print-call-by-hand.py gdb/testsuite: Fix formatting of python script 2022-10-11 11:22:37 +02:00
py-arch-reg-groups.exp gdb/testsuite: use 'end' at the end of python blocks 2022-10-10 10:23:59 +01:00
py-arch-reg-names.exp gdb/testsuite: use 'end' at the end of python blocks 2022-10-10 10:23:59 +01:00
py-arch.c
py-arch.exp Accept gdb.Value in more Python APIs 2022-07-08 14:14:58 -06:00
py-as-string.c
py-as-string.exp
py-auto-load-chaining-f1.c
py-auto-load-chaining-f1.o-gdb.py
py-auto-load-chaining-f2.c
py-auto-load-chaining-f2.o-gdb.py
py-auto-load-chaining.c
py-auto-load-chaining.exp
py-autoloaded-pretty-printers-in-newobjfile-event-lib.cc
py-autoloaded-pretty-printers-in-newobjfile-event-lib.h
py-autoloaded-pretty-printers-in-newobjfile-event-main.cc
py-autoloaded-pretty-printers-in-newobjfile-event.exp
py-autoloaded-pretty-printers-in-newobjfile-event.py
py-bad-printers.c
py-bad-printers.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-bad-printers.py
py-block.c
py-block.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-bp-locations.c gdb/python: Add BreakpointLocation type 2022-07-28 11:20:46 -06:00
py-bp-locations.exp gdb/python: Add BreakpointLocation type 2022-07-28 11:20:46 -06:00
py-breakpoint-create-fail.c
py-breakpoint-create-fail.exp
py-breakpoint-create-fail.py
py-breakpoint.c
py-breakpoint.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-caller-is.c
py-caller-is.exp
py-charset.exp
py-cmd.c
py-cmd.exp gdb/testsuite: add test for Python commands redefining itself 2022-12-16 11:38:28 +00:00
py-completion.exp
py-completion.py
py-connection-removed.exp gdb: have target_stack automate reference count handling 2022-12-14 13:57:21 +00:00
py-connection.c
py-connection.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-disasm.c gdb/python: fix invalid use disassemble_info::stream 2022-07-25 19:26:24 +01:00
py-disasm.exp [gdb/testsuite] Fix gdb.python/py-disasm.exp on s390x 2022-12-13 13:06:15 +01:00
py-disasm.py [gdb/testsuite] Fix gdb.python/py-disasm.exp on s390x 2022-12-13 13:06:15 +01:00
py-doc-reformat.exp
py-error.exp
py-error.py
py-event-load.c Add gdb.free_objfile event registry 2022-07-18 11:25:34 -06:00
py-event-load.exp Add gdb.free_objfile event registry 2022-07-18 11:25:34 -06:00
py-event-load.py Add gdb.free_objfile event registry 2022-07-18 11:25:34 -06:00
py-events-shlib.c
py-events.c
py-events.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-events.py
py-evsignal.exp
py-evthreads.c
py-evthreads.exp
py-explore-cc.exp
py-explore.c
py-explore.cc
py-explore.exp
py-finish-breakpoint2.cc [gdb/python] Fix gdb.python/py-finish-breakpoint2.exp for -m32 2022-12-31 08:51:40 +01:00
py-finish-breakpoint2.exp [gdb/python] Fix gdb.python/py-finish-breakpoint2.exp for -m32 2022-12-31 08:51:40 +01:00
py-finish-breakpoint2.py
py-finish-breakpoint-deletion.c Fix deletion of FinishBreakpoints 2022-11-18 10:50:45 -05:00
py-finish-breakpoint-deletion.exp Fix deletion of FinishBreakpoints 2022-11-18 10:50:45 -05:00
py-finish-breakpoint-deletion.py Fix deletion of FinishBreakpoints 2022-11-18 10:50:45 -05:00
py-finish-breakpoint.c
py-finish-breakpoint.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-finish-breakpoint.py
py-format-address.c
py-format-address.exp
py-format-string.c
py-format-string.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-format-string.py Add 'summary' mode to Value.format_string 2022-07-15 09:26:54 -06:00
py-frame-args.c
py-frame-args.exp
py-frame-args.py
py-frame-inline.c
py-frame-inline.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-frame.c
py-frame.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-framefilter-addr.c
py-framefilter-addr.exp
py-framefilter-addr.py
py-framefilter-gdb.py
py-framefilter-invalidarg-gdb.py
py-framefilter-invalidarg.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-framefilter-invalidarg.py
py-framefilter-mi.c
py-framefilter-mi.exp
py-framefilter.c
py-framefilter.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-framefilter.py
py-function.exp
py-inferior-leak.c
py-inferior-leak.exp
py-inferior-leak.py
py-inferior.c
py-inferior.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-infthread.c
py-infthread.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-label-symbol-value.c gdb: fix crash when getting the value of a label symbol 2022-12-16 13:51:08 +00:00
py-label-symbol-value.exp gdb: fix crash when getting the value of a label symbol 2022-12-16 13:51:08 +00:00
py-lazy-string.c
py-lazy-string.exp
py-linetable.c
py-linetable.exp
py-linetable.S
py-lookup-type.exp
py-mi-cmd.exp
py-mi-cmd.py
py-mi-events-gdb.py
py-mi-events.c
py-mi-events.exp
py-mi-objfile-gdb.py
py-mi-objfile.c
py-mi-objfile.exp
py-mi-var-info-path-expression.c
py-mi-var-info-path-expression.exp
py-mi-var-info-path-expression.py
py-mi.exp
py-nested-maps.c
py-nested-maps.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-nested-maps.py
py-objfile-script-gdb.py
py-objfile-script.c
py-objfile-script.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-objfile.c
py-objfile.exp gdb/testsuite: make gdb_unload use gdb_test_multiple 2022-11-29 11:43:54 -05:00
py-parameter.exp GDB/Python: Make None' stand for unlimited' in setting integer parameters 2022-10-21 08:54:18 +01:00
py-pending-frame-level.c
py-pending-frame-level.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-pending-frame-level.py
py-pp-integral.c
py-pp-integral.exp
py-pp-integral.py
py-pp-maint.c
py-pp-maint.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-pp-maint.py
py-pp-re-notag.c
py-pp-re-notag.exp
py-pp-re-notag.py
py-pp-registration.c
py-pp-registration.exp
py-pp-registration.py
py-prettyprint.c
py-prettyprint.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-prettyprint.py
py-progspace.c
py-progspace.exp Accept gdb.Value in more Python APIs 2022-07-08 14:14:58 -06:00
py-prompt.c
py-prompt.exp
py-rbreak-func2.c
py-rbreak.c
py-rbreak.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-record-btrace-threads.c
py-record-btrace-threads.exp
py-record-btrace.c
py-record-btrace.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-record-full.c
py-record-full.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-recurse-unwind.c
py-recurse-unwind.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-recurse-unwind.py
py-rvalue-ref-value-cc.cc
py-rvalue-ref-value-cc.exp
py-section-script.c
py-section-script.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-section-script.py
py-send-packet.c
py-send-packet.exp gdb/testsuite: fix failure in gdb.python/py-send-packet.exp 2022-11-17 14:36:35 +00:00
py-send-packet.py Run 'black' on gdb 2022-07-15 07:55:32 -06:00
py-shared-sl.c
py-shared.c
py-shared.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-source-styling.c
py-source-styling.exp
py-startup-opt.exp
py-strfns.c
py-strfns.exp
py-symbol-2.c
py-symbol.c
py-symbol.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-symtab.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-sync-interp.c
py-sync-interp.exp
py-template.cc
py-template.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-thrhandle.c
py-thrhandle.exp
py-type.c
py-type.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-typeprint.cc
py-typeprint.exp
py-typeprint.py
py-unwind-inline.c
py-unwind-inline.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-unwind-inline.py
py-unwind-maint.c
py-unwind-maint.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-unwind-maint.py
py-unwind-user-regs.c
py-unwind-user-regs.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-unwind-user-regs.py
py-unwind.c
py-unwind.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
py-unwind.py Fix crash in gdbpy_parse_register_id 2022-08-21 08:03:42 -06:00
py-value-cc.cc
py-value-cc.exp
py-value.c
py-value.exp gdb/testsuite: remove perror calls when failing to run 2022-12-05 16:38:24 -05:00
py-xmethods.cc
py-xmethods.exp
py-xmethods.py
python-1.c
python.c
python.exp gdb/testsuite: remove use of then keyword from gdb.python/*.exp 2022-11-28 21:04:09 +00:00
source1
source2.py
tui-window-disabled.c
tui-window-disabled.exp
tui-window-disabled.py
tui-window-names.exp [gdb/testsuite] Add skip_python_tests in gdb.python/tui-window-names.exp 2022-10-24 08:36:42 +02:00
tui-window.exp
tui-window.py