]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
binutils: objdump, readelf: BTF dumping support
authorNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 20:45:45 +0000 (21:45 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 20:45:45 +0000 (21:45 +0100)
objdump and readelf's --ctf option can now dump BTF as well (in CTF dumping
format, which is quite high-level and C-like compared to bpftool btf dump:
both have their uses).

binutils/objdump.c
binutils/readelf.c

index bb791e2a8b334816466c510fa401c8b279e81a2e..1cf0b267414eac1fb196e75a0458964a7fc3765a 100644 (file)
@@ -4875,12 +4875,22 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name,
   ctf_next_t *i = NULL;
   const char *name;
   size_t member = 0;
+  int try_defaults = 0;
   int err;
 
   if (sect_name == NULL)
-    sect_name = ".ctf";
+    {
+      sect_name = ".ctf";
+      try_defaults = 1;
+    }
 
   sec = read_section (abfd, sect_name, &ctfdata);
+  if (sec == NULL && try_defaults)
+    {
+      sect_name = ".BTF";
+      sec = read_section (abfd, sect_name, &ctfdata);
+    }
+
   if (sec == NULL)
     {
       my_bfd_nonfatal (bfd_get_filename (abfd));
@@ -4936,7 +4946,7 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name,
       return;
     }
 
-  printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));
+  printf (_("Contents of type section %s:\n"), sanitize_string (sect_name));
 
   while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)
     {
index 062ad3eb7900910de81786031ce783bac7d1b5a7..b0199679f98a87976ff0da566a6a7b8051b2a579 100644 (file)
@@ -17045,9 +17045,9 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
       strsect.cts_data = strdata;
     }
 
-  /* Load the CTF file and dump it.  It may be a raw CTF section, or an archive:
-     libctf papers over the difference, so we can pretend it is always an
-     archive.  */
+  /* Load the section and dump it.  It may be a raw CTF or BTF section, or an
+     archive: libctf papers over the difference, so we can pretend it is always
+     an archive.  */
 
   if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
     {
@@ -17071,11 +17071,11 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
   ret = true;
 
   if (filedata->is_separate)
-    printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
+    printf (_("\nDump of type section '%s' in linked file %s:\n"),
            printable_section_name (filedata, section),
            filedata->file_name);
   else
-    printf (_("\nDump of CTF section '%s':\n"),
+    printf (_("\nDump of type section '%s':\n"),
            printable_section_name (filedata, section));
 
  while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)