Just to follow up, this was fairly easy to do with ptrace.  I'll attach
the small resulting C file below in case anyone is interested, or to
seed future Google searches.

#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/user.h>

// Compilation: gcc -o tracer tracer-64.c
// Usage: ./tracer ./program and arguments to program
int main(int argc, char *argv[]){
  FILE * fd = fopen("trace", "a");
  int status;
  pid_t child;
  struct user_regs_struct regs;
  long ins;
  child = fork();

  switch (child=fork()){
  case -1: // error
    printf("fork error\n");
    return 1;
    break;
  case 0:  // child
    ptrace(PTRACE_TRACEME, 0, NULL, NULL);
    execvp(argv[1], &argv[1]);
    break;
  default: // parent
    while(1) {
      wait(&status);
      if(WIFEXITED(status)) break;
      ptrace(PTRACE_GETREGS, child, NULL, &regs);
      // The following two lines print the value of the current instruction
      // ins = ptrace(PTRACE_PEEKTEXT, child, regs.rip, NULL);
      // fprintf(fd, "0x%lx 0x%lx\n", regs.rip, ins);
      fprintf(fd, "%d\n", regs.rip);
      ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);
    }
    return status;
    break;
  }
}
-- 
Eric Schulte
http://cs.unm.edu/~eschulte/
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to