Skip to contentSkip to conversation

gdb/or1k: Add linux debugging support

PATCH RESEND Superseded Stafford Horne 3 participants 5 messages Dec 7, 2018 – Dec 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 gdb/or1k: Add linux debugging support

(Resend to include binutils list)

Up until now OpenRISC GDB only has supported bare metal debugging. This patch adds linux userspace debugging and core dump analysis support.

The changes are loosely based on nios2 and riscv implementations.

This was tested with linux 4.20 core dumps for executables linked against musl libc.

bfd/ChangeLog:

* elf32-or1k.c (or1k_grok_prstatus): New function. (or1k_grok_psinfo): Likewise.

gdb/ChangeLog:

* Makefile.in (ALL_TARGET_OBS): Add or1k-linux-tdep.o.
* configure.tgt: Add or1k*-*-linux*.
* or1k-linux-tdep.c: New file.
* or1k-tdep.c (or1k_gdbarch_init): Call gdbarch_init_osabi.

---
 bfd/elf32-or1k.c      |  55 ++++++++++++++
 gdb/Makefile.in       |   1 +
 gdb/configure.tgt     |   8 ++
 gdb/or1k-linux-tdep.c | 170 ++++++++++++++++++++++++++++++++++++++++++
 gdb/or1k-tdep.c       |   3 +
 5 files changed, 237 insertions(+)
 create mode 100644 gdb/or1k-linux-tdep.c
bfd/elf32-or1k.c +55 -0
index a2b0ff147f..8edd7584e4 100644
@@ -3226,6 +3226,58 @@ elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 
 }
 
+/* Implement elf_backend_grok_prstatus:
+   Support for core dump NOTE sections.  */
+static bfd_boolean
+or1k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+  int offset;
+  size_t size;
+
+  switch (note->descsz)
+    {
+    default:
+      return FALSE;
+
+    case 212:	      /* Linux/OpenRISC */
+      /* pr_cursig */
+      elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
+
+      /* pr_pid */
+      elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
+
+      /* pr_reg */
+      offset = 72;
+      size = 132;
+
+      break;
+    }
+
+  /* Make a ".reg/999" section.  */
+  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
+					  size, note->descpos + offset);
+}
+
+/* Implement elf_backend_grok_psinfo.  */
+static bfd_boolean
+or1k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+  switch (note->descsz)
+    {
+    default:
+      return FALSE;
+
+    case 128:	      /* Linux/OpenRISC elf_prpsinfo */
+      elf_tdata (abfd)->core->program
+	= _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
+      elf_tdata (abfd)->core->command
+	= _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
+    }
+
+  return TRUE;
+}
+
+
 #define ELF_ARCH			bfd_arch_or1k
 #define ELF_MACHINE_CODE		EM_OR1K
 #define ELF_TARGET_ID			OR1K_ELF_DATA
@@ -3269,4 +3321,7 @@ elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 #define elf_backend_adjust_dynamic_symbol	or1k_elf_adjust_dynamic_symbol
 #define elf_backend_finish_dynamic_symbol	or1k_elf_finish_dynamic_symbol
 
+#define elf_backend_grok_prstatus	  or1k_grok_prstatus
+#define elf_backend_grok_psinfo		  or1k_grok_psinfo
+
 #include "elf32-target.h"
gdb/Makefile.in +1 -0
index 1099d710c9..b8cb130b9f 100644
@@ -740,6 +740,7 @@ ALL_TARGET_OBS = \
 	nios2-tdep.o \
 	nto-tdep.o \
 	obsd-tdep.o \
+	or1k-linux-tdep.o \
 	or1k-tdep.o \
 	ppc-fbsd-tdep.o \
 	ppc-linux-tdep.o \
gdb/configure.tgt +8 -0
index 9b646fa1a2..27f122ad04 100644
@@ -471,6 +471,14 @@ nios2*-*-*)
 	gdb_target_obs="nios2-tdep.o"
 	;;
 
+or1k*-*-linux*)
+	# Target: OpenCores OpenRISC 1000 32-bit running Linux
+	gdb_target_obs="or1k-tdep.o or1k-linux-tdep.o solib-svr4.o \
+			symfile-mem.o glibc-tdep.o linux-tdep.o"
+	gdb_sim=../sim/or1k/libsim.a
+	build_gdbserver=yes
+	;;
+
 or1k-*-* | or1knd-*-*)
 	# Target: OpenCores OpenRISC 1000 32-bit implementation bare metal
 	gdb_target_obs="or1k-tdep.o"
gdb/or1k-linux-tdep.c new file +170 -0

170 lines not on this page · raw message

gdb/or1k-tdep.c +3 -0
index a9ef44baac..1949605626 100644
@@ -1256,6 +1256,9 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       tdesc_use_registers (gdbarch, tdesc, tdesc_data);
     }
 
+  /* Hook in ABI-specific overrides, if they have been registered.  */
+  gdbarch_init_osabi (info, gdbarch);
+
   return gdbarch;
 }
 
Signature · 1 line
2.19.1
#1 lore raw

PATCH RESEND 1/1 gdb/or1k: Add linux debugging support

Hi Stafford,

Quoted 4 lines

bfd/ChangeLog:

* elf32-or1k.c (or1k_grok_prstatus): New function. (or1k_grok_psinfo): Likewise.

This part is approved.

Cheers
Nick

#2 lore raw

PATCH RESEND 1/1 gdb/or1k: Add linux debugging support

Quoted 8 lines · Nick Clifton

Hi Stafford,

Quoted 4 lines

bfd/ChangeLog:

* elf32-or1k.c (or1k_grok_prstatus): New function. (or1k_grok_psinfo): Likewise.

This part is approved.

Thank you for reviewing.

-Stafford

#4 lore raw

PATCH RESEND 1/1 gdb/or1k: Add linux debugging support

Quoted 9 lines · Pedro Alves
Quoted 4 lines · Stafford Horne

(Resend to include binutils list)

Up until now OpenRISC GDB only has supported bare metal debugging. This patch adds linux userspace debugging and core dump analysis support.

Could you send a patch to documents this addition in the gdb/NEWS file?

https://sourceware.org/gdb/wiki/ContributionChecklist#Documentation

Hello,

Sorry, I meant to do that but forgot to get around to it. I have just sent the patch.

-Stafford