[PATCH] Getter and setter for Dwfl's offline_next_address

Martin Rodriguez Reboredo yakoyoku@gmail.com
Wed Mar 6 19:22:49 GMT 2024


Added new functions dwfl_get_offline_next_address and
dwfl_set_offline_next_address which will get plus set said field from
the Dwfl struct. This is a requirement for listing functions from their
addresses when using libdwfl offline, otherwise wrong symbols are going
to be returned.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
---
This is meant to replace a patch that only had the setter [1].

Link: https://sourceware.org/pipermail/elfutils-devel/2024q1/006874.html [1]

 libdwfl/libdwfl.h            |  6 +++++
 libdwfl/offline.c            | 12 ++++++++++
 tests/dwfl-offline-address.c | 43 ++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 tests/dwfl-offline-address.c

diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h
index 49ad6664..08aa61c4 100644
--- a/libdwfl/libdwfl.h
+++ b/libdwfl/libdwfl.h
@@ -109,6 +109,12 @@ extern int dwfl_errno (void);
 extern const char *dwfl_errmsg (int err);
 
 
+/* Get the next offline address.  */
+extern GElf_Addr dwfl_get_offline_next_address (Dwfl *dwfl);
+
+/* Set the next offline address.  */
+extern void dwfl_set_offline_next_address (Dwfl *dwfl, GElf_Addr addr);
+
 /* Start reporting the current set of segments and modules to the library.
    All existing segments are wiped.  Existing modules are marked to be
    deleted, and will not be found via dwfl_addrmodule et al if they are not
diff --git a/libdwfl/offline.c b/libdwfl/offline.c
index e9ab0cc1..ca770fac 100644
--- a/libdwfl/offline.c
+++ b/libdwfl/offline.c
@@ -35,6 +35,18 @@
 #include "libdwflP.h"
 #include <fcntl.h>
 
+GElf_Addr
+dwfl_get_offline_next_address (Dwfl *dwfl)
+{
+  return dwfl->offline_next_address;
+}
+
+void
+dwfl_set_offline_next_address (Dwfl *dwfl, GElf_Addr addr)
+{
+  dwfl->offline_next_address = addr;
+}
+
 /* Since dwfl_report_elf lays out the sections already, this will only be
    called when the section headers of the debuginfo file are being
    consulted instead, or for the section placed at 0.  With binutils
diff --git a/tests/dwfl-offline-address.c b/tests/dwfl-offline-address.c
new file mode 100644
index 00000000..9a33b95a
--- /dev/null
+++ b/tests/dwfl-offline-address.c
@@ -0,0 +1,43 @@
+#include <config.h>
+#include <assert.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+#include <argp.h>
+#include ELFUTILS_HEADER(dwfl)
+#include <dwarf.h>
+#include "system.h"
+
+#define OFFLINE_REDZONE 0x10000
+
+static const Dwfl_Callbacks offline_callbacks =
+  {
+    .find_debuginfo = INTUSE(dwfl_standard_find_debuginfo),
+    .section_address = INTUSE(dwfl_offline_section_address),
+  };
+
+int
+main (int argc, char **argv)
+{
+  Dwfl *dwfl = dwfl_begin (&offline_callbacks);
+  assert (dwfl != NULL);
+
+  if (dwfl_get_offline_next_address (dwfl) != OFFLINE_REDZONE)
+    {
+      dwfl_end (dwfl);
+      return 1;
+    }
+
+  int result = 0;
+  dwfl_set_offline_next_address (dwfl, 0);
+  if (dwfl_get_offline_next_address (dwfl) != 0)
+	  result = 1;
+
+  dwfl_end (dwfl);
+
+  return result;
+}
-- 
2.44.0



More information about the Elfutils-devel mailing list