develop
Petr Mrázek 2009-11-01 10:56:23 +00:00
parent 482e8b4447
commit 02a12782a7
1 changed files with 21 additions and 22 deletions

@ -110,7 +110,7 @@ bool isStopped(pid_t pid)
bool Process::attach() bool Process::attach()
{ {
int status; int status;
cout << "Attach: start" << endl; //cout << "Attach: start" << endl;
// check if another process is attached // check if another process is attached
if(g_pProcess != NULL) if(g_pProcess != NULL)
{ {
@ -118,10 +118,9 @@ bool Process::attach()
} }
if(!isStopped(my_handle)) if(!isStopped(my_handle))
{ {
for(int i = 0 ; i < 5 ; i++) // kill (SIGSTOP)
{
status = kill(my_handle,SIGSTOP); status = kill(my_handle,SIGSTOP);
cout << "sent SIGSTOP" << endl; //cout << "sent SIGSTOP" << endl;
if(status != -1) if(status != -1)
{ {
break; break;
@ -129,17 +128,17 @@ bool Process::attach()
else else
{ {
perror("kill(SIGSTOP)"); perror("kill(SIGSTOP)");
cin.ignore(); return false;
}
} }
// wait for the process to stop
while (!isStopped(my_handle)) while (!isStopped(my_handle))
{ {
usleep(5000); usleep(5000);
cout << "wait step" << endl; //cout << "wait step" << endl;
} }
} }
usleep(10000); //usleep(10000);
cout << "Attach: after conditional stop" << endl; //cout << "Attach: after conditional stop" << endl;
// can we attach? // can we attach?
if (ptrace(PTRACE_ATTACH , my_handle, NULL, NULL) == -1) if (ptrace(PTRACE_ATTACH , my_handle, NULL, NULL) == -1)
{ {
@ -148,8 +147,8 @@ bool Process::attach()
cerr << "attach failed on pid " << my_handle << endl; cerr << "attach failed on pid " << my_handle << endl;
return false; return false;
} }
usleep(10000); //usleep(10000);
cout << "Attach: after ptrace" << endl; //cout << "Attach: after ptrace" << endl;
/* /*
while(true) while(true)
{ {
@ -186,7 +185,7 @@ bool Process::attach()
g_ProcessHandle = my_handle; g_ProcessHandle = my_handle;
g_ProcessMemFile = proc_pid_mem; g_ProcessMemFile = proc_pid_mem;
cout << "Attach: after opening /proc/"<< my_handle <<"/mem" << endl; //cout << "Attach: after opening /proc/"<< my_handle <<"/mem" << endl;
return true; // we are attached return true; // we are attached
} }
} }
@ -195,7 +194,7 @@ bool Process::detach()
{ {
if(!attached) return false; if(!attached) return false;
int result = 0; int result = 0;
cout << "detach: start" << endl; //cout << "detach: start" << endl;
result = close(g_ProcessMemFile);// close /proc/PID/mem result = close(g_ProcessMemFile);// close /proc/PID/mem
if(result == -1) if(result == -1)
{ {
@ -205,7 +204,7 @@ bool Process::detach()
} }
else else
{ {
cout << "detach: after closing /proc/"<< my_handle <<"/mem" << endl; //cout << "detach: after closing /proc/"<< my_handle <<"/mem" << endl;
g_ProcessMemFile = -1; g_ProcessMemFile = -1;
result = ptrace(PTRACE_DETACH, my_handle, NULL, NULL); result = ptrace(PTRACE_DETACH, my_handle, NULL, NULL);
if(result == -1) if(result == -1)
@ -223,7 +222,7 @@ bool Process::detach()
// continue, wait for it to recover // continue, wait for it to recover
kill(my_handle,SIGCONT); kill(my_handle,SIGCONT);
while (isStopped(my_handle)); while (isStopped(my_handle));
usleep(10000); //usleep(10000);
// we finish // we finish
return true; return true;
} }