public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Disable get_ptrace_pid for NetBSD
@ 2020-03-18 16:29 Kamil Rytarowski
  2020-03-18 20:48 ` Tom Tromey
  2020-03-18 21:15 ` Simon Marchi
  0 siblings, 2 replies; 10+ messages in thread
From: Kamil Rytarowski @ 2020-03-18 16:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: simark, Kamil Rytarowski

Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
The process id on NetBSD is stored always in the pid field of ptid.

gdb/ChangeLog:

	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
	* inf-ptrace.c: Likewise.
	* (inf_ptrace_target::resume): Update.
	* (inf_ptrace_target::xfer_partial): Likewise.
---
 gdb/ChangeLog    |  7 +++++++
 gdb/inf-ptrace.c | 19 +++++++++++++++++--
 gdb/inf-ptrace.h |  2 ++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 84964dc00ac..36e333ec8ba 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2020-03-18  Kamil Rytarowski  <n54@gmx.com>
+
+	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
+	* inf-ptrace.c: Likewise.
+	* (inf_ptrace_target::resume): Update.
+	* (inf_ptrace_target::xfer_partial): Likewise.
+
 2020-03-17  Kamil Rytarowski  <n54@gmx.com>

 	* regformats/regdef.h: Put reg in gdb namespace.
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index db17a76d946..e8bf66ed45f 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -313,8 +313,12 @@ inf_ptrace_target::kill ()
   target_mourn_inferior (inferior_ptid);
 }

+#ifndef __NetBSD__
 /* Return which PID to pass to ptrace in order to observe/control the
-   tracee identified by PTID.  */
+   tracee identified by PTID.
+
+   Unlike most other Operating Systems, NetBSD tracks both pid and lwp
+   and avoids this function.  */

 pid_t
 get_ptrace_pid (ptid_t ptid)
@@ -328,6 +332,7 @@ get_ptrace_pid (ptid_t ptid)
     pid = ptid.pid ();
   return pid;
 }
+#endif

 /* Resume execution of thread PTID, or all threads if PTID is -1.  If
    STEP is nonzero, single-step it.  If SIGNAL is nonzero, give it
@@ -344,7 +349,13 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
        single-threaded processes, so simply resume the inferior.  */
     pid = inferior_ptid.pid ();
   else
-    pid = get_ptrace_pid (ptid);
+    {
+#ifdef __NetBSD__
+      pid = ptid. pid();
+#else
+      pid = get_ptrace_pid (ptid);
+#endif
+    }

   if (catch_syscall_enabled () > 0)
     request = PT_SYSCALL;
