From: Simon Marchi <simon.marchi@ericsson.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/4] Add thread after updating gdbarch when exec'ing
Date: Tue, 05 Sep 2017 15:30:00 -0000 [thread overview]
Message-ID: <7522acaf-4982-c10c-8260-802073db5ffd@ericsson.com> (raw)
In-Reply-To: <20170905103731.GF8425@1170ee0b50d5>
On 2017-09-05 12:37 PM, Yao Qi wrote:
> On 17-08-27 12:15:33, Simon Marchi wrote:
>> As mentioned in the previous patch, we should avoid doing register reads
>> after a process does an exec and before we've updated that inferior's
>> gdbarch. Otherwise, we may interpret the registers using the wrong
>> architecture. When a process does an exec with "follow-exec-mode new",
>> a new inferior is added by follow_exec. The gdbarch of that new
>> inferior is at first set to some default value, probably specific to the
>> gdb build (I get "i386" here), which may not be the right one. It is
>> updated later by the call to target_find_description. Before that
>> point, if we try to read the inferior's registers, we may not interpret
>> them correctly. This has been exposed by a failure in
>> gdb.base/foll-exec-mode.exp after the previous patch, with:
>>
>> Remote 'g' packet reply is too long (expected 312 bytes, got 816 bytes)
>>
>> The call to "add_thread" done just after adding the inferior is
>> problematic, because it ends up reading the registers (because the ptid
>> is re-used, we end up doing a switch_to_thread to it, which tries to
>> update stop_pc). The registers returned by gdbserver are the x86-64
>> ones, while we try to interpret them using the "i386" gdbarch.
>
> The analysis is great!
>
>>
>> Postponing the call to add_thread to until the target
>> description/gdbarch has been updated seems to fix the issue.
>
> This imposes an odd restriction on using add_thread, that is, we must
> keep in mind that we can't use add_thread until the inferior's gdbarch
> or target description is updated. The question in my mind is that why
> do we need to update stop_pc in add_thread? or can we remove stop_pc?
Instinctively, I'd say that we should probably get rid of stop_pc, and instead
get the same info through the current thread instead.
I have a question for you, since you know much more about tdesc than me. Installing
a default tdesc (e.g. i386) that is replaced just after with the right tdesc
(e.g. i386:x86-64) creates the risk, like in this case, of using the wrong tdesc.
Do you think it would be feasible (and a good idea) to instead have no tdesc
installed until we figure out which one to use? We could then catch other operations
that are done while the wrong tdesc is present.
For now I'll push this patchset, so that it is in 8.1, but I feel it's just
covering the real problem of having the wrong tdesc installed.
Thanks for the review,
Simon
next prev parent reply other threads:[~2017-09-05 15:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-18 11:10 Check for truncated registers in process_g_packet Lionel Flandrin
2016-10-18 15:50 ` Simon Marchi
2016-10-18 16:07 ` Lionel Flandrin
2016-10-27 15:23 ` Lionel Flandrin
2016-11-08 10:37 ` Pedro Alves
2017-08-25 10:53 ` Yao Qi
2017-08-25 21:05 ` Simon Marchi
2017-08-25 22:55 ` Simon Marchi
2017-08-27 10:16 ` [PATCH 0/4] Try to fix the gdb.multi/multi-arch-exec.exp failure Simon Marchi
2017-08-27 10:16 ` [PATCH 3/4] Add thread after updating gdbarch when exec'ing Simon Marchi
2017-09-05 10:37 ` Yao Qi
2017-09-05 15:30 ` Simon Marchi [this message]
2017-09-05 15:44 ` Simon Marchi
2017-08-27 10:16 ` [PATCH 2/4] Read stop_pc after updating the " Simon Marchi
2017-09-05 10:12 ` Yao Qi
2017-08-27 10:16 ` [PATCH 1/4] Improve "'g' reply is is to long" error message Simon Marchi
2017-09-05 9:49 ` Yao Qi
2017-08-27 10:16 ` [PATCH 4/4] Test different follow-exec-mode settings in gdb.multi/multi-arch-exec.exp Simon Marchi
2017-09-05 10:40 ` Yao Qi
2017-09-05 15:40 ` Simon Marchi
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=7522acaf-4982-c10c-8260-802073db5ffd@ericsson.com \
--to=simon.marchi@ericsson.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