From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 58E623858C3A; Tue, 19 Oct 2021 18:15:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58E623858C3A From: "simon.marchi at polymtl dot ca" To: gdb-prs@sourceware.org Subject: [Bug gdb/28471] Internal error on Assertion `pid != 0' on AIX Date: Tue, 19 Oct 2021 18:15:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: 11.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: simon.marchi at polymtl dot ca X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Oct 2021 18:15:59 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D28471 Simon Marchi changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |simon.marchi at polymtl do= t ca --- Comment #1 from Simon Marchi --- Hi, Not too familiar with AIX, but I'll try to help. The AIX target suffers fr= om bit-rot, as you found out, so needs a bit of updating. The inferior_ptid is used as "the current thread" value. A lot of function= s in GDB work on a ptid or thread, but don't take a ptid or thread as argument.= =20 Instead, they read inferior_ptid. But as explained in the comment you quoted, target_wait doesn't work that w= ay.=20 It is used to pull an event out of the target, it doesn't operate on a spec= ific thread. Clearing inferior_ptid prior to calling target_wait (instead of leaving it set to some random value) ensures the target doesn't rely on it, like some targets historically did. So already, the first line of aix_thread_target::wait is suspicious: scoped_restore save_inferior_ptid =3D make_scoped_restore (&inferior_ptid= ); This saves the value of inferior_ptid and restores it at the end of the sco= pe.=20 But we know there is nothing to restore, the entry value of inferior_ptid is meaningless. What I understand from the current code (it would need to be confirmed by somebody who knows AIX) is that we are dealing with something like userspace threads. The process layer (rs6000-nat) just knows about a single process / thread, with ptid (pid=3D1234, lwp=3D0, tid=3D0). The aix-thread target si= ts on top and exposes the threads that are managed by some userspace threading librar= y.=20 Threads managed by aix-thread would therefore have ptids (pid=3D1234, lwp= =3D0, tid=3D1), (pid=3D1234, lwp=3D0, tid=3D2), and so forth. The ptid argument passed to target_wait acts as a filter, it asks the target "get me events only for that ptid". So let's say the core of GDB passes ptid=3D(pid=3D1234, lwp=3D0, tid=3D2), the aix-thread modifies that ptid to= clear the tid field (function pid_to_prc) before passing the filter to the target bel= ow, because the tid field doesn't make sense to the target below and would conf= use it. I think that is correct, but the subsequent line: inferior_ptid =3D ptid_t (inferior_ptid.pid ()); doesn't make sense anymore, and should be removed. Then, here: if (ptid.pid () =3D=3D -1) return ptid_t (-1); Means: if the target didn't produce an interesting event, return early. Th= is looks correct, but could be made nicer as: if (ptid =3D=3D minus_one_ptid) return minus_one_ptid; Now, if the target below did return an interesting even, we go in pd_activa= te or pd_update. These functions rely on inferior_ptid, but they shouldn't th= at needs to be fixed. Let's assume that the target below returned an event for ptid (pid=3D1234, lwp=3D0, tid=3D0), I suppose that pd_activate and pd_upda= te will do some bookeeping and will fill in that tid field, so that aix_thread_target::wait returns a ptid for a specific tid. These functions used to rely on inferior_ptid, I suppose they can just be changed to accept= the ptid (the one returned by the target below) as argument. And do the thing = that makes sense, like: /* If this target is not active, return the ptid as returned by the tar= get below. */ if (!pd_active) return ptid_passed_as_argument; // used to say inferior_ptid One question I would have for an AIX expert is: is this threading model / library still used today, or is it just some ancient stuff? Userspace thre= ads are rare these days, so it's possible that this aix-thread target isn't actually useful, and just gets in the way, and that threads are managed and exposed by the kernel, and therefore managed by the rs6000-nat target If s= o, maybe aix-thread.c could be removed. And one last thing: since rs6000-nat.c is AIX-specific, it should be named = as such, rs6000-aix-nat.c. If you plan on touching that area, could you please make this change? --=20 You are receiving this mail because: You are on the CC list for the bug.=