Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.