@@ -528,7 +539,11 @@ inf_ptrace_target::xfer_partial (enum target_object object,
 				 const gdb_byte *writebuf,
 				 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
+#ifdef __NetBSD__
+  pid_t pid = inferior_ptid. pid();
+#else
   pid_t pid = get_ptrace_pid (inferior_ptid);
+#endif

   switch (object)
     {
diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h
index dd0733736f2..340d41d8beb 100644
--- a/gdb/inf-ptrace.h
+++ b/gdb/inf-ptrace.h
@@ -78,9 +78,11 @@ struct inf_ptrace_target : public inf_child_target
   void detach_success (inferior *inf);
 };

+#ifndef __NetBSD__
 /* Return which PID to pass to ptrace in order to observe/control the
    tracee identified by PTID.  */

 extern pid_t get_ptrace_pid (ptid_t);
+#endif

 #endif
--
2.25.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 16:29 [PATCH] Disable get_ptrace_pid for NetBSD Kamil Rytarowski
@ 2020-03-18 20:48 ` Tom Tromey
  2020-03-18 20:54   ` Tom Tromey
  2020-03-18 21:15 ` Simon Marchi
  1 sibling, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2020-03-18 20:48 UTC (permalink / raw)
  To: Kamil Rytarowski; +Cc: gdb-patches, simark

>>>>> "Kamil" == Kamil Rytarowski <n54@gmx.com> writes:

Kamil> Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
Kamil> The process id on NetBSD is stored always in the pid field of ptid.

Kamil> gdb/ChangeLog:

Kamil> 	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
Kamil> 	* inf-ptrace.c: Likewise.
Kamil> 	* (inf_ptrace_target::resume): Update.
Kamil> 	* (inf_ptrace_target::xfer_partial): Likewise.

Kamil> +#ifndef __NetBSD__
Kamil>  /* Return which PID to pass to ptrace in order to observe/control the
Kamil> -   tracee identified by PTID.  */
Kamil> +   tracee identified by PTID.
Kamil> +
Kamil> +   Unlike most other Operating Systems, NetBSD tracks both pid and lwp
Kamil> +   and avoids this function.  */

Kamil>  pid_t
Kamil>  get_ptrace_pid (ptid_t ptid)
Kamil> @@ -328,6 +332,7 @@ get_ptrace_pid (ptid_t ptid)
Kamil>      pid = ptid.pid ();
Kamil>    return pid;

Why not make just the body of this function

#ifdef __NetBSD__
  return ptid.pid ()
#else
  ... old code


That would mean fewer #ifs.

Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 20:48 ` Tom Tromey
@ 2020-03-18 20:54   ` Tom Tromey
  2020-03-18 21:22     ` Simon Marchi
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2020-03-18 20:54 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Kamil Rytarowski, simark, gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> Why not make just the body of this function

Tom> #ifdef __NetBSD__
Tom>   return ptid.pid ()
Tom> #else
Tom>   ... old code

Tom> That would mean fewer #ifs.

I see that's what you did originally and Simon requested this version.

Personally I think the new patch is uglier than the original, on the
basis that use of "#if" generally makes the code harder to understand.

Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 16:29 [PATCH] Disable get_ptrace_pid for NetBSD Kamil Rytarowski
  2020-03-18 20:48 ` Tom Tromey
@ 2020-03-18 21:15 ` Simon Marchi
  2020-03-18 21:40   ` Kamil Rytarowski
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2020-03-18 21:15 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches; +Cc: Tom Tromey

On 2020-03-18 12:29 p.m., Kamil Rytarowski wrote:
> Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
> The process id on NetBSD is stored always in the pid field of ptid.
> 
> gdb/ChangeLog:
> 
> 	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
> 	* inf-ptrace.c: Likewise.
> 	* (inf_ptrace_target::resume): Update.
> 	* (inf_ptrace_target::xfer_partial): Likewise.
> ---
>  gdb/ChangeLog    |  7 +++++++
>  gdb/inf-ptrace.c | 19 +++++++++++++++++--
>  gdb/inf-ptrace.h |  2 ++
>  3 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 84964dc00ac..36e333ec8ba 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,10 @@
> +2020-03-18  Kamil Rytarowski  <n54@gmx.com>
> +
> +	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
> +	* inf-ptrace.c: Likewise.
> +	* (inf_ptrace_target::resume): Update.
> +	* (inf_ptrace_target::xfer_partial): Likewise.
> +
>  2020-03-17  Kamil Rytarowski  <n54@gmx.com>
> 
>  	* regformats/regdef.h: Put reg in gdb namespace.
> diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
> index db17a76d946..e8bf66ed45f 100644
> --- a/gdb/inf-ptrace.c
> +++ b/gdb/inf-ptrace.c
> @@ -313,8 +313,12 @@ inf_ptrace_target::kill ()
>    target_mourn_inferior (inferior_ptid);
>  }
> 
> +#ifndef __NetBSD__
>  /* Return which PID to pass to ptrace in order to observe/control the
> -   tracee identified by PTID.  */
> +   tracee identified by PTID.
> +
> +   Unlike most other Operating Systems, NetBSD tracks both pid and lwp
> +   and avoids this function.  */
> 
>  pid_t
>  get_ptrace_pid (ptid_t ptid)
> @@ -328,6 +332,7 @@ get_ptrace_pid (ptid_t ptid)
>      pid = ptid.pid ();
>    return pid;
>  }
> +#endif
> 
>  /* Resume execution of thread PTID, or all threads if PTID is -1.  If
>     STEP is nonzero, single-step it.  If SIGNAL is nonzero, give it
> @@ -344,7 +349,13 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
>         single-threaded processes, so simply resume the inferior.  */
>      pid = inferior_ptid.pid ();
>    else
> -    pid = get_ptrace_pid (ptid);
> +    {
> +#ifdef __NetBSD__
> +      pid = ptid. pid();
> +#else
> +      pid = get_ptrace_pid (ptid);
> +#endif
> +    }

To avoid the ifdefs in this more complex code, can't you use a gdb_ptrace function like in
the other patches?  This time, it would look like:

static int
gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr,
	    PTRACE_TYPE_ARG4 data)
{
#ifdef __NetBSD__
  return ptrace (request, ptid.pid (), addr, data);
#else
  pid_t pid = get_ptrace_pid (ptid);
  return ptrace (request, pid, addr, data);
#endif
}

Simon


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 20:54   ` Tom Tromey
@ 2020-03-18 21:22     ` Simon Marchi
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2020-03-18 21:22 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Kamil Rytarowski, gdb-patches

On 2020-03-18 4:54 p.m., Tom Tromey wrote:
>>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
> 
> Tom> Why not make just the body of this function
> 
> Tom> #ifdef __NetBSD__
> Tom>   return ptid.pid ()
> Tom> #else
> Tom>   ... old code
> 
> Tom> That would mean fewer #ifs.
> 
> I see that's what you did originally and Simon requested this version.
> 
> Personally I think the new patch is uglier than the original, on the
> basis that use of "#if" generally makes the code harder to understand.
> 
> Tom
> 

Indeed, I suggested that.  I am hoping that we can isolate the ifdefs in these
"gdb_ptrace" functions (we should probably find a better name for those...), to
which you pass a "ptid" and do the right thing according to the current OS.  I
agree that adding ifdefs in the more complex code is ugly and less readable.

If my suggestion doesn't work well in practice, then feel free to revert to your
original solution, I certainly don't want to impose it if it turns out not to be
a good idea.

Simon

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 21:15 ` Simon Marchi
@ 2020-03-18 21:40   ` Kamil Rytarowski
  2020-03-18 21:43     ` Simon Marchi
  0 siblings, 1 reply; 10+ messages in thread
From: Kamil Rytarowski @ 2020-03-18 21:40 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: Tom Tromey


[-- Attachment #1.1: Type: text/plain, Size: 3092 bytes --]

On 18.03.2020 22:15, Simon Marchi wrote:
> On 2020-03-18 12:29 p.m., Kamil Rytarowski wrote:
>> Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
>> The process id on NetBSD is stored always in the pid field of ptid.
>>
>> gdb/ChangeLog:
>>
>> 	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
>> 	* inf-ptrace.c: Likewise.
>> 	* (inf_ptrace_target::resume): Update.
>> 	* (inf_ptrace_target::xfer_partial): Likewise.
>> ---
>>  gdb/ChangeLog    |  7 +++++++
>>  gdb/inf-ptrace.c | 19 +++++++++++++++++--
>>  gdb/inf-ptrace.h |  2 ++
>>  3 files changed, 26 insertions(+), 2 deletions(-)
>>
>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>> index 84964dc00ac..36e333ec8ba 100644
>> --- a/gdb/ChangeLog
>> +++ b/gdb/ChangeLog
>> @@ -1,3 +1,10 @@
>> +2020-03-18  Kamil Rytarowski  <n54@gmx.com>
>> +
>> +	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
>> +	* inf-ptrace.c: Likewise.
>> +	* (inf_ptrace_target::resume): Update.
>> +	* (inf_ptrace_target::xfer_partial): Likewise.
>> +
>>  2020-03-17  Kamil Rytarowski  <n54@gmx.com>
>>
>>  	* regformats/regdef.h: Put reg in gdb namespace.
>> diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
>> index db17a76d946..e8bf66ed45f 100644
>> --- a/gdb/inf-ptrace.c
>> +++ b/gdb/inf-ptrace.c
>> @@ -313,8 +313,12 @@ inf_ptrace_target::kill ()
>>    target_mourn_inferior (inferior_ptid);
>>  }
>>
>> +#ifndef __NetBSD__
>>  /* Return which PID to pass to ptrace in order to observe/control the
>> -   tracee identified by PTID.  */
>> +   tracee identified by PTID.
>> +
>> +   Unlike most other Operating Systems, NetBSD tracks both pid and lwp
>> +   and avoids this function.  */
>>
>>  pid_t
>>  get_ptrace_pid (ptid_t ptid)
>> @@ -328,6 +332,7 @@ get_ptrace_pid (ptid_t ptid)
>>      pid = ptid.pid ();
>>    return pid;
>>  }
>> +#endif
>>
>>  /* Resume execution of thread PTID, or all threads if PTID is -1.  If
>>     STEP is nonzero, single-step it.  If SIGNAL is nonzero, give it
>> @@ -344,7 +349,13 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
>>         single-threaded processes, so simply resume the inferior.  */
>>      pid = inferior_ptid.pid ();
>>    else
>> -    pid = get_ptrace_pid (ptid);
>> +    {
>> +#ifdef __NetBSD__
>> +      pid = ptid. pid();
>> +#else
>> +      pid = get_ptrace_pid (ptid);
>> +#endif
>> +    }
> 
> To avoid the ifdefs in this more complex code, can't you use a gdb_ptrace function like in
> the other patches?  This time, it would look like:
> 
> static int
> gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr,
> 	    PTRACE_TYPE_ARG4 data)
> {
> #ifdef __NetBSD__
>   return ptrace (request, ptid.pid (), addr, data);
> #else
>   pid_t pid = get_ptrace_pid (ptid);
>   return ptrace (request, pid, addr, data);
> #endif
> }
> 
> Simon
> 

