diff options
-rw-r--r-- | gdb/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/exec.c | 5 | ||||
-rw-r--r-- | gdb/gdbcore.h | 5 | ||||
-rw-r--r-- | gdb/infcmd.c | 2 | ||||
-rw-r--r-- | gdb/remote.c | 2 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/jit-attach-pie.c | 61 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/jit-attach-pie.exp | 48 |
8 files changed, 133 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index eda3fa2..ffbdc3d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +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. + 2016-09-28 Pedro Alves <palves@redhat.com> * infcall.c (run_inferior_call): Remove input from the event @@ -158,7 +158,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; @@ -233,6 +233,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) @@ -241,6 +243,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 ec8b498..af7508a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1800,7 +1800,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/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 |