public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Aditya Vidyadhar Kamath <ADITYA.VIDYADHAR.KAMATH@ibm.com>,
	Joel Brobecker via Gdb-patches <gdb-patches@sourceware.org>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: Re: [PATCH] Use current_inferior ()->pid for AIX
Date: Thu, 21 Apr 2022 10:51:54 -0400	[thread overview]
Message-ID: <4516dbf7-2655-39c5-0614-8235df05248e@polymtl.ca> (raw)
In-Reply-To: <BN8PR15MB2867490F2E1E86011C613655B5ED9@BN8PR15MB2867.namprd15.prod.outlook.com>

> diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
> index 5cf1214c65e..d4d181b155e 100644
> --- a/gdb/rs6000-aix-nat.c
> +++ b/gdb/rs6000-aix-nat.c
> @@ -529,7 +529,7 @@ rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
>  	}
>
>        /* Ignore terminated detached child processes.  */
> -      if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ())
> +      if (!WIFSTOPPED (status) && pid != pid_t(current_inferior ()->pid))

As stated in my previous message, you should not assume which is the
current inferior, when entering the wait method.  The current code was
written a while ago, probably before GDB gained support for
multi-inferior.  So if we are to change this code, we should bring it up
to current standards, as much as possible.

Imagine that your target is currently debugging two inferiors executing
simultaneously (I don't know if the AIX target supports that, but let's
pretend that it does).  The event you get from waitpid could be for
either inferior.  So you can't simply ignore an event if it is for the
non-current inferior.

When you have a multi-threaded (pthread) inferior on AIX and call
waitpid on it, what does it return when some thread get a signal?  Does
it return the pid of the process, or a specific tid?  My reading of the
code in aix-thread.c and of the snippet above makes me think that the
kernel returns the process' pid.  And then get_signaled_thread in
aix-thread.c takes care of finding the specific thread that got a
signal, somehow.

So my intuition is that here it would make sense to call
find_inferior_pid with the value returned by waitpid, to see if this is
for an inferior we know or for a "terminated detached child process", as
the comment above says.  If we have no inferior with that pid, we can
probably ignore the event.  If we have an inferior with that pid, then
we return its pid and status.

Note that inferior_ptid variable at this point will still be null_ptid
(and that's ok).  Back in aix_thread_target::wait (if using the
aix-thread target), the simplest thing to do is probably to call
find_inferior_pid with the pid returned by `beneath ()->wait` and make
it the current inferior with switch_to_inferior_no_thread.  Then, the
rest of the code (pd_update and pd_activate) can correctly assume that
they have the right current inferior, so can use
`current_inferior()->pid`.

I don't know if that actually makes sense.  I would actually try it on
an AIX machine on the GCC compile farm, but I can't get GDB to build on
it, and I don't really have time to look into it:

  CXX      thread-pool.o
In file included from ../../src/binutils-gdb/gdbsupport/thread-pool.cc:21:0:
../../src/binutils-gdb/gdbsupport/../gdbsupport/thread-pool.h: In member function 'std::future<void> gdb::thread_pool::post_task(std::function<void()>&&)':
../../src/binutils-gdb/gdbsupport/../gdbsupport/thread-pool.h:68:3: error: return type 'class std::future<void>' is incomplete

Simon

  parent reply	other threads:[~2022-04-21 14:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  6:58 Aditya Vidyadhar Kamath
2022-03-29 13:01 ` Simon Marchi
2022-03-30 13:04   ` Aditya Vidyadhar Kamath
2022-04-05 12:15     ` Aditya Vidyadhar Kamath
2022-04-05 12:47     ` Simon Marchi
2022-04-12 13:32       ` Aditya Vidyadhar Kamath
2022-04-18  6:33         ` Aditya Vidyadhar Kamath
2022-04-21 11:41         ` Aditya Vidyadhar Kamath
2022-04-21 14:51         ` Simon Marchi [this message]
     [not found]           ` <BN8PR15MB2867D6D625DD0B353C99D3A3B5DD9@BN8PR15MB2867.namprd15.prod.outlook.com>
2022-05-30 12:45             ` Simon Marchi
2022-06-10 14:47               ` Aditya Vidyadhar Kamath
2022-06-15  4:03                 ` Aditya Vidyadhar Kamath
2022-06-23 20:40                   ` Aditya Vidyadhar Kamath
2022-06-27 12:55                 ` Fw: " Aditya Vidyadhar Kamath
2022-06-27 15:11                   ` Simon Marchi
2022-07-04 19:28                   ` Simon Marchi
2022-07-06  4:25                     ` Fw: RE: [PATCH] Fix assert pid != 0 assertion failure in AIX Aditya Vidyadhar Kamath
2022-07-06 17:50                       ` Simon Marchi
2022-07-07  8:27                         ` Aditya Vidyadhar Kamath
2022-07-07 13:56                           ` Simon Marchi
     [not found] <BN6PR15MB13130BF943A019871F8F4E0EB5119@BN6PR15MB1313.namprd15.prod.outlook.com>
2022-05-02 14:50 ` [PATCH] Use current_inferior ()->pid for AIX Ulrich Weigand

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=4516dbf7-2655-39c5-0614-8235df05248e@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=ADITYA.VIDYADHAR.KAMATH@ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sangamesh.swamy@in.ibm.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).