[Ltrace-devel] 3 patches for ltrace - fixes "armhf" target

Greg Alexander ltracedeb at galexander.org
Wed Mar 6 15:47:14 UTC 2013


Hi all -

Thanks for work on ltrace, it is fabulous.

I am using Debian on armhf, and I built ltrace from
ltrace_0.5.3.orig.tar.gz that I downloaded from the Debian pool.
I found a few problems on this target, and corrected them.  The patches
aren't long so I'm just going to append them at the bottom of this email,
but let me know if I should have done something different.

First patch corrects a build problem, header files were included in the
wrong order, so just use "common.h" instead.

Second patch corrects syscall tracing.  For whatever reason, my EABI
syscalls calls are using the ARM-Thumb encoding of the SWI/SVC
instruction, so I just added a condition for that.

Third patch provides fallback behavior if PTRACE_SINGLESTEP is
unavailable.  There is a #if to check for __sparc__ or __ia64__ to avoid
PTRACE_SINGLESTEP, and I left that alone, but probably it should go away
too.  My patch tries PTRACE_SINGLESTEP, but if -1 is returned then it
falls back to the same behavior as on sparc/ia64.  I think that is a
better solution than adding __arm__ to the #if, because if the kernel
does change to support PTRACE_SINGLESTEP here, it will not be any more
work for ltrace to support it.

Thank you!
- Greg


--- ltrace-0.5.3.orig/sysdeps/linux-gnu/arm/breakpoint.c	2009-07-25 11:13:02.000000000 -0400
+++ ltrace-0.5.3/sysdeps/linux-gnu/arm/breakpoint.c	2013-03-06 09:21:41.803584766 -0500
@@ -25,9 +25,7 @@
 #include <sys/ptrace.h>
 #include "config.h"
 #include "arch.h"
-#include "options.h"
-#include "output.h"
-#include "debug.h"
+#include "common.h"
 
 void
 arch_enable_breakpoint(pid_t pid, Breakpoint *sbp) {
--- ltrace-0.5.3.orig/sysdeps/linux-gnu/arm/trace.c	2009-07-25 11:13:02.000000000 -0400
+++ ltrace-0.5.3/sysdeps/linux-gnu/arm/trace.c	2013-03-06 09:41:38.078585339 -0500
@@ -52,6 +52,9 @@
 		if (insn == 0xef000000 || insn == 0x0f000000) {
 			/* EABI syscall */
 			*sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, off_r7, 0);
+		} else if ((insn & 0xffff0000) == 0xdf000000) {
+			/* EABI syscall "encoding T1" (thumb) */
+			*sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, off_r7, 0);
 		} else if ((insn & 0xfff00000) == 0xef900000) {
 			/* old ABI syscall */
 			*sysnum = insn & 0xfffff;
--- ltrace-0.5.3.orig/sysdeps/linux-gnu/trace.c	2009-07-25 11:13:02.000000000 -0400
+++ ltrace-0.5.3/sysdeps/linux-gnu/trace.c	2013-03-06 10:26:15.368586617 -0500
@@ -122,7 +122,10 @@
 #if defined __sparc__  || defined __ia64___
 		ptrace(PTRACE_SYSCALL, pid, 0, signum);
 #else
-		ptrace(PTRACE_SINGLESTEP, pid, 0, signum);
+		if (ptrace(PTRACE_SINGLESTEP, pid, 0, signum) == -1) {
+			ptrace(PTRACE_SYSCALL, pid, 0, signum);
+		}
+
 #endif
 	} else {
 		ptrace(PTRACE_SYSCALL, pid, 0, signum);
@@ -158,7 +161,9 @@
 		/* we don't want to singlestep here */
 		continue_process(proc->pid);
 #else
-		ptrace(PTRACE_SINGLESTEP, proc->pid, 0, 0);
+		if (ptrace(PTRACE_SINGLESTEP, proc->pid, 0, 0) == -1) {
+			continue_process(proc->pid);
+		}
 #endif
 	}
 }



More information about the Ltrace-devel mailing list