From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by sourceware.org (Postfix) with ESMTPS id BE830394354E for ; Tue, 17 Mar 2020 16:46:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584463605; bh=eWUWLkgZiYLyKE6tVnODZt1d5/mSwauUMTfbx3M6eC4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jXwfQ0g//YJLWyGkWqHRa0LfKTb6d67DmPsXKy8Lpc0h5ItuGrfqPF/FrPI0+/BZq 7zL4Qdp3WkHGR4jgwdFwCnXg3oWhJ7JSvQZ8h0unVCRImx3ZkIvXk466Tm7of9Ki86 i3RqJrjReuhXz3Kj9rHFPBbVBFKZZybfcS3reErY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([89.79.191.25]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MfYPY-1jl54f07hI-00fx1c; Tue, 17 Mar 2020 17:46:45 +0100 From: Kamil Rytarowski To: gdb-patches@sourceware.org Cc: simark@simark.ca, cbiesinger@google.com, Kamil Rytarowski Subject: [PATCH v4] Add support for NetBSD threads in sparc-nat.c Date: Tue, 17 Mar 2020 17:46:03 +0100 Message-Id: <20200317164603.10840-1-n54@gmx.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:sVwRer8gpkOZIiLyGOil5WsufhoeDppNJLHaw8R5OIocBaH7FU6 GXkyQXvZ8wCraMSb6Qnr7cXTlCo7iIm9RrNH7NwlEsOzrKzmKrlimt5Ssm3G+k1js2AIQnE AjC6hsd2jNvU1wTIqwmRRfBpzq6krf1KW7tCBJgrHysQK/A01Q5pbHyLEbocvxpzX6heEa+ B2jSeleJ+EsbwZjnRU5/A== X-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EONGNq8KLJtAYLiyGVlfI TL9UOHCQM4l6oSuUg6La+viO+TjB0Kdo2Ud1PaIpRdquNYNwwSGf3P2xCVuYzFHCPuo35Asl+ XRPcfoN7nS7msYmgr9s4iPFvPlBaj26RyAcrI7gaOIaJdFaY/wMA75ImCyAJ4f7r+0qGo971s yYymsawb14/Xoo4pfmjwlrxMF/nnQ/+vV6qaUxWQQ63iELo050D8uhoyFGxotBBPM2AOw= X-Spam-Status: No, score=-25.4 required=5.0 tests=DKIM_SIGNED, DKIM_VALID, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 17 Mar 2020 16:46:51 -0000 NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads. This file is still shared with other targets that use different 4th argume= nt type, that is always unused. =2D-- gdb/sparc-nat.c | 50 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c index dff0f521565..10cc01375ed 100644 =2D-- a/gdb/sparc-nat.c +++ b/gdb/sparc-nat.c @@ -78,6 +78,19 @@ typedef struct fp_status fpregset_t; #define PTRACE_SETFPREGS PT_SETFPREGS #endif +static int +gdb_ptrace (int request, ptid_t pid, void *addr) +{ +#ifdef __NetBSD__ + /* Support for NetBSD threads: unlike other ptrace implementations in t= his + file, NetBSD requires that we pass both the pid and lwp. */ + return ptrace (request, ptid (). pid (), addr, ptid ().lwp ()); +#else + pid_t pid =3D get_ptrace_pid (ptid); + return ptrace (request, pid, addr, 0); +#endif +} + /* Register set description. */ const struct sparc_gregmap *sparc_gregmap; const struct sparc_fpregmap *sparc_fpregmap; @@ -137,22 +150,7 @@ void sparc_fetch_inferior_registers (struct regcache *regcache, int regnum) { struct gdbarch *gdbarch =3D regcache->arch (); - pid_t pid; - - /* NOTE: cagney/2002-12-03: This code assumes that the currently - selected light weight processes' registers can be written - directly into the selected thread's register cache. This works - fine when given an 1:1 LWP:thread model (such as found on - GNU/Linux) but will, likely, have problems when used on an N:1 - (userland threads) or N:M (userland multiple LWP) model. In the - case of the latter two, the LWP's registers do not necessarily - belong to the selected thread (the LWP could be in the middle of - executing the thread switch code). - - These functions should instead be parameterized with an explicit - object (struct regcache, struct thread_info?) into which the LWPs - registers can be written. */ - pid =3D get_ptrace_pid (regcache->ptid ()); + ptid_t ptid =3D regcache->ptid (); if (regnum =3D=3D SPARC_G0_REGNUM) { @@ -166,7 +164,7 @@ sparc_fetch_inferior_registers (struct regcache *regca= che, int regnum) { gregset_t regs; - if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) =3D= =3D -1) + if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) ®s) =3D= =3D -1) perror_with_name (_("Couldn't get registers")); sparc_supply_gregset (sparc_gregmap, regcache, -1, ®s); @@ -178,7 +176,7 @@ sparc_fetch_inferior_registers (struct regcache *regca= che, int regnum) { fpregset_t fpregs; - if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) = =3D=3D -1) + if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs)= =3D=3D -1) perror_with_name (_("Couldn't get floating point status")); sparc_supply_fpregset (sparc_fpregmap, regcache, -1, &fpregs); @@ -189,22 +187,18 @@ void sparc_store_inferior_registers (struct regcache *regcache, int regnum) { struct gdbarch *gdbarch =3D regcache->arch (); - pid_t pid; - - /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers - about threaded assumptions. */ - pid =3D get_ptrace_pid (regcache->ptid ()); + ptid_t ptid =3D regcache->ptid (); if (regnum =3D=3D -1 || sparc_gregset_supplies_p (gdbarch, regnum)) { gregset_t regs; - if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) =3D= =3D -1) + if (gdb_ptrace (PTRACE_GETREGS, ptid, (PTRACE_TYPE_ARG3) ®s) =3D= =3D -1) perror_with_name (_("Couldn't get registers")); sparc_collect_gregset (sparc_gregmap, regcache, regnum, ®s); - if (ptrace (PTRACE_SETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) =3D= =3D -1) + if (gdb_ptrace (PTRACE_SETREGS, ptid, (PTRACE_TYPE_ARG3) ®s) =3D= =3D -1) perror_with_name (_("Couldn't write registers")); /* Deal with the stack regs. */ @@ -225,7 +219,7 @@ sparc_store_inferior_registers (struct regcache *regca= che, int regnum) { fpregset_t fpregs, saved_fpregs; - if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) = =3D=3D -1) + if (gdb_ptrace (PTRACE_GETFPREGS, ptid, (PTRACE_TYPE_ARG3) &fpregs)= =3D=3D -1) perror_with_name (_("Couldn't get floating-point registers")); memcpy (&saved_fpregs, &fpregs, sizeof (fpregs)); @@ -237,8 +231,8 @@ sparc_store_inferior_registers (struct regcache *regca= che, int regnum) to write the registers if nothing changed. */ if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) !=3D 0) { - if (ptrace (PTRACE_SETFPREGS, pid, - (PTRACE_TYPE_ARG3) &fpregs, 0) =3D=3D -1) + if (gdb_ptrace (PTRACE_SETFPREGS, ptid, + (PTRACE_TYPE_ARG3) &fpregs) =3D=3D -1) perror_with_name (_("Couldn't write floating-point registers")); } =2D- 2.25.0