[PATCH] Disable get_ptrace_pid for NetBSD

Kamil Rytarowski
2020-03-18T16:29:59Z

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