From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id ED5F3385741C for ; Thu, 21 Apr 2022 14:52:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED5F3385741C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 23LEptCw012908 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 10:52:00 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 23LEptCw012908 Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 802121E01D; Thu, 21 Apr 2022 10:51:55 -0400 (EDT) Message-ID: <4516dbf7-2655-39c5-0614-8235df05248e@polymtl.ca> Date: Thu, 21 Apr 2022 10:51:54 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] Use current_inferior ()->pid for AIX Content-Language: tl To: Aditya Vidyadhar Kamath , Joel Brobecker via Gdb-patches Cc: Sangamesh Mallayya References: <5f142468-bc68-9128-d4d6-80cf36f12a48@polymtl.ca> <87169b93-8be2-5ccd-6b58-51b395a367bd@polymtl.ca> From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 21 Apr 2022 14:51:55 +0000 X-Spam-Status: No, score=-3040.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2022 14:52:04 -0000 > 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 gdb::thread_pool::post_task(std::function&&)': ../../src/binutils-gdb/gdbsupport/../gdbsupport/thread-pool.h:68:3: error: return type 'class std::future' is incomplete Simon