From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 232B53857C55 for ; Fri, 31 Mar 2023 03:45:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 232B53857C55 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x22f.google.com with SMTP id r16so15733703oij.5 for ; Thu, 30 Mar 2023 20:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680234300; x=1682826300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P6o8q8XzCAYSqf85kVdH5Rz1kNJ3aViJj45pHmrC0hA=; b=P1C/VMtcPoqVf2QXu3mZp4IBWPx4c/FIRZyWt9Uz84gDCF10Wz4A3A7byENZdrWYXM nM6y5eHTuOrcgCtpEyuzqVTolVyb8Xi5QEsuQqp3nheYcmyUEOPwLPm+A3GBu5Lzj4Az BSpIqAKdXdmhW8eC+B1Ds1hCJg35TsoFMM9rsxWl8ffqkTnPVTXlGKO4RPKuwa+8qMR0 CFsyoM222anB0RvMDY/l/WPDc0XECHIvfF7KH5c6G0gJu653pI17l/tUpuXHPMBFgHq6 esQycp/2VnblYSqd5rn+2rpohiupP0p4jWOPfW0Jibf4Zq7ubAAlab6XS36THr55efFX 5OGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680234300; x=1682826300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P6o8q8XzCAYSqf85kVdH5Rz1kNJ3aViJj45pHmrC0hA=; b=i9xaPTCRJV9NXnL6lXT1yo9c286FGm4WqHpAFcA9mTmZ9/Jta95PlAglkUFz1l02G5 mkVO3bpOjjICfBp2RA51dX1Zx0rrYkn9Vg6O6kuOcnV8UTT3SunwDQVBp9N1ttRCJ8TZ s9itAGE9GWputGRqAZMe37fRQ5YmiMGq+kHQPL1k8ZRfBMTqJi20XF2FDlzxdHgI6TLK hOEps9JpRwM6OOp63tenDy/njS+rPjj14t2MHINZI+xyn04gdG9vttjvrdfHVcF7yFeN rtWdRC6l2dRfkXuQxCRH+4IEkthsvEnSMioNr4PD8iWZQFsXkfheF4c5YgqpMAkMHYV5 KYuA== X-Gm-Message-State: AO0yUKVLab5/x3+E/ryaFXNjGJsTmqcHZrnqwl8eUDwH8rPDEMajSvxH Vc+MMykkh/Mr3ukT8cgKwGZccVffBvJJDMO9syM= X-Google-Smtp-Source: AK7set8yx3pAY9F8gnuPAEcJRARW6mZMdJNu6V3t+hp9ferSGYbiNYKnHk/dTVrVdo21lsGLFwNr5A== X-Received: by 2002:a54:410b:0:b0:360:fd4c:11ab with SMTP id l11-20020a54410b000000b00360fd4c11abmr11205729oic.1.1680234300234; Thu, 30 Mar 2023 20:45:00 -0700 (PDT) Received: from localhost ([177.124.15.55]) by smtp.gmail.com with ESMTPSA id y2-20020a4ad642000000b0051134f333d3sm415555oos.16.2023.03.30.20.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 20:44:59 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Thiago Jung Bauermann , Pedro Alves Subject: [PATCH 2/5] gdbserver: Use the PID of the current process instead of the current thread Date: Fri, 31 Mar 2023 03:44:29 +0000 Message-Id: <20230331034432.3037148-3-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230331034432.3037148-1-thiago.bauermann@linaro.org> References: <20230331034432.3037148-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Commit 43e5fbd8b788 ("gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap") used current_thread->id.pid () to get the current process' PID. Pedro then mentioned that using current_process ()->pid is more to the point. He added that "sometimes there's a current process, but not a current thread, so when we don't actually need a thread, current_process() is better". So this patch goes through the places that use current_thread to get the current process' PID and changes them to use current_process () instead. Suggested-by: Pedro Alves --- gdbserver/linux-aarch64-low.cc | 10 +++++----- gdbserver/linux-arm-low.cc | 6 +++--- gdbserver/linux-ppc-low.cc | 6 +++--- gdbserver/mem-break.cc | 2 +- gdbserver/regcache.cc | 2 +- gdbserver/server.cc | 2 +- gdbserver/tracepoint.cc | 2 +- gdbserver/win32-i386-low.cc | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 2ed6e95562c5..0c524c036d89 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -436,7 +436,7 @@ aarch64_target::low_insert_point (raw_bkpt_type type, CORE_ADDR addr, int ret; enum target_hw_bp_type targ_type; struct aarch64_debug_reg_state *state - = aarch64_get_debug_reg_state (pid_of (current_thread)); + = aarch64_get_debug_reg_state (current_process ()->pid); if (show_debug_regs) fprintf (stderr, "insert_point on entry (addr=0x%08lx, len=%d)\n", @@ -487,7 +487,7 @@ aarch64_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr, int ret; enum target_hw_bp_type targ_type; struct aarch64_debug_reg_state *state - = aarch64_get_debug_reg_state (pid_of (current_thread)); + = aarch64_get_debug_reg_state (current_process ()->pid); if (show_debug_regs) fprintf (stderr, "remove_point on entry (addr=0x%08lx, len=%d)\n", @@ -575,7 +575,7 @@ aarch64_target::low_stopped_data_address () = aarch64_remove_non_address_bits ((CORE_ADDR) siginfo.si_addr); /* Check if the address matches any watched address. */ - state = aarch64_get_debug_reg_state (pid_of (current_thread)); + state = aarch64_get_debug_reg_state (current_process ()->pid); for (i = aarch64_num_wp_regs - 1; i >= 0; --i) { const unsigned int offset @@ -846,7 +846,7 @@ aarch64_target::low_arch_setup () if (is_elf64) { struct aarch64_features features; - int pid = current_thread->id.pid (); + int pid = current_process ()->pid; features.vq = aarch64_sve_get_vq (tid); /* A-profile PAC is 64-bit only. */ @@ -3323,7 +3323,7 @@ aarch64_target::supports_memory_tagging () #endif } - return (linux_get_hwcap2 (current_thread->id.pid (), 8) & HWCAP2_MTE) != 0; + return (linux_get_hwcap2 (current_process ()->pid, 8) & HWCAP2_MTE) != 0; } bool diff --git a/gdbserver/linux-arm-low.cc b/gdbserver/linux-arm-low.cc index 5975b44af0ae..76d15baa8512 100644 --- a/gdbserver/linux-arm-low.cc +++ b/gdbserver/linux-arm-low.cc @@ -636,7 +636,7 @@ arm_target::low_insert_point (raw_bkpt_type type, CORE_ADDR addr, pts[i] = p; /* Only update the threads of the current process. */ - for_each_thread (current_thread->id.pid (), [&] (thread_info *thread) + for_each_thread (current_process ()->pid, [&] (thread_info *thread) { update_registers_callback (thread, watch, i); }); @@ -681,7 +681,7 @@ arm_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr, pts[i].control = arm_hwbp_control_disable (pts[i].control); /* Only update the threads of the current process. */ - for_each_thread (current_thread->id.pid (), [&] (thread_info *thread) + for_each_thread (current_process ()->pid, [&] (thread_info *thread) { update_registers_callback (thread, watch, i); }); @@ -958,7 +958,7 @@ get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self) static const struct target_desc * arm_read_description (void) { - unsigned long arm_hwcap = linux_get_hwcap (current_thread->id.pid (), 4); + unsigned long arm_hwcap = linux_get_hwcap (current_process ()->pid, 4); if (arm_hwcap & HWCAP_IWMMXT) return arm_linux_read_description (ARM_FP_TYPE_IWMMXT); diff --git a/gdbserver/linux-ppc-low.cc b/gdbserver/linux-ppc-low.cc index f8dd770b8eb3..fe44ba47992b 100644 --- a/gdbserver/linux-ppc-low.cc +++ b/gdbserver/linux-ppc-low.cc @@ -894,8 +894,8 @@ ppc_target::low_arch_setup () /* The value of current_process ()->tdesc needs to be set for this call. */ - ppc_hwcap = linux_get_hwcap (current_thread->id.pid (), features.wordsize); - ppc_hwcap2 = linux_get_hwcap2 (current_thread->id.pid (), features.wordsize); + ppc_hwcap = linux_get_hwcap (current_process ()->pid, features.wordsize); + ppc_hwcap2 = linux_get_hwcap2 (current_process ()->pid, features.wordsize); features.isa205 = ppc_linux_has_isa205 (ppc_hwcap); @@ -1097,7 +1097,7 @@ is_elfv2_inferior (void) const struct target_desc *tdesc = current_process ()->tdesc; int wordsize = register_size (tdesc, 0); - if (!linux_get_auxv (current_thread->id.pid (), wordsize, AT_PHDR, &phdr)) + if (!linux_get_auxv (current_process ()->pid, wordsize, AT_PHDR, &phdr)) return def_res; /* Assume ELF header is at the beginning of the page where program headers diff --git a/gdbserver/mem-break.cc b/gdbserver/mem-break.cc index c669842228d0..4cd7a3de093f 100644 --- a/gdbserver/mem-break.cc +++ b/gdbserver/mem-break.cc @@ -1392,7 +1392,7 @@ set_single_step_breakpoint (CORE_ADDR stop_at, ptid_t ptid) { struct single_step_breakpoint *bp; - gdb_assert (current_ptid.pid () == ptid.pid ()); + gdb_assert (current_process ()->pid == ptid.pid ()); bp = (struct single_step_breakpoint *) set_breakpoint_type_at (single_step_breakpoint, stop_at, NULL); diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 0b1141662ac6..15dda96965f1 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -106,7 +106,7 @@ void regcache_invalidate (void) { /* Only update the threads of the current process. */ - int pid = current_thread->id.pid (); + int pid = current_process ()->pid; regcache_invalidate_pid (pid); } diff --git a/gdbserver/server.cc b/gdbserver/server.cc index b6786baafadd..b6c23f280f86 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1469,7 +1469,7 @@ handle_qxfer_exec_file (const char *annex, if (current_thread == NULL) return -1; - pid = pid_of (current_thread); + pid = current_process ()->pid; } else { diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc index 3f60989e4c7f..590210260bf5 100644 --- a/gdbserver/tracepoint.cc +++ b/gdbserver/tracepoint.cc @@ -6813,7 +6813,7 @@ static int run_inferior_command (char *cmd, int len) { int err = -1; - int pid = current_ptid.pid (); + int pid = current_process ()->pid; trace_debug ("run_inferior_command: running: %s", cmd); diff --git a/gdbserver/win32-i386-low.cc b/gdbserver/win32-i386-low.cc index f78e01206785..af96b464681b 100644 --- a/gdbserver/win32-i386-low.cc +++ b/gdbserver/win32-i386-low.cc @@ -57,7 +57,7 @@ x86_dr_low_set_addr (int regnum, CORE_ADDR addr) gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR); /* Only update the threads of this process. */ - for_each_thread (current_thread->id.pid (), update_debug_registers); + for_each_thread (current_process ()->pid, update_debug_registers); } /* Update the inferior's DR7 debug control register from STATE. */ @@ -66,7 +66,7 @@ static void x86_dr_low_set_control (unsigned long control) { /* Only update the threads of this process. */ - for_each_thread (current_thread->id.pid (), update_debug_registers); + for_each_thread (current_process ()->pid, update_debug_registers); } /* Return the current value of a DR register of the current thread's