From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] [native x86 GNU/Linux] Access debug register mirror from the corresponding inferior.
Date: Thu, 07 Feb 2013 16:59:00 -0000 [thread overview]
Message-ID: <20130207165907.GB15297@host2.jankratochvil.net> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2013-02-07 16:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-07 16:33 Pedro Alves
2013-02-07 16:59 ` Jan Kratochvil [this message]
2013-02-11 21:10 ` Pedro Alves
2013-02-12 12:36 ` Pedro Alves
2013-02-12 16:50 ` Jan Kratochvil
2013-02-13 15:04 ` Pedro Alves
2013-02-13 14:20 ` Yufeng Zhang
2013-02-13 14:51 ` Pedro Alves
2013-02-13 15:14 ` Pedro Alves
2013-02-13 15:21 ` Marcus Shawcroft
2013-02-13 16:02 ` [native AAarch64 GNU/Linux] Access debug register mirror from the corresponding process Pedro Alves
2013-02-13 18:57 ` Yufeng Zhang
2013-02-13 19:04 ` Pedro Alves
2013-02-14 10:13 ` Yufeng Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130207165907.GB15297@host2.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox