[PATCH] syscall.c:788: warning: unused variable ‘pid’

Denys Vlasenko dvlasenk at redhat.com
Fri Jan 23 16:33:31 UTC 2009


Hi Michal.

On Tue, 2009-01-20 at 09:28 -0500, Michal Nowak wrote:
> On i386 building strace from CVS emits following warning:
> 
> if gcc -DHAVE_CONFIG_H -I. -I. -I. -Ilinux/i386 -I./linux/i386 -Ilinux -I./linux   -Wall -g -O2 -MT syscall.o -MD -MP -MF ".deps/syscall.Tpo" -c -o syscall.o syscall.c; \
> 	then mv -f ".deps/syscall.Tpo" ".deps/syscall.Po"; else rm -f ".deps/syscall.Tpo"; exit 1; fi
> syscall.c: In function ‘get_scno’:
> syscall.c:788: warning: unused variable ‘pid’
> 
> Attached patch fixes it by disabling [1] for archs, which don't
> actually use it. I successfully tested/compiled it on i386 and 
> IA-64.

Oh no :(

        long scno = 0;
 #ifndef USE_PROCFS
+#if defined(S390) || defined(S390X) || defined(X86_64) || defined(ARM) \
+       || defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64) || defined(SPARC) \
+       || defined(SPARC64) || (defined(IA64) && defined(PTRACE_GETSIGINFO))
        int pid = tcp->pid;
-#endif /* !PROCFS */
+#endif /* 
+                               S390 || S390X || X86_64 || ARM || LINUX_MIPSN32 || LINUX_MIPSN64 
+                               || SPARC || SPARC64 || (IA64 && PTRACE_GETSIGINFO) */
+#endif /* !USE_PROCFS */


#ifdef forest is a Bad Thing. Avoid it. It's far better to just move
"int pid = tcp->pid;" into every arch block which needs it
and/or use tcp->pid instead of pid.

My version is below. I applied it ti cvs.

Thanks for bugging me about this problem.
--
vda


diff -u -r1.107 syscall.c
--- syscall.c	17 Jan 2009 01:06:18 -0000	1.107
+++ syscall.c	23 Jan 2009 16:26:07 -0000
@@ -780,13 +780,9 @@
 #endif /* FREEBSD */
 
 int
-get_scno(tcp)
-struct tcb *tcp;
+get_scno(struct tcb *tcp)
 {
 	long scno = 0;
-#ifndef USE_PROCFS
-	int pid = tcp->pid;
-#endif /* !PROCFS */
 
 #ifdef LINUX
 #if defined(S390) || defined(S390X)
@@ -833,7 +829,7 @@
 		if (upeek(tcp, PT_PSWADDR, &pc) < 0)
 			return -1;
 		errno = 0;
-		opcode = ptrace(PTRACE_PEEKTEXT, pid, (char *)(pc-sizeof(long)), 0);
+		opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(pc-sizeof(long)), 0);
 		if (errno) {
 			perror("peektext(pc-oneword)");
 			return -1;
@@ -874,7 +870,7 @@
 				return -1;
 			svc_addr += tmp;
 
-			scno = ptrace(PTRACE_PEEKTEXT, pid, svc_addr, 0);
+			scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0);
 			if (errno)
 				return -1;
 #if defined(S390X)
@@ -916,6 +912,7 @@
 	if (!(tcp->flags & TCB_INSYSCALL)) {
 	  	static int currpers = -1;
 		long val;
+		int pid = tcp->pid;
 
 		/* Check CS register value. On x86-64 linux it is:
 		 * 	0x33	for long mode (64 bit)
@@ -1004,7 +1001,7 @@
 			 * magic SIGTRAP. Moot anyway, PTRACE_GETSIGINFO
 			 * doesn't fail.
 			 */
-			ptrace(PTRACE_GETSIGINFO, pid, (void*) 0, (void*) &si);
+			ptrace(PTRACE_GETSIGINFO, tcp->pid, (void*) 0, (void*) &si);
 			if (si.si_code == SI_USER)
 				return 0;
 #else
@@ -1023,7 +1020,7 @@
 	/*
 	 * Read complete register set in one go.
 	 */
-	if (ptrace(PTRACE_GETREGS, pid, NULL, (void *)&regs) == -1)
+	if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (void *)&regs) == -1)
 		return -1;
 
 	/*
@@ -1051,7 +1048,7 @@
 			 * Get the ARM-mode system call number
 			 */
 			errno = 0;
-			scno = ptrace(PTRACE_PEEKTEXT, pid, (void *)(regs.ARM_pc - 4), NULL);
+			scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(regs.ARM_pc - 4), NULL);
 			if (errno)
 				return -1;
 
@@ -1105,7 +1102,7 @@
 #elif defined (LINUX_MIPSN32)
 	unsigned long long regs[38];
 
-	if (ptrace (PTRACE_GETREGS, pid, NULL, (long) &regs) < 0)
+	if (ptrace (PTRACE_GETREGS, tcp->pid, NULL, (long) &regs) < 0)
 		return -1;
 	a3 = regs[REG_A3];
 	r2 = regs[REG_V0];
@@ -1183,14 +1180,14 @@
 	}
 #elif defined (SPARC) || defined (SPARC64)
 	/* Everything we need is in the current register set. */
-	if (ptrace(PTRACE_GETREGS,pid,(char *)&regs,0) < 0)
+	if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0)
 		return -1;
 
 	/* If we are entering, then disassemble the syscall trap. */
 	if (!(tcp->flags & TCB_INSYSCALL)) {
 		/* Retrieve the syscall trap instruction. */
 		errno = 0;
-		trap = ptrace(PTRACE_PEEKTEXT,pid,(char *)regs.r_pc,0);
+		trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.r_pc, 0);
 #if defined(SPARC64)
 		trap >>= 32;
 #endif






More information about the Strace-devel mailing list