patches/ltrace/0.5.2/120-debian-ltrace-0.5.2-2.patch
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Wed Dec 26 13:30:51 2012 +0100 (2012-12-26)
changeset 3145 598880dab0f3
permissions -rw-r--r--
libc/glibc: both glibc and eglibc have pkgversion and bugurl

Well, all eglibc version we support do, and latest glibc versions
we support do.

Not all glibc versions do, but older versions simply ignore the
unrecognised ./configure flags.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
     1 --- ltrace-0.5.2.orig/TODO
     2 +++ ltrace-0.5.2/TODO
     3 @@ -37,3 +37,4 @@
     4  * debug: change "-d" option to be something like "-d elf,events", or "-d breakpoints"
     5  * Find out if a process is sharing memory with its parent?
     6  * When using -p, find out if that process is sharing memory with other procs
     7 +* After a clone(), syscalls may be seen as sysrets in s390 (see trace.c:syscall_p())
     8 --- ltrace-0.5.2.orig/process_event.c
     9 +++ ltrace-0.5.2/process_event.c
    10 @@ -170,7 +170,7 @@
    11  			enable_breakpoint(proc->pid, proc->breakpoint_being_enabled);
    12  			proc->breakpoint_being_enabled = NULL;
    13  		}
    14 -		if (proc->parent->state == STATE_ATTACHED && options.follow) {
    15 +		if (options.follow) {
    16  			proc->state = STATE_ATTACHED;
    17  		} else {
    18  			proc->state = STATE_IGNORED;
    19 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/ppc/trace.c
    20 +++ ltrace-0.5.2/sysdeps/linux-gnu/ppc/trace.c
    21 @@ -50,9 +50,9 @@
    22  			*sysnum =
    23  			    (int)ptrace(PTRACE_PEEKUSER, proc->pid,
    24  					sizeof(long) * PT_R0, 0);
    25 -			if (proc->callstack_depth > 0
    26 -			    && proc->callstack[proc->callstack_depth -
    27 -					       1].is_syscall) {
    28 +			if (proc->callstack_depth > 0 &&
    29 +					proc->callstack[proc->callstack_depth - 1].is_syscall &&
    30 +					proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
    31  				return 2;
    32  			}
    33  			return 1;
    34 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/i386/trace.c
    35 +++ ltrace-0.5.2/sysdeps/linux-gnu/i386/trace.c
    36 @@ -32,7 +32,8 @@
    37  		*sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ORIG_EAX, 0);
    38  
    39  		if (proc->callstack_depth > 0 &&
    40 -		    proc->callstack[proc->callstack_depth - 1].is_syscall) {
    41 +				proc->callstack[proc->callstack_depth - 1].is_syscall &&
    42 +				proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
    43  			return 2;
    44  		}
    45  
    46 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/ia64/trace.c
    47 +++ ltrace-0.5.2/sysdeps/linux-gnu/ia64/trace.c
    48 @@ -106,8 +106,8 @@
    49  		if (insn == 0x1000000000 || insn == 0x1ffffffffff) {
    50  			*sysnum = r15;
    51  			if (proc->callstack_depth > 0 &&
    52 -			    proc->callstack[proc->callstack_depth -
    53 -					    1].is_syscall) {
    54 +				proc->callstack[proc->callstack_depth - 1].is_syscall &&
    55 +				proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
    56  				return 2;
    57  			}
    58  			return 1;
    59 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/m68k/trace.c
    60 +++ ltrace-0.5.2/sysdeps/linux-gnu/m68k/trace.c
    61 @@ -36,9 +36,8 @@
    62  		if (*sysnum >= 0) {
    63  			depth = proc->callstack_depth;
    64  			if (depth > 0 &&
    65 -			    proc->callstack[depth - 1].is_syscall &&
    66 -			    proc->callstack[depth - 1].c_un.syscall ==
    67 -			    *sysnum) {
    68 +					proc->callstack[depth - 1].is_syscall &&
    69 +					proc->callstack[depth - 1].c_un.syscall == *sysnum) {
    70  				return 2;
    71  			} else {
    72  				return 1;
    73 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/alpha/trace.c
    74 +++ ltrace-0.5.2/sysdeps/linux-gnu/alpha/trace.c
    75 @@ -36,8 +36,9 @@
    76  			return 0;
    77  		*sysnum =
    78  		    ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */ , 0);
    79 -		if (proc->callstack_depth > 0
    80 -		    && proc->callstack[proc->callstack_depth - 1].is_syscall) {
    81 +		if (proc->callstack_depth > 0 &&
    82 +		    proc->callstack[proc->callstack_depth - 1].is_syscall &&
    83 +			proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
    84  			return 2;
    85  		}
    86  		if (*sysnum >= 0 && *sysnum < 500) {
    87 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/sparc/trace.c
    88 +++ ltrace-0.5.2/sysdeps/linux-gnu/sparc/trace.c
    89 @@ -33,9 +33,9 @@
    90  		insn = ptrace(PTRACE_PEEKTEXT, proc->pid, ip, 0);
    91  		if ((insn & 0xc1f8007f) == 0x81d00010) {
    92  			*sysnum = ((proc_archdep *) proc->arch_ptr)->regs.r_g1;
    93 -			if ((proc->callstack_depth > 0)
    94 -			    && proc->callstack[proc->callstack_depth -
    95 -					       1].is_syscall) {
    96 +			if (proc->callstack_depth > 0 &&
    97 +					proc->callstack[proc->callstack_depth - 1].is_syscall &&
    98 +					proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
    99  				return 2;
   100  			} else if (*sysnum >= 0) {
   101  				return 1;
   102 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/mipsel/trace.c
   103 +++ ltrace-0.5.2/sysdeps/linux-gnu/mipsel/trace.c
   104 @@ -60,33 +60,34 @@
   105  int
   106  syscall_p(Process *proc, int status, int *sysnum) {
   107  	if (WIFSTOPPED(status)
   108 -	    && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
   109 -       /* get the user's pc (plus 8) */
   110 -       long pc = (long)get_instruction_pointer(proc);
   111 -       /* fetch the SWI instruction */
   112 -       int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
   113 -       int num = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 8, 0);
   114 -       
   115 -/*
   116 -  On a mipsel,  syscall looks like:
   117 -  24040fa1    li v0, 0x0fa1   # 4001 --> _exit syscall
   118 -  0000000c    syscall
   119 - */
   120 -      if(insn!=0x0000000c){
   121 -          return 0;
   122 -      }
   123 -
   124 -      *sysnum = (num & 0xFFFF) - 4000;
   125 -      /* if it is a syscall, return 1 or 2 */
   126 -      if (proc->callstack_depth > 0 &&
   127 -          proc->callstack[proc->callstack_depth - 1].is_syscall) {
   128 -          return 2;
   129 -      }
   130 -      
   131 -      if (*sysnum >= 0) {
   132 -          return 1;
   133 -      }
   134 -   }
   135 +			&& WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
   136 +		/* get the user's pc (plus 8) */
   137 +		long pc = (long)get_instruction_pointer(proc);
   138 +		/* fetch the SWI instruction */
   139 +		int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
   140 +		int num = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 8, 0);
   141 +
   142 +		/*
   143 +		   On a mipsel,  syscall looks like:
   144 +		   24040fa1    li v0, 0x0fa1   # 4001 --> _exit syscall
   145 +		   0000000c    syscall
   146 +		 */
   147 +		if(insn!=0x0000000c){
   148 +			return 0;
   149 +		}
   150 +
   151 +		*sysnum = (num & 0xFFFF) - 4000;
   152 +		/* if it is a syscall, return 1 or 2 */
   153 +		if (proc->callstack_depth > 0 &&
   154 +				proc->callstack[proc->callstack_depth - 1].is_syscall &&
   155 +				proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
   156 +			return 2;
   157 +		}
   158 +
   159 +		if (*sysnum >= 0) {
   160 +			return 1;
   161 +		}
   162 +	}
   163  	return 0;
   164  }
   165  /**
   166 @@ -119,34 +120,34 @@
   167  */
   168  long
   169  gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info) {
   170 -    long ret;
   171 -    debug(2,"type %d arg %d",type,arg_num);
   172 -    if (type == LT_TOF_FUNCTION || type == LT_TOF_SYSCALL){
   173 -        if(arg_num <4){
   174 -            ret=ptrace(PTRACE_PEEKUSER,proc->pid,off_a0+arg_num,0);
   175 -            debug(2,"ret = %#lx",ret);
   176 -            return ret;
   177 -        } else {
   178 -            // If we need this, I think we can look at [sp+16] for arg_num==4.
   179 -            CP;
   180 -            return 0;
   181 -        }
   182 -    } 
   183 -    if(arg_num>=0){
   184 -       fprintf(stderr,"args on return?");
   185 -    }
   186 -    if(type == LT_TOF_FUNCTIONR) {
   187 -        return  ptrace(PTRACE_PEEKUSER,proc->pid,off_v0,0);
   188 -    }
   189 -    if (type == LT_TOF_SYSCALLR) {
   190 -        unsigned a3=ptrace(PTRACE_PEEKUSER, proc->pid,off_a3,0);
   191 -        unsigned v0=ptrace(PTRACE_PEEKUSER, proc->pid,off_v0,0);
   192 -        if(!a3){
   193 -            return v0;
   194 -        }
   195 -        return -1;
   196 -    }
   197 -    fprintf(stderr, "gimme_arg called with wrong arguments\n");
   198 +	long ret;
   199 +	debug(2,"type %d arg %d",type,arg_num);
   200 +	if (type == LT_TOF_FUNCTION || type == LT_TOF_SYSCALL){
   201 +		if(arg_num <4){
   202 +			ret=ptrace(PTRACE_PEEKUSER,proc->pid,off_a0+arg_num,0);
   203 +			debug(2,"ret = %#lx",ret);
   204 +			return ret;
   205 +		} else {
   206 +			// If we need this, I think we can look at [sp+16] for arg_num==4.
   207 +			CP;
   208 +			return 0;
   209 +		}
   210 +	} 
   211 +	if(arg_num>=0){
   212 +		fprintf(stderr,"args on return?");
   213 +	}
   214 +	if(type == LT_TOF_FUNCTIONR) {
   215 +		return  ptrace(PTRACE_PEEKUSER,proc->pid,off_v0,0);
   216 +	}
   217 +	if (type == LT_TOF_SYSCALLR) {
   218 +		unsigned a3=ptrace(PTRACE_PEEKUSER, proc->pid,off_a3,0);
   219 +		unsigned v0=ptrace(PTRACE_PEEKUSER, proc->pid,off_v0,0);
   220 +		if(!a3){
   221 +			return v0;
   222 +		}
   223 +		return -1;
   224 +	}
   225 +	fprintf(stderr, "gimme_arg called with wrong arguments\n");
   226  	return 0;
   227  }
   228  
   229 --- ltrace-0.5.2.orig/sysdeps/linux-gnu/x86_64/trace.c
   230 +++ ltrace-0.5.2/sysdeps/linux-gnu/x86_64/trace.c
   231 @@ -41,7 +41,8 @@
   232  		*sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 8 * ORIG_RAX, 0);
   233  
   234  		if (proc->callstack_depth > 0 &&
   235 -		    proc->callstack[proc->callstack_depth - 1].is_syscall) {
   236 +				proc->callstack[proc->callstack_depth - 1].is_syscall &&
   237 +				proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
   238  			return 2;
   239  		}
   240