//---------------------------------------------------------------- // mytracer.cpp // // Here is an experimental 'prototype' for a debugging tool, // based on the Linux 'ptrace()' programming interface. // // programmer: ALLAN CRUSE // written on: 13 NOV 2003 //---------------------------------------------------------------- #include #include #include #include #include char *regname[ 17 ] = { "EBX", "ECX", "EDX", "ESI", "EDI", "EBP", "EAX", "DS", "ES", "FS", "GS", "---", "EIP", "CS", "EFL", "ESP", "SS" }; int main( int argc, char **argv ) { int pid = fork(); if ( !pid ) { ptrace( PTRACE_TRACEME, 0, 0, 0 ); execve( argv[1], NULL, NULL ); exit(1); } int status = 0; wait( &status ); for (int step = 0; step < 8; step++) { unsigned int address; for (int i = 0; i < 17; i++) { address = ptrace( PTRACE_PEEKUSER, pid, i<<2 ); printf( "\n%02X: %08X ", i<<2, address ); printf( " (%s) ", regname[ i ] ); } printf( "\n" ); getchar(); ptrace( PTRACE_SINGLESTEP, pid, 0, 0 ); status = 0; wait( &status ); } ptrace( PTRACE_CONT, pid ); status = 0; wait( &status ); printf( "\nparent-process \'%s\' is quitting\n", argv[0] ); }