This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] [native x86 GNU/Linux] Access debug register mirror from the corresponding inferior.
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Thu, 7 Feb 2013 17:59:07 +0100
- Subject: Re: [PATCH] [native x86 GNU/Linux] Access debug register mirror from the corresponding inferior.
- References: <20130207163339.19427.73350.stgit@brno.lan>
On Thu, 07 Feb 2013 17:33:39 +0100, Pedro Alves wrote:
> There's one wrinkle though, and one which we already handle somewhat.
> When detaching the fork child that we're not interested in debugging
> (set detach-on-fork off / follow-fork parent), we don't even create an
set detach-on-fork on
> inferior for that fork child, so there's no place to get the struct
> i386_debug_reg_state from, as that's stored in the inferior.
>
> I thought of more than one way to fix this, and this seemed the
> simplest - special case the null inferior case.
>
> Other options involved creating a about_to_detach/about_to_fork_detach
> hook;
>
> Create a target side "struct process_info", thus decoupling from
> struct inferior (mildly complicated, lots of mechanical changes across
> all native targets that do x86 watchpoints, or
>
> Always creating an inferior (that has lots of complications).
I tried that in the past and I agree it was not worth it.
> --- a/gdb/amd64-linux-nat.c
> +++ b/gdb/amd64-linux-nat.c
> @@ -394,9 +394,22 @@ amd64_linux_prepare_to_resume (struct lwp_info *lwp)
>
> if (lwp->arch_private->debug_registers_changed)
> {
> - struct i386_debug_reg_state *state = i386_debug_reg_state ();
> + int pid = ptid_get_pid (lwp->ptid);
> + struct inferior *inf = find_inferior_pid (pid);
> + struct i386_debug_reg_state *state;
> int i;
>
> + if (inf == NULL)
> + {
> + /* NULL means this is a fork child we're not interested in
> + debugging being detached. We want to leave it with its
> + debug registers cleared. */
> + amd64_linux_dr_set (lwp->ptid, DR_CONTROL, 0);
> + return;
> + }
It is already handled by this code which seems to be skipped by this patch.
if (detached_inf_pid != ptid_get_pid (inferior_ptid))
{
/* Reinitialize the local cache if INFERIOR_PTID is
different from the LWP last detached.
Linux kernel before 2.6.33 commit
72f674d203cd230426437cdcf7dd6f681dad8b0d
will inherit hardware debug registers from parent
on fork/vfork/clone. Newer Linux kernels create such tasks with
zeroed debug registers.
GDB will remove all breakpoints (and watchpoints) from the forked
off process. We also need to reset the debug registers in that
process to be compatible with the older Linux kernels.
Copy the debug registers mirrors into the new process so that all
breakpoints and watchpoints can be removed together. The debug
registers mirror will become zeroed in the end before detaching
the forked off process. */
detached_inf_pid = ptid_get_pid (inferior_ptid);
detached_inf_data_local = *inf_data;
}
Also it seems incorrect to me to use 'ptid_get_pid (inferior_ptid)' there when
the detached LWP may not come from the current inferior, it is expected to be
the PID of the process remaining under control of GDB.
I did not try it but what about temporarily switching current inferior?
Thanks,
Jan