From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 7/8] Initialise target descrption after skipping extra traps for --wrapper
Date: Thu, 23 Jul 2015 23:26:00 -0000 [thread overview]
Message-ID: <55B17806.2060000@redhat.com> (raw)
In-Reply-To: <1437392126-29503-8-git-send-email-yao.qi@linaro.org>
On 07/20/2015 12:35 PM, Yao Qi wrote:
> Nowadays, when --wrapper is used, GDBserver skips extra traps/stops
> in the wrapper program, and stops at the first instruction of the
> program to be debugged. However, GDBserver created target description
> in the first stop of inferior, and the executable of the inferior
> is the wrapper program rather than the program to be debugged. In
> this way, the target description can be wrong if the architectures
> of wrapper program and program to be debugged are different. This
> is shown by some fails in gdb.server/wrapper.exp on buildbot.
>
> We are testing i686-linux GDB (Fedora-i686) on an x86_64-linux box
> (fedora-x86-64-4) in buildbot, such configuration causes fails in
> gdb.server/wrapper.exp like this:
>
> spawn /home/gdb-buildbot-2/fedora-x86-64-4/fedora-i686/build/gdb/testsuite/../../gdb/gdbserver/gdbserver --once --wrapper env TEST=1 -- :2346 /home/gdb-buildbot-2/fedora-x86-64-4/fedora-i686/build/gdb/testsuite/outputs/gdb.server/wrapper/wrapper
> Process /home/gdb-buildbot-2/fedora-x86-64-4/fedora-i686/build/gdb/testsuite/outputs/gdb.server/wrapper/wrapper created; pid = 8795
> Can't debug 64-bit process with 32-bit GDBserver
> Exiting
> target remote localhost:2346
> localhost:2346: Connection timed out.
> (gdb) FAIL: gdb.server/wrapper.exp: setting breakpoint at marker
>
> See https://sourceware.org/ml/gdb-testers/2015-q3/msg01541.html
>
> In this case, program to be debugged ("wrapper") is 32-bit but wrapper
> program ("/usr/bin/env") is 64-bit, so GDBserver gets the 64-bit
> target description instead of 32-bit.
>
> The root cause of this problem is that GDBserver creates target
> description too early, and the rationale of fix could be creating
> target description once the GDBserver skips extra traps and inferior
> stops at the first instruction of the program we want to debug. IOW,
> when GDBserver skips extra traps, the inferior's tdesc is NULL, and
> mywait and its callees shouldn't use inferior's tdesc, so in this
> patch, we do the shortcut if proc->tdesc == NULL, see changes in
> linux_resume_one_lwp_throw and need_step_over_p.
>
> In linux_low_filter_event, if target description isn't initialised and
> GDBserver attached the process, we create target description immediately,
> because GDBserver don't have to skip extra traps for attach, IOW, it
> makes no sense to use --attach and --wrapper together. Otherwise, the
> process is launched by GDBserver, we keep the status pending, and return.
>
> After GDBserver skipped extra traps in start_inferior, we call a
> target_ops hook arch_setup to initialise target description there.
>
Great, thanks for doing this. Looks generally good to me. One
comment below.
> @@ -3651,6 +3671,31 @@ linux_resume_one_lwp_throw (struct lwp_info *lwp,
> struct thread_info *thread = get_lwp_thread (lwp);
> struct thread_info *saved_thread;
> int fast_tp_collecting;
> + struct process_info *proc = get_thread_process (thread);
> +
> + if (proc->tdesc == NULL)
> + {
> + /* Target description isn't initialised because the program hasn't
> + stop at the first instruction. It means GDBserver skips the
"hasn't stopped" ... "first instruction yet".
> + extra traps from the wrapper program (see option --wrapper),
> + and GDBserver just simply resumes the program without accessing
> + inferior registers, because target description is unavailable
> + at this point. */
> + errno = 0;
> + lwp->stepping = step;
> + ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread),
> + (PTRACE_TYPE_ARG3) 0,
> + /* Coerce to a uintptr_t first to avoid potential gcc warning
> + of coercing an 8 byte integer to a 4 byte pointer. */
> + (PTRACE_TYPE_ARG4) (uintptr_t) signal);
> +
> + if (errno)
> + perror_with_name ("resuming thread");
> +
> + lwp->stopped = 0;
> + lwp->stop_reason = TARGET_STOPPED_BY_NO_REASON;
> + return;
Instead of this whole code block, I think we should be able to skip
the bits in the function that require accessing registers. E.g.,
this:
/* Cancel actions that rely on GDB not changing the PC (e.g., the
user used the "jump" command, or "set $pc = foo"). */
if (lwp->stop_pc != get_pc (lwp))
{
/* Collecting 'while-stepping' actions doesn't make sense
anymore. */
release_while_stepping_state_list (thread);
}
Could be guarded by:
if (thread->while_stepping != NULL)
And this:
if (the_low_target.get_pc != NULL)
{
struct regcache *regcache = get_thread_regcache (current_thread, 1);
lwp->stop_pc = (*the_low_target.get_pc) (regcache);
if (debug_threads)
{
debug_printf (" %s from pc 0x%lx\n", step ? "step" : "continue",
(long) lwp->stop_pc);
}
}
could be guarded by:
if (proc->tdesc == NULL)
Did you try that?
> + }
>
> if (lwp->stopped == 0)
> return;
Thanks,
Pedro Alves
next prev parent reply other threads:[~2015-07-23 23:26 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-20 11:35 [PATCH 0/8] Fix various issues in --wrapper in GDBserver Yao Qi
2015-07-20 11:35 ` [PATCH 4/8] Test --wrapper when restarting process Yao Qi
2015-07-23 22:59 ` Pedro Alves
2015-07-20 11:35 ` [PATCH 1/8] Disallow using --attach and --wrapper together Yao Qi
2015-07-23 22:29 ` Pedro Alves
2015-07-24 8:44 ` Yao Qi
2015-07-24 8:51 ` Pedro Alves
2015-07-20 11:35 ` [PATCH 2/8] Test --wrapper in extended-remote Yao Qi
2015-07-23 22:35 ` Pedro Alves
2015-07-20 11:36 ` [PATCH 8/8] Remove proc->priv->new_inferior Yao Qi
2015-07-23 23:27 ` Pedro Alves
2015-07-20 11:36 ` [PATCH 3/8] Set general_thread after restart Yao Qi
2015-07-23 22:58 ` Pedro Alves
2015-07-24 9:33 ` Yao Qi
2015-07-24 9:53 ` Pedro Alves
2015-07-24 11:31 ` Yao Qi
2015-07-20 11:36 ` [PATCH 6/8] Set proc->priv->new_inferior out of linux_add_process Yao Qi
2015-07-23 23:26 ` Pedro Alves
2015-07-20 11:36 ` [PATCH 7/8] Initialise target descrption after skipping extra traps for --wrapper Yao Qi
2015-07-23 23:26 ` Pedro Alves [this message]
2015-07-24 11:12 ` Yao Qi
2015-07-24 11:52 ` Pedro Alves
2015-07-24 13:08 ` Yao Qi
2015-07-24 13:44 ` Pedro Alves
2015-07-20 11:36 ` [PATCH 5/8] Refactor start_inferior Yao Qi
2015-07-23 23:27 ` Pedro Alves
2015-07-24 13:49 ` [PATCH 0/8] Fix various issues in --wrapper in GDBserver Yao Qi
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=55B17806.2060000@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.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