[Ltrace-devel] [PATCH 02/11] Add umovebytes to move a range of bytes from the traced process to ltrace

Joe Damato ice799 at gmail.com
Mon Nov 8 23:47:35 UTC 2010


---
 common.h                  |    4 +---
 sysdeps/linux-gnu/trace.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/common.h b/common.h
index 753d3dc..45d38fc 100644
--- a/common.h
+++ b/common.h
@@ -256,9 +256,7 @@ extern long gimme_arg(enum tof type, Process * proc, int arg_num, arg_type_info
 extern void save_register_args(enum tof type, Process * proc);
 extern int umovestr(Process * proc, void * addr, int len, void * laddr);
 extern int umovelong (Process * proc, void * addr, long * result, arg_type_info * info);
+extern size_t umovebytes (Process *proc, void * addr, void * laddr, size_t count);
 extern int ffcheck(void * maddr);
 extern void * sym2addr(Process *, struct library_symbol *);
 
-#if 0				/* not yet */
-extern int umoven(Process * proc, void * addr, int len, void * laddr);
-#endif
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index 75d0d55..9f61a03 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -171,6 +171,42 @@ continue_after_breakpoint(Process *proc, Breakpoint *sbp) {
 	}
 }
 
+size_t
+umovebytes(Process *proc, void *addr, void *laddr, size_t len) {
+
+	union {
+		long a;
+		char c[sizeof(long)];
+	} a;
+	int i;
+	int offset = 0, started = 0;
+	size_t bytes_read = 0;
+
+	while (offset < len) {
+		a.a = ptrace(PTRACE_PEEKTEXT, proc->pid, addr + offset, 0);
+		if (errno) {
+			if (started && (errno == EPERM || errno == EIO))
+				return bytes_read;
+
+			if (addr != 0 && errno != EIO && errno != ESRCH)
+				return -1;
+		}
+		started = 1;
+
+		if (len - offset >= sizeof(long)) {
+			memcpy(laddr + offset, &a.c[0], sizeof(long));
+			bytes_read += sizeof(long);
+		}
+		else {
+			memcpy(laddr + offset, &a.c[0], len - offset);
+			bytes_read += (len - offset);
+		}
+		offset += sizeof(long);
+	}
+
+	return bytes_read;
+}
+
 /* Read a series of bytes starting at the process's memory address
    'addr' and continuing until a NUL ('\0') is seen or 'len' bytes
    have been read.
-- 
1.7.0.4




More information about the Ltrace-devel mailing list