From 8620ab640abd6617a3b090fc0c35a791cc0ec423 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 18 May 2021 23:33:41 +0100 Subject: [PATCH] exists_non_stop_target: Avoid flushing frames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $ make check RUNTESTFLAGS="--target_board=native-extended-gdbserver" TESTS="gdb.base/signest.exp" make[1]: Entering directory '/home/pedro/gdb/mygit/build/gdb/testsuite' Nothing to be done for all... make check-single make[2]: Entering directory '/home/pedro/gdb/mygit/build/gdb/testsuite' rootme=`pwd`; export rootme; srcdir=/home/pedro/gdb/mygit/src/gdb/testsuite ; export srcdir ; EXPECT=`if [ "${READ1}" != "" ] ; then echo ${rootme}/expect-read1; elif [ -f ${rootme}/../../expect/expect ] ; then echo ${rootme}/../../expect/expect ; else echo expect ; fi` ; export EXPECT ; EXEEXT= ; export EXEEXT ; LD_LIBRARY_PATH=$rootme/../../expect:$rootme/../../libstdc++:$rootme/../../tk/unix:$rootme/../../tcl/unix:$rootme/../../bfd:$rootme/../../opcodes:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; if [ -f ${rootme}/../../expect/expect ] ; then TCL_LIBRARY=${srcdir}/../../tcl/library ; export TCL_LIBRARY ; fi ; runtest --status --target_board=native-extended-gdbserver gdb.base/signest.exp Using /home/pedro/gdb/mygit/src/gdb/testsuite/lib/gdb.exp as tool init file. NOTE: Dejagnu's default_target_compile is missing support for Go, using local override NOTE: Dejagnu's default_target_compile is missing support for Rust, using local override Test run by pedro on Wed May 19 00:00:39 2021 Native configuration is x86_64-pc-linux-gnu === gdb tests === Schedule of variations: native-extended-gdbserver Running target native-extended-gdbserver Using /home/pedro/gdb/mygit/src/gdb/testsuite/boards/../boards/native-extended-gdbserver.exp as board description file for target. Using /home/pedro/gdb/mygit/src/gdb/testsuite/boards/../boards/gdbserver-base.exp as board description file for target. Using /home/pedro/gdb/mygit/src/gdb/testsuite/boards/../boards/local-board.exp as board description file for target. configuring for gdbserver local testing (extended-remote) Using /home/pedro/gdb/mygit/src/gdb/testsuite/config/extended-gdbserver.exp as tool-and-target-specific interface file. Running /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/signest.exp ... ERROR: GDB process no longer exists === gdb Summary === # of expected passes 4 # of unresolved testcases 1 Infinite recursion: (top-gdb) bt 20 #0 0x0000561d6a1bfeff in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #1 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #2 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #3 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #4 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #5 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #6 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #7 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #8 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #9 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #10 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #11 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #12 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #13 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #14 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #15 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #16 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #17 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #18 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #19 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 (More stack frames follow...) (top-gdb) bt -30 #157054 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #157055 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #157056 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #157057 0x0000561d6a1bfeb8 in get_frame_arch (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2939 #157058 0x0000561d6a1b989f in frame_unwind_find_by_frame (this_frame=0x561d6b19f9c0, this_cache=0x561d6b19f9d8) at /home/pedro/gdb/mygit/src/gdb/frame-unwind.c:174 #157059 0x0000561d6a1bff04 in frame_unwind_arch (next_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:2950 #157060 0x0000561d6a1bbc65 in frame_unwind_pc (this_frame=0x561d6b19f9c0) at /home/pedro/gdb/mygit/src/gdb/frame.c:970 #157061 0x0000561d6a1bf54c in get_frame_pc (frame=0x561d6b19fa90) at /home/pedro/gdb/mygit/src/gdb/frame.c:2625 #157062 0x0000561d6a1bf63e in get_frame_address_in_block (this_frame=0x561d6b19fa90) at /home/pedro/gdb/mygit/src/gdb/frame.c:2655 #157063 0x0000561d6a0cae7f in dwarf2_frame_cache (this_frame=0x561d6b19fa90, this_cache=0x561d6b19faa8) at /home/pedro/gdb/mygit/src/gdb/dwarf2/frame.c:1010 #157064 0x0000561d6a0cb928 in dwarf2_frame_this_id (this_frame=0x561d6b19fa90, this_cache=0x561d6b19faa8, this_id=0x561d6b19faf0) at /home/pedro/gdb/mygit/src/gdb/dwarf2/frame.c:1227 #157065 0x0000561d6a1baf72 in compute_frame_id (fi=0x561d6b19fa90) at /home/pedro/gdb/mygit/src/gdb/frame.c:588 #157066 0x0000561d6a1bb16e in get_frame_id (fi=0x561d6b19fa90) at /home/pedro/gdb/mygit/src/gdb/frame.c:636 #157067 0x0000561d6a1bb224 in get_stack_frame_id (next_frame=0x561d6b19fa90) at /home/pedro/gdb/mygit/src/gdb/frame.c:650 #157068 0x0000561d6a26ecd0 in insert_hp_step_resume_breakpoint_at_frame (return_frame=0x561d6b19fa90) at /home/pedro/gdb/mygit/src/gdb/infrun.c:7809 #157069 0x0000561d6a26b88a in handle_signal_stop (ecs=0x7ffc67022830) at /home/pedro/gdb/mygit/src/gdb/infrun.c:6428 #157070 0x0000561d6a269d81 in handle_inferior_event (ecs=0x7ffc67022830) at /home/pedro/gdb/mygit/src/gdb/infrun.c:5741 #157071 0x0000561d6a265bd0 in fetch_inferior_event () at /home/pedro/gdb/mygit/src/gdb/infrun.c:4120 #157072 0x0000561d6a244c24 in inferior_event_handler (event_type=INF_REG_EVENT) at /home/pedro/gdb/mygit/src/gdb/inf-loop.c:41 #157073 0x0000561d6a435cc4 in remote_async_serial_handler (scb=0x561d6b4a8990, context=0x561d6b4a4c48) at /home/pedro/gdb/mygit/src/gdb/remote.c:14403 #157074 0x0000561d6a460bc5 in run_async_handler_and_reschedule (scb=0x561d6b4a8990) at /home/pedro/gdb/mygit/src/gdb/ser-base.c:138 #157075 0x0000561d6a460cae in fd_event (error=0, context=0x561d6b4a8990) at /home/pedro/gdb/mygit/src/gdb/ser-base.c:189 #157076 0x0000561d6a76a191 in handle_file_event (file_ptr=0x561d6b233ae0, ready_mask=1) at /home/pedro/gdb/mygit/src/gdbsupport/event-loop.cc:575 #157077 0x0000561d6a76a743 in gdb_wait_for_event (block=1) at /home/pedro/gdb/mygit/src/gdbsupport/event-loop.cc:701 #157078 0x0000561d6a7694ee in gdb_do_one_event () at /home/pedro/gdb/mygit/src/gdbsupport/event-loop.cc:237 #157079 0x0000561d6a2df16b in start_event_loop () at /home/pedro/gdb/mygit/src/gdb/main.c:421 #157080 0x0000561d6a2df2b6 in captured_command_loop () at /home/pedro/gdb/mygit/src/gdb/main.c:481 #157081 0x0000561d6a2e0d16 in captured_main (data=0x7ffc67022bd0) at /home/pedro/gdb/mygit/src/gdb/main.c:1353 #157082 0x0000561d6a2e0da8 in gdb_main (args=0x7ffc67022bd0) at /home/pedro/gdb/mygit/src/gdb/main.c:1370 #157083 0x0000561d69eb3d82 in main (argc=13, argv=0x7ffc67022cf8, envp=0x7ffc67022d68) at /home/pedro/gdb/mygit/src/gdb/gdb.c:33 The annota1.exp change is necessary because we'd get a regression otherwise: @@ -238,8 +238,6 @@ Continuing. ▒▒breakpoints-invalid -▒▒frames-invalid - ▒▒breakpoint 3 Breakpoint 3, @@ -276,7 +274,7 @@ printf.c ▒▒pre-prompt (gdb) ▒▒prompt -PASS: gdb.base/annota1.exp: continue to printf +FAIL: gdb.base/annota1.exp: continue to printf ... before this patch avoids flushing the frame cache. We still need to match frames-invalid because against gdbserver + "maint set target non-stop on", some other code path flushes the frame cache resulting in the annotation being emitted anyway. --- gdb/target.c | 11 +++++++++-- gdb/testsuite/gdb.base/annota1.exp | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index 78327a2a6c3..d5ac3d79434 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -4388,11 +4388,18 @@ exists_non_stop_target () if (target_is_non_stop_p ()) return true; - scoped_restore_current_thread restore_thread; + /* We can get here quite deep in core code, e.g., from + target_terminal::inferior(). Avoid switching thread context or + anything that would communicate with the target (e.g., to fetch + registers), or flushing e.g., the frame cache, as we may end up + called from within the frame building code. We just switch + inferior in order to be able to call through the + target_stack. */ + scoped_restore_current_inferior restore_inferior; for (inferior *inf : all_inferiors ()) { - switch_to_inferior_no_thread (inf); + set_current_inferior (inf); if (target_is_non_stop_p ()) return true; } diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp index 3689f49fa1b..0e28dc8556f 100644 --- a/gdb/testsuite/gdb.base/annota1.exp +++ b/gdb/testsuite/gdb.base/annota1.exp @@ -24,6 +24,7 @@ if ![target_can_use_run_cmd] { } set breakpoints_invalid "\r\n\032\032breakpoints-invalid\r\n" +set frames_invalid "\r\n\032\032frames-invalid\r\n" # # test running programs @@ -226,7 +227,7 @@ gdb_test_multiple "break printf" "break printf" { # # get to printf # -set pat_begin "\r\n\032\032post-prompt\r\nContinuing.\r\n\r\n\032\032starting\r\n\r\n\032\032frames-invalid\r\n${breakpoints_invalid}\r\n\032\032frames-invalid\r\n" +set pat_begin "\r\n\032\032post-prompt\r\nContinuing.\r\n\r\n\032\032starting\r\n${frames_invalid}${breakpoints_invalid}(${frames_invalid})?" set pat_adjust "warning: Breakpoint 3 address previously adjusted from $hex to $hex.\r\n" set pat_end "\r\n\032\032breakpoint 3\r\n\r\nBreakpoint 3, \r\n\032\032frame-begin 0 $hex\r\n\r\n(\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n)*.*\032\032frame-function-name\r\n.*printf(@.*)?\r\n\032\032frame-args\r\n.*\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$"