[6/8] gdbserver: use current_process in ps_getpid

Message ID 20221117194241.1776125-7-simon.marchi@efficios.com
State Committed
Commit c0cb02a4cf590f3cb64cdcc1b5bf539196333160
Headers
Series Fix some commit_resumed_state assertion failures (PR 28275) |

Commit Message

Simon Marchi Nov. 17, 2022, 7:42 p.m. UTC
  The following patch ("gdbserver: switch to right process in
find_one_thread") makes it so find_one_thread calls into libthread_db
with a current process but no current thread.  This tripped on ps_getpid
using current_thread in order to get the process' pid.  Get the pid from
`current_process ()` instead, which removes the need to have a current
thread.  Eventually, it would be good to get it from the
gdb_ps_prochandle_t structure, to avoid the need for a current process
as well.

Change-Id: I9d2fae266419199a2fbc2fde0a5104c6e0dbd2d5
---
 gdbserver/proc-service.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Andrew Burgess Nov. 18, 2022, 11:33 a.m. UTC | #1
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> The following patch ("gdbserver: switch to right process in
> find_one_thread") makes it so find_one_thread calls into libthread_db
> with a current process but no current thread.  This tripped on ps_getpid
> using current_thread in order to get the process' pid.  Get the pid from
> `current_process ()` instead, which removes the need to have a current
> thread.  Eventually, it would be good to get it from the
> gdb_ps_prochandle_t structure, to avoid the need for a current process
> as well.

LGTM.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Change-Id: I9d2fae266419199a2fbc2fde0a5104c6e0dbd2d5
> ---
>  gdbserver/proc-service.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gdbserver/proc-service.cc b/gdbserver/proc-service.cc
> index a49e2b25a47..f86c0e99923 100644
> --- a/gdbserver/proc-service.cc
> +++ b/gdbserver/proc-service.cc
> @@ -158,5 +158,5 @@ ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregs
>  pid_t
>  ps_getpid (gdb_ps_prochandle_t ph)
>  {
> -  return pid_of (current_thread);
> +  return current_process ()->pid;
>  }
> -- 
> 2.37.3
  
Simon Marchi Nov. 18, 2022, 4:21 p.m. UTC | #2
On 11/18/22 06:33, Andrew Burgess via Gdb-patches wrote:
> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
>> The following patch ("gdbserver: switch to right process in
>> find_one_thread") makes it so find_one_thread calls into libthread_db
>> with a current process but no current thread.  This tripped on ps_getpid
>> using current_thread in order to get the process' pid.  Get the pid from
>> `current_process ()` instead, which removes the need to have a current
>> thread.  Eventually, it would be good to get it from the
>> gdb_ps_prochandle_t structure, to avoid the need for a current process
>> as well.
> 
> LGTM.
> 
> Reviewed-By: Andrew Burgess <aburgess@redhat.com>
> 
> Thanks,
> Andrew

Thanks, pushed.

Simon
  

Patch

diff --git a/gdbserver/proc-service.cc b/gdbserver/proc-service.cc
index a49e2b25a47..f86c0e99923 100644
--- a/gdbserver/proc-service.cc
+++ b/gdbserver/proc-service.cc
@@ -158,5 +158,5 @@  ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregs
 pid_t
 ps_getpid (gdb_ps_prochandle_t ph)
 {
-  return pid_of (current_thread);
+  return current_process ()->pid;
 }