2000-03-08 17:44:54 +01:00
|
|
|
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
/* Wine internal debugger
|
|
|
|
* Interface to Windows debugger API
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright 2000 Eric Pouech
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-03-08 17:44:54 +01:00
|
|
|
*/
|
|
|
|
|
2003-11-27 01:59:36 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
#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
|
|
|
|
2000-05-03 19:48:21 +02:00
|
|
|
#include "wincon.h"
|
2002-06-04 23:31:10 +02:00
|
|
|
#include "winreg.h"
|
2000-03-26 15:37:39 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winternl.h"
|
2002-12-13 00:34:01 +01:00
|
|
|
#include "excpt.h"
|
2003-11-27 01:59:36 +01:00
|
|
|
#include "wine/exception.h"
|
2002-06-04 23:31:10 +02:00
|
|
|
#include "wine/library.h"
|
2003-06-30 22:19:42 +02:00
|
|
|
#include "winnls.h"
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
|
|
|
|
|
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;
|
2002-08-29 00:21:20 +02:00
|
|
|
CONTEXT DEBUG_context;
|
2002-07-20 22:18:17 +02:00
|
|
|
BOOL DEBUG_InteractiveP = FALSE;
|
2002-08-29 00:21:20 +02:00
|
|
|
static BOOL DEBUG_InException = 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;
|
2002-07-20 22:18:17 +02:00
|
|
|
static enum {none_mode = 0, winedbg_mode, automatic_mode, gdb_mode} local_mode;
|
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
DBG_INTVAR DEBUG_IntVars[DBG_IV_LAST];
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
void DEBUG_OutputA(const char* buffer, int len)
|
2000-04-30 14:21:15 +02:00
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buffer, len, NULL, NULL);
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
void DEBUG_OutputW(const WCHAR* buffer, int len)
|
2002-05-25 23:18:34 +02:00
|
|
|
{
|
2003-06-30 22:19:42 +02:00
|
|
|
char* ansi = NULL;
|
|
|
|
int newlen;
|
|
|
|
|
|
|
|
/* do a serious Unicode to ANSI conversion
|
|
|
|
FIXME: should CP_ACP be GetConsoleCP()? */
|
|
|
|
newlen = WideCharToMultiByte(CP_ACP, 0, buffer, len, NULL, 0, NULL, NULL);
|
|
|
|
if(newlen)
|
|
|
|
{
|
|
|
|
ansi = (char*)DBG_alloc(newlen);
|
|
|
|
if(ansi)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, buffer, len, ansi, newlen, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall back to a simple Unicode to ANSI conversion in case WC2MB failed */
|
|
|
|
if(!ansi)
|
|
|
|
{
|
|
|
|
ansi = DBG_alloc(len);
|
|
|
|
if(ansi)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
ansi[i] = (char)buffer[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
newlen = len;
|
|
|
|
}
|
|
|
|
/* else we are having REALLY bad luck today */
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ansi)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_OutputA(ansi, newlen);
|
2003-06-30 22:19:42 +02:00
|
|
|
DBG_free(ansi);
|
|
|
|
}
|
2002-05-25 23:18:34 +02:00
|
|
|
}
|
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
int DEBUG_Printf(const char* format, ...)
|
2000-04-13 21:31:58 +02:00
|
|
|
{
|
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
|
|
|
|
2001-12-24 21:23:57 +01:00
|
|
|
if (len <= -1 || len >= sizeof(buf)) {
|
2000-05-05 20:14:34 +02:00
|
|
|
len = sizeof(buf) - 1;
|
|
|
|
buf[len] = 0;
|
|
|
|
buf[len - 1] = buf[len - 2] = buf[len - 3] = '.';
|
|
|
|
}
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_OutputA(buf, len);
|
2000-04-30 14:21:15 +02:00
|
|
|
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; \
|
2001-12-21 21:29:58 +01:00
|
|
|
div->type = DEBUG_GetBasicType(_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)) {
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Cannot create WineDbg key in registry\n");
|
2000-05-01 16:22:02 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < DBG_IV_LAST; i++) {
|
|
|
|
if (read) {
|
|
|
|
if (!DEBUG_IntVars[i].pval) {
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!RegQueryValueEx(hkey, DEBUG_IntVars[i].name, 0,
|
2000-05-01 16:22:02 +02:00
|
|
|
&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)
|
2002-06-01 01:06:46 +02:00
|
|
|
RegSetValueEx(hkey, DEBUG_IntVars[i].name, 0,
|
2000-05-01 16:22:02 +02:00
|
|
|
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;
|
|
|
|
}
|
2002-06-01 01:06:46 +02: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;
|
2002-06-01 01:06:46 +02: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;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
DBG_PROCESS* DEBUG_AddProcess(DWORD pid, HANDLE h, const char* imageName)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2002-07-20 22:18:17 +02:00
|
|
|
DBG_PROCESS* p;
|
|
|
|
|
|
|
|
if ((p = DEBUG_GetProcess(pid)))
|
|
|
|
{
|
|
|
|
if (p->handle != 0)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Process (%lu) is already defined\n", pid);
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p->handle = h;
|
|
|
|
p->imageName = imageName ? DBG_strdup(imageName) : NULL;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(p = DBG_alloc(sizeof(DBG_PROCESS)))) return NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
void DEBUG_DelProcess(DBG_PROCESS* p)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2001-05-21 20:33:15 +02:00
|
|
|
int i;
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
while (p->threads) DEBUG_DelThread(p->threads);
|
|
|
|
|
2002-07-30 02:06:34 +02:00
|
|
|
for (i = 0; i < p->num_delayed_bp; i++)
|
|
|
|
if (p->delayed_bp[i].is_symbol)
|
|
|
|
DBG_free(p->delayed_bp[i].u.symbol.name);
|
|
|
|
|
2001-05-21 20:33:15 +02:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
BOOL DEBUG_ProcessGetString(char* buffer, int size, HANDLE hp, LPSTR addr)
|
2000-03-10 23:25:07 +01:00
|
|
|
{
|
|
|
|
DWORD sz;
|
|
|
|
*(WCHAR*)buffer = 0;
|
|
|
|
return (addr && ReadProcessMemory(hp, addr, buffer, size, &sz));
|
|
|
|
}
|
|
|
|
|
2003-09-30 03:04:19 +02:00
|
|
|
BOOL DEBUG_ProcessGetStringIndirect(char* buffer, int size, HANDLE hp, LPVOID addr, BOOL unicode)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
|
|
|
LPVOID ad;
|
|
|
|
DWORD sz;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-09-30 03:04:19 +02:00
|
|
|
if (addr && ReadProcessMemory(hp, addr, &ad, sizeof(ad), &sz) && sz == sizeof(ad) && ad)
|
|
|
|
{
|
|
|
|
if (!unicode) ReadProcessMemory(hp, ad, buffer, size, &sz);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR *buffW = DBG_alloc( size * sizeof(WCHAR) );
|
|
|
|
ReadProcessMemory(hp, ad, buffW, size*sizeof(WCHAR), &sz);
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, buffW, sz/sizeof(WCHAR), buffer, size, NULL, NULL );
|
|
|
|
DBG_free(buffW);
|
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
return TRUE;
|
2003-09-30 03:04:19 +02:00
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
*(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;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (!p) return NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
for (t = p->threads; t; t = t->next)
|
|
|
|
if (t->tid == tid) break;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
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;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
t->handle = h;
|
|
|
|
t->tid = tid;
|
|
|
|
t->start = start;
|
|
|
|
t->teb = teb;
|
|
|
|
t->process = p;
|
|
|
|
t->wait_for_first_exception = 0;
|
2002-04-01 23:03:13 +02:00
|
|
|
t->exec_mode = EXEC_CONT;
|
|
|
|
t->exec_count = 0;
|
|
|
|
|
2003-02-11 23:05:06 +01:00
|
|
|
snprintf(t->name, sizeof(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) {
|
2002-06-01 01:06:46 +02:00
|
|
|
if (DEBUG_CurrThread->process->num_threads == 1 ||
|
2000-04-13 21:31:58 +02:00
|
|
|
DBG_IVAR(BreakAllThreadsStartup)) {
|
2000-03-26 15:37:39 +02:00
|
|
|
DBG_VALUE value;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-03-26 15:37:39 +02:00
|
|
|
DEBUG_SetBreakpoints(FALSE);
|
|
|
|
value.type = NULL;
|
|
|
|
value.cookie = DV_TARGET;
|
|
|
|
value.addr.seg = 0;
|
|
|
|
value.addr.off = (DWORD)DEBUG_CurrThread->start;
|
2002-07-30 02:06:34 +02:00
|
|
|
DEBUG_AddBreakpointFromValue(&value);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-02-11 23:05:06 +01:00
|
|
|
static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de);
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DEBUG_Attach
|
|
|
|
*
|
|
|
|
* Sets the debuggee to <pid>
|
|
|
|
* cofe instructs winedbg what to do when first exception is received
|
|
|
|
* (break=FALSE, continue=TRUE)
|
|
|
|
* wfe is set to TRUE if DEBUG_Attach should also proceed with all debug events
|
|
|
|
* until the first exception is received (aka: attach to an already running process)
|
|
|
|
*/
|
|
|
|
BOOL DEBUG_Attach(DWORD pid, BOOL cofe, BOOL wfe)
|
2000-06-18 21:30:24 +02:00
|
|
|
{
|
2003-02-11 23:05:06 +01:00
|
|
|
DEBUG_EVENT de;
|
|
|
|
|
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)) {
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Can't attach process %lx: error %ld\n", pid, GetLastError());
|
2001-07-11 19:33:08 +02:00
|
|
|
DEBUG_DelProcess(DEBUG_CurrProcess);
|
2000-06-18 21:30:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
DEBUG_CurrProcess->continue_on_first_exception = cofe;
|
2003-02-11 23:05:06 +01:00
|
|
|
|
|
|
|
if (wfe) /* shall we proceed all debug events until we get an exception ? */
|
|
|
|
{
|
|
|
|
DEBUG_InteractiveP = FALSE;
|
|
|
|
while (DEBUG_CurrProcess && WaitForDebugEvent(&de, INFINITE))
|
|
|
|
{
|
|
|
|
if (DEBUG_HandleDebugEvent(&de)) break;
|
|
|
|
}
|
|
|
|
if (DEBUG_CurrProcess) DEBUG_InteractiveP = TRUE;
|
|
|
|
}
|
2000-06-18 21:30:24 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-02-27 02:29:18 +01:00
|
|
|
BOOL DEBUG_Detach(void)
|
|
|
|
{
|
|
|
|
/* remove all set breakpoints in debuggee code */
|
|
|
|
DEBUG_SetBreakpoints(FALSE);
|
2002-06-01 01:06:46 +02:00
|
|
|
/* needed for single stepping (ugly).
|
2002-02-27 02:29:18 +01:00
|
|
|
* should this be handled inside the server ??? */
|
|
|
|
#ifdef __i386__
|
|
|
|
DEBUG_context.EFlags &= ~STEP_FLAG;
|
|
|
|
#endif
|
|
|
|
SetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context);
|
|
|
|
DebugActiveProcessStop(DEBUG_CurrProcess->pid);
|
|
|
|
DEBUG_DelProcess(DEBUG_CurrProcess);
|
|
|
|
/* FIXME: should zero out the symbol table too */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-08-29 00:21:20 +02:00
|
|
|
static BOOL DEBUG_FetchContext(void)
|
|
|
|
{
|
|
|
|
DEBUG_context.ContextFlags = CONTEXT_CONTROL
|
|
|
|
| CONTEXT_INTEGER
|
|
|
|
#ifdef CONTEXT_SEGMENTS
|
|
|
|
| CONTEXT_SEGMENTS
|
|
|
|
#endif
|
|
|
|
#ifdef CONTEXT_DEBUG_REGISTERS
|
|
|
|
| CONTEXT_DEBUG_REGISTERS
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
if (!GetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context))
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_WARN("Can't get thread's context\n");
|
2002-08-29 00:21:20 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
static BOOL DEBUG_ExceptionProlog(BOOL is_debug, BOOL force, DWORD code)
|
|
|
|
{
|
|
|
|
DBG_ADDR addr;
|
|
|
|
int newmode;
|
|
|
|
|
2002-08-29 00:21:20 +02:00
|
|
|
DEBUG_InException = TRUE;
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_GetCurrentAddress(&addr);
|
|
|
|
DEBUG_SuspendExecution();
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (!is_debug)
|
|
|
|
{
|
2000-09-24 05:15:50 +02:00
|
|
|
if (!addr.seg)
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf(" in 32-bit code (0x%08lx)", addr.off);
|
2000-06-18 21:30:24 +02:00
|
|
|
else
|
2003-12-15 20:53:08 +01:00
|
|
|
switch (DEBUG_GetSelectorType(addr.seg))
|
2000-09-24 05:15:50 +02:00
|
|
|
{
|
|
|
|
case MODE_32:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf(" in 32-bit code (%04lx:%08lx)", addr.seg, addr.off);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case MODE_16:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf(" in 16-bit code (%04lx:%04lx)", addr.seg, addr.off);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case MODE_VM86:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf(" in vm86 code (%04lx:%04lx)", addr.seg, addr.off);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case MODE_INVALID:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf(" bad CS (%lx)", addr.seg);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf(".\n");
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_LoadEntryPoints("Loading new modules symbols:\n");
|
2003-12-15 20:53:08 +01:00
|
|
|
/*
|
|
|
|
* Do a quiet backtrace so that we have an idea of what the situation
|
|
|
|
* is WRT the source files.
|
|
|
|
*/
|
|
|
|
DEBUG_BackTrace(DEBUG_CurrTid, FALSE);
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!force && is_debug &&
|
|
|
|
DEBUG_ShouldContinue(&addr, code,
|
2002-04-01 23:03:13 +02:00
|
|
|
&DEBUG_CurrThread->exec_count))
|
2000-06-18 21:30:24 +02:00
|
|
|
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" };
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("In %s mode.\n", names[newmode] );
|
2000-09-24 05:15:50 +02:00
|
|
|
DEBUG_CurrThread->dbg_mode = newmode;
|
|
|
|
}
|
2000-06-18 21:30:24 +02:00
|
|
|
|
|
|
|
DEBUG_DoDisplay();
|
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
if (!is_debug && !force) {
|
2000-06-18 21:30:24 +02:00
|
|
|
/* This is a real crash, dump some info */
|
2002-08-02 21:00:53 +02:00
|
|
|
DEBUG_InfoRegisters(&DEBUG_context);
|
2000-06-18 21:30:24 +02:00
|
|
|
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 ||
|
2002-04-01 23:03:13 +02:00
|
|
|
(DEBUG_CurrThread->exec_mode == EXEC_STEPI_OVER) ||
|
|
|
|
(DEBUG_CurrThread->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 */
|
2002-06-01 01:06:46 +02:00
|
|
|
DEBUG_FindNearestSymbol(&addr, TRUE, NULL, 0, &list);
|
2000-07-25 14:51:56 +02:00
|
|
|
if (list.sourcefile) DEBUG_List(&list, NULL, 0);
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-04-01 23:03:13 +02:00
|
|
|
static void DEBUG_ExceptionEpilog(void)
|
2000-06-18 21:30:24 +02:00
|
|
|
{
|
2002-04-01 23:03:13 +02:00
|
|
|
DEBUG_RestartExecution(DEBUG_CurrThread->exec_count);
|
2000-06-18 21:30:24 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-04-01 23:03:13 +02:00
|
|
|
if (DEBUG_CurrThread->exec_mode == EXEC_CONT)
|
|
|
|
DEBUG_CurrThread->exec_count = 0;
|
2002-08-29 00:21:20 +02:00
|
|
|
DEBUG_InException = FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
|
|
|
|
2003-08-21 23:28:51 +02:00
|
|
|
static DWORD DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL force)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2001-04-09 20:31:47 +02:00
|
|
|
BOOL is_debug = FALSE;
|
|
|
|
THREADNAME_INFO *pThreadName;
|
|
|
|
DBG_THREAD *pThread;
|
|
|
|
|
2002-04-01 23:03:13 +02:00
|
|
|
assert(DEBUG_CurrThread);
|
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))
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Thread ID=0x%lx renamed using MS VC6 extension (name==\"%s\")\n",
|
|
|
|
pThread->tid, pThread->name);
|
2003-08-21 23:28:51 +02:00
|
|
|
return DBG_CONTINUE;
|
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 */
|
2003-08-21 23:28:51 +02:00
|
|
|
return DBG_EXCEPTION_NOT_HANDLED;
|
2000-09-24 05:15:50 +02:00
|
|
|
}
|
|
|
|
|
2000-03-08 17:44:54 +01:00
|
|
|
if (!is_debug)
|
|
|
|
{
|
|
|
|
/* print some infos */
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("%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:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("divide by zero");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_INT_OVERFLOW:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("overflow");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("array bounds");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("illegal instruction");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_STACK_OVERFLOW:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("stack overflow");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_PRIV_INSTRUCTION:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("privileged instruction");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
|
|
|
if (rec->NumberParameters == 2)
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("page fault on %s access to 0x%08lx",
|
|
|
|
rec->ExceptionInformation[0] ? "write" : "read",
|
|
|
|
rec->ExceptionInformation[1]);
|
2000-03-08 17:44:54 +01:00
|
|
|
else
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("page fault");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_DATATYPE_MISALIGNMENT:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Alignment");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
2001-11-24 00:10:08 +01:00
|
|
|
case DBG_CONTROL_C:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("^C");
|
2001-11-24 00:10:08 +01:00
|
|
|
break;
|
2000-03-08 17:44:54 +01:00
|
|
|
case CONTROL_C_EXIT:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("^C");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
2003-04-04 21:41:31 +02:00
|
|
|
case STATUS_POSSIBLE_DEADLOCK:
|
2001-08-07 21:32:14 +02:00
|
|
|
{
|
|
|
|
DBG_ADDR addr;
|
|
|
|
|
|
|
|
addr.seg = 0;
|
|
|
|
addr.off = rec->ExceptionInformation[0];
|
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("wait failed on critical section ");
|
2001-08-07 21:32:14 +02:00
|
|
|
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
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("\n");
|
2003-08-21 23:28:51 +02:00
|
|
|
return DBG_EXCEPTION_NOT_HANDLED;
|
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] );
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("unimplemented function %s.%s called", dll, name );
|
2000-10-27 00:03:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-10-29 00:56:58 +01:00
|
|
|
case EXCEPTION_WINE_ASSERTION:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("assertion failed");
|
2002-10-29 00:56:58 +01:00
|
|
|
break;
|
2000-09-24 05:15:50 +02:00
|
|
|
case EXCEPTION_VM86_INTx:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("interrupt %02lx in vm86 mode",
|
2000-09-24 05:15:50 +02:00
|
|
|
rec->ExceptionInformation[0]);
|
|
|
|
break;
|
|
|
|
case EXCEPTION_VM86_STI:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("sti in vm86 mode");
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case EXCEPTION_VM86_PICRETURN:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("PIC return in vm86 mode");
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
2003-02-24 21:38:44 +01:00
|
|
|
case EXCEPTION_FLT_DENORMAL_OPERAND:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("denormal float operand");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("divide by zero");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_INEXACT_RESULT:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("inexact float result");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_INVALID_OPERATION:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("invalid float operation");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_OVERFLOW:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("floating pointer overflow");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_UNDERFLOW:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("floating pointer underflow");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_STACK_CHECK:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("floating point stack check");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
2000-03-08 17:44:54 +01:00
|
|
|
default:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("%08lx", rec->ExceptionCode);
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (local_mode == automatic_mode)
|
2001-10-22 21:00:34 +02:00
|
|
|
{
|
|
|
|
DEBUG_ExceptionProlog(is_debug, FALSE, rec->ExceptionCode);
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_ExceptionEpilog();
|
2003-08-21 23:28:51 +02:00
|
|
|
return 0; /* terminate execution */
|
2001-10-22 21:00:34 +02:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_ExceptionProlog(is_debug, force, rec->ExceptionCode))
|
|
|
|
{
|
|
|
|
DEBUG_InteractiveP = TRUE;
|
2003-08-21 23:28:51 +02:00
|
|
|
return 0;
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2002-04-01 23:03:13 +02:00
|
|
|
DEBUG_ExceptionEpilog();
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2003-08-21 23:28:51 +02:00
|
|
|
return DBG_CONTINUE;
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2004-02-03 01:14:12 +01:00
|
|
|
char buffer[256];
|
|
|
|
DWORD cont = DBG_CONTINUE;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2000-05-11 23:43:43 +02:00
|
|
|
DEBUG_CurrPid = de->dwProcessId;
|
|
|
|
DEBUG_CurrTid = de->dwThreadId;
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if ((DEBUG_CurrProcess = DEBUG_GetProcess(de->dwProcessId)) != NULL)
|
|
|
|
DEBUG_CurrThread = DEBUG_GetThread(DEBUG_CurrProcess, de->dwThreadId);
|
|
|
|
else
|
|
|
|
DEBUG_CurrThread = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
switch (de->dwDebugEventCode)
|
|
|
|
{
|
|
|
|
case EXCEPTION_DEBUG_EVENT:
|
|
|
|
if (!DEBUG_CurrThread)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("%08lx:%08lx: not a registered process or thread (perhaps a 16 bit one ?)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId);
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2000-05-05 20:14:34 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: exception code=%08lx\n",
|
|
|
|
de->dwProcessId, de->dwThreadId,
|
|
|
|
de->u.Exception.ExceptionRecord.ExceptionCode);
|
2000-05-05 20:14:34 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_CurrProcess->continue_on_first_exception)
|
|
|
|
{
|
|
|
|
DEBUG_CurrProcess->continue_on_first_exception = FALSE;
|
|
|
|
if (!DBG_IVAR(BreakOnAttach)) break;
|
|
|
|
}
|
|
|
|
|
2002-08-29 00:21:20 +02:00
|
|
|
if (DEBUG_FetchContext())
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2003-08-21 23:28:51 +02:00
|
|
|
cont = DEBUG_HandleException(&de->u.Exception.ExceptionRecord,
|
2002-08-29 00:21:20 +02:00
|
|
|
de->u.Exception.dwFirstChance,
|
|
|
|
DEBUG_CurrThread->wait_for_first_exception);
|
2003-08-21 23:28:51 +02:00
|
|
|
if (cont && DEBUG_CurrThread)
|
2002-08-29 00:21:20 +02:00
|
|
|
{
|
|
|
|
DEBUG_CurrThread->wait_for_first_exception = 0;
|
|
|
|
SetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context);
|
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case CREATE_THREAD_DEBUG_EVENT:
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: create thread D @%08lx\n", de->dwProcessId, de->dwThreadId,
|
|
|
|
(unsigned long)(LPVOID)de->u.CreateThread.lpStartAddress);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_CurrProcess == NULL)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Unknown process\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (DEBUG_GetThread(DEBUG_CurrProcess, de->dwThreadId) != NULL)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("Thread already listed, skipping\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_CurrThread = DEBUG_AddThread(DEBUG_CurrProcess,
|
|
|
|
de->dwThreadId,
|
|
|
|
de->u.CreateThread.hThread,
|
|
|
|
de->u.CreateThread.lpStartAddress,
|
|
|
|
de->u.CreateThread.lpThreadLocalBase);
|
|
|
|
if (!DEBUG_CurrThread)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Couldn't create thread\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
DEBUG_InitCurrThread();
|
|
|
|
break;
|
2001-08-06 19:51:52 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case CREATE_PROCESS_DEBUG_EVENT:
|
|
|
|
DEBUG_ProcessGetStringIndirect(buffer, sizeof(buffer),
|
|
|
|
de->u.CreateProcessInfo.hProcess,
|
2003-09-30 03:04:19 +02:00
|
|
|
de->u.CreateProcessInfo.lpImageName,
|
|
|
|
de->u.CreateProcessInfo.fUnicode);
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: create process '%s'/%p @%08lx (%ld<%ld>)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId,
|
|
|
|
buffer, de->u.CreateProcessInfo.lpImageName,
|
|
|
|
(unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress,
|
|
|
|
de->u.CreateProcessInfo.dwDebugInfoFileOffset,
|
|
|
|
de->u.CreateProcessInfo.nDebugInfoSize);
|
2002-07-20 22:18:17 +02:00
|
|
|
|
|
|
|
DEBUG_CurrProcess = DEBUG_AddProcess(de->dwProcessId,
|
|
|
|
de->u.CreateProcessInfo.hProcess,
|
|
|
|
buffer[0] ? buffer : "<Debugged Process>");
|
|
|
|
if (DEBUG_CurrProcess == NULL)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Couldn't create process\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: create thread I @%08lx\n",
|
|
|
|
de->dwProcessId, de->dwThreadId,
|
|
|
|
(unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_CurrThread = DEBUG_AddThread(DEBUG_CurrProcess,
|
|
|
|
de->dwThreadId,
|
|
|
|
de->u.CreateProcessInfo.hThread,
|
|
|
|
de->u.CreateProcessInfo.lpStartAddress,
|
|
|
|
de->u.CreateProcessInfo.lpThreadLocalBase);
|
|
|
|
if (!DEBUG_CurrThread)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Couldn't create thread\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2004-02-03 01:14:12 +01:00
|
|
|
else
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-02-03 01:14:12 +01:00
|
|
|
struct elf_info elf_info;
|
2002-05-25 23:07:58 +02:00
|
|
|
|
2004-02-03 01:14:12 +01:00
|
|
|
DEBUG_InitCurrProcess();
|
|
|
|
DEBUG_InitCurrThread();
|
2000-06-08 07:02:19 +02:00
|
|
|
|
2004-02-03 01:14:12 +01:00
|
|
|
elf_info.flags = ELF_INFO_MODULE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-02-03 01:14:12 +01:00
|
|
|
if (DEBUG_ReadWineLoaderDbgInfo(DEBUG_CurrProcess->handle, &elf_info) != DIL_ERROR &&
|
|
|
|
DEBUG_SetElfSoLoadBreakpoint(&elf_info))
|
|
|
|
{
|
|
|
|
/* then load the main module's symbols */
|
|
|
|
DEBUG_LoadPEModule(DEBUG_CurrProcess->imageName,
|
|
|
|
de->u.CreateProcessInfo.hFile,
|
|
|
|
de->u.CreateProcessInfo.lpBaseOfImage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG_DelThread(DEBUG_CurrProcess->threads);
|
|
|
|
DEBUG_DelProcess(DEBUG_CurrProcess);
|
|
|
|
DEBUG_Printf("Couldn't load process\n");
|
|
|
|
}
|
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case EXIT_THREAD_DEBUG_EVENT:
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: exit thread (%ld)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->u.ExitThread.dwExitCode);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_CurrThread == NULL)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Unknown thread\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FIXME: remove break point set on thread startup */
|
|
|
|
DEBUG_DelThread(DEBUG_CurrThread);
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: exit process (%ld)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->u.ExitProcess.dwExitCode);
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_CurrProcess == NULL)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Unknown process\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* just in case */
|
|
|
|
DEBUG_SetBreakpoints(FALSE);
|
|
|
|
/* kill last thread */
|
|
|
|
DEBUG_DelThread(DEBUG_CurrProcess->threads);
|
|
|
|
DEBUG_DelProcess(DEBUG_CurrProcess);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Process of pid=%08lx has terminated\n", DEBUG_CurrPid);
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case LOAD_DLL_DEBUG_EVENT:
|
|
|
|
if (DEBUG_CurrThread == NULL)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Unknown thread\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
DEBUG_ProcessGetStringIndirect(buffer, sizeof(buffer),
|
|
|
|
DEBUG_CurrThread->process->handle,
|
2003-09-30 03:04:19 +02:00
|
|
|
de->u.LoadDll.lpImageName,
|
|
|
|
de->u.LoadDll.fUnicode);
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: loads DLL %s @%08lx (%ld<%ld>)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId,
|
|
|
|
buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll,
|
|
|
|
de->u.LoadDll.dwDebugInfoFileOffset,
|
|
|
|
de->u.LoadDll.nDebugInfoSize);
|
2002-07-20 22:18:17 +02:00
|
|
|
_strupr(buffer);
|
2004-02-03 01:14:12 +01:00
|
|
|
DEBUG_LoadPEModule(buffer, de->u.LoadDll.hFile, de->u.LoadDll.lpBaseOfDll);
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_CheckDelayedBP();
|
|
|
|
if (DBG_IVAR(BreakOnDllLoad))
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Stopping on DLL %s loading at %08lx\n",
|
2002-07-20 22:18:17 +02:00
|
|
|
buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll);
|
2003-08-21 23:28:51 +02:00
|
|
|
if (DEBUG_FetchContext()) cont = 0;
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case UNLOAD_DLL_DEBUG_EVENT:
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: unload DLL @%08lx\n", de->dwProcessId, de->dwThreadId,
|
|
|
|
(unsigned long)de->u.UnloadDll.lpBaseOfDll);
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case OUTPUT_DEBUG_STRING_EVENT:
|
|
|
|
if (DEBUG_CurrThread == NULL)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Unknown thread\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_ProcessGetString(buffer, sizeof(buffer),
|
|
|
|
DEBUG_CurrThread->process->handle,
|
|
|
|
de->u.DebugString.lpDebugStringData);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
/* FIXME unicode de->u.DebugString.fUnicode ? */
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: output debug string (%s)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, buffer);
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
case RIP_EVENT:
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: rip error=%ld type=%ld\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->u.RipInfo.dwError,
|
|
|
|
de->u.RipInfo.dwType);
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
default:
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("%08lx:%08lx: unknown event (%ld)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->dwDebugEventCode);
|
2000-03-26 15:37:39 +02:00
|
|
|
}
|
2003-08-21 23:28:51 +02:00
|
|
|
if (!cont) return TRUE; /* stop execution */
|
|
|
|
ContinueDebugEvent(de->dwProcessId, de->dwThreadId, cont);
|
|
|
|
return FALSE; /* continue execution */
|
2000-03-26 15:37:39 +02:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
static void DEBUG_ResumeDebuggee(DWORD cont)
|
2000-03-26 15:37:39 +02:00
|
|
|
{
|
2002-08-29 00:21:20 +02:00
|
|
|
if (DEBUG_InException)
|
|
|
|
{
|
|
|
|
DEBUG_ExceptionEpilog();
|
2002-07-20 22:18:17 +02:00
|
|
|
#ifdef __i386__
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("Exiting debugger PC=%lx EFL=%08lx mode=%d count=%d\n",
|
|
|
|
DEBUG_context.Eip, DEBUG_context.EFlags,
|
|
|
|
DEBUG_CurrThread->exec_mode, DEBUG_CurrThread->exec_count);
|
2002-07-20 22:18:17 +02:00
|
|
|
#else
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("Exiting debugger PC=%lx EFL=%08lx mode=%d count=%d\n",
|
|
|
|
0L, 0L,
|
|
|
|
DEBUG_CurrThread->exec_mode, DEBUG_CurrThread->exec_count);
|
2002-07-20 22:18:17 +02:00
|
|
|
#endif
|
2002-08-29 00:21:20 +02:00
|
|
|
if (DEBUG_CurrThread)
|
|
|
|
{
|
|
|
|
if (!SetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context))
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Cannot set ctx on %lu\n", DEBUG_CurrTid);
|
2002-08-29 00:21:20 +02:00
|
|
|
DEBUG_CurrThread->wait_for_first_exception = 0;
|
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
2002-08-29 00:21:20 +02:00
|
|
|
DEBUG_InteractiveP = FALSE;
|
2002-07-20 22:18:17 +02:00
|
|
|
if (!ContinueDebugEvent(DEBUG_CurrPid, DEBUG_CurrTid, cont))
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Cannot continue on %lu (%lu)\n", DEBUG_CurrTid, cont);
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
void DEBUG_WaitNextException(DWORD cont, int count, int mode)
|
|
|
|
{
|
|
|
|
DEBUG_EVENT de;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (cont == DBG_CONTINUE)
|
2002-02-27 02:29:18 +01:00
|
|
|
{
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_CurrThread->exec_count = count;
|
|
|
|
DEBUG_CurrThread->exec_mode = mode;
|
2002-02-27 02:29:18 +01:00
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_ResumeDebuggee(cont);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
while (DEBUG_CurrProcess && WaitForDebugEvent(&de, INFINITE))
|
|
|
|
{
|
|
|
|
if (DEBUG_HandleDebugEvent(&de)) break;
|
|
|
|
}
|
|
|
|
if (!DEBUG_CurrProcess) return;
|
|
|
|
DEBUG_InteractiveP = TRUE;
|
|
|
|
#ifdef __i386__
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("Entering debugger PC=%lx EFL=%08lx mode=%d count=%d\n",
|
|
|
|
DEBUG_context.Eip, DEBUG_context.EFlags,
|
|
|
|
DEBUG_CurrThread->exec_mode, DEBUG_CurrThread->exec_count);
|
2002-07-20 22:18:17 +02:00
|
|
|
#else
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_TRACE("Entering debugger PC=%lx EFL=%08lx mode=%d count=%d\n",
|
|
|
|
0L, 0L,
|
|
|
|
DEBUG_CurrThread->exec_mode, DEBUG_CurrThread->exec_count);
|
2002-07-20 22:18:17 +02:00
|
|
|
#endif
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
static DWORD DEBUG_MainLoop(void)
|
2001-10-22 21:00:34 +02:00
|
|
|
{
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_EVENT de;
|
2001-10-22 21:00:34 +02:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("WineDbg starting on pid %lx\n", DEBUG_CurrPid);
|
2001-10-22 21:00:34 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
/* wait for first exception */
|
|
|
|
while (WaitForDebugEvent(&de, INFINITE))
|
2001-10-22 21:00:34 +02:00
|
|
|
{
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_HandleDebugEvent(&de)) break;
|
|
|
|
}
|
|
|
|
if (local_mode == automatic_mode)
|
|
|
|
{
|
|
|
|
/* print some extra information */
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Modules:\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_WalkModules();
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Threads:\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_WalkThreads();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG_InteractiveP = TRUE;
|
2002-07-30 01:50:59 +02:00
|
|
|
DEBUG_Parser(NULL);
|
2001-10-22 21:00:34 +02:00
|
|
|
}
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("WineDbg terminated on pid %lx\n", DEBUG_CurrPid);
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2001-10-22 21:00:34 +02:00
|
|
|
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;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
/* FIXME: shouldn't need the CREATE_NEW_CONSOLE, but as usual CUI:s need it
|
|
|
|
* while GUI:s don't
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!CreateProcess(NULL, cmdLine, NULL, NULL,
|
2002-07-20 22:18:17 +02:00
|
|
|
FALSE, DEBUG_PROCESS|DEBUG_ONLY_THIS_PROCESS|CREATE_NEW_CONSOLE,
|
|
|
|
NULL, NULL, &startup, &info))
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Couldn't start process '%s'\n", cmdLine);
|
2000-06-18 21:30:24 +02:00
|
|
|
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) {
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Run (%s) with '%s'\n", pgm, args);
|
2000-06-18 21:30:24 +02:00
|
|
|
} else {
|
|
|
|
if (!DEBUG_LastCmdLine) {
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Cannot find previously used command line.\n");
|
2000-06-18 21:30:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DEBUG_Start(DEBUG_LastCmdLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-04 03:18:20 +01:00
|
|
|
BOOL DEBUG_InterruptDebuggee(void)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Ctrl-C: stopping debuggee\n");
|
2003-03-04 03:18:20 +01:00
|
|
|
/* FIXME: since we likely have a single process, signal the first process
|
|
|
|
* in list
|
|
|
|
*/
|
2003-12-15 20:53:08 +01:00
|
|
|
if (!DEBUG_ProcessList) return FALSE;
|
|
|
|
DEBUG_ProcessList->continue_on_first_exception = FALSE;
|
|
|
|
return DebugBreakProcess(DEBUG_ProcessList->handle);
|
2003-03-04 03:18:20 +01:00
|
|
|
}
|
|
|
|
|
2002-06-02 23:20:02 +02:00
|
|
|
static BOOL WINAPI DEBUG_CtrlCHandler(DWORD dwCtrlType)
|
|
|
|
{
|
|
|
|
if (dwCtrlType == CTRL_C_EVENT)
|
|
|
|
{
|
2003-03-04 03:18:20 +01:00
|
|
|
return DEBUG_InterruptDebuggee();
|
2002-06-02 23:20:02 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:10:08 +01:00
|
|
|
static void DEBUG_InitConsole(void)
|
|
|
|
{
|
2002-06-02 23:20:02 +02:00
|
|
|
/* set our control-C handler */
|
|
|
|
SetConsoleCtrlHandler(DEBUG_CtrlCHandler, TRUE);
|
2002-09-04 20:42:13 +02:00
|
|
|
|
|
|
|
/* set our own title */
|
|
|
|
SetConsoleTitle("Wine Debugger");
|
2001-11-24 00:10:08 +01:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
static int DEBUG_Usage(void)
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Usage: winedbg [--debugmsg dbgoptions] [--auto] [--gdb] cmdline\n" );
|
2002-07-20 22:18:17 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-05-12 01:06:32 +02:00
|
|
|
int main(int argc, char** argv)
|
2000-03-09 19:45:43 +01:00
|
|
|
{
|
2000-06-18 21:30:24 +02:00
|
|
|
DWORD retv = 0;
|
2002-07-20 22:18:17 +02:00
|
|
|
unsigned gdb_flags = 0;
|
2000-04-30 14:21:15 +02:00
|
|
|
|
2002-07-30 02:03:34 +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
|
|
|
|
2002-06-04 23:31:10 +02:00
|
|
|
/* parse options */
|
|
|
|
while (argc > 1 && argv[1][0] == '-')
|
2001-10-22 21:00:34 +02:00
|
|
|
{
|
2002-06-04 23:31:10 +02:00
|
|
|
if (!strcmp( argv[1], "--auto" ))
|
|
|
|
{
|
2002-07-20 22:18:17 +02:00
|
|
|
if (local_mode != none_mode) return DEBUG_Usage();
|
|
|
|
local_mode = automatic_mode;
|
2002-06-04 23:31:10 +02:00
|
|
|
/* force some internal variables */
|
|
|
|
DBG_IVAR(BreakOnDllLoad) = 0;
|
2002-07-20 22:18:17 +02:00
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp( argv[1], "--gdb" ))
|
|
|
|
{
|
|
|
|
if (local_mode != none_mode) return DEBUG_Usage();
|
|
|
|
local_mode = gdb_mode;
|
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp( argv[1], "--no-start") == 0 && local_mode == gdb_mode)
|
|
|
|
{
|
|
|
|
gdb_flags |= 1;
|
|
|
|
argc--; argv++; /* as we don't use argv[0] */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(argv[1], "--with-xterm") == 0 && local_mode == gdb_mode)
|
|
|
|
{
|
|
|
|
gdb_flags |= 2;
|
|
|
|
argc--; argv++; /* as we don't use argv[0] */
|
2002-06-04 23:31:10 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp( argv[1], "--debugmsg" ) && argv[2])
|
|
|
|
{
|
|
|
|
wine_dbg_parse_options( argv[2] );
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
|
|
|
continue;
|
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
return DEBUG_Usage();
|
2001-10-22 21:00:34 +02:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (local_mode == none_mode) local_mode = winedbg_mode;
|
|
|
|
|
2003-02-11 23:05:06 +01:00
|
|
|
/* try the form <myself> pid */
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_CurrPid == 0 && argc == 2)
|
|
|
|
{
|
|
|
|
char* ptr;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_CurrPid = strtol(argv[1], &ptr, 10);
|
|
|
|
if (DEBUG_CurrPid == 0 || ptr == NULL ||
|
2003-02-11 23:05:06 +01:00
|
|
|
!DEBUG_Attach(DEBUG_CurrPid, local_mode != gdb_mode, FALSE))
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_CurrPid = 0;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-02-11 23:05:06 +01:00
|
|
|
/* try the form <myself> pid evt (Win32 JIT debugger) */
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_CurrPid == 0 && argc == 3)
|
|
|
|
{
|
2000-04-30 14:21:15 +02:00
|
|
|
HANDLE hEvent;
|
2000-06-18 21:30:24 +02:00
|
|
|
DWORD pid;
|
2002-07-20 22:18:17 +02:00
|
|
|
char* ptr;
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if ((pid = strtol(argv[1], &ptr, 10)) != 0 && ptr != NULL &&
|
|
|
|
(hEvent = (HANDLE)strtol(argv[2], &ptr, 10)) != 0 && ptr != NULL)
|
|
|
|
{
|
2003-02-11 23:05:06 +01:00
|
|
|
if (!DEBUG_Attach(pid, TRUE, FALSE))
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2001-04-14 00:26:23 +02:00
|
|
|
/* don't care about result */
|
|
|
|
SetEvent(hEvent);
|
2000-05-11 23:43:43 +02:00
|
|
|
goto leave;
|
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
if (!SetEvent(hEvent))
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Invalid event handle: %p\n", hEvent);
|
2001-04-14 00:26:23 +02:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
CloseHandle(hEvent);
|
2000-06-18 21:30:24 +02:00
|
|
|
DEBUG_CurrPid = pid;
|
2000-05-11 23:43:43 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DEBUG_CurrPid == 0 && argc > 1)
|
|
|
|
{
|
2000-06-18 21:30:24 +02:00
|
|
|
int i, len;
|
|
|
|
LPSTR cmdLine;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
if (!(cmdLine = DBG_alloc(len = 1))) goto oom_leave;
|
|
|
|
cmdLine[0] = '\0';
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
2000-06-18 21:30:24 +02:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (!DEBUG_Start(cmdLine))
|
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("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
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
/* don't save local vars in gdb mode */
|
|
|
|
if (local_mode == gdb_mode && DEBUG_CurrPid)
|
|
|
|
return DEBUG_GdbRemote(gdb_flags);
|
2000-04-30 14:21:15 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
DEBUG_InitConsole();
|
|
|
|
|
|
|
|
retv = DEBUG_MainLoop();
|
|
|
|
/* don't save modified variables in auto mode */
|
|
|
|
if (local_mode != automatic_mode) 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:
|
2003-12-15 20:53:08 +01:00
|
|
|
DEBUG_Printf("Out of memory\n");
|
2000-06-18 21:30:24 +02:00
|
|
|
goto leave;
|
|
|
|
}
|