Results 1 to 3 of 3
Is there a program out there like ltrace that will allow the user to determine every line of code executed by another program?
Once upon a time I created such ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-02-2004 #1Just Joined!
- Join Date
- Mar 2004
- Location
- Minneapolis, MN
- Posts
- 10
tracing program execution
Is there a program out there like ltrace that will allow the user to determine every line of code executed by another program?
Once upon a time I created such a program on DomainOS (Apollo Computer) called 'tca' (Test Coverage Analyzer). You could execute a program then post-process the trace log to find out what lines of code where (or weren't) executed. It was an internal-only program. It would be nice to, at least, find some way of generating the PC counter history of the program execution.
Thanks!
Joel
- 12-03-2004 #2Just Joined!
- Join Date
- Aug 2004
- Posts
- 17
Try strace.
- 12-05-2004 #3Just Joined!
- Join Date
- Mar 2004
- Location
- Minneapolis, MN
- Posts
- 10
I think I have what I want as an example of starting point. My version of Sandeep's "small example" outputs the instruction count and instruction pointer.
Here the URL containing Sandeep's example: http://linuxgazette.net/issue81/sandeep.html
Here's my variant showing the instruction count and instruction pointer:
**MOD_EDIT: added 'code' tagsCode:#include <stdio.h> #include <stdlib.h> #include <signal.h> #include <syscall.h> #include <sys/ptrace.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <errno.h> #include <linux/user.h> int main(void) { long long counter = 0; /* machine instruction counter */ int wait_val; /* child's return value */ int pid; /* child's process id */ struct user_regs_struct regs; puts("Please wait"); switch (pid = fork()) { case -1: perror("fork"); break; case 0: /* child process starts */ ptrace(PTRACE_TRACEME, 0, 0, 0); /* * must be called in order to allow the * control over the child process */ execl("/bin/ls", "ls", NULL); /* * executes the program and causes * the child to stop and send a signal * to the parent, the parent can now * switch to PTRACE_SINGLESTEP */ break; /* child process ends */ default:/* parent process starts */ wait(&wait_val); /* * parent waits for child to stop at next * instruction (execl()) */ while (wait_val == 1407 ) { if (ptrace(PTRACE_GETREGS, pid, 0, ®s) != 0) perror("ptrace gr"); printf("%lld %08x\n", counter, regs.eip ); counter++; if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0) perror("ptrace ss"); /* * switch to singlestep tracing and * release child * if unable call error. */ wait(&wait_val); /* wait for next instruction to complete */ } /* * continue to stop, wait and release until * the child is finished; wait_val != 1407 * Low=0177L and High=05 (SIGTRAP) */ } printf("Number of machine instructions : %lld\n", counter); return 0; }


Reply With Quote
