public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* readelf: Pull advance_pc() in file scope
@ 2021-03-18  9:25 tbaeder
  2021-03-18  9:25 ` [PATCH] " tbaeder
  0 siblings, 1 reply; 2+ messages in thread
From: tbaeder @ 2021-03-18  9:25 UTC (permalink / raw)
  To: elfutils-devel

Giving this another shot since pulling all the parsing code into
libdwP.h seems a bit overkill (and potentially buggy of course). The
downside is that run_advance_pc() takes 6 arguments instead of the 4
that it takes in libdwarf_getsrclines.c





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] readelf: Pull advance_pc() in file scope
  2021-03-18  9:25 readelf: Pull advance_pc() in file scope tbaeder
@ 2021-03-18  9:25 ` tbaeder
  0 siblings, 0 replies; 2+ messages in thread
From: tbaeder @ 2021-03-18  9:25 UTC (permalink / raw)
  To: elfutils-devel

From: Timm Bäder <tbaeder@redhat.com>

Make advance_pc() a static function so we can get rid of another nested
function. Rename it to run_advance_pc() and use a local advance_pc()
macro to pass all the local variables. This is similar to what the
equivalent code in libdw/dwarf_getsrclines.c is doing.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
 src/readelf.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/readelf.c b/src/readelf.c
index b9740455..c44d06d1 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -8373,6 +8373,23 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp,
   return readp;
 }
 
+/* Only used via run_advance_pc() macro */
+static inline void
+run_advance_pc (unsigned int op_advance,
+                unsigned int minimum_instr_len,
+                unsigned int max_ops_per_instr,
+                unsigned int *op_addr_advance,
+                Dwarf_Word *address,
+                unsigned int *op_index)
+{
+  const unsigned int advanced_op_index = (*op_index) + op_advance;
+
+  *op_addr_advance = minimum_instr_len * (advanced_op_index
+                                         / max_ops_per_instr);
+  *address = *address + *op_addr_advance;
+  *op_index = advanced_op_index % max_ops_per_instr;
+}
+
 static void
 print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
 			  Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
@@ -8763,13 +8780,8 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
       /* Apply the "operation advance" from a special opcode
 	 or DW_LNS_advance_pc (as per DWARF4 6.2.5.1).  */
       unsigned int op_addr_advance;
-      inline void advance_pc (unsigned int op_advance)
-      {
-	op_addr_advance = minimum_instr_len * ((op_index + op_advance)
-					       / max_ops_per_instr);
-	address += op_addr_advance;
-	op_index = (op_index + op_advance) % max_ops_per_instr;
-      }
+#define advance_pc(op_advance) run_advance_pc(op_advance, minimum_instr_len, \
+                      max_ops_per_instr, &op_addr_advance, &address, &op_index)
 
       if (max_ops_per_instr == 0)
 	{
-- 
2.26.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-18  9:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18  9:25 readelf: Pull advance_pc() in file scope tbaeder
2021-03-18  9:25 ` [PATCH] " tbaeder

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).