> Christopher Faylor:
> You can stop another thread with a
"SuspendThread()" call and you can
> cause the thread to resume in another location with a
"ResumeThread()"
> by changing the EIP that is passed to it. However, if
you do that while
> you are in the middle of a low-level Windows function
which, say, holds
> a mutex, then you are going to eventually run into
problems.
I wanted to try this with the following changes in
remoted.c,
but I could'nt find a way to get the EIP of the new address,
i.e.
"continueHere:".
How could that be done?
#include <windows.h>//Added
static HANDLE h_main_thread = 0;//Added
static void
interrupt_query (void)
{
target_terminal_ours ();
if (query ("Interrupted while waiting for the
program.n
Give up (and stop debugging it)? "))
{
target_mourn_inferior ();
if (h_main_thread){//Added
CONTEXT threadContext;//Added
SuspendThread(h_main_thread);//Added
GetThreadContext(h_main_thread,&threadContext);//Added
threadContext.Eip = &continueHere;//Added and
wished it would work
SetThreadContext(h_main_thread,&threadContext);//Added
ResumeThread(h_main_thread);//Added
ExitThread(0);//Added
}//Added
continueHere://Added and wished it would work
deprecated_throw_reason (RETURN_QUIT);
}
target_terminal_inferior ();
}
...
static ptid_t
remote_wait (ptid_t ptid, struct target_waitstatus *status)
{
...
h_main_thread=GetCurrentThread();//Added
ofunc = signal (SIGINT, remote_interrupt);
getpkt (&rs->buf, &rs->buf_size, 1);
signal (SIGINT, ofunc);
h_main_thread=0;//Added
....
> Christopher Faylor:
> You'd need to use overlapped I/O for those situations.
If you do that
> then you'd have to decide whether you want gdb to work
on Windows 9x/Me
> or not.
This seems less brute force:
WSARecv(), WSAWaitForMultipleEvents() instead of recv()
and let WSAWaitForMultipleEvents() return through an event
signaled in
interrupt_query()
and if that event happened, continue calling
deprecated_throw_reason
(RETURN_QUIT); this time from the main thread.
|