[v2,2/2] gdb: Implement native dumpcore function for NetBSD

Message ID 20200728154602.3824-2-n54@gmx.com
State New
Headers show
Series
  • [v2,1/2] gdb: Implement native dumpcore function
Related show

Commit Message

Kamil Rytarowski July 28, 2020, 3:46 p.m.
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_native_dumpcore)
       (nbsd_nat_target::native_dumpcore): New declarations.
       * nbsd-nat.c (nbsd_nat_target::supports_native_dumpcore)
       (nbsd_nat_target::native_dumpcore): New functions.
---
 gdb/ChangeLog  |  7 +++++++
 gdb/nbsd-nat.c | 19 +++++++++++++++++++
 gdb/nbsd-nat.h |  2 ++
 3 files changed, 28 insertions(+)

--
2.26.2

Comments

Tom Tromey Aug. 5, 2020, 4:24 p.m. | #1
>>>>> "Kamil" == Kamil Rytarowski <n54@gmx.com> writes:


Kamil> Define supports_dumpcore and dumpcore for NetBSD, that wraps
Kamil> the ptrace(2) call with the PT_DUMPCORE operation.

Kamil> +  return ptrace (PT_DUMPCORE, pid, const_cast<char *>(filename),
Kamil> +		 strlen (filename)) != -1;

If this can fail it is probably better to call perror_with_name or
error or something along those lines.

Tom
Kamil Rytarowski Aug. 13, 2020, 5:16 p.m. | #2
On 05.08.2020 18:24, Tom Tromey wrote:
>>>>>> "Kamil" == Kamil Rytarowski <n54@gmx.com> writes:

>

> Kamil> Define supports_dumpcore and dumpcore for NetBSD, that wraps

> Kamil> the ptrace(2) call with the PT_DUMPCORE operation.

>

> Kamil> +  return ptrace (PT_DUMPCORE, pid, const_cast<char *>(filename),

> Kamil> +		 strlen (filename)) != -1;

>

> If this can fail it is probably better to call perror_with_name or

> error or something along those lines.

>


I've switched to perror_with_name in v3 and I have checked that it can
fail and be handled gracefully.

> Tom

>

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 118bb4f89a2..75b9a0bd13d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@ 
+2020-07-28  Kamil Rytarowski  <n54@gmx.com>
+
+	* nbsd-nat.h (nbsd_nat_target::supports_native_dumpcore)
+	(nbsd_nat_target::native_dumpcore): New declarations.
+	* nbsd-nat.c (nbsd_nat_target::supports_native_dumpcore)
+	(nbsd_nat_target::native_dumpcore): New functions.
+
 2020-07-28  Kamil Rytarowski  <n54@gmx.com>

 	* target.h (supports_native_dumpcore, native_dumpcore): New
diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
index a9405ebf862..c893c5498bb 100644
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -845,3 +845,22 @@  nbsd_nat_target::supports_multi_process ()
 {
   return true;
 }
+
+/* Implement the "supports_dumpcore" target_ops method.  */
+
+bool
+nbsd_nat_target::supports_dumpcore ()
+{
+  return true;
+}
+
+/* Implement the "dumpcore" target_ops method.  */
+
+bool
+nbsd_nat_target::dumpcore (const char *filename)
+{
+  pid_t pid = inferior_ptid.pid ();
+
+  return ptrace (PT_DUMPCORE, pid, const_cast<char *>(filename),
+		 strlen (filename)) != -1;
+}
diff --git a/gdb/nbsd-nat.h b/gdb/nbsd-nat.h
index 0a7048ecf35..550ea6a5d8d 100644
--- a/gdb/nbsd-nat.h
+++ b/gdb/nbsd-nat.h
@@ -49,6 +49,8 @@  struct nbsd_nat_target : public inf_ptrace_target
     override;

   bool supports_multi_process () override;
+  bool supports_dumpcore () override;
+  bool dumpcore (const char* filename) override;
 };

 #endif /* nbsd-nat.h */