Fixed hangup in w32 native debugging on dc after ctrl+c

This commit is contained in:
yetmorecode 2015-08-13 14:02:11 +02:00 committed by pancake
parent fa6f91895f
commit 3c6c74555d
2 changed files with 29 additions and 41 deletions

View File

@ -470,42 +470,17 @@ R_API int r_debug_step_over(RDebug *dbg, int steps) {
return i;
}
#if __WINDOWS__
static int winbreak=0;
static void static_debug_native_break(void *d) {
static BOOL WINAPI (*w32_dbgbreak)(HANDLE) = NULL;
static HANDLE WINAPI (*w32_openprocess)(DWORD, BOOL, DWORD) = NULL;
RDebug *dbg = (RDebug *)d;
HANDLE lib;
HANDLE hProcess;
lib = LoadLibrary ("kernel32.dll");
if (!w32_dbgbreak) {
w32_dbgbreak = (HANDLE WINAPI (*)(HANDLE))
GetProcAddress (GetModuleHandle ("kernel32"),
"DebugBreakProcess");
}
if (!w32_openprocess) {
w32_openprocess=(HANDLE WINAPI (*)(DWORD, BOOL, DWORD))
GetProcAddress (GetModuleHandle ("kernel32"),
"OpenProcess");
}
if (w32_dbgbreak!=NULL && w32_openprocess!=NULL) {
hProcess=w32_openprocess(PROCESS_ALL_ACCESS,FALSE, dbg->pid );
winbreak=1;
w32_dbgbreak(hProcess);
CloseHandle(lib);
CloseHandle(hProcess);
}
}
#endif
#if __WINDOWS__
void w32_break_process (void *);
#endif
R_API int r_debug_continue_kill(RDebug *dbg, int sig) {
ut64 pc;
int retwait, ret = R_FALSE;
if (!dbg)
return R_FALSE;
#if __WINDOWS__
r_cons_break(static_debug_native_break,dbg);
r_cons_break(w32_break_process, dbg);
#endif
repeat:
if (r_debug_is_dead (dbg))
@ -516,12 +491,6 @@ repeat:
dbg->signum = 0;
retwait = r_debug_wait (dbg);
#if __WINDOWS__
if (winbreak) {
int tmp=ret;
ret=dbg->tid;
dbg->tid=tmp;
winbreak=0;
}
if (retwait != R_DBG_REASON_DEAD) {
ret = dbg->tid;
}

View File

@ -297,13 +297,12 @@ static int debug_exception_event (DEBUG_EVENT *de) {
case 0x4000001f:
eprintf ("(%d) WOW64 loaded.\n", de->dwProcessId);
return 1;
break;
#endif
/* MS_VC_EXCEPTION */
case 0x406D1388:
eprintf ("(%d) MS_VC_EXCEPTION (%x) in thread %d\n",
de->dwProcessId, code, de->dwThreadId);
break;
return 1;
default:
eprintf ("(%d) Unknown exception %x in thread %d\n",
de->dwProcessId, code, de->dwThreadId);
@ -411,9 +410,8 @@ static int w32_dbg_wait(RDebug *dbg, int pid) {
/* save thread id */
tid = de.dwThreadId;
//pid = de.dwProcessId;
dbg->tid=tid;
dbg->tid = tid;
code = de.dwDebugEventCode;
//eprintf("code: %x pid=%08x tid=%08x\n",code,pid,tid);
/* Ctrl-C? */
/* get kind of event */
switch (code) {
@ -448,12 +446,12 @@ static int w32_dbg_wait(RDebug *dbg, int pid) {
ret = R_DBG_REASON_EXIT_TID;
break;
case LOAD_DLL_DEBUG_EVENT:
dllname = get_file_name_from_handle(de.u.LoadDll.hFile);
dllname = get_file_name_from_handle (de.u.LoadDll.hFile);
eprintf ("(%d) Loading library at %p (%s)\n",
pid, de.u.LoadDll.lpBaseOfDll,
dllname ? dllname : "no name");
if (dllname) {
free(dllname);
free (dllname);
}
r_debug_native_continue (dbg, pid, tid, -1);
next_event = 1;
@ -652,4 +650,25 @@ int w32_terminate_process (RDebug *dbg, int pid) {
return R_TRUE;
}
void w32_break_process (void *d) {
static BOOL WINAPI (*w32_dbgbreak)(HANDLE) = NULL;
RDebug *dbg = (RDebug *)d;
HANDLE lib;
HANDLE process = dbg->process_handle;
lib = LoadLibrary ("kernel32.dll");
if (lib == NULL) {
print_lasterr ((char *)__FUNCTION__, "LoadLibrary");
return;
}
if (!w32_dbgbreak) {
w32_dbgbreak = (HANDLE WINAPI (*)(HANDLE))
GetProcAddress (GetModuleHandle ("kernel32"),
"DebugBreakProcess");
}
if (process != INVALID_HANDLE_VALUE && w32_dbgbreak != NULL) {
w32_dbgbreak (process);
}
CloseHandle (lib);
}
#include "maps/windows.c"