[PATCH 6/7] gdb: introduce ctf_debuginfo_reader

Guinevere Larsen guinevere@redhat.com
Tue Dec 17 17:41:21 GMT 2024


This commit adds yet another derived class of debuginfo_reader, which
will be used to read CTF information, and alters the ELF objfile reader
to use this new class.

Since there isn't any extra information necessary for reading CTF,
ctf_reader_struct is not introduced along with it. A new
_initialize_ctfread function was added to register the ctf debuginfo
reader at initialization time.
---
 gdb/ctfread.c | 20 ++++++++++++++++++--
 gdb/ctfread.h |  8 +++++++-
 gdb/elfread.c | 12 ++++++++----
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index ee7c30f7d87..be387d42a66 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -1599,7 +1599,7 @@ build_ctf_archive_member (ctf_dict_t *ctf, const char *name, void *arg)
    called from elfread.c.  It does a quick pass through the
    .ctf section to set up the partial symbol table.  */
 
-void
+static void
 elfctf_build_psymtabs (struct objfile *of)
 {
   struct ctf_per_tu_data pcu;
@@ -1632,10 +1632,26 @@ elfctf_build_psymtabs (struct objfile *of)
 
 #else
 
-void
+static void
 elfctf_build_psymtabs (struct objfile *of)
 {
   /* Nothing to do if CTF is disabled.  */
 }
 
 #endif /* ENABLE_LIBCTF */
+
+/* See ctfread.c.  */
+void
+ctf_debuginfo_reader::process_objfile (struct objfile *of, void *void_ctx)
+{
+  elfctf_build_psymtabs (of);
+}
+
+ctf_debuginfo_reader ctf_reader;
+
+void _initialize_ctfread ();
+void
+_initialize_ctfread ()
+{
+  register_debuginfo_reader_with_format ("ctf", &ctf_reader);
+}
diff --git a/gdb/ctfread.h b/gdb/ctfread.h
index ff348a2487b..234e259af07 100644
--- a/gdb/ctfread.h
+++ b/gdb/ctfread.h
@@ -20,6 +20,12 @@
 #ifndef CTFREAD_H
 #define CTFREAD_H
 
-extern void elfctf_build_psymtabs (struct objfile *objfile);
+#include "debuginfo-reader.h"
+
+class ctf_debuginfo_reader : public debuginfo_reader {
+public:
+  /* Main interface for reading debuginfo in the objfile.  */
+  void process_objfile (struct objfile *objfile, void *void_ctx) override;
+};
 
 #endif /* CTFREAD_H */
diff --git a/gdb/elfread.c b/gdb/elfread.c
index bfdce4f91af..5403c3963b0 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1380,18 +1380,22 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	}
     }
 
+  debuginfo_reader *ctf_reader = find_debuginfo_reader_by_format ("ctf");
+  if (ctf_reader == nullptr)
+    warning (_("No support for ctf debuginfo"));
+
   /* Read the CTF section only if there is no DWARF info.  */
-  if (always_read_ctf && ei.ctfsect)
+  if (ctf_reader != nullptr && always_read_ctf && ei.ctfsect)
     {
-      elfctf_build_psymtabs (objfile);
+      ctf_reader->process_objfile (objfile, nullptr);
     }
 
   bool has_dwarf2 = elf_symfile_read_dwarf2 (objfile, symfile_flags);
 
   /* Read the CTF section only if there is no DWARF info.  */
-  if (!always_read_ctf && !has_dwarf2 && ei.ctfsect)
+  if (ctf_reader != nullptr && !always_read_ctf && !has_dwarf2 && ei.ctfsect)
     {
-      elfctf_build_psymtabs (objfile);
+      ctf_reader->process_objfile (objfile, nullptr);
     }
 
   /* Copy relocations are used by some ABIs using the ELF format, so
-- 
2.47.1



More information about the Gdb-patches mailing list