how can i generate a record of all instructions executed by a given pr - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how can i generate a record of all instructions executed by a given pr

ksinghksingh Posts: 4Member
Hi All,

I have written a small program to tracing a child process instruction by instruction and recording them all. what my aim is to count all the instruction executed inside the child process and maintain their cycle time needd to execute.

My program is as follows: But it not working properly. i am using Linux operating system. please help.

Code:

#include
#include
#include
#include
#include
#include
#include
int main()
{ pid_t child;
const int long_size = sizeof(long);
child = fork();
if(child == 0)
{
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
execl("./test.out", "test.out", NULL);
}
else
{
int status;
struct user_regs_struct regs;
int start = 0;
long ins;
unsigned char ch;
while(1)
{
wait(&status);
if(WIFEXITED(status))
break;
if(status != 1407)
break;
ptrace(PTRACE_GETREGS, child, NULL, &regs);
ins = ptrace(PTRACE_PEEKTEXT, child, regs.eip, NULL);
printf("EIP: %lx Instruction executed: %lx
", regs.eip, ch);
ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);

}
}
return 0;
}

Sign In or Register to comment.