From patchwork Thu Jul 30 12:52:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 7932 Received: (qmail 121292 invoked by alias); 30 Jul 2015 12:52:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 121283 invoked by uid 89); 30 Jul 2015 12:52:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f178.google.com Received: from mail-pd0-f178.google.com (HELO mail-pd0-f178.google.com) (209.85.192.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 30 Jul 2015 12:52:37 +0000 Received: by pdbnt7 with SMTP id nt7so24285396pdb.0 for ; Thu, 30 Jul 2015 05:52:35 -0700 (PDT) X-Received: by 10.70.132.135 with SMTP id ou7mr106276709pdb.112.1438260755429; Thu, 30 Jul 2015 05:52:35 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id wp5sm2137921pab.22.2015.07.30.05.52.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jul 2015 05:52:34 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] Remove get_thread_id Date: Thu, 30 Jul 2015 13:52:24 +0100 Message-Id: <1438260744-14116-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch removes get_thread_id from aarch64-linux-nat.c, arm-linux-nat.c and xtensa-linux-nat.c. get_thread_id was added in this commit below in 2000, 41c49b06c471443d3baf2eaa2463a315f9b5edca https://sourceware.org/ml/gdb-patches/2000-04/msg00398.html which predates the ptid_t stuff added into GDB. Nowadays, lwpid of inferior_ptid is only zero when the inferior is created (in fork-child.c:fork_inferior) and its lwpid will be set after linux_nat_wait_1 gets the first event. After that, lwpid of inferior_ptid is not zero for linux-nat target, then we can use ptid_get_lwp, so this function isn't needed anymore. Even when GDB attaches to a process, the lwp of inferior_ptid isn't zero, see linux-nat.c:linux_nat_attach, /* The ptrace base target adds the main thread with (pid,0,0) format. Decorate it with lwp info. */ ptid = ptid_build (ptid_get_pid (inferior_ptid), ptid_get_pid (inferior_ptid), 0); Note that linux_nat_xfer_partial shifts lwpid to pid for inferior_ptid temperately for calling linux_ops->to_xfer_partial, but all the affected functions in this patch are called in linux_ops->to_xfer_partial. I think we can safely remove get_thread_id for all linux native targets. Regression tested on arm-linux and aarch64-linux. Unable to build native GDB and test it on xtensa-linux. gdb: 2015-07-29 Yao Qi * aarch64-linux-nat.c (get_thread_id): Remove. (debug_reg_change_callback): Call ptid_get_lwp instead of get_thread_id. (fetch_gregs_from_thread): Likewise. (store_gregs_to_thread): Likewise. (fetch_fpregs_from_thread): Likewise. (store_fpregs_to_thread): Likewise. (aarch64_linux_get_debug_reg_capacity): Likewise. * arm-linux-nat.c (get_thread_id): Remove. (GET_THREAD_ID): Update macro to use ptid_get_lwp. * xtensa-linux-nat.c (get_thread_id): Remove. (GET_THREAD_ID): Update macro to use ptid_get_lwp. * arm-linux-nat.c (get_thread_id): Remove. (GET_THREAD_ID): Remove. (fetch_fpregs): Call ptid_get_lwp instead of GET_THREAD_ID. (store_fpregs, fetch_regs, store_regs): Likewise. (fetch_wmmx_regs, store_wmmx_regs): Likewise. (fetch_vfp_regs, store_vfp_regs): Likewise. (arm_linux_read_description): Likewise. (arm_linux_get_hwbp_cap): Likewise. * xtensa-linux-nat.c (get_thread_id): Remove. (GET_THREAD_ID): Remove. (fetch_gregs, store_gregs): Call ptid_get_lwp instead of GET_THREAD_ID. --- gdb/aarch64-linux-nat.c | 26 +++++--------------------- gdb/arm-linux-nat.c | 37 ++++++++++--------------------------- gdb/xtensa-linux-nat.c | 18 ++++-------------- 3 files changed, 19 insertions(+), 62 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index e6d65c0..624b748 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -48,22 +48,6 @@ #define TRAP_HWBKPT 0x0004 #endif -/* On GNU/Linux, threads are implemented as pseudo-processes, in which - case we may be tracing more than one process at a time. In that - case, inferior_ptid will contain the main process ID and the - individual thread (process) ID. get_thread_id () is used to get - the thread id if it's available, and the process id otherwise. */ - -static int -get_thread_id (ptid_t ptid) -{ - int tid = ptid_get_lwp (ptid); - - if (0 == tid) - tid = ptid_get_pid (ptid); - return tid; -} - /* Per-process data. We don't bind this to a per-inferior registry because of targets like x86 GNU/Linux that need to keep track of processes that aren't bound to any inferior (e.g., fork children, @@ -181,7 +165,7 @@ debug_reg_change_callback (struct lwp_info *lwp, void *ptr) { struct aarch64_dr_update_callback_param *param_p = (struct aarch64_dr_update_callback_param *) ptr; - int pid = get_thread_id (lwp->ptid); + int pid = ptid_get_lwp (lwp->ptid); int idx = param_p->idx; int is_watchpoint = param_p->is_watchpoint; struct arch_lwp_info *info = lwp->arch_private; @@ -266,7 +250,7 @@ fetch_gregs_from_thread (struct regcache *regcache) and arm. */ gdb_static_assert (sizeof (regs) >= 18 * 4); - tid = get_thread_id (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); iovec.iov_base = ®s; if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) @@ -303,7 +287,7 @@ store_gregs_to_thread (const struct regcache *regcache) /* Make sure REGS can hold all registers contents on both aarch64 and arm. */ gdb_static_assert (sizeof (regs) >= 18 * 4); - tid = get_thread_id (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); iovec.iov_base = ®s; if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) @@ -347,7 +331,7 @@ fetch_fpregs_from_thread (struct regcache *regcache) and arm. */ gdb_static_assert (sizeof regs >= VFP_REGS_SIZE); - tid = get_thread_id (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); iovec.iov_base = ®s; @@ -394,7 +378,7 @@ store_fpregs_to_thread (const struct regcache *regcache) /* Make sure REGS can hold all VFP registers contents on both aarch64 and arm. */ gdb_static_assert (sizeof regs >= VFP_REGS_SIZE); - tid = get_thread_id (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); iovec.iov_base = ®s; diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c index ff156d0..e64f870 100644 --- a/gdb/arm-linux-nat.c +++ b/gdb/arm-linux-nat.c @@ -66,23 +66,6 @@ extern int arm_apcs_32; -/* On GNU/Linux, threads are implemented as pseudo-processes, in which - case we may be tracing more than one process at a time. In that - case, inferior_ptid will contain the main process ID and the - individual thread (process) ID. get_thread_id () is used to get - the thread id if it's available, and the process id otherwise. */ - -static int -get_thread_id (ptid_t ptid) -{ - int tid = ptid_get_lwp (ptid); - if (0 == tid) - tid = ptid_get_pid (ptid); - return tid; -} - -#define GET_THREAD_ID(PTID) get_thread_id (PTID) - /* Get the whole floating point state of the process and store it into regcache. */ @@ -93,7 +76,7 @@ fetch_fpregs (struct regcache *regcache) gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE]; /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); /* Read the floating point state. */ if (have_ptrace_getregset == TRIBOOL_TRUE) @@ -133,7 +116,7 @@ store_fpregs (const struct regcache *regcache) gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE]; /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); /* Read the floating point state. */ if (have_ptrace_getregset == TRIBOOL_TRUE) @@ -193,7 +176,7 @@ fetch_regs (struct regcache *regcache) elf_gregset_t regs; /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); if (have_ptrace_getregset == TRIBOOL_TRUE) { @@ -223,7 +206,7 @@ store_regs (const struct regcache *regcache) elf_gregset_t regs; /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); /* Fetch the general registers. */ if (have_ptrace_getregset == TRIBOOL_TRUE) @@ -277,7 +260,7 @@ fetch_wmmx_regs (struct regcache *regcache) int ret, regno, tid; /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf); if (ret < 0) @@ -306,7 +289,7 @@ store_wmmx_regs (const struct regcache *regcache) int ret, regno, tid; /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf); if (ret < 0) @@ -351,7 +334,7 @@ fetch_vfp_regs (struct regcache *regcache) struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); if (have_ptrace_getregset == TRIBOOL_TRUE) { @@ -383,7 +366,7 @@ store_vfp_regs (const struct regcache *regcache) struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); /* Get the thread id for the ptrace call. */ - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); if (have_ptrace_getregset == TRIBOOL_TRUE) { @@ -553,7 +536,7 @@ arm_linux_read_description (struct target_ops *ops) { elf_gregset_t gpregs; struct iovec iov; - int tid = GET_THREAD_ID (inferior_ptid); + int tid = ptid_get_lwp (inferior_ptid); iov.iov_base = &gpregs; iov.iov_len = sizeof (gpregs); @@ -636,7 +619,7 @@ arm_linux_get_hwbp_cap (void) int tid; unsigned int val; - tid = GET_THREAD_ID (inferior_ptid); + tid = ptid_get_lwp (inferior_ptid); if (ptrace (PTRACE_GETHBPREGS, tid, 0, &val) < 0) available = 0; else diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c index 7f530ce..77ad3e0 100644 --- a/gdb/xtensa-linux-nat.c +++ b/gdb/xtensa-linux-nat.c @@ -42,16 +42,6 @@ hardware-specific overlays. */ #include "xtensa-xtregs.c" -static int -get_thread_id (ptid_t ptid) -{ - int tid = ptid_get_lwp (ptid); - if (0 == tid) - tid = ptid_get_pid (ptid); - return tid; -} -#define GET_THREAD_ID(PTID) get_thread_id (PTID) - void fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum) @@ -181,7 +171,7 @@ supply_fpregset (struct regcache *regcache, static void fetch_gregs (struct regcache *regcache, int regnum) { - int tid = GET_THREAD_ID (inferior_ptid); + int tid = ptid_get_lwp (inferior_ptid); const gdb_gregset_t regs; int areg; @@ -200,7 +190,7 @@ fetch_gregs (struct regcache *regcache, int regnum) static void store_gregs (struct regcache *regcache, int regnum) { - int tid = GET_THREAD_ID (inferior_ptid); + int tid = ptid_get_lwp (inferior_ptid); gdb_gregset_t regs; int areg; @@ -228,7 +218,7 @@ static int xtreg_high; static void fetch_xtregs (struct regcache *regcache, int regnum) { - int tid = GET_THREAD_ID (inferior_ptid); + int tid = ptid_get_lwp (inferior_ptid); const xtensa_regtable_t *ptr; char xtregs [XTENSA_ELF_XTREG_SIZE]; @@ -244,7 +234,7 @@ fetch_xtregs (struct regcache *regcache, int regnum) static void store_xtregs (struct regcache *regcache, int regnum) { - int tid = GET_THREAD_ID (inferior_ptid); + int tid = ptid_get_lwp (inferior_ptid); const xtensa_regtable_t *ptr; char xtregs [XTENSA_ELF_XTREG_SIZE];