Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: Simon Marchi <simark@simark.ca>, Tom Tromey <tom@tromey.com>,
	Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 02/23] Don't rely on inferior_ptid in record_full_wait
Date: Sat, 1 Aug 2020 12:32:25 -0700	[thread overview]
Message-ID: <93dfb190-2d7d-8337-b2b0-df160d1a0bf6@FreeBSD.org> (raw)
In-Reply-To: <9d4243a6-3b43-802b-b1d6-4cd0497205af@simark.ca>

On 8/1/20 9:14 AM, Simon Marchi wrote:
> On 2020-07-30 11:17 p.m., Tom Tromey wrote:
>>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>>
>> Pedro> The multi-target patch sets inferior_ptid to null_ptid before handling
>> Pedro> a target event, and thus before calling target_wait, in order to catch
>> Pedro> places in target_ops::wait implementations that are incorrectly
>> Pedro> relying on inferior_ptid (which could otherwise be a ptid of a
>> Pedro> different target, for example).  That caught this instance in
>> Pedro> record-full.c.
>>
>> I found a few target_ops::wait implementations doing "return
>> inferior_ptid" in error cases.  Based on this comment, and the comment
>> for target_wait, I suspect these should actually return minus_one_ptid
>> instead.
>>
>> I've appended the patch so you can see what it looks like.  I haven't
>> tried it at all.  Does this seem correct?
> 
> I think you are right that it's incorrect, but...
> 
>> diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
>> index ae0b0f7ff0d..2cae87023f9 100644
>> --- a/gdb/inf-ptrace.c
>> +++ b/gdb/inf-ptrace.c
>> @@ -343,7 +343,7 @@ inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
>>  	  /* Claim it exited with unknown signal.  */
>>  	  ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
>>  	  ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
>> -	  return inferior_ptid;
>> +	  return minus_one_ptid;
>>  	}
> 
> I don't know if this makes sense: you tell the core of GDB that some
> process was signalled (terminated by a signal), but you don't tell
> what process it is.  I am not sure what the core of GDB can do with
> this information.
> 
> The contract that the `wait` implementations must respect is not
> very well documented I believe, so it's not clear which value is
> valid with which event.  But I expect that tying a
> TARGET_WAITKIND_SIGNALLED event with a minus_one_ptid (or null_ptid
> for that matter) is invalid, and will just break down later in
> handle_inferior_event, where we handle this kind of event:
> 
>     case TARGET_WAITKIND_EXITED:
>     case TARGET_WAITKIND_SIGNALLED:
>       {
> 	/* Depending on the system, ecs->ptid may point to a thread or
> 	   to a process.  On some targets, target_mourn_inferior may
> 	   need to have access to the just-exited thread.  That is the
> 	   case of GNU/Linux's "checkpoint" support, for example.
> 	   Call the switch_to_xxx routine as appropriate.  */
> 	thread_info *thr = find_thread_ptid (ecs->target, ecs->ptid);
> 	if (thr != nullptr)
> 	  switch_to_thread (thr);
> 	else
> 	  {
> 	    inferior *inf = find_inferior_ptid (ecs->target, ecs->ptid);
> 	    switch_to_inferior_no_thread (inf);
> 	  }
> 
> find_thread_ptid will return nullptr, so we'll go in the else.
> find_inferior_ptid will return nullptr, which we'll pass to
> switch_to_inferior_no_thread, and it will assert somewhere in there.

Note that prior to my fix to inf-ptrace.c in f37e5866aa, I was tripping
over this case and it did indeed result in an assertion failure as
wait was returning null_ptid.  I kind of think an error like an assertion
failure is the right behavior as it's really an indication of a bug.
Arguably though inf-ptrace.c should not return null_ptid that later
triggers an obscure assertion failure, but instead it should probably
just die with an explicit error() or the like.  It's not really clear
to me that we should be trying to do anything to gracefully handle an
ENOCHILD error.

-- 
John Baldwin


  reply	other threads:[~2020-08-01 19:32 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 23:28 [PATCH 00/23] Multi-target support Pedro Alves
2019-09-06 23:28 ` [PATCH 02/23] Don't rely on inferior_ptid in record_full_wait Pedro Alves
2020-07-31  3:17   ` Tom Tromey
2020-08-01 16:14     ` Simon Marchi
2020-08-01 19:32       ` John Baldwin [this message]
2020-08-01 20:47         ` Tom Tromey
2020-08-01 20:46       ` Tom Tromey
2020-08-01 22:56         ` Simon Marchi
2020-08-02 17:52           ` Tom Tromey
2020-08-03  0:08             ` Simon Marchi
2019-09-06 23:28 ` [PATCH 13/23] Delete exit_inferior_silent(int pid) Pedro Alves
2019-09-06 23:28 ` [PATCH 10/23] Some get_last_target_status tweaks Pedro Alves
2019-09-09 18:53   ` Tom Tromey
2019-10-17  1:14     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 01/23] Preserve selected thread in all-stop w/ background execution Pedro Alves
2019-10-09  9:36   ` Aktemur, Tankut Baris
2019-10-16 23:54     ` [PATCH v1.1 " Pedro Alves
2019-10-17 10:21       ` Aktemur, Tankut Baris
2019-09-06 23:28 ` [PATCH 15/23] Fix reconnecting to a gdbserver already debugging multiple processes, I Pedro Alves
2019-09-06 23:28 ` [PATCH 09/23] switch inferior/thread before calling target methods Pedro Alves
2019-09-06 23:28 ` [PATCH 06/23] Don't check target is running in remote_target::mourn_inferior Pedro Alves
2019-09-06 23:28 ` [PATCH 19/23] gdbarch-selftests.c: No longer error out if debugging something Pedro Alves
2019-09-06 23:28 ` [PATCH 03/23] Make "show remote exec-file" inferior-aware Pedro Alves
2019-09-06 23:28 ` [PATCH 16/23] Fix reconnecting to a gdbserver already debugging multiple processes, II Pedro Alves
2019-09-06 23:28 ` [PATCH 20/23] Revert 'Remove unused struct serial::name field' Pedro Alves
2019-09-06 23:47   ` Christian Biesinger via gdb-patches
2019-09-08 19:30     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 17/23] Multi-target support Pedro Alves
2019-09-11 17:11   ` Tom Tromey
2019-10-17  1:54     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 11/23] tfile_target::close: trace_fd can't be -1 Pedro Alves
2019-09-06 23:28 ` [PATCH 08/23] Introduce switch_to_inferior_no_thread Pedro Alves
2019-09-09 18:42   ` Tom Tromey
2019-10-17  1:07     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 18/23] Add multi-target tests Pedro Alves
2019-10-09 16:01   ` Aktemur, Tankut Baris
2019-10-17  0:55     ` Pedro Alves
2019-09-06 23:33 ` [PATCH 23/23] Multi-target: NEWS and user manual Pedro Alves
2019-09-07  6:33   ` Eli Zaretskii
2019-10-17  2:08     ` Pedro Alves
2019-10-17  7:55       ` Eli Zaretskii
2019-10-17  2:42     ` Pedro Alves
2019-10-17  8:14       ` Eli Zaretskii
2019-10-17 15:31         ` Pedro Alves
2019-09-06 23:34 ` [PATCH 04/23] exceptions.c:print_flush: Remove obsolete check Pedro Alves
2019-09-09 18:07   ` Tom Tromey
2019-09-06 23:35 ` [PATCH 05/23] Make target_ops::has_execution take an 'inferior *' instead of a ptid_t Pedro Alves
2019-09-09 18:12   ` Tom Tromey
2019-09-06 23:36 ` [PATCH 14/23] Tweak handling of remote errors in response to resumption packet Pedro Alves
2019-10-09 13:35   ` Aktemur, Tankut Baris
2019-10-17  0:54     ` [PATCH 14.5/23] Avoid another inferior_ptid reference in gdb/remote.c (Re: [PATCH 14/23] Tweak handling of remote errors in response to resumption packet) Pedro Alves
2019-09-06 23:36 ` [PATCH 12/23] Use all_non_exited_inferiors in infrun.c Pedro Alves
2019-09-06 23:36 ` [PATCH 07/23] Delete unnecessary code from kill_command Pedro Alves
2019-10-01 10:19   ` Aktemur, Tankut Baris
2019-10-01 13:28     ` Aktemur, Tankut Baris
2019-09-06 23:37 ` [PATCH 22/23] Require always-non-stop for multi-target resumptions Pedro Alves
2019-09-06 23:37 ` [PATCH 21/23] Add "info connections" command, "info inferiors" connection number/string Pedro Alves
2019-09-09 20:18   ` Tom Tromey
2019-10-17  2:21     ` Pedro Alves
2019-10-17 14:23       ` Tom Tromey
2019-09-07 11:19 ` [PATCH 00/23] Multi-target support Philippe Waroquiers
2019-09-08 20:06   ` Pedro Alves
2019-09-08 20:50     ` Philippe Waroquiers
2019-10-16 19:08       ` Pedro Alves
2019-10-16 19:14       ` [PATCH] Avoid inferior_ptid reference in gdb/remote.c (Re: [PATCH 00/23] Multi-target support) Pedro Alves
2019-09-09 19:09 ` [PATCH 00/23] Multi-target support Tom Tromey
2019-09-09 20:22 ` Tom Tromey

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=93dfb190-2d7d-8337-b2b0-df160d1a0bf6@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=simark@simark.ca \
    --cc=tom@tromey.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