I will go for it, but only for a selection of ptrace () calls in this file.

In certain places there would need to be need to compose ptid_t out of
plain pid. Another case is PT_TRACE_ME.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 21:40   ` Kamil Rytarowski
@ 2020-03-18 21:43     ` Simon Marchi
  2020-03-18 21:45       ` Kamil Rytarowski
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2020-03-18 21:43 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches; +Cc: Tom Tromey

On 2020-03-18 5:40 p.m., Kamil Rytarowski wrote:
> I will go for it, but only for a selection of ptrace () calls in this file.
> 
> In certain places there would need to be need to compose ptid_t out of
> plain pid. Another case is PT_TRACE_ME.

My understanding for those is that there's no difference between NetBSD and
the other platforms.

Simon

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 21:43     ` Simon Marchi
@ 2020-03-18 21:45       ` Kamil Rytarowski
  0 siblings, 0 replies; 10+ messages in thread
From: Kamil Rytarowski @ 2020-03-18 21:45 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: Tom Tromey


[-- Attachment #1.1: Type: text/plain, Size: 480 bytes --]

On 18.03.2020 22:43, Simon Marchi wrote:
> On 2020-03-18 5:40 p.m., Kamil Rytarowski wrote:
>> I will go for it, but only for a selection of ptrace () calls in this file.
>>
>> In certain places there would need to be need to compose ptid_t out of
>> plain pid. Another case is PT_TRACE_ME.
> 
> My understanding for those is that there's no difference between NetBSD and
> the other platforms.
> 

This is correct, at least in the usage out there.

> Simon
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Disable get_ptrace_pid for NetBSD
  2020-03-18 21:49 Kamil Rytarowski
@ 2020-03-18 21:51 ` Kamil Rytarowski
  0 siblings, 0 replies; 10+ messages in thread
