public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: elfutils-devel@sourceware.org
Subject: [PATCH 12/14] tests: Optionally dump all units in dwarf-getmacros
Date: Wed, 27 Sep 2023 11:21:01 -0700	[thread overview]
Message-ID: <4453f4ff42a3234e60438733bcf1147451b7c2a7.1695837512.git.osandov@fb.com> (raw)
In-Reply-To: <cover.1695837512.git.osandov@fb.com>

From: Omar Sandoval <osandov@fb.com>

If instead of a CU offset an empty string is given as the second
argument, dump all units.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 tests/ChangeLog         |  3 +++
 tests/dwarf-getmacros.c | 51 +++++++++++++++++++++++++++++++++--------
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 4380c57f..97261444 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -17,6 +17,9 @@
 	* dwarf-getmacros.c (mac): Add DW_MACRO_define_sup,
 	DW_MACRO_define_strx, DW_MACRO_undef_sup, and DW_MACRO_undef_strx
 	cases to opcode switch statement.
+	(getmacros): New function.
+	(main): If second argument is empty, call getmacros on every unit.
+	Otherwise, call getmacros on given unit.
 
 2023-04-21  Frank Ch. Eigler <fche@redhat.com>
 
diff --git a/tests/dwarf-getmacros.c b/tests/dwarf-getmacros.c
index e291bfd2..8381d42c 100644
--- a/tests/dwarf-getmacros.c
+++ b/tests/dwarf-getmacros.c
@@ -121,26 +121,57 @@ include (Dwarf *dbg, Dwarf_Off macoff, ptrdiff_t token)
       }
 }
 
+static void
+getmacros (Dwarf *dbg, Dwarf_Die *die, bool new_style)
+{
+  for (ptrdiff_t off = new_style ? DWARF_GETMACROS_START : 0;
+       (off = dwarf_getmacros (die, mac, dbg, off)); )
+    if (off == -1)
+      {
+	puts (dwarf_errmsg (-1));
+	break;
+      }
+}
+
 int
 main (int argc, char *argv[])
 {
   assert (argc >= 3);
   const char *name = argv[1];
-  ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
   bool new_style = argc > 3;
 
   int fd = open (name, O_RDONLY);
   Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
 
-  Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
-
-  for (ptrdiff_t off = new_style ? DWARF_GETMACROS_START : 0;
-       (off = dwarf_getmacros (cudie, mac, dbg, off)); )
-    if (off == -1)
-      {
-	puts (dwarf_errmsg (dwarf_errno ()));
-	break;
-      }
+  if (argv[2][0] == '\0')
+    {
+      Dwarf_CU *cu = NULL;
+      Dwarf_Die cudie, subdie;
+      uint8_t unit_type;
+      while (dwarf_get_units (dbg, cu, &cu, NULL,
+			      &unit_type, &cudie, &subdie) == 0)
+	{
+	  Dwarf_Die *die = (unit_type == DW_UT_skeleton
+			    ? &subdie : &cudie);
+	  if (! dwarf_hasattr (die, DW_AT_macro_info)
+	      && ! dwarf_hasattr (die, DW_AT_GNU_macros)
+	      && ! dwarf_hasattr (die, DW_AT_macros))
+	    continue;
+	  printf ("CU %s\n", dwarf_diename (die));
+	  getmacros (dbg, die, new_style);
+	}
+    }
+  else
+    {
+      ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
+      Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
+      if (cudie == NULL)
+	{
+	  puts (dwarf_errmsg (-1));
+	  return 1;
+	}
+      getmacros (dbg, cudie, new_style);
+    }
 
   dwarf_end (dbg);
 
-- 
2.41.0


  parent reply	other threads:[~2023-09-27 18:21 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27 18:20 [PATCH 00/14] elfutils: DWARF package (.dwp) file support Omar Sandoval
2023-09-27 18:20 ` [PATCH 01/14] libdw: Make try_split_file static Omar Sandoval
2023-10-03 16:09   ` Mark Wielaard
2023-09-27 18:20 ` [PATCH 02/14] libdw: Handle split DWARF in dwarf_entrypc Omar Sandoval
2023-10-03 16:10   ` Mark Wielaard
2023-09-27 18:20 ` [PATCH 03/14] libdw: Handle DW_AT_ranges in split DWARF 5 skeleton in dwarf_ranges Omar Sandoval
2023-10-03 16:10   ` Mark Wielaard
2023-09-27 18:20 ` [PATCH 04/14] libdw: Handle other string forms in dwarf_macro_param2 Omar Sandoval
2023-10-03 16:11   ` Mark Wielaard
2023-09-27 18:20 ` [PATCH 05/14] libdw: Fix dwarf_macro_getsrcfiles for DWARF 5 Omar Sandoval
2023-10-03 21:29   ` Mark Wielaard
2023-09-27 18:20 ` [PATCH 06/14] libdw: Handle split DWARF in dwarf_macro_getsrcfiles Omar Sandoval
2023-10-03 21:49   ` Mark Wielaard
2023-09-27 18:20 ` [PATCH 07/14] libdw: Recognize .debug_[ct]u_index sections in dwarf_elf_begin Omar Sandoval
2023-11-01 14:03   ` Mark Wielaard
2023-11-01 17:30     ` Omar Sandoval
2023-09-27 18:20 ` [PATCH 08/14] libdw: Parse DWARF package file index sections Omar Sandoval
2023-11-01 23:07   ` Mark Wielaard
2023-11-07  6:45     ` Omar Sandoval
2023-09-27 18:20 ` [PATCH 09/14] libdw, libdwfl: Save original path of ELF file Omar Sandoval
2023-11-02 17:04   ` Mark Wielaard
2023-11-07  6:46     ` Omar Sandoval
2023-09-27 18:20 ` [PATCH 10/14] libdw: Try .dwp file in __libdw_find_split_unit() Omar Sandoval
2023-11-02 19:56   ` Mark Wielaard
2023-11-07  7:07     ` Omar Sandoval
2023-09-27 18:21 ` [PATCH 11/14] tests: Handle DW_MACRO_{define,undef}_{strx,sup} in dwarf-getmacros Omar Sandoval
2023-11-02 20:30   ` [PATCH 11/14] tests: Handle DW_MACRO_{define, undef}_{strx, sup} " Mark Wielaard
2023-09-27 18:21 ` Omar Sandoval [this message]
2023-11-02 20:39   ` [PATCH 12/14] tests: Optionally dump all units " Mark Wielaard
2023-09-27 18:21 ` [PATCH 13/14] libdw: Apply DWARF package file section offsets where appropriate Omar Sandoval
2023-11-02 22:20   ` Mark Wielaard
2023-11-07 16:55     ` Omar Sandoval
2023-09-27 18:21 ` [PATCH 14/14] libdw: Handle overflowed DW_SECT_INFO offsets in DWARF package file indexes Omar Sandoval
2023-09-27 19:20 ` [PATCH 00/14] elfutils: DWARF package (.dwp) file support Frank Ch. Eigler
2023-09-27 20:17   ` Omar Sandoval
2023-10-03 21:54 ` Mark Wielaard
2023-11-02 23:05 ` Mark Wielaard
2023-11-07 17:13   ` Omar Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4453f4ff42a3234e60438733bcf1147451b7c2a7.1695837512.git.osandov@fb.com \
    --to=osandov@osandov.com \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).