diff options
author | Hui Zhu <teawater@gmail.com> | 2014-06-08 19:11:09 +0800 |
---|---|---|
committer | Hui Zhu <teawater@gmail.com> | 2014-06-08 19:14:06 +0800 |
commit | c077881afaedb9b74063bee992b3e472b4b6e9ca (patch) | |
tree | 4f9100c9e015f5f6683ffe42011e78e4102c3514 /gdb/linux-nat.c | |
parent | ba2ffec39653bedebe1051d5d24954e9662781fa (diff) | |
download | gdb-c077881afaedb9b74063bee992b3e472b4b6e9ca.zip gdb-c077881afaedb9b74063bee992b3e472b4b6e9ca.tar.gz gdb-c077881afaedb9b74063bee992b3e472b4b6e9ca.tar.bz2 |
Fix gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version
https://sourceware.org/ml/gdb-patches/2014-04/msg00047.html
Got gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw)
(timeout) with Linux 2.6.32 and older version.
The rootcause is after the test use "set can-use-hw-watchpoints 0" let GDB
doesn't use hardware breakpoint and set a watchpoint on "global", GDB
continue will keep single step inside function "vfork".
The Linux 2.6.32 and older version doesn't have commit
6580807da14c423f0d0a708108e6df6ebc8bc83d (get more info please goto
http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=6580807da14c423f0d0a708108e6df6ebc8bc83d).
When the function "vfork" do syscall, the single step flag TIF_SINGLESTEP
will copy to child process.
Then GDB detach it, child process and parent process will be hanged.
So I make a patch that do a single step before detach. Then TIF_SINGLESTEP
of child process in old Linux kernel will be cleared before detach.
Child process in new Linux kernel will not be affected by this single step.
2014-06-08 Hui Zhu <hui@codesourcery.com>
* common/linux-ptrace.c (linux_disable_event_reporting): New
function.
* common/linux-ptrace.h (linux_disable_event_reporting): New
declaration.
* linux-nat.c (linux_child_follow_fork): Do a single step before
detach.
Diffstat (limited to 'gdb/linux-nat.c')
-rw-r--r-- | gdb/linux-nat.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 6ca5c7e..3b117b5 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -414,6 +414,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ if (detach_fork) { struct cleanup *old_chain; + int status = 0; /* Before detaching from the child, remove all breakpoints from it. If we forked, then this has already been taken @@ -447,7 +448,29 @@ holding the child stopped. Try \"set detach-on-fork\" or \ if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); - ptrace (PTRACE_DETACH, child_pid, 0, 0); + + /* When debugging an inferior in an architecture that supports + hardware single stepping on a kernel without commit + 6580807da14c423f0d0a708108e6df6ebc8bc83d, the vfork child + process starts with the TIF_SINGLESTEP/X86_EFLAGS_TF bits + set if the parent process had them set. + To work around this, single step the child process + once before detaching to clear the flags. */ + + if (!gdbarch_software_single_step_p (target_thread_architecture + (child_lp->ptid))) + { + int status; + + linux_disable_event_reporting (child_pid); + if (ptrace (PTRACE_SINGLESTEP, child_pid, 0, 0) < 0) + perror_with_name (_("Couldn't do single step")); + if (my_waitpid (child_pid, &status, 0) < 0) + perror_with_name (_("Couldn't wait vfork process")); + } + + if (WIFSTOPPED (status)) + ptrace (PTRACE_DETACH, child_pid, 0, WSTOPSIG (status)); do_cleanups (old_chain); } |