aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2016-09-29 17:38:16 +0200
committerJan Kratochvil <jan.kratochvil@redhat.com>2016-09-29 17:39:39 +0200
commitbb805577d2b212411fb7b0a2d01644567fac4e8d (patch)
tree975c7465c2f346d1122bc64221db7ca2ed176c9c /gdb/testsuite
parent50751e18f3f2fc47959a577a5754f1a2d80baf18 (diff)
downloadgdb-bb805577d2b212411fb7b0a2d01644567fac4e8d.zip
gdb-bb805577d2b212411fb7b0a2d01644567fac4e8d.tar.gz
gdb-bb805577d2b212411fb7b0a2d01644567fac4e8d.tar.bz2
PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression
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 <palves@redhat.com> Fix PR gdb/19828: gdb -p <process from a container>: internal error Message-ID: <cbdf2e04-4fa8-872a-2a23-08c9c1b26e00@redhat.com> 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: -> jit_breakpoint_re_set_internal() later: -> 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(). Applied. gdb/ChangeLog 2016-09-29 Jan Kratochvil <jan.kratochvil@redhat.com> 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-29 Jan Kratochvil <jan.kratochvil@redhat.com> 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.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.base/jit-attach-pie.c61
-rw-r--r--gdb/testsuite/gdb.base/jit-attach-pie.exp48
3 files changed, 115 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index ff0035e..b6243cf 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2016-09-29 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ 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.
+
2016-09-28 Pedro Alves <palves@redhat.com>
* gdb.base/infcall-input.c: New file.
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 <http://www.gnu.org/licenses/>. */
+
+#include <unistd.h>
+#include <stdint.h>
+#include <pthread.h>
+
+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 <http://www.gnu.org/licenses/>.
+
+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