From: Kamil Rytarowski @ 2020-03-18 21:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, gdb-patches@sourceware.org >> gdb-patches


[-- Attachment #1.1: Type: text/plain, Size: 5060 bytes --]

On 18.03.2020 22:49, Kamil Rytarowski wrote:
> Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
> The process id on NetBSD is stored always in the pid field of ptid.
> 

There is is one bug.

I'm going to fix and submit a new version.

> gdb/ChangeLog:
> 
> 	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
> 	* inf-ptrace.c: Likewise.
> 	* (gdb_ptrace): Add.
> 	* (inf_ptrace_target::resume): Update.
> 	* (inf_ptrace_target::xfer_partial): Likewise.
> ---
>  gdb/ChangeLog    |  8 ++++++++
>  gdb/inf-ptrace.c | 32 +++++++++++++++++++++++---------
>  gdb/inf-ptrace.h |  2 ++
>  3 files changed, 33 insertions(+), 9 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 84964dc00ac..406414cee76 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,11 @@
> +2020-03-18  Kamil Rytarowski  <n54@gmx.com>
> +
> +	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
> +	* inf-ptrace.c: Likewise.
> +	* (gdb_ptrace): Add.
> +	* (inf_ptrace_target::resume): Update.
> +	* (inf_ptrace_target::xfer_partial): Likewise.
> +
>  2020-03-17  Kamil Rytarowski  <n54@gmx.com>
> 
>  	* regformats/regdef.h: Put reg in gdb namespace.
> diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
> index db17a76d946..304a749f3f3 100644
> --- a/gdb/inf-ptrace.c
> +++ b/gdb/inf-ptrace.c
> @@ -37,6 +37,18 @@
> 
>  \f
> 
> +static int
> +gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr,
> +	    PTRACE_TYPE_ARG4 data)
> +{
> +#ifdef __NetBSD__
> +  return ptrace (request, ptid.pid (), addr, data);
> +#else
> +  pid_t pid = get_ptrace_pid (ptid);
> +  return ptrace (request, pid, addr, data);
> +#endif
> +}
> +
>  /* A unique_ptr helper to unpush a target.  */
> 
>  struct target_unpusher
> @@ -313,8 +325,12 @@ inf_ptrace_target::kill ()
>    target_mourn_inferior (inferior_ptid);
>  }
> 
> +#ifndef __NetBSD__
>  /* Return which PID to pass to ptrace in order to observe/control the
> -   tracee identified by PTID.  */
> +   tracee identified by PTID.
> +
> +   Unlike most other Operating Systems, NetBSD tracks both pid and lwp
> +   and avoids this function.  */
> 
>  pid_t
>  get_ptrace_pid (ptid_t ptid)
> @@ -328,6 +344,7 @@ get_ptrace_pid (ptid_t ptid)
>      pid = ptid.pid ();
>    return pid;
>  }
> +#endif
> 
>  /* Resume execution of thread PTID, or all threads if PTID is -1.  If
>     STEP is nonzero, single-step it.  If SIGNAL is nonzero, give it
> @@ -336,15 +353,12 @@ get_ptrace_pid (ptid_t ptid)
>  void
>  inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
>  {
> -  pid_t pid;
>    int request;
> 
>    if (minus_one_ptid == ptid)
>      /* Resume all threads.  Traditionally ptrace() only supports
>         single-threaded processes, so simply resume the inferior.  */
> -    pid = inferior_ptid.pid ();
> -  else
> -    pid = get_ptrace_pid (ptid);
> +    ptid = inferior_ptid;
> 
>    if (catch_syscall_enabled () > 0)
>      request = PT_SYSCALL;
> @@ -365,7 +379,7 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
>       where it was.  If GDB wanted it to start some other way, we have
>       already written a new program counter value to the child.  */
>    errno = 0;
> -  ptrace (request, pid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal));
> +  gdb_ptrace (request, ptid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal));
>    if (errno != 0)
>      perror_with_name (("ptrace"));
>  }
> @@ -528,7 +542,7 @@ inf_ptrace_target::xfer_partial (enum target_object object,
>  				 const gdb_byte *writebuf,
>  				 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
>  {
> -  pid_t pid = get_ptrace_pid (inferior_ptid);
> +  ptid_t ptid = inferior_ptid;
> 
>    switch (object)
>      {
> @@ -552,7 +566,7 @@ inf_ptrace_target::xfer_partial (enum target_object object,
>  	piod.piod_len = len;
> 
>  	errno = 0;
> -	if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
> +	if (gdb_ptrace (PT_IO, ptid, (caddr_t)&piod, 0) == 0)
>  	  {
>  	    /* Return the actual number of bytes read or written.  */
>  	    *xfered_len = piod.piod_len;
> @@ -588,7 +602,7 @@ inf_ptrace_target::xfer_partial (enum target_object object,
>  	piod.piod_len = len;
> 
>  	errno = 0;
> -	if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
> +	if (gdb_ptrace (PT_IO, ptid, (caddr_t)&piod, 0) == 0)
>  	  {
>  	    /* Return the actual number of bytes read or written.  */
>  	    *xfered_len = piod.piod_len;
> diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h
> index dd0733736f2..340d41d8beb 100644
> --- a/gdb/inf-ptrace.h
> +++ b/gdb/inf-ptrace.h
> @@ -78,9 +78,11 @@ struct inf_ptrace_target : public inf_child_target
>    void detach_success (inferior *inf);
>  };
> 
> +#ifndef __NetBSD__
>  /* Return which PID to pass to ptrace in order to observe/control the
>     tracee identified by PTID.  */
> 
>  extern pid_t get_ptrace_pid (ptid_t);
> +#endif
> 
>  #endif
> --
> 2.25.0
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] Disable get_ptrace_pid for NetBSD
@ 2020-03-18 21:49 Kamil Rytarowski
  2020-03-18 21:51 ` Kamil Rytarowski
  0 siblings, 1 reply; 10+ messages in thread
From: Kamil Rytarowski @ 2020-03-18 21:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, Kamil Rytarowski

Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
The process id on NetBSD is stored always in the pid field of ptid.

gdb/ChangeLog:

	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
	* inf-ptrace.c: Likewise.
	* (gdb_ptrace): Add.
	* (inf_ptrace_target::resume): Update.
	* (inf_ptrace_target::xfer_partial): Likewise.
---
 gdb/ChangeLog    |  8 ++++++++
 gdb/inf-ptrace.c | 32 +++++++++++++++++++++++---------
 gdb/inf-ptrace.h |  2 ++
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 84964dc00ac..406414cee76 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2020-03-18  Kamil Rytarowski  <n54@gmx.com>
+
+	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
+	* inf-ptrace.c: Likewise.
+	* (gdb_ptrace): Add.
+	* (inf_ptrace_target::resume): Update.
+	* (inf_ptrace_target::xfer_partial): Likewise.
+
 2020-03-17  Kamil Rytarowski  <n54@gmx.com>

 	* regformats/regdef.h: Put reg in gdb namespace.
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index db17a76d946..304a749f3f3 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -37,6 +37,18 @@

 \f

+static int
+gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr,
+	    PTRACE_TYPE_ARG4 data)
+{
+#ifdef __NetBSD__
+  return ptrace (request, ptid.pid (), addr, data);
+#else
+  pid_t pid = get_ptrace_pid (ptid);
+  return ptrace (request, pid, addr, data);
+#endif
+}
+
 /* A unique_ptr helper to unpush a target.  */

 struct target_unpusher
@@ -313,8 +325,12 @@ inf_ptrace_target::kill ()
   target_mourn_inferior (inferior_ptid);
 }

+#ifndef __NetBSD__
 /* Return which PID to pass to ptrace in order to observe/control the
-   tracee identified by PTID.  */
+   tracee identified by PTID.
+
+   Unlike most other Operating Systems, NetBSD tracks both pid and lwp
+   and avoids this function.  */

 pid_t
 get_ptrace_pid (ptid_t ptid)
@@ -328,6 +344,7 @@ get_ptrace_pid (ptid_t ptid)
     pid = ptid.pid ();
   return pid;
 }
+#endif

 /* Resume execution of thread PTID, or all threads if PTID is -1.  If
    STEP is nonzero, single-step it.  If SIGNAL is nonzero, give it
@@ -336,15 +353,12 @@ get_ptrace_pid (ptid_t ptid)
 void
 inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
 {
-  pid_t pid;
   int request;

   if (minus_one_ptid == ptid)
     /* Resume all threads.  Traditionally ptrace() only supports
        single-threaded processes, so simply resume the inferior.  */
-    pid = inferior_ptid.pid ();
-  else
-    pid = get_ptrace_pid (ptid);
+    ptid = inferior_ptid;

   if (catch_syscall_enabled () > 0)
     request = PT_SYSCALL;
@@ -365,7 +379,7 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
      where it was.  If GDB wanted it to start some other way, we have
      already written a new program counter value to the child.  */
   errno = 0;
-  ptrace (request, pid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal));
+  gdb_ptrace (request, ptid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal));
   if (errno != 0)
     perror_with_name (("ptrace"));
 }
@@ -528,7 +542,7 @@ inf_ptrace_target::xfer_partial (enum target_object object,
 				 const gdb_byte *writebuf,
 				 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
-  pid_t pid = get_ptrace_pid (inferior_ptid);
+  ptid_t ptid = inferior_ptid;

   switch (object)
     {
@@ -552,7 +566,7 @@ inf_ptrace_target::xfer_partial (enum target_object object,
 	piod.piod_len = len;

 	errno = 0;
-	if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
+	if (gdb_ptrace (PT_IO, ptid, (caddr_t)&piod, 0) == 0)
 	  {
 	    /* Return the actual number of bytes read or written.  */
 	    *xfered_len = piod.piod_len;
@@ -588,7 +602,7 @@ inf_ptrace_target::xfer_partial (enum target_object object,
 	piod.piod_len = len;

 	errno = 0;
-	if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
+	if (gdb_ptrace (PT_IO, ptid, (caddr_t)&piod, 0) == 0)
 	  {
 	    /* Return the actual number of bytes read or written.  */
 	    *xfered_len = piod.piod_len;
diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h
index dd0733736f2..340d41d8beb 100644
--- a/gdb/inf-ptrace.h
+++ b/gdb/inf-ptrace.h
@@ -78,9 +78,11 @@ struct inf_ptrace_target : public inf_child_target
   void detach_success (inferior *inf);
 };

+#ifndef __NetBSD__
 /* Return which PID to pass to ptrace in order to observe/control the
    tracee identified by PTID.  */

 extern pid_t get_ptrace_pid (ptid_t);
+#endif

 #endif
--
2.25.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-03-18 21:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18 16:29 [PATCH] Disable get_ptrace_pid for NetBSD Kamil Rytarowski
2020-03-18 20:48 ` Tom Tromey
2020-03-18 20:54   ` Tom Tromey
2020-03-18 21:22     ` Simon Marchi
2020-03-18 21:15 ` Simon Marchi
2020-03-18 21:40   ` Kamil Rytarowski
2020-03-18 21:43     ` Simon Marchi
2020-03-18 21:45       ` Kamil Rytarowski
2020-03-18 21:49 Kamil Rytarowski
2020-03-18 21:51 ` Kamil Rytarowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).