From eed01b8fe7b7889cefe6b1d7e6aa807a8ae022c1 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Oct 06 2016 13:22:49 +0000 Subject: Rebase to FSF GDB 7.11.90.20161006 (pre-7.12 branch snapshot). --- diff --git a/.gitignore b/.gitignore index 1ed1fa1..ae9eafd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /gdb-libstdc++-v3-python-6.1.1-20160817.tar.xz /v1.5.tar.gz -/gdb-7.11.90.20160929.tar.xz +/gdb-7.11.90.20161006.tar.xz diff --git a/gdb-rhbz1375553-attach-jit-debug.patch b/gdb-rhbz1375553-attach-jit-debug.patch deleted file mode 100644 index 65594be..0000000 --- a/gdb-rhbz1375553-attach-jit-debug.patch +++ /dev/null @@ -1,339 +0,0 @@ -Regression: gdb --pid $(pidof qemu-system-x86_64) stopped working with gdb 7.11.1 -https://bugzilla.redhat.com/show_bug.cgi?id=1375553 - -http://sourceware.org/ml/gdb-patches/2016-09/msg00387.html -Subject: [patch+7.12] PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression - - ---cNdxnHkX5QqsyA0e -Content-Type: text/plain; charset=us-ascii -Content-Disposition: inline - -Hi, - -Regression: gdb --pid $(pidof qemu-system-x86_64) stopped working with gdb 7.11.1 -https://sourceware.org/bugzilla/show_bug.cgi?id=20609 - -It was reported for qemu-system-x86_64 but it happens for any multithreaded -inferior with a JIT debugging hook. - -136613ef0c6850427317e57be1b644080ff6decb is the first bad commit -Author: Pedro Alves - Fix PR gdb/19828: gdb -p : internal error -Message-ID: -https://sourceware.org/ml/gdb-patches/2016-05/msg00450.html - -jit_breakpoint_re_set() is specific by trying to insert a breakpoint into the -main executable, not into a shared library. During attachment GDB thinks it -needs to use 'breakpoint always-inserted' from -breakpoints_should_be_inserted_now() as a newly attached thread is -'thread_info->executing' due to 'lwp_info->must_set_ptrace_flags' enabled and -the task not yet stopped. This did not happen before the 'bad commit' above -which adds tracking of such thread. - -GDB then fails to insert the breakpoints to invalid address as PIE executable -gets properly relocated during later phase of attachment. One can see in the -backtraces below: -#11 in setup_inferior (from_tty=0) at infcmd.c:2663 - -> jit_breakpoint_re_set_internal() -later: -#5 in setup_inferior (from_tty=0) at infcmd.c:2673 - -> svr4_exec_displacement() - -One can suppress the initial breakpoint_re_set() call as there will be another -breakpoint_re_set() done from the final post_create_inferior() call in -setup_inferior(). - -BTW additionally 'threads_executing' cache bool is somehow stale (somewhere is -missing update_threads_executing()). I was trying to deal with that in my -first/second attempt below but in my final third attempt (attached) I have -left it as it is. - -First attempt trying not to falsely require 'breakpoint always-inserted': - https://people.redhat.com/jkratoch/rhbz1375553-fix1.patch -Reduced first attempt: - https://people.redhat.com/jkratoch/rhbz1375553-fix2.patch - -The third attempt suppresses breakpoint insertion until PIE executable gets -relocated by svr4_exec_displacement(). Attached. - -No regressions on {x86_64,x86_64-m32,i686}-fedora26pre-linux-gnu. - -OK for check-in for trunk + 7.12? - - -Jan - - -#0 jit_breakpoint_re_set_internal (gdbarch=0x25befe0, ps_data=0x23b37e0) at jit.c:1045 -#1 in jit_breakpoint_re_set () at jit.c:1408 -#2 in breakpoint_re_set () at breakpoint.c:14665 -#3 in clear_symtab_users (add_flags=4) at symfile.c:2970 -#4 in finish_new_objfile (objfile=0x25b6d10, add_flags=4) at symfile.c:1109 -#5 in symbol_file_add_with_addrs (abfd=0x25b4bd0, name=0x25b3970 "/tmp/a.out", add_flags=4, addrs=0x0, flags=0, parent=0x0) at symfile.c:1233 -#6 in symbol_file_add_from_bfd (abfd=0x25b4bd0, name=0x25b3970 "/tmp/a.out", add_flags=4, addrs=0x0, flags=0, parent=0x0) at symfile.c:1276 -#7 in symbol_file_add (name=0x25b3970 "/tmp/a.out", add_flags=4, addrs=0x0, flags=0) at symfile.c:1290 -#8 in symbol_file_add_main_1 (args=0x25b3970 "/tmp/a.out", from_tty=0, flags=0) at symfile.c:1315 -#9 in symbol_file_add_main (args=0x25b3970 "/tmp/a.out", from_tty=0) at symfile.c:1306 -#10 in exec_file_locate_attach (pid=2502, from_tty=0) at exec.c:235 -#11 in setup_inferior (from_tty=0) at infcmd.c:2663 -#12 in stop_all_threads () at infrun.c:4630 -#13 in stop_waiting (ecs=0x7fffffffd400) at infrun.c:7710 -#14 in handle_signal_stop (ecs=0x7fffffffd400) at infrun.c:5765 -#15 in handle_inferior_event_1 (ecs=0x7fffffffd400) at infrun.c:5395 -#16 in handle_inferior_event (ecs=0x7fffffffd400) at infrun.c:5426 -#17 in fetch_inferior_event (client_data=0x0) at infrun.c:3972 -#18 in inferior_event_handler (event_type=INF_REG_EVENT, client_data=0x0) at inf-loop.c:44 -#19 in handle_target_event (error=0, client_data=0x0) at linux-nat.c:4523 -#20 in handle_file_event (file_ptr=0x25ad330, ready_mask=1) at event-loop.c:733 -#21 in gdb_wait_for_event (block=0) at event-loop.c:859 -#22 in gdb_do_one_event () at event-loop.c:322 -#23 in wait_sync_command_done () at top.c:568 -#24 in maybe_wait_sync_command_done (was_sync=0) at top.c:587 -#25 in catch_command_errors (command=0x745e0c , arg=0x7fffffffdd08 "2502", from_tty=1) at main.c:377 -#26 in captured_main (data=0x7fffffffd800) at main.c:1065 -#27 in gdb_main (args=0x7fffffffd800) at main.c:1159 -#28 in main (argc=10, argv=0x7fffffffd908) at gdb.c:32 - -#0 svr4_exec_displacement (displacementp=0x7fffffffced0) at solib-svr4.c:2634 -#1 in svr4_relocate_main_executable () at solib-svr4.c:3031 -#2 in svr4_solib_create_inferior_hook (from_tty=0) at solib-svr4.c:3092 -#3 in solib_create_inferior_hook (from_tty=0) at solib.c:1276 -#4 in post_create_inferior (target=0x21ee980 , from_tty=0) at infcmd.c:445 -#5 in setup_inferior (from_tty=0) at infcmd.c:2673 -#6 in stop_all_threads () at infrun.c:4630 -#7 in stop_waiting (ecs=0x7fffffffd400) at infrun.c:7710 -#8 in handle_signal_stop (ecs=0x7fffffffd400) at infrun.c:5765 -#9 in handle_inferior_event_1 (ecs=0x7fffffffd400) at infrun.c:5395 -#10 in handle_inferior_event (ecs=0x7fffffffd400) at infrun.c:5426 -#11 in fetch_inferior_event (client_data=0x0) at infrun.c:3972 -#12 in inferior_event_handler (event_type=INF_REG_EVENT, client_data=0x0) at inf-loop.c:44 -#13 in handle_target_event (error=0, client_data=0x0) at linux-nat.c:4523 -#14 in handle_file_event (file_ptr=0x25ad330, ready_mask=1) at event-loop.c:733 -#15 in gdb_wait_for_event (block=0) at event-loop.c:859 -#16 in gdb_do_one_event () at event-loop.c:322 -#17 in wait_sync_command_done () at top.c:568 -#18 in maybe_wait_sync_command_done (was_sync=0) at top.c:587 -#19 in catch_command_errors (command=0x745e0c , arg=0x7fffffffdd08 "2502", from_tty=1) at main.c:377 -#20 in captured_main (data=0x7fffffffd800) at main.c:1065 -#21 in gdb_main (args=0x7fffffffd800) at main.c:1159 -#22 in main (argc=10, argv=0x7fffffffd908) at gdb.c:32 - ---cNdxnHkX5QqsyA0e -Content-Type: text/plain; charset=us-ascii -Content-Disposition: inline; filename="jitbp.patch" - -gdb/ChangeLog -2016-09-27 Jan Kratochvil - - PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression - * exec.c (exec_file_locate_attach): Add parameter defer_bp_reset. - Use it. - * gdbcore.h (exec_file_locate_attach): Add parameter defer_bp_reset. - * infcmd.c (setup_inferior): Update caller. - * remote.c (remote_add_inferior): Likewise. - -gdb/testsuite/ChangeLog -2016-09-27 Jan Kratochvil - - PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression - * gdb.base/jit-attach-pie.c: New file. - * gdb.base/jit-attach-pie.exp: New file. - -diff --git a/gdb/exec.c b/gdb/exec.c -index 00c31d3..f16cb4b 100644 ---- a/gdb/exec.c -+++ b/gdb/exec.c -@@ -157,7 +157,7 @@ exception_print_same (struct gdb_exception e1, struct gdb_exception e2) - /* See gdbcore.h. */ - - void --exec_file_locate_attach (int pid, int from_tty) -+exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty) - { - char *exec_file, *full_exec_path = NULL; - struct cleanup *old_chain; -@@ -232,6 +232,8 @@ exec_file_locate_attach (int pid, int from_tty) - - TRY - { -+ if (defer_bp_reset) -+ current_inferior ()->symfile_flags |= SYMFILE_DEFER_BP_RESET; - symbol_file_add_main (full_exec_path, from_tty); - } - CATCH (err, RETURN_MASK_ERROR) -@@ -240,6 +242,7 @@ exec_file_locate_attach (int pid, int from_tty) - warning ("%s", err.message); - } - END_CATCH -+ current_inferior ()->symfile_flags &= ~SYMFILE_DEFER_BP_RESET; - - do_cleanups (old_chain); - } -diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h -index 8b101bc..6aa9afa 100644 ---- a/gdb/gdbcore.h -+++ b/gdb/gdbcore.h -@@ -154,9 +154,10 @@ extern void exec_file_attach (const char *filename, int from_tty); - /* If the filename of the main executable is unknown, attempt to - determine it. If a filename is determined, proceed as though - it was just specified with the "file" command. Do nothing if -- the filename of the main executable is already known. */ -+ the filename of the main executable is already known. -+ DEFER_BP_RESET uses SYMFILE_DEFER_BP_RESET for the main symbol file. */ - --extern void exec_file_locate_attach (int pid, int from_tty); -+extern void exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty); - - extern void exec_file_clear (int from_tty); - -diff --git a/gdb/infcmd.c b/gdb/infcmd.c -index 44a1fd1..8e34b7e 100644 ---- a/gdb/infcmd.c -+++ b/gdb/infcmd.c -@@ -2660,7 +2660,7 @@ setup_inferior (int from_tty) - /* If no exec file is yet known, try to determine it from the - process itself. */ - if (get_exec_file (0) == NULL) -- exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty); -+ exec_file_locate_attach (ptid_get_pid (inferior_ptid), 1, from_tty); - else - { - reopen_exec_file (); -diff --git a/gdb/remote.c b/gdb/remote.c -index 910ac81..b460bb1 100644 ---- a/gdb/remote.c -+++ b/gdb/remote.c -@@ -1799,7 +1799,7 @@ remote_add_inferior (int fake_pid_p, int pid, int attached, - /* If no main executable is currently open then attempt to - open the file that was executed to create this inferior. */ - if (try_open_exec && get_exec_file (0) == NULL) -- exec_file_locate_attach (pid, 1); -+ exec_file_locate_attach (pid, 0, 1); - - return inf; - } -diff --git a/gdb/testsuite/gdb.base/jit-attach-pie.c b/gdb/testsuite/gdb.base/jit-attach-pie.c -new file mode 100644 -index 0000000..5080bde ---- /dev/null -+++ b/gdb/testsuite/gdb.base/jit-attach-pie.c -@@ -0,0 +1,61 @@ -+/* This testcase is part of GDB, the GNU debugger. -+ -+ Copyright 2016 Free Software Foundation, Inc. -+ -+ This program is free software; you can redistribute it and/or modify -+ it under the terms of the GNU General Public License as published by -+ the Free Software Foundation; either version 3 of the License, or -+ (at your option) any later version. -+ -+ This program is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ GNU General Public License for more details. -+ -+ You should have received a copy of the GNU General Public License -+ along with this program. If not, see . */ -+ -+#include -+#include -+#include -+ -+struct jit_code_entry -+{ -+ struct jit_code_entry *next_entry; -+ struct jit_code_entry *prev_entry; -+ const char *symfile_addr; -+ uint64_t symfile_size; -+}; -+ -+struct jit_descriptor -+{ -+ uint32_t version; -+ /* This type should be jit_actions_t, but we use uint32_t -+ to be explicit about the bitwidth. */ -+ uint32_t action_flag; -+ struct jit_code_entry *relevant_entry; -+ struct jit_code_entry *first_entry; -+}; -+ -+struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 }; -+ -+void __jit_debug_register_code() -+{ -+} -+ -+static void * -+thread_proc (void *arg) -+{ -+ sleep (60); -+ return arg; -+} -+ -+int -+main (void) -+{ -+ pthread_t thread; -+ -+ pthread_create (&thread, NULL, thread_proc, 0); -+ pthread_join (thread, NULL); -+ return 0; -+} -diff --git a/gdb/testsuite/gdb.base/jit-attach-pie.exp b/gdb/testsuite/gdb.base/jit-attach-pie.exp -new file mode 100644 -index 0000000..2c25733 ---- /dev/null -+++ b/gdb/testsuite/gdb.base/jit-attach-pie.exp -@@ -0,0 +1,48 @@ -+# Copyright (C) 2016 Free Software Foundation, Inc. -+# -+# This program is free software; you can redistribute it and/or modify -+# it under the terms of the GNU General Public License as published by -+# the Free Software Foundation; either version 3 of the License, or -+# (at your option) any later version. -+# -+# This program is distributed in the hope that it will be useful, -+# but WITHOUT ANY WARRANTY; without even the implied warranty of -+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+# GNU General Public License for more details. -+# -+# You should have received a copy of the GNU General Public License -+# along with this program. If not, see . -+ -+if {![can_spawn_for_attach]} { -+ return 0 -+} -+ -+standard_testfile .c -+set executable ${testfile} -+ -+if { [build_executable ${testfile}.exp $executable $srcfile \ -+ [list debug pthreads "additional_flags=-fPIE -pie"]] } { -+ return -1 -+} -+ -+# Start the program running and then wait for a bit, to be sure -+# that it can be attached to. -+ -+set test_spawn_id [spawn_wait_for_attach $binfile] -+set testpid [spawn_id_get_pid $test_spawn_id] -+ -+# gdb_load ("file" command) must not be executed for the bug reproducibility. -+# That includes prepare_for_testing or clean_restart. -+gdb_start -+ -+set test "attach" -+gdb_test_multiple "attach $testpid" $test { -+ -re "Attaching to process $testpid\r\n.*Cannot insert breakpoint .*\r\n$gdb_prompt $" { -+ fail $test -+ } -+ -re "Attaching to process $testpid\r\n.*\r\n$gdb_prompt $" { -+ pass $test -+ } -+} -+ -+kill_wait_spawned_process $test_spawn_id - ---cNdxnHkX5QqsyA0e-- - diff --git a/gdb-upstream.patch b/gdb-upstream.patch index 87364af..649804b 100644 --- a/gdb-upstream.patch +++ b/gdb-upstream.patch @@ -53,3 +53,680 @@ Date: Sun Sep 11 16:53:09 2016 -0400 } static void + + +commit f389f6fef76d7cf8e8beb7061edff2155c284898 +Author: Jan Kratochvil +Date: Wed Oct 5 21:56:46 2016 +0200 + + testsuite: Fix recent GCC FAIL: gdb.arch/i386-signal.exp + + gcc-6.2.1-2.fc24.x86_64 + + (gdb) backtrace 10^M + (gdb) FAIL: gdb.arch/i386-signal.exp: backtrace 10 + + (gdb) disas/s + Dump of assembler code for function main: + .../gdb/testsuite/gdb.arch/i386-signal.c: + 30 { + 0x000000000040057f <+0>: push %rbp + 0x0000000000400580 <+1>: mov %rsp,%rbp + 31 setup (); + 0x0000000000400583 <+4>: callq 0x400590 + => 0x0000000000400588 <+9>: mov $0x0,%eax + 32 } + 0x000000000040058d <+14>: pop %rbp + 0x000000000040058e <+15>: retq + End of assembler dump. + + The .exp patch is an obvious typo fix I think. The regex was written to + accept "ADDR in main" and I find it OK as checking .debug_line validity is not + the purpose of this testfile. + + gcc-4.8.5-11.el7.x86_64 did not put the 'mov $0x0,%eax' instruction there at + all so there was no problem with .debug_line. + + gdb/testsuite/ChangeLog + 2016-10-05 Jan Kratochvil + + * gdb.arch/i386-signal.exp (backtrace 10): Fix #2 typo. + +### a/gdb/testsuite/ChangeLog +### b/gdb/testsuite/ChangeLog +## -1,3 +1,7 @@ ++2016-10-05 Jan Kratochvil ++ ++ * gdb.arch/i386-signal.exp (backtrace 10): Fix #2 typo. ++ + 2016-10-05 Yao Qi + + * lib/gdb.exp (support_complex_tests): Return zero if +--- a/gdb/testsuite/gdb.arch/i386-signal.exp ++++ b/gdb/testsuite/gdb.arch/i386-signal.exp +@@ -35,6 +35,6 @@ gdb_load ${binfile} + + runto func + gdb_test "backtrace 10" \ +- "#0 ($hex in )?func.*\r\n#1 \r\n#2 ($hex in)?main.*" ++ "#0 ($hex in )?func.*\r\n#1 \r\n#2 ($hex in )?main.*" + + gdb_test "finish" "Run till exit from \#0 func.*" + + +commit e027976f02ce8ed4cf0da79238226c03a640f2b3 +Author: Pedro Alves +Date: Thu Oct 6 12:57:39 2016 +0100 + + Fix a few gdb.base/jit-simple.exp problems + + I noticed that we sometimes get this: + + (gdb) print &__jit_debug_descriptor + $1 = (struct jit_descriptor *) 0x601040 <__jit_debug_descriptor> + (gdb) PASS: gdb.base/jit-simple.exp: blah 1 + [...] + (gdb) run + [...] + Starting program: build/gdb/testsuite/outputs/gdb.base/jit-simple/jit-simple + Unsupported JIT protocol version 4 in descriptor (expected 1) + + Breakpoint 2, main () at src/gdb/testsuite/gdb.base/jit-simple.c:36 + 36 return 0; + (gdb) print &__jit_debug_descriptor + $2 = (struct jit_descriptor *) 0x601040 <__jit_debug_descriptor> + (gdb) PASS: gdb.base/jit-simple.exp: blah 1 + + All tests PASSed, but note the "Unsupported JIT protocol version 4" + message. + + Also notice that "__jit_debug_descriptor" has the same address before + and after the rerun, while the test is built in a way that should make + that address change between runs. + + The test doesn't catch any of this because it doesn't compare + before/after addresses. + + And then notice the "blah 1" test messages. "blah" is clearly a WIP + message, but it should be at least "blah 2" the second time. :-) + + The reason this sometimes happens is that the test recompiles the + program and expects gdb to reload it automaticallyt on "run". However, + if the original program and the new recompilation happen to be in the + same second, then gdb does not realize that the binary needs to be + reloaded. (This is an old problem out of scope of this series.) If + that happens, then GDB ends up using the wrong symbols for the program + that it spawns, reads the JIT descriptor out of the wrong address, + finds garbage, and prints that "unsupported version" notice. + + Fix that in the same way gdb.base/reread.exp handles it -- by sleeping + one second before recompiling. + + gdb/testsuite/ChangeLog: + 2016-10-06 Pedro Alves + + * gdb.base/jit-simple.exp (top level) Delete get_compiler_info + call. + (jit_run): Delete. + (jit_test_reread): Use with_test_prefix. Reload the main binary + explicitly. Compare the before/after addresses of the JIT + descriptor. + +### a/gdb/testsuite/ChangeLog +### b/gdb/testsuite/ChangeLog +## -1,3 +1,12 @@ ++2016-10-06 Pedro Alves ++ ++ * gdb.base/jit-simple.exp (top level) Delete get_compiler_info ++ call. ++ (jit_run): Delete. ++ (jit_test_reread): Use with_test_prefix. Reload the main binary ++ explicitly. Compare the before/after addresses of the JIT ++ descriptor. ++ + 2016-10-03 Antoine Tremblay + 2016-10-03 Simon Marchi + +--- a/gdb/testsuite/gdb.base/jit-simple.exp ++++ b/gdb/testsuite/gdb.base/jit-simple.exp +@@ -18,16 +18,6 @@ if {[skip_shlib_tests]} { + return -1 + } + +-if {[get_compiler_info]} { +- warning "Could not get compiler info" +- untested jit-simple.exp +- return 1 +-} +- +-# +-# test running programs +-# +- + standard_testfile + + if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { +@@ -35,39 +25,43 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { + return -1 + } + +-# A helper for jit_test_reread that invokes gdb_run_cmd. +-proc jit_run {msg} { +- global decimal gdb_prompt +- +- gdb_run_cmd +- gdb_test "" "Inferior .* exited.*" $msg +-} +- + # Test re-running an inferior with a JIT descriptor, where the JIT + # descriptor changes address between runs. + # http://sourceware.org/bugzilla/show_bug.cgi?id=13431 + proc jit_test_reread {} { + global testfile binfile subdir srcfile srcdir ++ global hex + +- clean_restart $testfile ++ with_test_prefix "initial run" { ++ clean_restart $testfile + +- # jit_run "initial run" +- runto_main +- +- gdb_test "print &__jit_debug_descriptor" "= .*" "blah 1" ++ runto_main + +- gdb_rename_execfile $binfile ${binfile}x ++ set addr_before [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ ++ "get address of __jit_debug_descriptor"] ++ } + +- if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DSPACER}] != "" } { +- fail "recompile $srcfile" +- } else { +- pass "recompile $srcfile" ++ with_test_prefix "second run" { ++ # Ensure that the new executable is at least one second newer ++ # than the old. If the recompilation happens in the same ++ # second, gdb might not reload the executable automatically. ++ sleep 1 + +- # jit_run "second run" ++ gdb_rename_execfile $binfile ${binfile}x ++ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DSPACER}] != "" } { ++ fail "recompile" ++ return ++ } else { ++ pass "recompile" ++ } + + runto_main +- gdb_test "print &__jit_debug_descriptor" "= .*" "blah 1" ++ ++ set addr_after [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ ++ "get address of __jit_debug_descriptor"] + } ++ ++ gdb_assert {$addr_before != $addr_after} "address changed" + } + + jit_test_reread + + +commit f8da6fe399c8dafa98e7dbed36d3562a919768f5 +Author: Pedro Alves +Date: Thu Oct 6 12:57:40 2016 +0100 + + Fix PR11094: JIT breakpoint is not properly recreated on reruns + + Even though this was supposedly in the gdb 7.2 timeframe, the testcase + in PR11094 crashes current GDB with a segfault: + + Program received signal SIGSEGV, Segmentation fault. + 0x00000000005ee894 in event_location_to_string (location=0x0) at + src/gdb/location.c:412 + 412 if (EL_STRING (location) == NULL) + (top-gdb) bt + #0 0x00000000005ee894 in event_location_to_string (location=0x0) at + src/gdb/location.c:412 + #1 0x000000000057411a in print_breakpoint_location (b=0x18288e0, loc=0x0) at + src/gdb/breakpoint.c:6201 + #2 0x000000000057483f in print_one_breakpoint_location (b=0x18288e0, + loc=0x182cf10, loc_number=0, last_loc=0x7fffffffd258, allflag=1) + at src/gdb/breakpoint.c:6473 + #3 0x00000000005751e1 in print_one_breakpoint (b=0x18288e0, + last_loc=0x7fffffffd258, allflag=1) at + src/gdb/breakpoint.c:6707 + #4 0x000000000057589c in breakpoint_1 (args=0x0, allflag=1, filter=0x0) at + src/gdb/breakpoint.c:6947 + #5 0x0000000000575aa8 in maintenance_info_breakpoints (args=0x0, from_tty=0) + at src/gdb/breakpoint.c:7026 + [...] + + This is GDB trying to print the location spec of the JIT event + breakpoint, but that's an internal breakpoint without one. + + If I add a NULL check, then we see that the JIT breakpoint is now + pending (because its location has shlib_disabled set): + + (gdb) maint info breakpoints + Num Type Disp Enb Address What + [...] + -8 jit events keep y inf 1 + [...] + + But that's incorrect. GDB should have managed to recreate the JIT + breakpoint's location for the second run. So the problem is + elsewhere. + + The problem is that if the JIT loads at the same address on the second + run, we never recreate the JIT breakpoint, because we hit this early + return: + + static int + jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, + struct jit_program_space_data *ps_data) + { + [...] + if (ps_data->cached_code_address == addr) + return 0; + + [...] + delete_breakpoint (ps_data->jit_breakpoint); + [...] + ps_data->jit_breakpoint = create_jit_event_breakpoint (gdbarch, addr); + + Fix this by deleting the breakpoint and discarding the cached code + address when the objfile where the previous JIT breakpoint was found + is deleted/unloaded in the first place. + + The test that was originally added for PR11094 doesn't trip on this + because: + + #1 - It doesn't test the case of the JIT descriptor's address _not_ + changing between reruns. + + #2 - And then it doesn't do "maint info breakpoints", or really + anything with the JIT at all. + + #3 - and even then, to trigger the problem the JIT descriptor needs + to be in a separate library, while the current test puts it in + the main program. + + The patch extends the test to cover all combinations of these + scenarios. + + gdb/ChangeLog: + 2016-10-06 Pedro Alves + + * jit.c (free_objfile_data): Delete the JIT breakpoint and clear + the cached code address. + + gdb/testsuite/ChangeLog: + 2016-10-06 Pedro Alves + + * gdb.base/jit-simple-dl.c: New file. + * gdb.base/jit-simple-jit.c: New file, factored out from ... + * gdb.base/jit-simple.c: ... this. + * gdb.base/jit-simple.exp (jit_run): Delete. + (build_jit): New proc. + (jit_test_reread): Recompile either the main program or the shared + library, depending on what is being tested. Skip changing address + if caller wants to. Compare before/after addresses. If testing + standalone, explicitly load the binary. Test "maint info + breakpoints". + (top level): Add "standalone vs shared lib" and "change address" + vs "same address" axes. + +### a/gdb/ChangeLog +### b/gdb/ChangeLog +## -1,3 +1,8 @@ ++2016-10-06 Pedro Alves ++ ++ * jit.c (free_objfile_data): Delete the JIT breakpoint and clear ++ the cached code address. ++ + 2016-10-03 Simon Marchi + + * infrun.c (restore_current_uiout_cleanup): Move to ui-out.c. +--- a/gdb/jit.c ++++ b/gdb/jit.c +@@ -1482,7 +1482,11 @@ free_objfile_data (struct objfile *objfile, void *data) + = ((struct jit_program_space_data *) + program_space_data (objfile->pspace, jit_program_space_data)); + if (ps_data != NULL && ps_data->objfile == objfile) +- ps_data->objfile = NULL; ++ { ++ ps_data->objfile = NULL; ++ delete_breakpoint (ps_data->jit_breakpoint); ++ ps_data->cached_code_address = 0; ++ } + } + + xfree (data); +### a/gdb/testsuite/ChangeLog +### b/gdb/testsuite/ChangeLog +## -1,5 +1,20 @@ + 2016-10-06 Pedro Alves + ++ * gdb.base/jit-simple-dl.c: New file. ++ * gdb.base/jit-simple-jit.c: New file, factored out from ... ++ * gdb.base/jit-simple.c: ... this. ++ * gdb.base/jit-simple.exp (jit_run): Delete. ++ (build_jit): New proc. ++ (jit_test_reread): Recompile either the main program or the shared ++ library, depending on what is being tested. Skip changing address ++ if caller wants to. Compare before/after addresses. If testing ++ standalone, explicitly load the binary. Test "maint info ++ breakpoints". ++ (top level): Add "standalone vs shared lib" and "change address" ++ vs "same address" axes. ++ ++2016-10-06 Pedro Alves ++ + * gdb.base/jit-simple.exp (top level) Delete get_compiler_info + call. + (jit_run): Delete. +--- /dev/null ++++ b/gdb/testsuite/gdb.base/jit-simple-dl.c +@@ -0,0 +1,25 @@ ++/* This testcase is part of GDB, the GNU debugger. ++ ++ Copyright 2016 Free Software Foundation, Inc. ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 3 of the License, or ++ (at your option) any later version. ++ ++ This program is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program. If not, see . */ ++ ++/* A stub program that links with a simple library that uses the JIT ++ API. */ ++ ++int ++main (void) ++{ ++ return 0; ++} +--- /dev/null ++++ b/gdb/testsuite/gdb.base/jit-simple-jit.c +@@ -0,0 +1,50 @@ ++/* This testcase is part of GDB, the GNU debugger. ++ ++ Copyright 2012-2016 Free Software Foundation, Inc. ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 3 of the License, or ++ (at your option) any later version. ++ ++ This program is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program. If not, see . */ ++ ++/* Simple library using the JIT API. */ ++ ++#include ++ ++struct jit_code_entry ++{ ++ struct jit_code_entry *next_entry; ++ struct jit_code_entry *prev_entry; ++ const char *symfile_addr; ++ uint64_t symfile_size; ++}; ++ ++struct jit_descriptor ++{ ++ uint32_t version; ++ /* This type should be jit_actions_t, but we use uint32_t ++ to be explicit about the bitwidth. */ ++ uint32_t action_flag; ++ struct jit_code_entry *relevant_entry; ++ struct jit_code_entry *first_entry; ++}; ++ ++#ifdef SPACER ++/* This exists to change the address of __jit_debug_descriptor. */ ++int spacer = 4; ++#endif ++ ++struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 }; ++ ++void ++__jit_debug_register_code (void) ++{ ++} +--- a/gdb/testsuite/gdb.base/jit-simple.c ++++ b/gdb/testsuite/gdb.base/jit-simple.c +@@ -1,37 +1,26 @@ +-/* Simple program using the JIT API. */ ++/* This testcase is part of GDB, the GNU debugger. + +-#include ++ Copyright 2016 Free Software Foundation, Inc. + +-struct jit_code_entry +-{ +- struct jit_code_entry *next_entry; +- struct jit_code_entry *prev_entry; +- const char *symfile_addr; +- uint64_t symfile_size; +-}; ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 3 of the License, or ++ (at your option) any later version. + +-struct jit_descriptor +-{ +- uint32_t version; +- /* This type should be jit_actions_t, but we use uint32_t +- to be explicit about the bitwidth. */ +- uint32_t action_flag; +- struct jit_code_entry *relevant_entry; +- struct jit_code_entry *first_entry; +-}; ++ This program is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. + +-#ifdef SPACER +-/* This exists to change the address of __jit_debug_descriptor. */ +-int spacer = 4; +-#endif ++ You should have received a copy of the GNU General Public License ++ along with this program. If not, see . */ + +-struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 }; ++/* Simple standalone program using the JIT API. */ + +-void __jit_debug_register_code() +-{ +-} ++#include "jit-simple-jit.c" + +-int main() ++int ++main (void) + { + return 0; + } +--- a/gdb/testsuite/gdb.base/jit-simple.exp ++++ b/gdb/testsuite/gdb.base/jit-simple.exp +@@ -13,6 +13,17 @@ + # You should have received a copy of the GNU General Public License + # along with this program. If not, see . + ++# Test re-running an inferior with a JIT descriptor, where the JIT ++# descriptor changes address between runs. ++# http://sourceware.org/bugzilla/show_bug.cgi?id=13431 ++ ++# Test both the case of the JIT reader being included in the main ++# program directly, and the case of the JIT reader being split out to ++# a shared library. ++ ++# For completeness, also test when the JIT descriptor does not change ++# address between runs. ++ + if {[skip_shlib_tests]} { + untested jit-simple.exp + return -1 +@@ -20,25 +31,81 @@ if {[skip_shlib_tests]} { + + standard_testfile + +-if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { ++set libname $testfile-jit ++set srcfile_lib $srcdir/$subdir/$libname.c ++set binfile_lib [standard_output_file $libname.so] ++ ++# Build a standalone JIT binary. ++ ++proc build_standalone_jit {{options ""}} { ++ global testfile srcfile binfile ++ ++ lappend options "debug" ++ ++ if {[build_executable $testfile.exp $testfile $srcfile $options] == -1} { ++ return -1 ++ } ++ ++ return 0 ++} ++ ++# Build the shared library JIT. ++ ++proc build_shared_jit {{options ""}} { ++ global testfile ++ global srcfile_lib binfile_lib ++ ++ lappend options "debug additional_flags=-fPIC" ++ if { [gdb_compile_shlib $srcfile_lib $binfile_lib $options] != "" } { ++ return -1 ++ } ++ ++ return 0 ++} ++ ++if {[build_standalone_jit] == -1} { ++ untested "could not compile $binfile" ++ return ++} ++ ++if {[build_shared_jit] == -1} { ++ untested "could not compile $binfile_lib" ++ return ++} ++ ++# Built the program that loads the JIT library. ++set srcfile_dl $testfile-dl.c ++set binfile_dl $binfile-dl ++set options [list debug shlib=${binfile_lib}] ++if {[gdb_compile ${srcdir}/${subdir}/${srcfile_dl} $binfile_dl executable \ ++ [list debug shlib=$binfile_lib]] == -1 } { + untested jit-simple.exp + return -1 + } + +-# Test re-running an inferior with a JIT descriptor, where the JIT +-# descriptor changes address between runs. +-# http://sourceware.org/bugzilla/show_bug.cgi?id=13431 +-proc jit_test_reread {} { +- global testfile binfile subdir srcfile srcdir ++# STANDALONE is true when the JIT reader is included directly in the ++# main program. False when the JIT reader is in a separate shared ++# library. If CHANGE_ADDR is true, force changing the JIT descriptor ++# changes address between runs. ++proc jit_test_reread {standalone change_addr} { ++ global testfile binfile subdir srcfile srcdir binfile_lib binfile_dl + global hex + + with_test_prefix "initial run" { +- clean_restart $testfile ++ if {$standalone} { ++ clean_restart $binfile ++ } else { ++ clean_restart $binfile_dl ++ } + + runto_main + + set addr_before [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ + "get address of __jit_debug_descriptor"] ++ ++ gdb_test "maint info breakpoints" \ ++ "jit events keep y $hex <__jit_debug_register_code>.*" \ ++ "maint info breakpoints shows jit breakpoint" + } + + with_test_prefix "second run" { +@@ -47,21 +114,49 @@ proc jit_test_reread {} { + # second, gdb might not reload the executable automatically. + sleep 1 + +- gdb_rename_execfile $binfile ${binfile}x +- if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DSPACER}] != "" } { +- fail "recompile" +- return +- } else { +- pass "recompile" ++ if ${change_addr} { ++ set options "additional_flags=-DSPACER" ++ if {$standalone} { ++ gdb_rename_execfile $binfile ${binfile}x ++ set res [build_standalone_jit $options] ++ } else { ++ gdb_rename_execfile $binfile_lib ${binfile_lib}x ++ set res [build_shared_jit $options] ++ } ++ if { $res == -1 } { ++ fail "recompile" ++ return ++ } else { ++ pass "recompile" ++ } + } + + runto_main + + set addr_after [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \ + "get address of __jit_debug_descriptor"] ++ ++ # This used to crash in the JIT-in-shared-library case: ++ # https://sourceware.org/bugzilla/show_bug.cgi?id=11094 ++ gdb_test "maint info breakpoints" \ ++ "jit events keep y $hex <__jit_debug_register_code>.*" \ ++ "maint info breakpoints shows jit breakpoint" + } + +- gdb_assert {$addr_before != $addr_after} "address changed" ++ if ${change_addr} { ++ gdb_assert {$addr_before != $addr_after} "address changed" ++ } else { ++ gdb_assert {$addr_before == $addr_after} "address didn't change" ++ } + } + +-jit_test_reread ++foreach standalone {1 0} { ++ with_test_prefix [expr ($standalone)?"standalone":"shared"] { ++ with_test_prefix "change addr" { ++ jit_test_reread $standalone 1 ++ } ++ with_test_prefix "same addr" { ++ jit_test_reread $standalone 0 ++ } ++ } ++} diff --git a/gdb.spec b/gdb.spec index aa84bd5..da95c2e 100644 --- a/gdb.spec +++ b/gdb.spec @@ -21,13 +21,13 @@ Name: %{?scl_prefix}gdb %global snapsrc 20160801 # See timestamp of source gnulib installed into gdb/gnulib/ . %global snapgnulib 20150822 -%global tardate 20160929 +%global tardate 20161006 %global tarname gdb-7.11.90.%{tardate} Version: 7.12 # The release always contains a leading reserved number, start it at 1. # `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing. -Release: 0.19.%{tardate}%{?dist} +Release: 0.20.%{tardate}%{?dist} License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and BSD and Public Domain and GFDL Group: Development/Debuggers @@ -598,9 +598,6 @@ Patch1144: gdb-bison-old.patch Patch1145: gdb-testsuite-casts.patch Patch1146: gdb-testsuite-m-static.patch -# Fix attachment of JIT-debug-enabled inf. (7.11.1 regression, RH BZ 1375553). -Patch1147: gdb-rhbz1375553-attach-jit-debug.patch - %if 0%{!?rhel:1} || 0%{?rhel} > 6 # RL_STATE_FEDORA_GDB would not be found for: # Patch642: gdb-readline62-ask-more-rh.patch @@ -936,7 +933,6 @@ done %patch1144 -p1 %patch1145 -p1 %patch1146 -p1 -%patch1147 -p1 %patch1075 -p1 %if 0%{?rhel:1} && 0%{?rhel} <= 7 @@ -1494,6 +1490,9 @@ then fi %changelog +* Thu Oct 6 2016 Jan Kratochvil - 7.12-0.20.20161006.fc25 +- Rebase to FSF GDB 7.11.90.20161006 (pre-7.12 branch snapshot). + * Thu Sep 29 2016 Jan Kratochvil - 7.12-0.19.20160929.fc25 - Rebase to FSF GDB 7.11.90.20160929 (pre-7.12 branch snapshot). - Fixes GDB crashes on inf. function call scripts (RH BZ 1378147, Pedro Alves). diff --git a/sources b/sources index a9f750a..cf3fdb3 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ 131d0dfd20cd6014c168fbcab9be2c43 gdb-libstdc++-v3-python-6.1.1-20160817.tar.xz 29efc08219d9d6a0536d58f9807c8722 v1.5.tar.gz -c235bf20f302f0393714ad1b654f9029 gdb-7.11.90.20160929.tar.xz +1018e904681aa0a64a1e315f808572ff gdb-7.11.90.20161006.tar.xz