2000-03-08 17:44:54 +01:00
|
|
|
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
/* Wine internal debugger
|
|
|
|
* Interface to Windows debugger API
|
|
|
|
* Eric Pouech (c) 2000
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2000-07-29 23:58:17 +02:00
|
|
|
#include <stdarg.h>
|
2000-03-08 17:44:54 +01:00
|
|
|
#include <stdio.h>
|
2000-04-13 21:31:58 +02:00
|
|
|
#include <string.h>
|
2000-03-08 17:44:54 +01:00
|
|
|
#include "debugger.h"
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2001-05-05 02:44:48 +02:00
|
|
|
#include "ntddk.h"
|
2000-03-26 15:37:39 +02:00
|
|
|
#include "thread.h"
|
2000-05-03 19:48:21 +02:00
|
|
|
#include "wincon.h"
|
2000-03-26 15:37:39 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
DBG_PROCESS* DEBUG_CurrProcess = NULL;
|
|
|
|
DBG_THREAD* DEBUG_CurrThread = NULL;
|
2000-05-11 23:43:43 +02:00
|
|
|
DWORD DEBUG_CurrTid;
|
|
|
|
DWORD DEBUG_CurrPid;
|
2000-03-26 15:37:39 +02:00
|
|
|
CONTEXT DEBUG_context;
|
2001-05-03 20:32:47 +02:00
|
|
|
BOOL DEBUG_interactiveP = FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
int curr_frame = 0;
|
|
|
|
static char* DEBUG_LastCmdLine = NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-06-24 14:52:13 +02:00
|
|
|
static DBG_PROCESS* DEBUG_ProcessList = NULL;
|
2001-10-22 21:00:34 +02:00
|
|
|
static int automatic_mode;
|
2000-04-30 14:21:15 +02:00
|
|
|
DBG_INTVAR DEBUG_IntVars[DBG_IV_LAST];
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
void DEBUG_Output(int chn, const char* buffer, int len)
|
|
|
|
{
|
|
|
|
if (DBG_IVAR(ConChannelMask) & chn)
|
|
|
|
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buffer, len, NULL, NULL);
|
|
|
|
if (DBG_IVAR(StdChannelMask) & chn)
|
|
|
|
fwrite(buffer, len, 1, stderr);
|
|
|
|
}
|
2000-04-13 21:31:58 +02:00
|
|
|
|
|
|
|
int DEBUG_Printf(int chn, const char* format, ...)
|
|
|
|
{
|
2001-05-03 20:32:47 +02:00
|
|
|
static char buf[4*1024];
|
2000-04-13 21:31:58 +02:00
|
|
|
va_list valist;
|
2000-04-30 14:21:15 +02:00
|
|
|
int len;
|
2000-04-13 21:31:58 +02:00
|
|
|
|
|
|
|
va_start(valist, format);
|
2000-07-29 23:58:17 +02:00
|
|
|
len = vsnprintf(buf, sizeof(buf), format, valist);
|
2000-04-13 21:31:58 +02:00
|
|
|
va_end(valist);
|
2000-05-05 20:14:34 +02:00
|
|
|
|
|
|
|
if (len <= -1) {
|
|
|
|
len = sizeof(buf) - 1;
|
|
|
|
buf[len] = 0;
|
|
|
|
buf[len - 1] = buf[len - 2] = buf[len - 3] = '.';
|
|
|
|
}
|
2000-04-30 14:21:15 +02:00
|
|
|
DEBUG_Output(chn, buf, len);
|
|
|
|
return len;
|
2000-04-13 21:31:58 +02:00
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
static BOOL DEBUG_IntVarsRW(int read)
|
2000-03-26 15:37:39 +02:00
|
|
|
{
|
|
|
|
HKEY hkey;
|
2000-04-30 14:21:15 +02:00
|
|
|
DWORD type = REG_DWORD;
|
2000-03-26 15:37:39 +02:00
|
|
|
DWORD val;
|
|
|
|
DWORD count = sizeof(val);
|
2000-04-30 14:21:15 +02:00
|
|
|
int i;
|
|
|
|
DBG_INTVAR* div = DEBUG_IntVars;
|
|
|
|
|
|
|
|
if (read) {
|
|
|
|
/* initializes internal vars table */
|
|
|
|
#define INTERNAL_VAR(_var,_val,_ref,_typ) \
|
|
|
|
div->val = _val; div->name = #_var; div->pval = _ref; \
|
|
|
|
div->type = _typ; div++;
|
2000-04-13 21:31:58 +02:00
|
|
|
#include "intvar.h"
|
|
|
|
#undef INTERNAL_VAR
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2000-05-11 23:43:43 +02:00
|
|
|
if (RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey)) {
|
2000-05-01 16:22:02 +02:00
|
|
|
/* since the IVars are not yet setup, DEBUG_Printf doesn't work,
|
|
|
|
* so don't use it */
|
|
|
|
fprintf(stderr, "Cannot create WineDbg key in registry\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < DBG_IV_LAST; i++) {
|
|
|
|
if (read) {
|
|
|
|
if (!DEBUG_IntVars[i].pval) {
|
|
|
|
if (!RegQueryValueEx(hkey, DEBUG_IntVars[i].name, 0,
|
|
|
|
&type, (LPSTR)&val, &count))
|
|
|
|
DEBUG_IntVars[i].val = val;
|
|
|
|
DEBUG_IntVars[i].pval = &DEBUG_IntVars[i].val;
|
2000-04-30 14:21:15 +02:00
|
|
|
} else {
|
2000-05-01 16:22:02 +02:00
|
|
|
*DEBUG_IntVars[i].pval = 0;
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
2000-05-01 16:22:02 +02:00
|
|
|
} else {
|
|
|
|
/* FIXME: type should be infered from basic type -if any- of intvar */
|
|
|
|
if (DEBUG_IntVars[i].pval == &DEBUG_IntVars[i].val)
|
|
|
|
RegSetValueEx(hkey, DEBUG_IntVars[i].name, 0,
|
|
|
|
type, (LPCVOID)DEBUG_IntVars[i].pval, count);
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
}
|
2000-05-01 16:22:02 +02:00
|
|
|
RegCloseKey(hkey);
|
2000-03-26 15:37:39 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2000-04-30 14:21:15 +02:00
|
|
|
|
|
|
|
DBG_INTVAR* DEBUG_GetIntVar(const char* name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < DBG_IV_LAST; i++) {
|
|
|
|
if (!strcmp(DEBUG_IntVars[i].name, name))
|
|
|
|
return &DEBUG_IntVars[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
|
|
|
static WINE_EXCEPTION_FILTER(wine_dbg)
|
|
|
|
{
|
2000-05-05 20:14:34 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "\nwine_dbg: Exception (%lx) inside debugger, continuing...\n", GetExceptionCode());
|
2000-03-26 15:37:39 +02:00
|
|
|
DEBUG_ExternalDebugger();
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2001-08-06 19:51:52 +02:00
|
|
|
DBG_PROCESS* DEBUG_GetProcess(DWORD pid)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2000-03-26 15:37:39 +02:00
|
|
|
DBG_PROCESS* p;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-06-24 14:52:13 +02:00
|
|
|
for (p = DEBUG_ProcessList; p; p = p->next)
|
2000-03-08 17:44:54 +01:00
|
|
|
if (p->pid == pid) break;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2001-08-06 19:51:52 +02:00
|
|
|
static DBG_PROCESS* DEBUG_AddProcess(DWORD pid, HANDLE h, const char* imageName)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2000-03-26 15:37:39 +02:00
|
|
|
DBG_PROCESS* p = DBG_alloc(sizeof(DBG_PROCESS));
|
2000-03-08 17:44:54 +01:00
|
|
|
if (!p)
|
|
|
|
return NULL;
|
|
|
|
p->handle = h;
|
|
|
|
p->pid = pid;
|
2001-08-06 19:51:52 +02:00
|
|
|
p->imageName = imageName ? DBG_strdup(imageName) : NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
p->threads = NULL;
|
2000-03-26 15:37:39 +02:00
|
|
|
p->num_threads = 0;
|
2000-05-05 20:14:34 +02:00
|
|
|
p->continue_on_first_exception = FALSE;
|
2000-03-26 15:37:39 +02:00
|
|
|
p->modules = NULL;
|
2000-11-15 23:16:26 +01:00
|
|
|
p->num_modules = 0;
|
2000-03-26 15:37:39 +02:00
|
|
|
p->next_index = 0;
|
2000-05-05 20:14:34 +02:00
|
|
|
p->dbg_hdr_addr = 0;
|
2001-05-21 20:33:15 +02:00
|
|
|
p->delayed_bp = NULL;
|
|
|
|
p->num_delayed_bp = 0;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-06-24 14:52:13 +02:00
|
|
|
p->next = DEBUG_ProcessList;
|
2000-03-08 17:44:54 +01:00
|
|
|
p->prev = NULL;
|
2000-06-24 14:52:13 +02:00
|
|
|
if (DEBUG_ProcessList) DEBUG_ProcessList->prev = p;
|
|
|
|
DEBUG_ProcessList = p;
|
2000-03-08 17:44:54 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
static void DEBUG_DelThread(DBG_THREAD* p);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
static void DEBUG_DelProcess(DBG_PROCESS* p)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2001-05-21 20:33:15 +02:00
|
|
|
int i;
|
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
if (p->threads != NULL) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Shouldn't happen\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
while (p->threads) DEBUG_DelThread(p->threads);
|
|
|
|
}
|
2001-05-21 20:33:15 +02:00
|
|
|
for (i = 0; i < p->num_delayed_bp; i++) {
|
|
|
|
DBG_free(p->delayed_bp[i].name);
|
|
|
|
}
|
|
|
|
DBG_free(p->delayed_bp);
|
2000-03-08 17:44:54 +01:00
|
|
|
if (p->prev) p->prev->next = p->next;
|
|
|
|
if (p->next) p->next->prev = p->prev;
|
2000-06-24 14:52:13 +02:00
|
|
|
if (p == DEBUG_ProcessList) DEBUG_ProcessList = p->next;
|
2000-06-18 21:30:24 +02:00
|
|
|
if (p == DEBUG_CurrProcess) DEBUG_CurrProcess = NULL;
|
2001-08-06 19:51:52 +02:00
|
|
|
DBG_free((char*)p->imageName);
|
2000-03-08 17:44:54 +01:00
|
|
|
DBG_free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DEBUG_InitCurrProcess(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-03-10 23:25:07 +01:00
|
|
|
static BOOL DEBUG_ProcessGetString(char* buffer, int size, HANDLE hp, LPSTR addr)
|
|
|
|
{
|
|
|
|
DWORD sz;
|
|
|
|
*(WCHAR*)buffer = 0;
|
|
|
|
return (addr && ReadProcessMemory(hp, addr, buffer, size, &sz));
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL DEBUG_ProcessGetStringIndirect(char* buffer, int size, HANDLE hp, LPVOID addr)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
|
|
|
LPVOID ad;
|
|
|
|
DWORD sz;
|
|
|
|
|
|
|
|
if ( addr
|
|
|
|
&& ReadProcessMemory(hp, addr, &ad, sizeof(ad), &sz)
|
|
|
|
&& sz == sizeof(ad)
|
|
|
|
&& ad
|
|
|
|
&& ReadProcessMemory(hp, ad, buffer, size, &sz))
|
|
|
|
return TRUE;
|
|
|
|
*(WCHAR*)buffer = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-08-06 19:51:52 +02:00
|
|
|
DBG_THREAD* DEBUG_GetThread(DBG_PROCESS* p, DWORD tid)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2000-03-26 15:37:39 +02:00
|
|
|
DBG_THREAD* t;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
|
|
|
for (t = p->threads; t; t = t->next)
|
|
|
|
if (t->tid == tid) break;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
static DBG_THREAD* DEBUG_AddThread(DBG_PROCESS* p, DWORD tid,
|
|
|
|
HANDLE h, LPVOID start, LPVOID teb)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2000-03-26 15:37:39 +02:00
|
|
|
DBG_THREAD* t = DBG_alloc(sizeof(DBG_THREAD));
|
2000-03-08 17:44:54 +01:00
|
|
|
if (!t)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
t->handle = h;
|
|
|
|
t->tid = tid;
|
|
|
|
t->start = start;
|
|
|
|
t->teb = teb;
|
|
|
|
t->process = p;
|
|
|
|
t->wait_for_first_exception = 0;
|
|
|
|
t->dbg_exec_mode = EXEC_CONT;
|
|
|
|
t->dbg_exec_count = 0;
|
2001-04-14 00:26:23 +02:00
|
|
|
sprintf(t->name, "%08lx", tid);
|
2000-03-26 15:37:39 +02:00
|
|
|
|
|
|
|
p->num_threads++;
|
2000-03-08 17:44:54 +01:00
|
|
|
t->next = p->threads;
|
|
|
|
t->prev = NULL;
|
|
|
|
if (p->threads) p->threads->prev = t;
|
|
|
|
p->threads = t;
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DEBUG_InitCurrThread(void)
|
|
|
|
{
|
|
|
|
if (DEBUG_CurrThread->start) {
|
2000-04-13 21:31:58 +02:00
|
|
|
if (DEBUG_CurrThread->process->num_threads == 1 ||
|
|
|
|
DBG_IVAR(BreakAllThreadsStartup)) {
|
2000-03-26 15:37:39 +02:00
|
|
|
DBG_VALUE value;
|
|
|
|
|
|
|
|
DEBUG_SetBreakpoints(FALSE);
|
|
|
|
value.type = NULL;
|
|
|
|
value.cookie = DV_TARGET;
|
|
|
|
value.addr.seg = 0;
|
|
|
|
value.addr.off = (DWORD)DEBUG_CurrThread->start;
|
2000-05-05 20:14:34 +02:00
|
|
|
DEBUG_AddBreakpoint(&value, NULL);
|
2000-03-26 15:37:39 +02:00
|
|
|
DEBUG_SetBreakpoints(TRUE);
|
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
} else {
|
|
|
|
DEBUG_CurrThread->wait_for_first_exception = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
static void DEBUG_DelThread(DBG_THREAD* t)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
|
|
|
if (t->prev) t->prev->next = t->next;
|
|
|
|
if (t->next) t->next->prev = t->prev;
|
|
|
|
if (t == t->process->threads) t->process->threads = t->next;
|
2000-03-26 15:37:39 +02:00
|
|
|
t->process->num_threads--;
|
2000-06-18 21:30:24 +02:00
|
|
|
if (t == DEBUG_CurrThread) DEBUG_CurrThread = NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
DBG_free(t);
|
|
|
|
}
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
BOOL DEBUG_Attach(DWORD pid, BOOL cofe)
|
|
|
|
{
|
2001-08-06 19:51:52 +02:00
|
|
|
if (!(DEBUG_CurrProcess = DEBUG_AddProcess(pid, 0, NULL))) return FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
|
|
|
if (!DebugActiveProcess(pid)) {
|
2001-07-11 19:33:08 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Can't attach process %lx: error %ld\n", pid, GetLastError());
|
|
|
|
DEBUG_DelProcess(DEBUG_CurrProcess);
|
|
|
|
DEBUG_CurrProcess = NULL;
|
2000-06-18 21:30:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
DEBUG_CurrProcess->continue_on_first_exception = cofe;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL DEBUG_ExceptionProlog(BOOL is_debug, BOOL force, DWORD code)
|
|
|
|
{
|
|
|
|
DBG_ADDR addr;
|
|
|
|
int newmode;
|
|
|
|
|
|
|
|
DEBUG_GetCurrentAddress(&addr);
|
|
|
|
DEBUG_SuspendExecution();
|
|
|
|
|
|
|
|
if (!is_debug) {
|
2000-09-24 05:15:50 +02:00
|
|
|
if (!addr.seg)
|
2001-08-15 19:40:31 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, " in 32-bit code (0x%08lx)", addr.off);
|
2000-06-18 21:30:24 +02:00
|
|
|
else
|
2000-09-24 05:15:50 +02:00
|
|
|
switch(DEBUG_GetSelectorType(addr.seg))
|
|
|
|
{
|
|
|
|
case MODE_32:
|
2001-08-15 19:40:31 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, " in 32-bit code (%04lx:%08lx)", addr.seg, addr.off);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case MODE_16:
|
2001-08-15 19:40:31 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, " in 16-bit code (%04lx:%04lx)", addr.seg, addr.off);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case MODE_VM86:
|
2001-08-15 19:40:31 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, " in vm86 code (%04lx:%04lx)", addr.seg, addr.off);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case MODE_INVALID:
|
2001-08-15 19:40:31 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, " bad CS (%lx)", addr.seg);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
}
|
2001-08-15 19:40:31 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, ".\n");
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2001-08-15 19:40:31 +02:00
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_LoadEntryPoints("Loading new modules symbols:\n");
|
|
|
|
|
|
|
|
if (!force && is_debug &&
|
2000-09-01 03:22:05 +02:00
|
|
|
DEBUG_ShouldContinue(&addr,
|
|
|
|
code,
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_CurrThread->dbg_exec_mode,
|
|
|
|
&DEBUG_CurrThread->dbg_exec_count))
|
|
|
|
return FALSE;
|
|
|
|
|
2000-09-24 05:15:50 +02:00
|
|
|
if ((newmode = DEBUG_GetSelectorType(addr.seg)) == MODE_INVALID) newmode = MODE_32;
|
2000-06-18 21:30:24 +02:00
|
|
|
if (newmode != DEBUG_CurrThread->dbg_mode)
|
2000-09-24 05:15:50 +02:00
|
|
|
{
|
|
|
|
static const char * const names[] = { "???", "16-bit", "32-bit", "vm86" };
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG,"In %s mode.\n", names[newmode] );
|
|
|
|
DEBUG_CurrThread->dbg_mode = newmode;
|
|
|
|
}
|
2000-06-18 21:30:24 +02:00
|
|
|
|
|
|
|
DEBUG_DoDisplay();
|
|
|
|
|
|
|
|
if (is_debug || force) {
|
|
|
|
/*
|
|
|
|
* Do a quiet backtrace so that we have an idea of what the situation
|
|
|
|
* is WRT the source files.
|
|
|
|
*/
|
2001-08-06 19:51:52 +02:00
|
|
|
DEBUG_BackTrace(DEBUG_CurrTid, FALSE);
|
2000-06-18 21:30:24 +02:00
|
|
|
} else {
|
|
|
|
/* This is a real crash, dump some info */
|
|
|
|
DEBUG_InfoRegisters();
|
|
|
|
DEBUG_InfoStack();
|
|
|
|
#ifdef __i386__
|
2000-09-24 05:15:50 +02:00
|
|
|
if (DEBUG_CurrThread->dbg_mode == MODE_16) {
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_InfoSegments(DEBUG_context.SegDs >> 3, 1);
|
|
|
|
if (DEBUG_context.SegEs != DEBUG_context.SegDs)
|
|
|
|
DEBUG_InfoSegments(DEBUG_context.SegEs >> 3, 1);
|
|
|
|
}
|
|
|
|
DEBUG_InfoSegments(DEBUG_context.SegFs >> 3, 1);
|
|
|
|
#endif
|
2001-08-06 19:51:52 +02:00
|
|
|
DEBUG_BackTrace(DEBUG_CurrTid, TRUE);
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_debug ||
|
|
|
|
(DEBUG_CurrThread->dbg_exec_mode == EXEC_STEPI_OVER) ||
|
|
|
|
(DEBUG_CurrThread->dbg_exec_mode == EXEC_STEPI_INSTR)) {
|
2000-07-25 14:51:56 +02:00
|
|
|
|
|
|
|
struct list_id list;
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
/* Show where we crashed */
|
|
|
|
curr_frame = 0;
|
2000-07-25 14:51:56 +02:00
|
|
|
DEBUG_DisassembleInstruction(&addr);
|
|
|
|
|
|
|
|
/* resets list internal arguments so we can look at source code when needed */
|
|
|
|
DEBUG_FindNearestSymbol(&addr, TRUE, NULL, 0, &list);
|
|
|
|
if (list.sourcefile) DEBUG_List(&list, NULL, 0);
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD DEBUG_ExceptionEpilog(void)
|
|
|
|
{
|
|
|
|
DEBUG_CurrThread->dbg_exec_mode = DEBUG_RestartExecution(DEBUG_CurrThread->dbg_exec_mode,
|
|
|
|
DEBUG_CurrThread->dbg_exec_count);
|
|
|
|
/*
|
|
|
|
* This will have gotten absorbed into the breakpoint info
|
|
|
|
* if it was used. Otherwise it would have been ignored.
|
|
|
|
* In any case, we don't mess with it any more.
|
|
|
|
*/
|
|
|
|
if (DEBUG_CurrThread->dbg_exec_mode == EXEC_CONT || DEBUG_CurrThread->dbg_exec_mode == EXEC_PASS)
|
|
|
|
DEBUG_CurrThread->dbg_exec_count = 0;
|
|
|
|
|
|
|
|
return (DEBUG_CurrThread->dbg_exec_mode == EXEC_PASS) ? DBG_EXCEPTION_NOT_HANDLED : DBG_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL force, LPDWORD cont)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2001-04-09 20:31:47 +02:00
|
|
|
BOOL is_debug = FALSE;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
THREADNAME_INFO *pThreadName;
|
|
|
|
DBG_THREAD *pThread;
|
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
*cont = DBG_CONTINUE;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
|
|
|
switch (rec->ExceptionCode)
|
|
|
|
{
|
|
|
|
case EXCEPTION_BREAKPOINT:
|
|
|
|
case EXCEPTION_SINGLE_STEP:
|
|
|
|
is_debug = TRUE;
|
|
|
|
break;
|
2001-04-09 20:31:47 +02:00
|
|
|
case EXCEPTION_NAME_THREAD:
|
|
|
|
pThreadName = (THREADNAME_INFO*)(rec->ExceptionInformation);
|
|
|
|
if (pThreadName->dwThreadID == -1)
|
|
|
|
pThread = DEBUG_CurrThread;
|
|
|
|
else
|
|
|
|
pThread = DEBUG_GetThread(DEBUG_CurrProcess, pThreadName->dwThreadID);
|
|
|
|
|
|
|
|
if (ReadProcessMemory(DEBUG_CurrThread->process->handle, pThreadName->szName,
|
|
|
|
pThread->name, 9, NULL))
|
|
|
|
DEBUG_Printf (DBG_CHN_MESG,
|
|
|
|
"Thread ID=0x%lx renamed using MS VC6 extension (name==\"%s\")\n",
|
|
|
|
pThread->tid, pThread->name);
|
|
|
|
return TRUE;
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2001-10-04 18:17:16 +02:00
|
|
|
if (first_chance && !is_debug && !force && !DBG_IVAR(BreakOnFirstChance))
|
2000-09-24 05:15:50 +02:00
|
|
|
{
|
|
|
|
/* pass exception to program except for debug exceptions */
|
|
|
|
*cont = is_debug ? DBG_CONTINUE : DBG_EXCEPTION_NOT_HANDLED;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
if (!is_debug)
|
|
|
|
{
|
|
|
|
/* print some infos */
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "%s: ",
|
|
|
|
first_chance ? "First chance exception" : "Unhandled exception");
|
2000-05-05 20:14:34 +02:00
|
|
|
switch (rec->ExceptionCode)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
|
|
|
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "divide by zero");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_INT_OVERFLOW:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "overflow");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "array bounds ");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "illegal instruction");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_STACK_OVERFLOW:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "stack overflow");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_PRIV_INSTRUCTION:
|
2001-10-21 17:18:15 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "privileged instruction");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
|
|
|
if (rec->NumberParameters == 2)
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "page fault on %s access to 0x%08lx",
|
2000-04-13 21:31:58 +02:00
|
|
|
rec->ExceptionInformation[0] ? "write" : "read",
|
2000-06-18 21:30:24 +02:00
|
|
|
rec->ExceptionInformation[1]);
|
2000-03-08 17:44:54 +01:00
|
|
|
else
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "page fault");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_DATATYPE_MISALIGNMENT:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Alignment");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
2001-11-24 00:10:08 +01:00
|
|
|
case DBG_CONTROL_C:
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "^C");
|
|
|
|
break;
|
2000-03-08 17:44:54 +01:00
|
|
|
case CONTROL_C_EXIT:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "^C");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_CRITICAL_SECTION_WAIT:
|
2001-08-07 21:32:14 +02:00
|
|
|
{
|
|
|
|
DBG_ADDR addr;
|
|
|
|
|
|
|
|
addr.seg = 0;
|
|
|
|
addr.off = rec->ExceptionInformation[0];
|
|
|
|
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "wait failed on critical section ");
|
|
|
|
DEBUG_PrintAddress(&addr, DEBUG_CurrThread->dbg_mode, FALSE);
|
|
|
|
}
|
2000-04-30 14:21:15 +02:00
|
|
|
if (!DBG_IVAR(BreakOnCritSectTimeOut))
|
2000-09-13 01:40:40 +02:00
|
|
|
{
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "\n");
|
2000-06-18 21:30:24 +02:00
|
|
|
return TRUE;
|
2000-09-13 01:40:40 +02:00
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
2000-10-27 00:03:34 +02:00
|
|
|
case EXCEPTION_WINE_STUB:
|
|
|
|
{
|
|
|
|
char dll[32], name[64];
|
|
|
|
DEBUG_ProcessGetString( dll, sizeof(dll), DEBUG_CurrThread->process->handle,
|
|
|
|
(char *)rec->ExceptionInformation[0] );
|
|
|
|
DEBUG_ProcessGetString( name, sizeof(name), DEBUG_CurrThread->process->handle,
|
|
|
|
(char *)rec->ExceptionInformation[1] );
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "unimplemented function %s.%s called", dll, name );
|
|
|
|
}
|
|
|
|
break;
|
2000-09-24 05:15:50 +02:00
|
|
|
case EXCEPTION_VM86_INTx:
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "interrupt %02lx in vm86 mode",
|
|
|
|
rec->ExceptionInformation[0]);
|
|
|
|
break;
|
|
|
|
case EXCEPTION_VM86_STI:
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "sti in vm86 mode");
|
|
|
|
break;
|
|
|
|
case EXCEPTION_VM86_PICRETURN:
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "PIC return in vm86 mode");
|
|
|
|
break;
|
2000-03-08 17:44:54 +01:00
|
|
|
default:
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "%08lx", rec->ExceptionCode);
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-15 19:40:31 +02:00
|
|
|
#if 0
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE,
|
|
|
|
"Entering debugger PC=%lx EFL=%08lx mode=%d count=%d\n",
|
2000-06-04 03:33:21 +02:00
|
|
|
#ifdef __i386__
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_context.Eip, DEBUG_context.EFlags,
|
2000-06-04 03:33:21 +02:00
|
|
|
#else
|
|
|
|
0L, 0L,
|
|
|
|
#endif
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_CurrThread->dbg_exec_mode, DEBUG_CurrThread->dbg_exec_count);
|
2001-08-15 19:40:31 +02:00
|
|
|
#endif
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2001-10-22 21:00:34 +02:00
|
|
|
if (automatic_mode)
|
|
|
|
{
|
|
|
|
DEBUG_ExceptionProlog(is_debug, FALSE, rec->ExceptionCode);
|
|
|
|
return FALSE; /* terminate execution */
|
|
|
|
}
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
if (DEBUG_ExceptionProlog(is_debug, force, rec->ExceptionCode)) {
|
2001-05-03 20:32:47 +02:00
|
|
|
DEBUG_interactiveP = TRUE;
|
2000-06-25 14:49:13 +02:00
|
|
|
while ((ret = DEBUG_Parser())) {
|
|
|
|
if (DEBUG_ValidateRegisters()) {
|
|
|
|
if (DEBUG_CurrThread->dbg_exec_mode != EXEC_PASS || first_chance)
|
|
|
|
break;
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Cannot pass on last chance exception. You must use cont\n");
|
|
|
|
}
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2001-05-03 20:32:47 +02:00
|
|
|
DEBUG_interactiveP = FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
|
|
|
*cont = DEBUG_ExceptionEpilog();
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2001-08-15 19:40:31 +02:00
|
|
|
#if 0
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE,
|
|
|
|
"Exiting debugger PC=%lx EFL=%08lx mode=%d count=%d\n",
|
2000-06-04 03:33:21 +02:00
|
|
|
#ifdef __i386__
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_context.Eip, DEBUG_context.EFlags,
|
2000-06-04 03:33:21 +02:00
|
|
|
#else
|
|
|
|
0L, 0L,
|
|
|
|
#endif
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_CurrThread->dbg_exec_mode, DEBUG_CurrThread->dbg_exec_count);
|
2001-08-15 19:40:31 +02:00
|
|
|
#endif
|
2000-03-08 17:44:54 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-04-13 21:31:58 +02:00
|
|
|
static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
|
|
|
char buffer[256];
|
2000-04-13 21:31:58 +02:00
|
|
|
BOOL ret;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2000-05-11 23:43:43 +02:00
|
|
|
DEBUG_CurrPid = de->dwProcessId;
|
|
|
|
DEBUG_CurrTid = de->dwThreadId;
|
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
__TRY {
|
2000-04-13 21:31:58 +02:00
|
|
|
ret = TRUE;
|
|
|
|
*cont = 0L;
|
2000-03-26 15:37:39 +02:00
|
|
|
|
|
|
|
if ((DEBUG_CurrProcess = DEBUG_GetProcess(de->dwProcessId)) != NULL)
|
|
|
|
DEBUG_CurrThread = DEBUG_GetThread(DEBUG_CurrProcess, de->dwThreadId);
|
2000-03-08 17:44:54 +01:00
|
|
|
else
|
|
|
|
DEBUG_CurrThread = NULL;
|
2000-03-26 15:37:39 +02:00
|
|
|
|
|
|
|
switch (de->dwDebugEventCode) {
|
2000-03-08 17:44:54 +01:00
|
|
|
case EXCEPTION_DEBUG_EVENT:
|
2000-04-13 21:31:58 +02:00
|
|
|
if (!DEBUG_CurrThread) {
|
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "%08lx:%08lx: not a registered process or thread (perhaps a 16 bit one ?)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId);
|
|
|
|
break;
|
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-05-05 20:14:34 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: exception code=%08lx\n",
|
2000-04-13 21:31:58 +02:00
|
|
|
de->dwProcessId, de->dwThreadId,
|
2000-05-05 20:14:34 +02:00
|
|
|
de->u.Exception.ExceptionRecord.ExceptionCode);
|
|
|
|
|
|
|
|
if (DEBUG_CurrProcess->continue_on_first_exception) {
|
|
|
|
DEBUG_CurrProcess->continue_on_first_exception = FALSE;
|
|
|
|
if (!DBG_IVAR(BreakOnAttach)) {
|
|
|
|
*cont = DBG_CONTINUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-04 03:33:21 +02:00
|
|
|
DEBUG_context.ContextFlags = CONTEXT_CONTROL
|
|
|
|
| CONTEXT_INTEGER
|
|
|
|
#ifdef CONTEXT_SEGMENTS
|
|
|
|
| CONTEXT_SEGMENTS
|
|
|
|
#endif
|
|
|
|
#ifdef CONTEXT_DEBUG_REGISTERS
|
|
|
|
| CONTEXT_DEBUG_REGISTERS
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
if (!GetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context)) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_WARN, "Can't get thread's context\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
ret = DEBUG_HandleException(&de->u.Exception.ExceptionRecord,
|
|
|
|
de->u.Exception.dwFirstChance,
|
|
|
|
DEBUG_CurrThread->wait_for_first_exception,
|
|
|
|
cont);
|
|
|
|
if (DEBUG_CurrThread) {
|
2000-03-08 17:44:54 +01:00
|
|
|
DEBUG_CurrThread->wait_for_first_exception = 0;
|
2000-04-13 21:31:58 +02:00
|
|
|
SetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context);
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CREATE_THREAD_DEBUG_EVENT:
|
2000-05-11 23:43:43 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread D @%08lx\n", de->dwProcessId, de->dwThreadId,
|
|
|
|
(unsigned long)(LPVOID)de->u.CreateThread.lpStartAddress);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
|
|
|
if (DEBUG_CurrProcess == NULL) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Unknown process\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
if (DEBUG_GetThread(DEBUG_CurrProcess, de->dwThreadId) != NULL) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "Thread already listed, skipping\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
DEBUG_CurrThread = DEBUG_AddThread(DEBUG_CurrProcess,
|
2000-03-26 15:37:39 +02:00
|
|
|
de->dwThreadId,
|
|
|
|
de->u.CreateThread.hThread,
|
|
|
|
de->u.CreateThread.lpStartAddress,
|
|
|
|
de->u.CreateThread.lpThreadLocalBase);
|
2000-03-08 17:44:54 +01:00
|
|
|
if (!DEBUG_CurrThread) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Couldn't create thread\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
DEBUG_InitCurrThread();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CREATE_PROCESS_DEBUG_EVENT:
|
2000-03-10 23:25:07 +01:00
|
|
|
DEBUG_ProcessGetStringIndirect(buffer, sizeof(buffer),
|
2000-03-26 15:37:39 +02:00
|
|
|
de->u.CreateProcessInfo.hProcess,
|
2000-04-13 21:31:58 +02:00
|
|
|
de->u.CreateProcessInfo.lpImageName);
|
2001-08-06 19:51:52 +02:00
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
/* FIXME unicode ? de->u.CreateProcessInfo.fUnicode */
|
2001-08-06 19:51:52 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create process '%s'/%p @%08lx (%ld<%ld>)\n",
|
2000-04-13 21:31:58 +02:00
|
|
|
de->dwProcessId, de->dwThreadId,
|
2001-08-06 19:51:52 +02:00
|
|
|
buffer, de->u.CreateProcessInfo.lpImageName,
|
2000-05-11 23:43:43 +02:00
|
|
|
(unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress,
|
2000-04-13 21:31:58 +02:00
|
|
|
de->u.CreateProcessInfo.dwDebugInfoFileOffset,
|
|
|
|
de->u.CreateProcessInfo.nDebugInfoSize);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-05-05 20:14:34 +02:00
|
|
|
if ((DEBUG_CurrProcess = DEBUG_GetProcess(de->dwProcessId)) != NULL) {
|
|
|
|
if (DEBUG_CurrProcess->handle) {
|
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Skipping already defined process\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DEBUG_CurrProcess->handle = de->u.CreateProcessInfo.hProcess;
|
2001-08-06 19:51:52 +02:00
|
|
|
if (DEBUG_CurrProcess->imageName == NULL)
|
|
|
|
DEBUG_CurrProcess->imageName = DBG_strdup(buffer[0] ? buffer : "<Debugged Process>");
|
|
|
|
|
2000-05-05 20:14:34 +02:00
|
|
|
} else {
|
|
|
|
DEBUG_CurrProcess = DEBUG_AddProcess(de->dwProcessId,
|
2001-08-06 19:51:52 +02:00
|
|
|
de->u.CreateProcessInfo.hProcess,
|
|
|
|
buffer[0] ? buffer : "<Debugged Process>");
|
2000-05-05 20:14:34 +02:00
|
|
|
if (DEBUG_CurrProcess == NULL) {
|
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Unknown process\n");
|
|
|
|
break;
|
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2000-05-11 23:43:43 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread I @%08lx\n",
|
2000-04-13 21:31:58 +02:00
|
|
|
de->dwProcessId, de->dwThreadId,
|
2000-05-11 23:43:43 +02:00
|
|
|
(unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
|
|
|
DEBUG_CurrThread = DEBUG_AddThread(DEBUG_CurrProcess,
|
2000-03-26 15:37:39 +02:00
|
|
|
de->dwThreadId,
|
|
|
|
de->u.CreateProcessInfo.hThread,
|
|
|
|
de->u.CreateProcessInfo.lpStartAddress,
|
|
|
|
de->u.CreateProcessInfo.lpThreadLocalBase);
|
2000-03-08 17:44:54 +01:00
|
|
|
if (!DEBUG_CurrThread) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Couldn't create thread\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_InitCurrProcess();
|
|
|
|
DEBUG_InitCurrThread();
|
2000-06-08 07:02:19 +02:00
|
|
|
|
2001-08-06 19:51:52 +02:00
|
|
|
DEBUG_LoadModule32(DEBUG_CurrProcess->imageName, de->u.CreateProcessInfo.hFile,
|
2000-04-13 21:31:58 +02:00
|
|
|
(DWORD)de->u.CreateProcessInfo.lpBaseOfImage);
|
2000-06-08 07:02:19 +02:00
|
|
|
|
|
|
|
if (buffer[0]) /* we got a process name */
|
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
if (!GetBinaryTypeA( buffer, &type ))
|
|
|
|
{
|
|
|
|
/* not a Windows binary, assume it's a Unix executable then */
|
2000-12-06 04:20:47 +01:00
|
|
|
char unixname[MAX_PATH];
|
2000-06-08 07:02:19 +02:00
|
|
|
/* HACK!! should fix DEBUG_ReadExecutableDbgInfo to accept DOS filenames */
|
2000-12-06 04:20:47 +01:00
|
|
|
if (wine_get_unix_file_name( buffer, unixname, sizeof(unixname) ))
|
2000-06-08 07:02:19 +02:00
|
|
|
{
|
2000-12-06 04:20:47 +01:00
|
|
|
DEBUG_ReadExecutableDbgInfo( unixname );
|
2000-06-08 07:02:19 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if it is a Windows binary, or an invalid or missing file name,
|
|
|
|
* we use wine itself as the main executable */
|
|
|
|
DEBUG_ReadExecutableDbgInfo( "wine" );
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EXIT_THREAD_DEBUG_EVENT:
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: exit thread (%ld)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->u.ExitThread.dwExitCode);
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
if (DEBUG_CurrThread == NULL) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Unknown thread\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FIXME: remove break point set on thread startup */
|
|
|
|
DEBUG_DelThread(DEBUG_CurrThread);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: exit process (%ld)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->u.ExitProcess.dwExitCode);
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
if (DEBUG_CurrProcess == NULL) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Unknown process\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-04-13 21:31:58 +02:00
|
|
|
/* just in case */
|
|
|
|
DEBUG_SetBreakpoints(FALSE);
|
2000-03-08 17:44:54 +01:00
|
|
|
/* kill last thread */
|
|
|
|
DEBUG_DelThread(DEBUG_CurrProcess->threads);
|
|
|
|
DEBUG_DelProcess(DEBUG_CurrProcess);
|
2000-06-18 21:30:24 +02:00
|
|
|
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Process of pid=%08lx has terminated\n", DEBUG_CurrPid);
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_DLL_DEBUG_EVENT:
|
|
|
|
if (DEBUG_CurrThread == NULL) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Unknown thread\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-03-10 23:25:07 +01:00
|
|
|
DEBUG_ProcessGetStringIndirect(buffer, sizeof(buffer),
|
|
|
|
DEBUG_CurrThread->process->handle,
|
2000-03-26 15:37:39 +02:00
|
|
|
de->u.LoadDll.lpImageName);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
/* FIXME unicode: de->u.LoadDll.fUnicode */
|
2000-05-11 23:43:43 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: loads DLL %s @%08lx (%ld<%ld>)\n",
|
2000-04-13 21:31:58 +02:00
|
|
|
de->dwProcessId, de->dwThreadId,
|
2000-05-11 23:43:43 +02:00
|
|
|
buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll,
|
2000-04-13 21:31:58 +02:00
|
|
|
de->u.LoadDll.dwDebugInfoFileOffset,
|
|
|
|
de->u.LoadDll.nDebugInfoSize);
|
2001-05-05 02:44:48 +02:00
|
|
|
_strupr(buffer);
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_LoadModule32(buffer, de->u.LoadDll.hFile, (DWORD)de->u.LoadDll.lpBaseOfDll);
|
2001-05-21 20:33:15 +02:00
|
|
|
DEBUG_CheckDelayedBP();
|
2000-07-10 15:05:44 +02:00
|
|
|
if (DBG_IVAR(BreakOnDllLoad)) {
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Stopping on DLL %s loading at %08lx\n",
|
|
|
|
buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll);
|
|
|
|
ret = DEBUG_Parser();
|
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNLOAD_DLL_DEBUG_EVENT:
|
2000-05-11 23:43:43 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: unload DLL @%08lx\n", de->dwProcessId, de->dwThreadId,
|
|
|
|
(unsigned long)de->u.UnloadDll.lpBaseOfDll);
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OUTPUT_DEBUG_STRING_EVENT:
|
|
|
|
if (DEBUG_CurrThread == NULL) {
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Unknown thread\n");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
DEBUG_ProcessGetString(buffer, sizeof(buffer),
|
|
|
|
DEBUG_CurrThread->process->handle,
|
2000-03-26 15:37:39 +02:00
|
|
|
de->u.DebugString.lpDebugStringData);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
/* fixme unicode de->u.DebugString.fUnicode ? */
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: output debug string (%s)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, buffer);
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RIP_EVENT:
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: rip error=%ld type=%ld\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->u.RipInfo.dwError,
|
|
|
|
de->u.RipInfo.dwType);
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-04-13 21:31:58 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: unknown event (%ld)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->dwDebugEventCode);
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
|
|
|
} __EXCEPT(wine_dbg) {
|
2000-04-13 21:31:58 +02:00
|
|
|
*cont = 0;
|
|
|
|
ret = TRUE;
|
2000-03-26 15:37:39 +02:00
|
|
|
}
|
|
|
|
__ENDTRY;
|
2000-04-13 21:31:58 +02:00
|
|
|
return ret;
|
2000-03-26 15:37:39 +02:00
|
|
|
}
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
static DWORD DEBUG_MainLoop(void)
|
2000-03-26 15:37:39 +02:00
|
|
|
{
|
|
|
|
DEBUG_EVENT de;
|
|
|
|
DWORD cont;
|
2000-06-18 21:30:24 +02:00
|
|
|
BOOL ret;
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2000-09-24 05:15:50 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, " on pid %lx\n", DEBUG_CurrPid);
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
for (ret = TRUE; ret; ) {
|
|
|
|
/* wait until we get at least one loaded process */
|
2000-06-24 14:52:13 +02:00
|
|
|
while (!DEBUG_ProcessList && (ret = DEBUG_Parser()));
|
2000-06-18 21:30:24 +02:00
|
|
|
if (!ret) break;
|
|
|
|
|
2000-06-24 14:52:13 +02:00
|
|
|
while (ret && DEBUG_ProcessList && WaitForDebugEvent(&de, INFINITE)) {
|
2000-06-18 21:30:24 +02:00
|
|
|
ret = DEBUG_HandleDebugEvent(&de, &cont);
|
|
|
|
ContinueDebugEvent(de.dwProcessId, de.dwThreadId, cont);
|
|
|
|
}
|
|
|
|
};
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2000-09-24 05:15:50 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "WineDbg terminated on pid %lx\n", DEBUG_CurrPid);
|
2000-04-30 14:21:15 +02:00
|
|
|
|
|
|
|
return 0;
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2001-10-22 21:00:34 +02:00
|
|
|
static DWORD DEBUG_AutoMode(void)
|
|
|
|
{
|
|
|
|
DEBUG_EVENT de;
|
|
|
|
DWORD cont;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, " on pid %lx\n", DEBUG_CurrPid);
|
|
|
|
|
|
|
|
while (ret && DEBUG_ProcessList && WaitForDebugEvent(&de, INFINITE))
|
|
|
|
{
|
|
|
|
ret = DEBUG_HandleDebugEvent(&de, &cont);
|
|
|
|
ContinueDebugEvent(de.dwProcessId, de.dwThreadId, cont);
|
|
|
|
}
|
|
|
|
/* print some extra information */
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Modules:\n");
|
|
|
|
DEBUG_WalkModules();
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Threads:\n");
|
|
|
|
DEBUG_WalkThreads();
|
|
|
|
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "WineDbg terminated on pid %lx\n", DEBUG_CurrPid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
static BOOL DEBUG_Start(LPSTR cmdLine)
|
|
|
|
{
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
if (!CreateProcess(NULL, cmdLine, NULL, NULL,
|
2001-11-24 00:10:08 +01:00
|
|
|
FALSE, DEBUG_PROCESS|DETACHED_PROCESS, NULL, NULL, &startup, &info)) {
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Couldn't start process '%s'\n", cmdLine);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
DEBUG_CurrPid = info.dwProcessId;
|
2001-08-06 19:51:52 +02:00
|
|
|
if (!(DEBUG_CurrProcess = DEBUG_AddProcess(DEBUG_CurrPid, 0, NULL))) return FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DEBUG_Run(const char* args)
|
|
|
|
{
|
|
|
|
DBG_MODULE* wmod = DEBUG_GetProcessMainModule(DEBUG_CurrProcess);
|
|
|
|
const char* pgm = (wmod) ? wmod->module_name : "none";
|
|
|
|
|
|
|
|
if (args) {
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Run (%s) with '%s'\n", pgm, args);
|
|
|
|
} else {
|
|
|
|
if (!DEBUG_LastCmdLine) {
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Cannot find previously used command line.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DEBUG_Start(DEBUG_LastCmdLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:10:08 +01:00
|
|
|
static void DEBUG_InitConsole(void)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
SMALL_RECT sr;
|
|
|
|
DWORD mode;
|
|
|
|
|
|
|
|
/* keep it as a cuiexe for now, so that Wine won't touch the Unix stdin,
|
|
|
|
* stdout and stderr streams
|
|
|
|
*/
|
|
|
|
if (DBG_IVAR(UseXTerm))
|
|
|
|
{
|
|
|
|
FreeConsole();
|
|
|
|
AllocConsole();
|
|
|
|
}
|
|
|
|
/* this would be nicer for output */
|
|
|
|
c.X = 132;
|
|
|
|
c.Y = 500;
|
|
|
|
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), c);
|
|
|
|
|
|
|
|
/* sets the console's window width accordingly */
|
|
|
|
sr.Left = 0;
|
|
|
|
sr.Top = 0;
|
|
|
|
sr.Right = c.X - 1;
|
|
|
|
sr.Bottom = 50;
|
|
|
|
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &sr);
|
|
|
|
|
|
|
|
/* put the line editing mode with the nice emacs features (FIXME: could be triggered by a IVAR) */
|
|
|
|
if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode))
|
|
|
|
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode | WINE_ENABLE_LINE_INPUT_EMACS);
|
|
|
|
}
|
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
int DEBUG_main(int argc, char** argv)
|
2000-03-09 19:45:43 +01:00
|
|
|
{
|
2000-06-18 21:30:24 +02:00
|
|
|
DWORD retv = 0;
|
2000-04-30 14:21:15 +02:00
|
|
|
|
|
|
|
/* Initialize the type handling stuff. */
|
|
|
|
DEBUG_InitTypes();
|
|
|
|
DEBUG_InitCVDataTypes();
|
|
|
|
|
2001-08-06 19:51:52 +02:00
|
|
|
/* Initialize internal vars (types must have been initialized before) */
|
2000-05-01 16:22:02 +02:00
|
|
|
if (!DEBUG_IntVarsRW(TRUE)) return -1;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2001-10-22 21:00:34 +02:00
|
|
|
if (argc > 1 && !strcmp( argv[1], "--auto" ))
|
|
|
|
{
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
automatic_mode = 1;
|
|
|
|
/* force some internal variables */
|
|
|
|
DBG_IVAR(UseXTerm) = 0;
|
|
|
|
DBG_IVAR(BreakOnDllLoad) = 0;
|
|
|
|
DBG_IVAR(ConChannelMask) = 0;
|
|
|
|
DBG_IVAR(StdChannelMask) = DBG_CHN_MESG;
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:10:08 +01:00
|
|
|
DEBUG_InitConsole();
|
|
|
|
|
2000-11-25 02:40:10 +01:00
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "WineDbg starting... ");
|
2001-05-03 20:32:47 +02:00
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
if (argc == 3) {
|
|
|
|
HANDLE hEvent;
|
2000-06-18 21:30:24 +02:00
|
|
|
DWORD pid;
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2000-12-29 06:38:00 +01:00
|
|
|
if ((pid = atoi(argv[1])) != 0 && (hEvent = (HANDLE)atoi(argv[2])) != 0) {
|
2001-04-14 00:26:23 +02:00
|
|
|
if (!DEBUG_Attach(pid, TRUE)) {
|
|
|
|
/* don't care about result */
|
|
|
|
SetEvent(hEvent);
|
2000-05-11 23:43:43 +02:00
|
|
|
goto leave;
|
|
|
|
}
|
2001-04-14 00:26:23 +02:00
|
|
|
if (!SetEvent(hEvent)) {
|
|
|
|
DEBUG_Printf(DBG_CHN_ERR, "Invalid event handle: %p\n", hEvent);
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
CloseHandle(hEvent);
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_CurrPid = pid;
|
2000-05-11 23:43:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
if (DEBUG_CurrPid == 0 && argc > 1) {
|
|
|
|
int i, len;
|
|
|
|
LPSTR cmdLine;
|
|
|
|
|
|
|
|
if (!(cmdLine = DBG_alloc(len = 1))) goto oom_leave;
|
|
|
|
cmdLine[0] = '\0';
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
len += strlen(argv[i]) + 1;
|
|
|
|
if (!(cmdLine = DBG_realloc(cmdLine, len))) goto oom_leave;
|
|
|
|
strcat(cmdLine, argv[i]);
|
|
|
|
cmdLine[len - 2] = ' ';
|
|
|
|
cmdLine[len - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DEBUG_Start(cmdLine)) {
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Couldn't start process '%s'\n", cmdLine);
|
2000-04-30 14:21:15 +02:00
|
|
|
goto leave;
|
2000-03-09 19:45:43 +01:00
|
|
|
}
|
2000-06-18 21:30:24 +02:00
|
|
|
DBG_free(DEBUG_LastCmdLine);
|
|
|
|
DEBUG_LastCmdLine = cmdLine;
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2001-10-22 21:00:34 +02:00
|
|
|
if (automatic_mode)
|
|
|
|
{
|
|
|
|
retv = DEBUG_AutoMode();
|
|
|
|
/* don't save modified variables in auto mode */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
retv = DEBUG_MainLoop();
|
|
|
|
/* saves modified variables */
|
|
|
|
DEBUG_IntVarsRW(FALSE);
|
|
|
|
}
|
2000-04-30 14:21:15 +02:00
|
|
|
|
2001-08-06 19:51:52 +02:00
|
|
|
leave:
|
2000-04-30 14:21:15 +02:00
|
|
|
return retv;
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
oom_leave:
|
|
|
|
DEBUG_Printf(DBG_CHN_MESG, "Out of memory\n");
|
|
|
|
goto leave;
|
|
|
|
}
|