public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <Lancelot.Six@amd.com>
To: Pedro Alves <pedro@palves.net>, gdb-patches@sourceware.org
Cc: lsix@lancelotsix.com
Subject: Re: [PATCH] gdb/amd-dbgapi-target: Use inf param in detach
Date: Fri, 14 Jul 2023 19:54:42 +0100	[thread overview]
Message-ID: <05217693-1a01-bffb-e74a-503b3fe3a604@amd.com> (raw)
In-Reply-To: <2c7f2ef1-dea2-5dbe-8d3f-b9b885be3b72@palves.net>



On 14/07/2023 19:35, Pedro Alves wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> On 2023-06-16 10:25, Lancelot SIX via Gdb-patches wrote:
>> Current implementation of amd_dbgapi_target::detach (inferior *, int)
>> does the following:
>>
>>    remove_breakpoints_inf (current_inferior ());
>>    detach_amd_dbgapi (inf);
>>    beneath ()->detach (inf, from_tty);
>>
>> I find that using a mix of `current_inferior ()` and `inf` disturbing.
>> At this point, we know that both are the same (target_detach does assert
>> that `inf == current_inferior ()` before calling target_ops::detach).
>>
>> To improve consistency, this patch replaces `current_inferior ()` with
>> `inf` in amd_dbgapi_target::detach.
>>
>> Change-Id: I01b7ba2e661c25839438354b509d7abbddb7c5ed
> 
> IMO this is a case of the target method's inferior * parameter having
> been added too soon -- it would only make sense to have it if nothing in
> the body of the target method implementations is relying on inf being
> current_inferior on entry.  But that is not the case, plenty of target_ops::detach
> code has that assumption.  The presence of an explicit inferior pointer should mean
> that detach target method implementations that call code that depends
> on the inferior being the current inferior, should be using a
> scoped_restore_current_thread/inferior before calling such global-state-assuming
> code.  But, they don't do that, instead, we have this mixed situation.  IMO, it would
> be better to remove the parameter to avoid confusion and stick to the
> (if explicit param, then switch global state to it if you need it) rule.
> 
> Anyhow, your patch doesn't make it worse, so it's fine with me.
> 

I can also go the other way around and always use `current_inferior ()` 
instead of the `inf` parameter in this detach implementation.

What bugged me here is the inconsistency from one line to the next.

Lancelot.

  reply	other threads:[~2023-07-14 18:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16  9:25 Lancelot SIX
2023-07-14 18:35 ` Pedro Alves
2023-07-14 18:54   ` Lancelot SIX [this message]
2023-07-14 19:18     ` Pedro Alves
2023-07-15  2:00       ` Simon Marchi
2023-07-19  8:56       ` Lancelot SIX

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=05217693-1a01-bffb-e74a-503b3fe3a604@amd.com \
    --to=lancelot.six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    --cc=pedro@palves.net \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).