Re: [PATCH 01/31] displaced step: pass down target_waitstatus instead of gdb_signal

Andrew Burgess via Gdb-patches
2023-03-22T21:29:50Z

Andrew Burgess <aburgess@redhat.com> writes:

> Pedro Alves <pedro@palves.net> writes:
>
>> On 2023-02-03 10:44 a.m., Andrew Burgess wrote:
>>> Pedro Alves <pedro@palves.net> writes:
>>>
>>>> This commit tweaks displaced_step_finish & friends to pass down a
>>>> target_waitstatus instead of a gdb_signal. This needed because a
>>>
>>> missing word: "This IS needed".
>>
>> Fixed.
>>
>>>> @@ -5699,7 +5696,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>>>> has been done. Perform cleanup for parent process here. Note
>>>> that this operation also cleans up the child process for vfork,
>>>> because their pages are shared. */
>>>> - displaced_step_finish (ecs->event_thread, GDB_SIGNAL_TRAP);
>>>> + displaced_step_finish (ecs->event_thread, ecs->ws);
>>>
>>> This change is interesting.
>>>
>>> If I understand the code correctly, this call will eventually end up in
>>> displaced_step_buffers::finish (displaced-stepping.c), which in turn
>>> calls displaced_step_instruction_executed_successfully.
>>>
>>> Previously, we always passed GDB_SIGNAL_TRAP here, which (if we ignore
>>> the watchpoint check in
>>> displaced_step_instruction_executed_successfully) means that
>>> displaced_step_instruction_executed_successfully would always return
>>> true, and then displaced_step_buffers::finish would call
>>> gdbarch_displaced_step_fixup.
>>>
>>> After this change, we know that esc->ws.kind is either
>>> TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED, so we know that
>>> displaced_step_instruction_executed_successfully will always return
>>> false, and displaced_step_buffers::finish will no longer call
>>> gdbarch_displaced_step_fixup.
>>>
>>
>> Good catch!
>>
>> I was tweaking the change to address your comment, and was coming to the
>> conclusion that what I really wanted was this:
>>
>> static bool
>> displaced_step_instruction_executed_successfully
>> (gdbarch *arch, const target_waitstatus &status)
>> {
>> if (status.kind () == TARGET_WAITKIND_STOPPED
>> && status.sig () != GDB_SIGNAL_TRAP)
>> return false;
>>
>> /* All other waitkinds can only happen if the instruction fully
>> executed. For example, a fork, or a syscall entry can only
>> happen if the syscall instruction actually executed. */
>>
>> (the comment is new)
>>
>> And then, I remembered, I actually wrote that early if like that originally,
>> and I changed it in response to this review:
>>
>> https://inbox.sourceware.org/gdb-patches/44f74af8-248b-1af8-3612-980c08607bf4@simark.ca/
>>
>> The review was totally right, it was my response that was misguided.
>>
>> But I'm confused because I am pretty sure that I wrote a reply to that
>> message, saying that I did not intend to change the behavior, so I'd "fix" it.
>> I can't find it in my outbox either, I guess I erroneously canceled my
>> email window instead of sending the message...
>>
>> Anyhow, looks like I made it worse while trying to address Simon's comment. :-P
>>
>> So I think I should go back to what I had, like before, and my response
>> to Simon should have been instead:
>>
>> - yes, the change is intended. If we stopped for an event other than
>> TARGET_WAITKIND_STOPPED, like for instance, TARGET_WAITKIND_FORKED,
>> TARGET_WAITKIND_SYSCALL_ENTRY, then it must be that the instruction
>> executed successfully, otherwise the syscall wouldn't have triggered.
>>
>>> What I don't understand well enough is what this actually means for a
>>> running inferior.
>>>
>>> It's odd because the comment in infrun.c (just above your change)
>>> indicates that to get to this point the displaced step must have
>>> completed successfully, while after this change, the new code path in
>>> displaced_step_buffers::finish indicates we believe the displaced step
>>> didn't complete successfully:
>>>
>>> /* Since the instruction didn't complete, all we can do is relocate the
>>> PC. */
>>>
>>> Do you know if any of our test cases hit this path?
>>>
>>
>> I know that you posted a series for this, which I plan to take a good look
>> at (I actually planned on doing that earlier this week, but I had a couple
>> major distractions, sorry).
>>
>> WDYT of the version below?
>
> I took a look through and I'm happy with it. But I would like you to
> consider holding off until my displaced step patch has some feedback.
>
> I'm currently rebasing the patch. My patch deletes
> displaced_step_instruction_executed_successfully, which I realised makes
> passing the signal (or now target_waitstatus) redundant. As such I'm
> just testing an additional patch in the series which touches every place
> you're touching - but removes the signal instead of changing it.
>
> I hope to post my updated series later today (once testing completes).

Pedro,

Thanks for your feedback on my displaced stepping series. You're right
that just checking the $pc isn't going to be enough. So I'm now
thinking that I should be passing the gdb_signal through to the
gdbarch_displaced_step_fixup function.

Rather than change things to pass through the gdb_signal though, and
then have this patch come along and s/gdb_signal/target_waitstatus/, I
wonder how you'd feel about merging this patch sooner rather than later?

I'm planning to rebase my displaced stepping series off this patch -- I
just want to check you'd be OK with this patch possibly landing before
the rest of this series?

Thanks,
Andrew