[RFC] gdb: wrap mdebug debuginfo reading in ifdefs

Message ID 20250103181413.414566-2-guinevere@redhat.com
State New
Headers
Series [RFC] gdb: wrap mdebug debuginfo reading in ifdefs |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Guinevere Larsen Jan. 3, 2025, 6:14 p.m. UTC
  This commit aims to allow a user to enable or disable mdebug support at
compilation time. In order to do that, 2 new macros are defined:
elf_read_mdebug and mips_read_mdebug. If support was requested at
compile time, these macros are turned into simple function calls to
elfmdebug_build_psymtabs and mipsmdebug_build_psymtabs. If support was
disabled, the macros are turned into warnings that mdebug is not
supported.

The final implementation will also contain changes to the configure
script.
---

Hi Tromey!

This is my best solution for using preprocessor ifs to define functions,
and mdebug is a simple case to test out. I don't quite love the final result,
so if you have better ideas I'm all ears!

---
 gdb/elfread.c    |  2 +-
 gdb/mdebugread.h | 22 ++++++++++++++++++++++
 gdb/mipsread.c   |  2 +-
 3 files changed, 24 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gdb/elfread.c b/gdb/elfread.c
index 7b98b8c29ce..093745bc59c 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1333,7 +1333,7 @@  elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	 information.  */
       swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
       if (swap)
-	elfmdebug_build_psymtabs (objfile, swap, ei.mdebugsect);
+	elf_read_mdebug (objfile, swap, ei.mdebugsect);
     }
   if (ei.stabsect)
     {
diff --git a/gdb/mdebugread.h b/gdb/mdebugread.h
index 3ef8f5163b1..4a76d9a0bda 100644
--- a/gdb/mdebugread.h
+++ b/gdb/mdebugread.h
@@ -54,4 +54,26 @@  extern void mipsmdebug_build_psymtabs (struct objfile *,
 				       const struct ecoff_debug_swap *,
 				       struct ecoff_debug_info *);
 
+#define MDEBUG_FORMAT_AVAILABLE 1
+
+#if MDEBUG_FORMAT_AVAILABLE
+# define elf_read_mdebug(objf, swap, asection) \
+  elfmdebug_build_psymtabs(objf, swap, asection)
+# define mips_read_mdebug(objf, swap, info) \
+  mipsmdebug_build_psymtabs(objf, swap, info)
+#else
+/* We need the second line here so that the compiler doesn't
+   complain about unused variables.  */
+# define elf_read_mdebug(objf, swap, asection) \
+  do { \
+    warning ("No mdebug support available"); \
+    (void) objf; (void) swap; (void) asection; \
+  } while (0)
+# define mips_read_mdebug(objf, swap, info) \
+  do { \
+    warning ("No mdebug support available"); \
+    (void) objf; (void) swap; (void) info; \
+  } while (0)
+#endif /* MDEBUG_FORMAT_AVAILABLE */
+
 #endif /* GDB_MDEBUGREAD_H */
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index 3d014b114d3..c05e744733d 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -69,7 +69,7 @@  mipscoff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   /* Now that the executable file is positioned at symbol table,
      process it and define symbols accordingly.  */
 
-  mipsmdebug_build_psymtabs (objfile, &ecoff_backend (abfd)->debug_swap,
+  mips_read_mdebug (objfile, &ecoff_backend (abfd)->debug_swap,
 			     &ecoff_data (abfd)->debug_info);
 
   /* Add alpha coff dynamic symbols.  */