Skip to contentSkip to conversation

strace fix

Linux-ia64 David Mosberger 1 participant 1 message Jul 31, 2001

lore
Share & tools
lore
#0 lore raw

Recently I noticed that strace reports bogus syscall return values after any execve() system call. This was quite annoying and it turns out to be due to the fact that strace was falling out of sync with the kernel due to an extra SIGTRAP that is being sent from the kernel's ELF loader. The patch below fixes this problem.

	--david
defs.h renamed from defs.h.~1.17.~ +3 -1
@@ -274,7 +274,9 @@
 #define TCB_FOLLOWFORK	00400	/* Process should have forks followed */
 #define TCB_REPRINT	01000	/* We should reprint this syscall on exit */
 #ifdef LINUX
-#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
+#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64)
+  /* When execve'ing an ELF binary, the kernel sends an extra SIGTRAP
+     which we need to ignore.  */
 #define TCB_WAITEXECVE	02000	/* ignore SIGTRAP after exceve */
 #endif /* ALPHA */
 #endif /* LINUX */
process.c renamed from process.c.~1.26.2.2.~ +1 -1
@@ -1162,7 +1162,7 @@
 		}
 	}
 #ifdef LINUX
-#if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
+#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64)
 	tcp->flags |= TCB_WAITEXECVE;
 #endif /* ALPHA || SPARC || POWERPC */
 #endif /* LINUX */
syscall.c renamed from syscall.c.~1.25.2.3.~ +4 -0
@@ -691,6 +691,10 @@
 			if (upeek(pid, PT_R8, &scno) < 0)
 				return -1;
 		} else {
+			if ((tcp->flags & TCB_WAITEXECVE)) {
+				tcp->flags &= ~TCB_WAITEXECVE;
+				return 0;
+			}
 			if (upeek (pid, PT_R15, &scno) < 0)
 				return -1;
 		}