https://bugzilla.redhat.com/show_bug.cgi?id=1375553 Christophe Fergeau 2016-09-13 run qemu-system-x86_64 (for this reproducer, no need for any arg) run gdb --pid $(pidof qemu-system-x86_64) This results in Attaching to process 27948 [New LWP 27952] [New LWP 27953] Warning: Cannot insert breakpoint -1. Cannot access memory at address 0x20bf00 (gdb) 0x00007fdf94bcd4b1 in ?? () and the gdb session is non-functional. This started happening with gdb-7.11.1-75.fc24 which is the first gdb 7.11.1 build, downgrading to gdb-7.11-74.fc24 avoids this issue. Jan Kratochvil 2016-09-14 136613ef0c6850427317e57be1b644080ff6decb is the first bad commit Author: Pedro Alves <palves@redhat.com> Fix PR gdb/19828: gdb -p <process from a container>: internal error
echo -e '#include <unistd.h>\nint __jit_debug_register_code,__jit_debug_descriptor;int main(){sleep(60);}'|gcc -fPIE -pie -x c -;./a.out &p=$!;sleep 0.1;gdb -q -iex 'set breakpoint always-inserted on' -iex 'set debug jit 1' -p $p [5] 322 Attaching to process 322 Reading symbols from /tmp/a.out...(no debugging symbols found)...done. jit_breakpoint_re_set_internal, breakpoint_addr = 0x201030 Warning: Cannot insert breakpoint -1. Cannot access memory at address 0x201030
[patch+7.12] PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression https://sourceware.org/ml/gdb-patches/2016-09/msg00387.html
The master branch has been updated by Jan Kratochvil <jkratoch@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bb805577d2b212411fb7b0a2d01644567fac4e8d commit bb805577d2b212411fb7b0a2d01644567fac4e8d Author: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Thu Sep 29 17:38:16 2016 +0200 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.
The gdb-7.12-branch branch has been updated by Jan Kratochvil <jkratoch@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b31567caa5d7ed8e9ad69f59a562c0494c0b3cbe commit b31567caa5d7ed8e9ad69f59a562c0494c0b3cbe Author: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Thu Sep 29 17:38:16 2016 +0200 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.
[commit+7.12] [patch+7.12] PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression https://sourceware.org/ml/gdb-patches/2016-09/msg00414.html