[Ltrace-devel] [PATCH 06/11] Create a function find_dynamic_entry_addr.
Joe Damato
ice799 at gmail.com
Mon Nov 8 23:47:39 UTC 2010
This functions searches the DYNAMIC vector of an inferior process searching for
the first entry whose d_tag matches. An out parameter is provided to copy out
address stored in the matching entry.
---
ltrace-elf.h | 1 +
sysdeps/linux-gnu/proc.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/ltrace-elf.h b/ltrace-elf.h
index 6ac143b..b21f6e3 100644
--- a/ltrace-elf.h
+++ b/ltrace-elf.h
@@ -34,6 +34,7 @@ struct ltelf {
#endif // __mips__
};
+#define ELF_MAX_SEGMENTS 50
#define LTE_HASH_MALLOCED 1
#define LTE_PLT_EXECUTABLE 2
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index 4251c1d..86ad301 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -1,6 +1,8 @@
#include "config.h"
+#include "common.h"
#include <sys/types.h>
+#include <link.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
@@ -34,3 +36,35 @@ pid2name(pid_t pid) {
}
return NULL;
}
+
+static int
+find_dynamic_entry_addr(Process *proc, void *pvAddr, int d_tag, void **addr) {
+ int i = 0, done = 0;
+ ElfW(Dyn) entry;
+
+ debug(DEBUG_FUNCTION, "find_dynamic_entry()");
+
+ if (addr == NULL || pvAddr == NULL || d_tag < 0 || d_tag > DT_NUM) {
+ return -1;
+ }
+
+ while ((!done) && (i < ELF_MAX_SEGMENTS) &&
+ (sizeof(entry) == umovebytes(proc, pvAddr, &entry, sizeof(entry))) &&
+ (entry.d_tag != DT_NULL)) {
+ if (entry.d_tag == d_tag) {
+ done = 1;
+ *addr = (void *)entry.d_un.d_val;
+ }
+ pvAddr += sizeof(entry);
+ i++;
+ }
+
+ if (done) {
+ debug(2, "found address: 0x%p in dtag %d\n", *addr, d_tag);
+ return 0;
+ }
+ else {
+ debug(2, "Couldn't address for dtag!\n");
+ return -1;
+ }
+}
--
1.7.0.4
More information about the Ltrace-devel
mailing list