gdb: Implement native dumpcore function for NetBSD
authorKamil Rytarowski <n54@gmx.com>
Thu, 13 Aug 2020 17:29:13 +0000 (19:29 +0200)
committerKamil Rytarowski <n54@gmx.com>
Thu, 13 Aug 2020 22:10:06 +0000 (00:10 +0200)
Define supports_dumpcore and dumpcore for NetBSD, that wraps
the ptrace(2) call with the PT_DUMPCORE operation.

gdb/ChangeLog:

       * nbsd-nat.h (nbsd_nat_target::supports_dumpcore)
       (nbsd_nat_target::dumpcore): New declarations.
       * nbsd-nat.c (nbsd_nat_target::supports_dumpcore)
       (nbsd_nat_target::dumpcore): New functions.

gdb/nbsd-nat.c
gdb/nbsd-nat.h

index 5b59f2130d770774b9e4ed32602b89742fde400a..52c4d185695308efcf35616b003bd40fdd63d2c9 100644 (file)
@@ -890,3 +890,23 @@ nbsd_nat_target::xfer_partial (enum target_object object,
                                              len, xfered_len);
     }
 }
+
+/* Implement the "supports_dumpcore" target_ops method.  */
+
+bool
+nbsd_nat_target::supports_dumpcore ()
+{
+  return true;
+}
+
+/* Implement the "dumpcore" target_ops method.  */
+
+void
+nbsd_nat_target::dumpcore (const char *filename)
+{
+  pid_t pid = inferior_ptid.pid ();
+
+  if (ptrace (PT_DUMPCORE, pid, const_cast<char *>(filename),
+             strlen (filename)) == -1)
+    perror_with_name (("ptrace"));
+}
index 665a71a0f7804e1837b932b185b4dfc57b449db0..b09d5b1e3bb600c3432702cc1564bfeef3526e1e 100644 (file)
@@ -55,6 +55,8 @@ struct nbsd_nat_target : public inf_ptrace_target
                                        const gdb_byte *writebuf,
                                        ULONGEST offset, ULONGEST len,
                                        ULONGEST *xfered_len) override;
+  bool supports_dumpcore () override;
+  void dumpcore (const char *filename) override;
 };
 
 #endif /* nbsd-nat.h */