2000-03-08 17:44:54 +01:00
|
|
|
/* Wine internal debugger
|
|
|
|
* Interface to Windows debugger API
|
2004-06-04 02:59:16 +02:00
|
|
|
* Copyright 2000-2004 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#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
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winternl.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"
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
/* TODO list:
|
|
|
|
*
|
|
|
|
* - minidump
|
|
|
|
* + allow winedbg in automatic mode to create a minidump (or add another option
|
|
|
|
* for that)
|
|
|
|
* + set a mode where winedbg would start (postmortem debugging) from a minidump
|
|
|
|
* - CPU adherence
|
2005-08-23 12:02:05 +02:00
|
|
|
* + we always assume the stack grows as on i386 (ie downwards)
|
2004-06-04 02:59:16 +02:00
|
|
|
* - UI
|
|
|
|
* + enable back the limited output (depth of structure printing and number of
|
|
|
|
* lines)
|
2004-07-04 02:25:15 +02:00
|
|
|
* + make the output as close as possible to what gdb does
|
2004-06-04 02:59:16 +02:00
|
|
|
* - symbol management:
|
|
|
|
* + symbol table loading is broken
|
2004-08-23 00:35:36 +02:00
|
|
|
* + in symbol_get_lvalue, we don't do any scoping (as C does) between local and
|
|
|
|
* global vars (we may need this to force some display for example). A solution
|
|
|
|
* would be always to return arrays with: local vars, global vars, thunks
|
2004-06-04 02:59:16 +02:00
|
|
|
* - type management:
|
|
|
|
* + some bits of internal types are missing (like type casts and the address
|
|
|
|
* operator)
|
|
|
|
* + the type for an enum's value is always inferred as int (winedbg & dbghelp)
|
|
|
|
* + most of the code implies that sizeof(void*) = sizeof(int)
|
|
|
|
* + all computations should be made on long long
|
|
|
|
* o expr computations are in int:s
|
|
|
|
* o bitfield size is on a 4-bytes
|
2005-11-18 13:05:44 +01:00
|
|
|
* + array_index and deref should be the same function (or should share the same
|
|
|
|
* core)
|
2004-08-23 00:35:36 +02:00
|
|
|
* - execution:
|
2004-06-04 02:59:16 +02:00
|
|
|
* + set a better fix for gdb (proxy mode) than the step-mode hack
|
|
|
|
* + implement function call in debuggee
|
|
|
|
* + trampoline management is broken when getting 16 <=> 32 thunk destination
|
|
|
|
* address
|
|
|
|
* + thunking of delayed imports doesn't work as expected (ie, when stepping,
|
|
|
|
* it currently stops at first insn with line number during the library
|
|
|
|
* loading). We should identify this (__wine_delay_import) and set a
|
|
|
|
* breakpoint instead of single stepping the library loading.
|
2004-09-28 04:13:27 +02:00
|
|
|
* + it's wrong to copy thread->step_over_bp into process->bp[0] (when
|
|
|
|
* we have a multi-thread debuggee). complete fix must include storing all
|
|
|
|
* thread's step-over bp in process-wide bp array, and not to handle bp
|
|
|
|
* when we have the wrong thread running into that bp
|
2005-11-16 12:23:07 +01:00
|
|
|
* + code in CREATE_PROCESS debug event doesn't work on Windows, as we cannot
|
|
|
|
* get the name of the main module this way. We should rewrite all this code
|
|
|
|
* and store in struct dbg_process as early as possible (before process
|
|
|
|
* creation or attachment), the name of the main module
|
|
|
|
* - global:
|
|
|
|
* + define a better way to enable the wine extensions (either DBG SDK function
|
|
|
|
* in dbghelp, or TLS variable, or environment variable or ...)
|
|
|
|
* + audit all files to ensure that we check all potential return values from
|
|
|
|
* every function call to catch the errors
|
|
|
|
* + BTW check also whether the exception mechanism is the best way to return
|
|
|
|
* errors (or find a proper fix for MinGW port)
|
|
|
|
* + use Wine standard list mechanism for all list handling
|
2004-06-04 02:59:16 +02:00
|
|
|
*/
|
|
|
|
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_process* dbg_curr_process = NULL;
|
|
|
|
struct dbg_thread* dbg_curr_thread = NULL;
|
|
|
|
DWORD dbg_curr_tid;
|
|
|
|
DWORD dbg_curr_pid;
|
|
|
|
CONTEXT dbg_context;
|
|
|
|
BOOL dbg_interactiveP = FALSE;
|
|
|
|
static char* dbg_last_cmd_line = NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static struct dbg_process* dbg_process_list = NULL;
|
|
|
|
static enum {none_mode = 0, winedbg_mode, automatic_mode, gdb_mode} dbg_action_mode;
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_internal_var dbg_internal_vars[DBG_IV_LAST];
|
|
|
|
const struct dbg_internal_var* dbg_context_vars;
|
|
|
|
static HANDLE dbg_houtput;
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
void dbg_outputA(const char* buffer, int len)
|
2000-04-30 14:21:15 +02:00
|
|
|
{
|
2005-03-07 13:26:48 +01:00
|
|
|
static char line_buff[4096];
|
|
|
|
static unsigned int line_pos;
|
|
|
|
|
|
|
|
DWORD w, i;
|
|
|
|
|
|
|
|
while (len > 0)
|
|
|
|
{
|
|
|
|
unsigned int count = min( len, sizeof(line_buff) - line_pos );
|
|
|
|
memcpy( line_buff + line_pos, buffer, count );
|
|
|
|
buffer += count;
|
|
|
|
len -= count;
|
|
|
|
line_pos += count;
|
|
|
|
for (i = line_pos; i > 0; i--) if (line_buff[i-1] == '\n') break;
|
|
|
|
if (!i) /* no newline found */
|
|
|
|
{
|
|
|
|
if (len > 0) i = line_pos; /* buffer is full, flush anyway */
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
WriteFile(dbg_houtput, line_buff, i, &w, NULL);
|
|
|
|
memmove( line_buff, line_buff + i, line_pos - i );
|
|
|
|
line_pos -= i;
|
|
|
|
}
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
void dbg_outputW(const WCHAR* buffer, int len)
|
2002-05-25 23:18:34 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
char* ansi = NULL;
|
|
|
|
int newlen;
|
2003-06-30 22:19:42 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
if (!(ansi = HeapAlloc(GetProcessHeap(), 0, newlen))) return;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, buffer, len, ansi, newlen, NULL, NULL);
|
|
|
|
dbg_outputA(ansi, newlen);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ansi);
|
|
|
|
}
|
2002-05-25 23:18:34 +02:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
int dbg_printf(const char* format, ...)
|
2000-04-13 21:31:58 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +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
|
|
|
|
2004-06-04 02:59:16 +02: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] = '.';
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_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
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static unsigned dbg_load_internal_vars(void)
|
2000-03-26 15:37:39 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
HKEY hkey;
|
|
|
|
DWORD type = REG_DWORD;
|
|
|
|
DWORD val;
|
|
|
|
DWORD count = sizeof(val);
|
|
|
|
int i;
|
|
|
|
struct dbg_internal_var* div = dbg_internal_vars;
|
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
/* initializes internal vars table */
|
2004-06-04 02:59:16 +02:00
|
|
|
#define INTERNAL_VAR(_var,_val,_ref,_tid) \
|
2000-04-30 14:21:15 +02:00
|
|
|
div->val = _val; div->name = #_var; div->pval = _ref; \
|
2004-06-04 02:59:16 +02:00
|
|
|
div->typeid = _tid; div++;
|
2000-04-13 21:31:58 +02:00
|
|
|
#include "intvar.h"
|
|
|
|
#undef INTERNAL_VAR
|
2004-06-04 02:59:16 +02:00
|
|
|
|
2005-06-13 20:56:00 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\WineDbg */
|
2004-06-04 02:59:16 +02:00
|
|
|
if (RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey))
|
|
|
|
{
|
|
|
|
WINE_ERR("Cannot create WineDbg key in registry\n");
|
|
|
|
return FALSE;
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
for (i = 0; i < DBG_IV_LAST; i++)
|
|
|
|
{
|
|
|
|
if (!dbg_internal_vars[i].pval)
|
|
|
|
{
|
|
|
|
if (!RegQueryValueEx(hkey, dbg_internal_vars[i].name, 0,
|
2005-07-07 14:08:42 +02:00
|
|
|
&type, (LPBYTE)&val, &count))
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_internal_vars[i].val = val;
|
|
|
|
dbg_internal_vars[i].pval = &dbg_internal_vars[i].val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
/* set up the debug variables for the CPU context */
|
|
|
|
dbg_context_vars = be_cpu->init_registers(&dbg_context);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned dbg_save_internal_vars(void)
|
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
int i;
|
|
|
|
|
2005-06-13 20:56:00 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\WineDbg */
|
2004-06-04 02:59:16 +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;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
for (i = 0; i < DBG_IV_LAST; i++)
|
|
|
|
{
|
|
|
|
/* FIXME: type should be infered from basic type -if any- of intvar */
|
|
|
|
if (dbg_internal_vars[i].pval == &dbg_internal_vars[i].val)
|
|
|
|
RegSetValueEx(hkey, dbg_internal_vars[i].name, 0,
|
|
|
|
REG_DWORD, (const void*)dbg_internal_vars[i].pval,
|
|
|
|
sizeof(*dbg_internal_vars[i].pval));
|
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
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
const struct dbg_internal_var* dbg_get_internal_var(const char* name)
|
2000-04-30 14:21:15 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
const struct dbg_internal_var* div;
|
2000-04-30 14:21:15 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
for (div = &dbg_internal_vars[DBG_IV_LAST - 1]; div >= dbg_internal_vars; div--)
|
|
|
|
{
|
|
|
|
if (!strcmp(div->name, name)) return div;
|
2000-04-30 14:21:15 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
for (div = dbg_context_vars; div->name; div++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(div->name, name)) return div;
|
|
|
|
}
|
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_process* dbg_get_process(DWORD pid)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_process* p;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
for (p = dbg_process_list; p; p = p->next)
|
2000-03-08 17:44:54 +01:00
|
|
|
if (p->pid == pid) break;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2005-05-24 13:46:25 +02:00
|
|
|
struct dbg_process* dbg_add_process(DWORD pid, HANDLE h)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2005-05-24 13:46:25 +02:00
|
|
|
/* FIXME: temporary */
|
|
|
|
extern struct be_process_io be_process_active_io;
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_process* p;
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if ((p = dbg_get_process(pid)))
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
|
|
|
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;
|
2005-05-24 13:46:25 +02:00
|
|
|
p->imageName = NULL;
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!(p = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dbg_process)))) return NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
p->handle = h;
|
|
|
|
p->pid = pid;
|
2005-05-24 13:46:25 +02:00
|
|
|
p->process_io = &be_process_active_io;
|
|
|
|
p->imageName = NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
p->threads = NULL;
|
2000-05-05 20:14:34 +02:00
|
|
|
p->continue_on_first_exception = FALSE;
|
2004-06-04 02:59:16 +02:00
|
|
|
p->next_bp = 1; /* breakpoint 0 is reserved for step-over */
|
|
|
|
memset(p->bp, 0, sizeof(p->bp));
|
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
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
p->next = dbg_process_list;
|
2000-03-08 17:44:54 +01:00
|
|
|
p->prev = NULL;
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_process_list) dbg_process_list->prev = p;
|
|
|
|
dbg_process_list = p;
|
2000-03-08 17:44:54 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2005-05-24 13:46:25 +02:00
|
|
|
void dbg_set_process_name(struct dbg_process* p, const char* imageName)
|
|
|
|
{
|
|
|
|
assert(p->imageName == NULL);
|
|
|
|
if (imageName)
|
|
|
|
{
|
|
|
|
char* tmp = HeapAlloc(GetProcessHeap(), 0, strlen(imageName) + 1);
|
|
|
|
if (tmp) p->imageName = strcpy(tmp, imageName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
void dbg_del_process(struct dbg_process* p)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2001-05-21 20:33:15 +02:00
|
|
|
int i;
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
while (p->threads) dbg_del_thread(p->threads);
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2002-07-30 02:06:34 +02:00
|
|
|
for (i = 0; i < p->num_delayed_bp; i++)
|
|
|
|
if (p->delayed_bp[i].is_symbol)
|
2004-06-04 02:59:16 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, p->delayed_bp[i].u.symbol.name);
|
2002-07-30 02:06:34 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, 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;
|
2004-06-04 02:59:16 +02:00
|
|
|
if (p == dbg_process_list) dbg_process_list = p->next;
|
|
|
|
if (p == dbg_curr_process) dbg_curr_process = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, (char*)p->imageName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, p);
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static void dbg_init_current_process(void)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
struct mod_loader_info
|
2000-03-10 23:25:07 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
HANDLE handle;
|
|
|
|
IMAGEHLP_MODULE* imh_mod;
|
|
|
|
};
|
2000-03-10 23:25:07 +01:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static BOOL CALLBACK mod_loader_cb(PSTR mod_name, DWORD base, void* ctx)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
struct mod_loader_info* mli = (struct mod_loader_info*)ctx;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!strcmp(mod_name, "<wine-loader>"))
|
2003-09-30 03:04:19 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (SymGetModuleInfo(mli->handle, base, mli->imh_mod))
|
|
|
|
return FALSE; /* stop enum */
|
2003-09-30 03:04:19 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
return TRUE;
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE* imh_mod)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
struct mod_loader_info mli;
|
|
|
|
DWORD opt;
|
|
|
|
|
|
|
|
/* this will resynchronize builtin dbghelp's internal ELF module list */
|
|
|
|
SymLoadModule(hProcess, 0, 0, 0, 0, 0);
|
|
|
|
mli.handle = hProcess;
|
|
|
|
mli.imh_mod = imh_mod;
|
|
|
|
imh_mod->SizeOfStruct = sizeof(*imh_mod);
|
|
|
|
imh_mod->BaseOfImage = 0;
|
|
|
|
/* this is a wine specific options to return also ELF modules in the
|
|
|
|
* enumeration
|
|
|
|
*/
|
|
|
|
SymSetOptions((opt = SymGetOptions()) | 0x40000000);
|
|
|
|
SymEnumerateModules(hProcess, mod_loader_cb, (void*)&mli);
|
|
|
|
SymSetOptions(opt);
|
|
|
|
|
|
|
|
return imh_mod->BaseOfImage != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dbg_thread* dbg_get_thread(struct dbg_process* p, DWORD tid)
|
|
|
|
{
|
|
|
|
struct 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;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid,
|
2004-09-28 04:13:27 +02:00
|
|
|
HANDLE h, void* teb)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_thread* t = HeapAlloc(GetProcessHeap(), 0, sizeof(struct 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->teb = teb;
|
|
|
|
t->process = p;
|
2004-06-04 02:59:16 +02:00
|
|
|
t->exec_mode = dbg_exec_cont;
|
2002-04-01 23:03:13 +02:00
|
|
|
t->exec_count = 0;
|
2004-08-23 00:35:36 +02:00
|
|
|
t->step_over_bp.enabled = FALSE;
|
|
|
|
t->step_over_bp.refcount = 0;
|
2005-05-23 18:22:44 +02:00
|
|
|
t->in_exception = FALSE;
|
2005-11-18 13:33:03 +01:00
|
|
|
t->frames = NULL;
|
|
|
|
t->num_frames = 0;
|
|
|
|
t->curr_frame = -1;
|
2002-04-01 23:03:13 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
snprintf(t->name, sizeof(t->name), "0x%08lx", tid);
|
2000-03-26 15:37:39 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static void dbg_init_current_thread(void* start)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (start)
|
|
|
|
{
|
2004-08-23 00:35:36 +02:00
|
|
|
if (dbg_curr_process->threads &&
|
|
|
|
!dbg_curr_process->threads->next && /* first thread ? */
|
2004-06-04 02:59:16 +02:00
|
|
|
DBG_IVAR(BreakAllThreadsStartup))
|
|
|
|
{
|
|
|
|
ADDRESS addr;
|
|
|
|
|
|
|
|
break_set_xpoints(FALSE);
|
|
|
|
addr.Mode = AddrModeFlat;
|
|
|
|
addr.Offset = (DWORD)start;
|
|
|
|
break_add_break(&addr, TRUE);
|
|
|
|
break_set_xpoints(TRUE);
|
2000-03-26 15:37:39 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
void dbg_del_thread(struct dbg_thread* t)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2005-11-18 13:33:03 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, t->frames);
|
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;
|
2004-06-04 02:59:16 +02:00
|
|
|
if (t == dbg_curr_thread) dbg_curr_thread = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, t);
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static unsigned dbg_handle_debug_event(DEBUG_EVENT* de);
|
2003-02-11 23:05:06 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
2004-06-04 02:59:16 +02:00
|
|
|
* dbg_attach_debuggee
|
2003-02-11 23:05:06 +01:00
|
|
|
*
|
|
|
|
* Sets the debuggee to <pid>
|
|
|
|
* cofe instructs winedbg what to do when first exception is received
|
|
|
|
* (break=FALSE, continue=TRUE)
|
2004-06-04 02:59:16 +02:00
|
|
|
* wfe is set to TRUE if dbg_attach_debuggee should also proceed with all debug events
|
2003-02-11 23:05:06 +01:00
|
|
|
* until the first exception is received (aka: attach to an already running process)
|
|
|
|
*/
|
2004-06-04 02:59:16 +02:00
|
|
|
BOOL dbg_attach_debuggee(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;
|
|
|
|
|
2005-05-24 13:46:25 +02:00
|
|
|
if (!(dbg_curr_process = dbg_add_process(pid, 0))) return FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!DebugActiveProcess(pid))
|
|
|
|
{
|
|
|
|
dbg_printf("Can't attach process %lx: error %ld\n", pid, GetLastError());
|
|
|
|
dbg_del_process(dbg_curr_process);
|
2000-06-18 21:30:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_process->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 ? */
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_interactiveP = FALSE;
|
|
|
|
while (dbg_curr_process && WaitForDebugEvent(&de, INFINITE))
|
2003-02-11 23:05:06 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_handle_debug_event(&de)) break;
|
2003-02-11 23:05:06 +01:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_process) dbg_interactiveP = TRUE;
|
2003-02-11 23:05:06 +01:00
|
|
|
}
|
2000-06-18 21:30:24 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
BOOL dbg_detach_debuggee(void)
|
2002-02-27 02:29:18 +01:00
|
|
|
{
|
|
|
|
/* remove all set breakpoints in debuggee code */
|
2004-06-04 02:59:16 +02:00
|
|
|
break_set_xpoints(FALSE);
|
2002-06-01 01:06:46 +02:00
|
|
|
/* needed for single stepping (ugly).
|
2004-06-04 02:59:16 +02:00
|
|
|
* should this be handled inside the server ???
|
|
|
|
*/
|
|
|
|
be_cpu->single_step(&dbg_context, FALSE);
|
|
|
|
SetThreadContext(dbg_curr_thread->handle, &dbg_context);
|
2005-05-23 18:22:44 +02:00
|
|
|
if (dbg_curr_thread->in_exception)
|
2004-06-04 02:59:16 +02:00
|
|
|
ContinueDebugEvent(dbg_curr_pid, dbg_curr_tid, DBG_CONTINUE);
|
|
|
|
if (!DebugActiveProcessStop(dbg_curr_pid)) return FALSE;
|
|
|
|
dbg_del_process(dbg_curr_process);
|
|
|
|
|
2002-02-27 02:29:18 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static unsigned dbg_fetch_context(void)
|
2002-08-29 00:21:20 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_context.ContextFlags = CONTEXT_CONTROL
|
|
|
|
| CONTEXT_INTEGER
|
2002-08-29 00:21:20 +02:00
|
|
|
#ifdef CONTEXT_SEGMENTS
|
2004-06-04 02:59:16 +02:00
|
|
|
| CONTEXT_SEGMENTS
|
2002-08-29 00:21:20 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONTEXT_DEBUG_REGISTERS
|
2004-06-04 02:59:16 +02:00
|
|
|
| CONTEXT_DEBUG_REGISTERS
|
2002-08-29 00:21:20 +02:00
|
|
|
#endif
|
2004-06-04 02:59:16 +02:00
|
|
|
;
|
|
|
|
if (!GetThreadContext(dbg_curr_thread->handle, &dbg_context))
|
2002-08-29 00:21:20 +02:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2005-05-23 18:22:44 +02:00
|
|
|
static unsigned dbg_exception_prolog(BOOL is_debug, const EXCEPTION_RECORD* rec)
|
2000-06-18 21:30:24 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
ADDRESS addr;
|
2004-09-28 04:13:27 +02:00
|
|
|
BOOL is_break;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
memory_get_current_pc(&addr);
|
|
|
|
break_suspend_execution();
|
2005-05-23 18:22:44 +02:00
|
|
|
dbg_curr_thread->excpt_record = *rec;
|
|
|
|
dbg_curr_thread->in_exception = TRUE;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
if (!is_debug)
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
switch (addr.Mode)
|
|
|
|
{
|
|
|
|
case AddrModeFlat: dbg_printf(" in 32-bit code (0x%08lx)", addr.Offset); break;
|
|
|
|
case AddrModeReal: dbg_printf(" in vm86 code (%04x:%04lx)", addr.Segment, addr.Offset); break;
|
|
|
|
case AddrMode1616: dbg_printf(" in 16-bit code (%04x:%04lx)", addr.Segment, addr.Offset); break;
|
2005-03-03 15:10:17 +01:00
|
|
|
case AddrMode1632: dbg_printf(" in 32-bit code (%04x:%08lx)", addr.Segment, addr.Offset); break;
|
2004-06-04 02:59:16 +02:00
|
|
|
default: dbg_printf(" bad address");
|
2000-09-24 05:15:50 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf(".\n");
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
/* this will resynchronize builtin dbghelp's internal ELF module list */
|
|
|
|
SymLoadModule(dbg_curr_process->handle, 0, 0, 0, 0, 0);
|
|
|
|
|
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.
|
|
|
|
*/
|
2005-11-18 13:33:03 +01:00
|
|
|
stack_fetch_frames();
|
2004-09-28 04:13:27 +02:00
|
|
|
if (is_debug &&
|
2005-05-23 18:22:44 +02:00
|
|
|
break_should_continue(&addr, rec->ExceptionCode, &dbg_curr_thread->exec_count, &is_break))
|
2000-06-18 21:30:24 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (addr.Mode != dbg_curr_thread->addr_mode)
|
2000-09-24 05:15:50 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
const char* name = NULL;
|
|
|
|
|
|
|
|
switch (addr.Mode)
|
|
|
|
{
|
|
|
|
case AddrMode1616: name = "16 bit"; break;
|
2005-03-03 15:10:17 +01:00
|
|
|
case AddrMode1632: name = "32 bit"; break;
|
2004-06-04 02:59:16 +02:00
|
|
|
case AddrModeReal: name = "vm86"; break;
|
|
|
|
case AddrModeFlat: name = "32 bit"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbg_printf("In %s mode.\n", name);
|
|
|
|
dbg_curr_thread->addr_mode = addr.Mode;
|
2000-09-24 05:15:50 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
display_print();
|
2000-06-18 21:30:24 +02:00
|
|
|
|
2004-09-28 04:13:27 +02:00
|
|
|
if (!is_debug)
|
2004-06-04 02:59:16 +02:00
|
|
|
{
|
2000-06-18 21:30:24 +02:00
|
|
|
/* This is a real crash, dump some info */
|
2004-06-04 02:59:16 +02:00
|
|
|
be_cpu->print_context(dbg_curr_thread->handle, &dbg_context);
|
|
|
|
stack_info();
|
|
|
|
be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context);
|
2005-11-18 13:33:03 +01:00
|
|
|
stack_backtrace(dbg_curr_tid);
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2005-10-03 13:04:29 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
static char* last_name;
|
|
|
|
static char* last_file;
|
|
|
|
|
|
|
|
char buffer[sizeof(SYMBOL_INFO) + 256];
|
|
|
|
SYMBOL_INFO* si = (SYMBOL_INFO*)buffer;
|
|
|
|
void* lin = memory_to_linear_addr(&addr);
|
|
|
|
DWORD64 disp64;
|
|
|
|
IMAGEHLP_LINE il;
|
|
|
|
DWORD disp;
|
|
|
|
|
|
|
|
si->SizeOfStruct = sizeof(*si);
|
|
|
|
si->MaxNameLen = 256;
|
|
|
|
il.SizeOfStruct = sizeof(il);
|
|
|
|
if (SymFromAddr(dbg_curr_process->handle, (DWORD_PTR)lin, &disp64, si) &&
|
|
|
|
SymGetLineFromAddr(dbg_curr_process->handle, (DWORD_PTR)lin, &disp, &il))
|
|
|
|
{
|
|
|
|
if ((!last_name || strcmp(last_name, si->Name)) ||
|
|
|
|
(!last_file || strcmp(last_file, il.FileName)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, last_name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, last_file);
|
|
|
|
last_name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(si->Name) + 1), si->Name);
|
|
|
|
last_file = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(il.FileName) + 1), il.FileName);
|
|
|
|
dbg_printf("%s () at %s:%ld\n", last_name, last_file, il.LineNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-28 04:13:27 +02:00
|
|
|
if (!is_debug || is_break ||
|
|
|
|
dbg_curr_thread->exec_mode == dbg_exec_step_over_insn ||
|
|
|
|
dbg_curr_thread->exec_mode == dbg_exec_step_into_insn)
|
2004-06-04 02:59:16 +02:00
|
|
|
{
|
2004-09-28 04:13:27 +02:00
|
|
|
ADDRESS tmp = addr;
|
2004-06-04 02:59:16 +02:00
|
|
|
/* Show where we crashed */
|
2004-09-28 04:13:27 +02:00
|
|
|
memory_disasm_one_insn(&tmp);
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2004-09-28 04:13:27 +02:00
|
|
|
source_list_from_addr(&addr, 0);
|
|
|
|
|
2000-06-18 21:30:24 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static void dbg_exception_epilog(void)
|
2000-06-18 21:30:24 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
break_restart_execution(dbg_curr_thread->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.
|
|
|
|
*/
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_thread->exec_mode == dbg_exec_cont)
|
|
|
|
dbg_curr_thread->exec_count = 0;
|
2005-05-23 18:22:44 +02:00
|
|
|
dbg_curr_thread->in_exception = FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
|
|
|
|
2005-05-23 18:22:44 +02:00
|
|
|
static DWORD dbg_handle_exception(const EXCEPTION_RECORD* rec, BOOL first_chance)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
BOOL is_debug = FALSE;
|
|
|
|
THREADNAME_INFO* pThreadName;
|
|
|
|
struct dbg_thread* pThread;
|
2001-04-09 20:31:47 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
assert(dbg_curr_thread);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2004-09-28 04:13:27 +02:00
|
|
|
WINE_TRACE("exception=%lx first_chance=%c\n",
|
|
|
|
rec->ExceptionCode, first_chance ? 'Y' : 'N');
|
|
|
|
|
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)
|
2004-06-04 02:59:16 +02:00
|
|
|
pThread = dbg_curr_thread;
|
2001-04-09 20:31:47 +02:00
|
|
|
else
|
2004-06-04 02:59:16 +02:00
|
|
|
pThread = dbg_get_thread(dbg_curr_process, pThreadName->dwThreadID);
|
2001-04-09 20:31:47 +02:00
|
|
|
|
2004-08-23 00:35:36 +02:00
|
|
|
if (dbg_read_memory(pThreadName->szName, pThread->name, 9))
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_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
|
|
|
}
|
|
|
|
|
2005-08-23 12:02:05 +02:00
|
|
|
if (first_chance && !is_debug && !DBG_IVAR(BreakOnFirstChance) &&
|
|
|
|
!(rec->ExceptionFlags & EH_STACK_INVALID))
|
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 */
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_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:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("divide by zero");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_INT_OVERFLOW:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("overflow");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("array bounds");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("illegal instruction");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_STACK_OVERFLOW:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("stack overflow");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_PRIV_INSTRUCTION:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("privileged instruction");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
|
|
|
if (rec->NumberParameters == 2)
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_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
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("page fault");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_DATATYPE_MISALIGNMENT:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("Alignment");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
2001-11-24 00:10:08 +01:00
|
|
|
case DBG_CONTROL_C:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("^C");
|
2001-11-24 00:10:08 +01:00
|
|
|
break;
|
2000-03-08 17:44:54 +01:00
|
|
|
case CONTROL_C_EXIT:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("^C");
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
2003-04-04 21:41:31 +02:00
|
|
|
case STATUS_POSSIBLE_DEADLOCK:
|
2004-06-04 02:59:16 +02:00
|
|
|
{
|
|
|
|
ADDRESS addr;
|
2001-08-07 21:32:14 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
addr.Mode = AddrModeFlat;
|
|
|
|
addr.Offset = rec->ExceptionInformation[0];
|
2001-08-07 21:32:14 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("wait failed on critical section ");
|
|
|
|
print_address(&addr, FALSE);
|
|
|
|
}
|
|
|
|
if (!DBG_IVAR(BreakOnCritSectTimeOut))
|
|
|
|
{
|
|
|
|
dbg_printf("\n");
|
|
|
|
return DBG_EXCEPTION_NOT_HANDLED;
|
|
|
|
}
|
|
|
|
break;
|
2000-10-27 00:03:34 +02:00
|
|
|
case EXCEPTION_WINE_STUB:
|
2004-06-04 02:59:16 +02:00
|
|
|
{
|
|
|
|
char dll[32], name[64];
|
2005-05-24 13:46:25 +02:00
|
|
|
memory_get_string(dbg_curr_process,
|
2004-08-23 00:35:36 +02:00
|
|
|
(void*)rec->ExceptionInformation[0], TRUE, FALSE,
|
2004-06-04 02:59:16 +02:00
|
|
|
dll, sizeof(dll));
|
2004-12-14 21:03:23 +01:00
|
|
|
if (HIWORD(rec->ExceptionInformation[1]))
|
2005-05-24 13:46:25 +02:00
|
|
|
memory_get_string(dbg_curr_process,
|
2004-12-14 21:03:23 +01:00
|
|
|
(void*)rec->ExceptionInformation[1], TRUE, FALSE,
|
|
|
|
name, sizeof(name));
|
|
|
|
else
|
|
|
|
sprintf( name, "%ld", rec->ExceptionInformation[1] );
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("unimplemented function %s.%s called", dll, name);
|
|
|
|
}
|
|
|
|
break;
|
2002-10-29 00:56:58 +01:00
|
|
|
case EXCEPTION_WINE_ASSERTION:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("assertion failed");
|
2002-10-29 00:56:58 +01:00
|
|
|
break;
|
2000-09-24 05:15:50 +02:00
|
|
|
case EXCEPTION_VM86_INTx:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("interrupt %02lx in vm86 mode", rec->ExceptionInformation[0]);
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case EXCEPTION_VM86_STI:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("sti in vm86 mode");
|
2000-09-24 05:15:50 +02:00
|
|
|
break;
|
|
|
|
case EXCEPTION_VM86_PICRETURN:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_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:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("denormal float operand");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("divide by zero");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_INEXACT_RESULT:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("inexact float result");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_INVALID_OPERATION:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("invalid float operation");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_OVERFLOW:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("floating pointer overflow");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_UNDERFLOW:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("floating pointer underflow");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
|
|
|
case EXCEPTION_FLT_STACK_CHECK:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("floating point stack check");
|
2003-02-24 21:38:44 +01:00
|
|
|
break;
|
2000-03-08 17:44:54 +01:00
|
|
|
default:
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("0x%08lx", rec->ExceptionCode);
|
2000-03-08 17:44:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-08-23 12:02:05 +02:00
|
|
|
if( (rec->ExceptionFlags & EH_STACK_INVALID) ) {
|
|
|
|
dbg_printf( ", invalid program stack" );
|
|
|
|
}
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_action_mode == automatic_mode)
|
2001-10-22 21:00:34 +02:00
|
|
|
{
|
2005-05-23 18:22:44 +02:00
|
|
|
dbg_exception_prolog(is_debug, rec);
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_exception_epilog();
|
2003-08-21 23:28:51 +02:00
|
|
|
return 0; /* terminate execution */
|
2001-10-22 21:00:34 +02:00
|
|
|
}
|
|
|
|
|
2005-05-23 18:22:44 +02:00
|
|
|
if (dbg_exception_prolog(is_debug, rec))
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_interactiveP = TRUE;
|
2003-08-21 23:28:51 +02:00
|
|
|
return 0;
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_exception_epilog();
|
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
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static unsigned dbg_handle_debug_event(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
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_pid = de->dwProcessId;
|
|
|
|
dbg_curr_tid = de->dwThreadId;
|
2000-05-11 23:43:43 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if ((dbg_curr_process = dbg_get_process(de->dwProcessId)) != NULL)
|
|
|
|
dbg_curr_thread = dbg_get_thread(dbg_curr_process, de->dwThreadId);
|
2002-07-20 22:18:17 +02:00
|
|
|
else
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_thread = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-07-20 22:18:17 +02:00
|
|
|
switch (de->dwDebugEventCode)
|
|
|
|
{
|
|
|
|
case EXCEPTION_DEBUG_EVENT:
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!dbg_curr_thread)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
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
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_process->continue_on_first_exception)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_process->continue_on_first_exception = FALSE;
|
2002-07-20 22:18:17 +02:00
|
|
|
if (!DBG_IVAR(BreakOnAttach)) break;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_fetch_context())
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
cont = dbg_handle_exception(&de->u.Exception.ExceptionRecord,
|
2004-09-28 04:13:27 +02:00
|
|
|
de->u.Exception.dwFirstChance);
|
2004-06-04 02:59:16 +02:00
|
|
|
if (cont && dbg_curr_thread)
|
2002-08-29 00:21:20 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
SetThreadContext(dbg_curr_thread->handle, &dbg_context);
|
2002-08-29 00:21:20 +02:00
|
|
|
}
|
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_PROCESS_DEBUG_EVENT:
|
2005-05-24 13:46:25 +02:00
|
|
|
dbg_curr_process = dbg_add_process(de->dwProcessId,
|
|
|
|
de->u.CreateProcessInfo.hProcess);
|
|
|
|
if (dbg_curr_process == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("Couldn't create process\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memory_get_string_indirect(dbg_curr_process,
|
2004-06-04 02:59:16 +02:00
|
|
|
de->u.CreateProcessInfo.lpImageName,
|
|
|
|
de->u.CreateProcessInfo.fUnicode,
|
|
|
|
buffer, sizeof(buffer));
|
2005-05-24 13:46:25 +02:00
|
|
|
if (!buffer[0]) strcpy(buffer, "<Debugged Process>");
|
|
|
|
|
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,
|
2004-06-04 02:59:16 +02:00
|
|
|
(unsigned long)(void*)de->u.CreateProcessInfo.lpStartAddress,
|
2003-12-15 20:53:08 +01:00
|
|
|
de->u.CreateProcessInfo.dwDebugInfoFileOffset,
|
|
|
|
de->u.CreateProcessInfo.nDebugInfoSize);
|
2005-05-24 13:46:25 +02:00
|
|
|
dbg_set_process_name(dbg_curr_process, buffer);
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!SymInitialize(dbg_curr_process->handle, NULL, TRUE))
|
|
|
|
dbg_printf("Couldn't initiate DbgHelp\n");
|
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,
|
2004-06-04 02:59:16 +02:00
|
|
|
(unsigned long)(void*)de->u.CreateProcessInfo.lpStartAddress);
|
|
|
|
|
|
|
|
dbg_curr_thread = dbg_add_thread(dbg_curr_process,
|
|
|
|
de->dwThreadId,
|
|
|
|
de->u.CreateProcessInfo.hThread,
|
|
|
|
de->u.CreateProcessInfo.lpThreadLocalBase);
|
|
|
|
if (!dbg_curr_thread)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
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-06-04 02:59:16 +02:00
|
|
|
dbg_init_current_process();
|
|
|
|
dbg_init_current_thread(de->u.CreateProcessInfo.lpStartAddress);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
|
|
|
WINE_TRACE("%08lx:%08lx: exit process (%ld)\n",
|
|
|
|
de->dwProcessId, de->dwThreadId, de->u.ExitProcess.dwExitCode);
|
|
|
|
|
|
|
|
if (dbg_curr_process == NULL)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
WINE_ERR("Unknown process\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!SymCleanup(dbg_curr_process->handle))
|
|
|
|
dbg_printf("Couldn't initiate DbgHelp\n");
|
|
|
|
/* just in case */
|
|
|
|
break_set_xpoints(FALSE);
|
|
|
|
/* kill last thread */
|
|
|
|
dbg_del_thread(dbg_curr_process->threads);
|
|
|
|
dbg_del_process(dbg_curr_process);
|
2002-05-25 23:07:58 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("Process of pid=0x%08lx has terminated\n", dbg_curr_pid);
|
|
|
|
break;
|
2000-06-08 07:02:19 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
case CREATE_THREAD_DEBUG_EVENT:
|
|
|
|
WINE_TRACE("%08lx:%08lx: create thread D @%08lx\n",
|
|
|
|
de->dwProcessId, de->dwThreadId,
|
|
|
|
(unsigned long)(void*)de->u.CreateThread.lpStartAddress);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_process == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("Unknown process\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dbg_get_thread(dbg_curr_process, de->dwThreadId) != NULL)
|
|
|
|
{
|
|
|
|
WINE_TRACE("Thread already listed, skipping\n");
|
|
|
|
break;
|
2004-02-03 01:14:12 +01:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
|
|
|
|
dbg_curr_thread = dbg_add_thread(dbg_curr_process,
|
|
|
|
de->dwThreadId,
|
|
|
|
de->u.CreateThread.hThread,
|
|
|
|
de->u.CreateThread.lpThreadLocalBase);
|
|
|
|
if (!dbg_curr_thread)
|
|
|
|
{
|
|
|
|
WINE_ERR("Couldn't create thread\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dbg_init_current_thread(de->u.CreateThread.lpStartAddress);
|
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
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_thread == NULL)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
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 */
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_del_thread(dbg_curr_thread);
|
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:
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_thread == NULL)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2003-12-15 20:53:08 +01:00
|
|
|
WINE_ERR("Unknown thread\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-05-24 13:46:25 +02:00
|
|
|
memory_get_string_indirect(dbg_curr_process,
|
2004-06-04 02:59:16 +02:00
|
|
|
de->u.LoadDll.lpImageName,
|
|
|
|
de->u.LoadDll.fUnicode,
|
|
|
|
buffer, sizeof(buffer));
|
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);
|
2004-06-04 02:59:16 +02:00
|
|
|
SymLoadModule(dbg_curr_process->handle, de->u.LoadDll.hFile, buffer, NULL,
|
|
|
|
(unsigned long)de->u.LoadDll.lpBaseOfDll, 0);
|
|
|
|
break_set_xpoints(FALSE);
|
|
|
|
break_check_delayed_bp();
|
|
|
|
break_set_xpoints(TRUE);
|
2002-07-20 22:18:17 +02:00
|
|
|
if (DBG_IVAR(BreakOnDllLoad))
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("Stopping on DLL %s loading at 0x%08lx\n",
|
|
|
|
buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll);
|
|
|
|
if (dbg_fetch_context()) 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:
|
2004-06-04 02:59:16 +02:00
|
|
|
WINE_TRACE("%08lx:%08lx: unload DLL @%08lx\n",
|
|
|
|
de->dwProcessId, de->dwThreadId,
|
2003-12-15 20:53:08 +01:00
|
|
|
(unsigned long)de->u.UnloadDll.lpBaseOfDll);
|
2004-06-04 02:59:16 +02:00
|
|
|
break_delete_xpoints_from_module((unsigned long)de->u.UnloadDll.lpBaseOfDll);
|
|
|
|
SymUnloadModule(dbg_curr_process->handle,
|
|
|
|
(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:
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_thread == NULL)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
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
|
|
|
|
2005-05-24 13:46:25 +02:00
|
|
|
memory_get_string(dbg_curr_process,
|
2004-08-23 00:35:36 +02:00
|
|
|
de->u.DebugString.lpDebugStringData, TRUE,
|
2004-06-04 02:59:16 +02:00
|
|
|
de->u.DebugString.fUnicode, buffer, sizeof(buffer));
|
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
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static void dbg_resume_debuggee(DWORD cont)
|
2000-03-26 15:37:39 +02:00
|
|
|
{
|
2005-05-23 18:22:44 +02:00
|
|
|
if (dbg_curr_thread->in_exception)
|
2002-08-29 00:21:20 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
ADDRESS addr;
|
|
|
|
|
|
|
|
dbg_exception_epilog();
|
|
|
|
memory_get_current_pc(&addr);
|
|
|
|
WINE_TRACE("Exiting debugger PC=0x%lx mode=%d count=%d\n",
|
|
|
|
addr.Offset, dbg_curr_thread->exec_mode,
|
|
|
|
dbg_curr_thread->exec_count);
|
|
|
|
if (dbg_curr_thread)
|
2002-08-29 00:21:20 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!SetThreadContext(dbg_curr_thread->handle, &dbg_context))
|
|
|
|
dbg_printf("Cannot set ctx on %lu\n", dbg_curr_tid);
|
2002-08-29 00:21:20 +02:00
|
|
|
}
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_interactiveP = FALSE;
|
|
|
|
if (!ContinueDebugEvent(dbg_curr_pid, dbg_curr_tid, cont))
|
|
|
|
dbg_printf("Cannot continue on %lu (%lu)\n", dbg_curr_tid, cont);
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
void dbg_wait_next_exception(DWORD cont, int count, int mode)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
|
|
|
DEBUG_EVENT de;
|
2004-06-04 02:59:16 +02:00
|
|
|
ADDRESS addr;
|
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
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_thread->exec_count = count;
|
|
|
|
dbg_curr_thread->exec_mode = mode;
|
2002-02-27 02:29:18 +01:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_resume_debuggee(cont);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
while (dbg_curr_process && WaitForDebugEvent(&de, INFINITE))
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_handle_debug_event(&de)) break;
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!dbg_curr_process) return;
|
|
|
|
dbg_interactiveP = TRUE;
|
|
|
|
|
|
|
|
memory_get_current_pc(&addr);
|
2004-09-28 04:13:27 +02:00
|
|
|
WINE_TRACE("Entering debugger PC=0x%lx mode=%d count=%d\n",
|
2004-06-04 02:59:16 +02:00
|
|
|
addr.Offset, dbg_curr_thread->exec_mode,
|
|
|
|
dbg_curr_thread->exec_count);
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2005-11-16 12:23:07 +01:00
|
|
|
static unsigned dbg_main_loop(HANDLE hFile)
|
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
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_process)
|
|
|
|
dbg_printf("WineDbg starting on pid 0x%lx\n", dbg_curr_pid);
|
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
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_handle_debug_event(&de)) break;
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
switch (dbg_action_mode)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
case automatic_mode:
|
2002-07-20 22:18:17 +02:00
|
|
|
/* print some extra information */
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("Modules:\n");
|
|
|
|
info_win32_module(0); /* print all modules */
|
|
|
|
dbg_printf("Threads:\n");
|
|
|
|
info_win32_threads();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dbg_interactiveP = TRUE;
|
2005-11-16 12:23:07 +01:00
|
|
|
parser_handle(hFile);
|
2001-10-22 21:00:34 +02:00
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("WineDbg terminated on pid 0x%lx\n", dbg_curr_pid);
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2001-10-22 21:00:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static unsigned dbg_start_debuggee(LPSTR cmdLine)
|
2000-06-18 21:30:24 +02:00
|
|
|
{
|
|
|
|
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,
|
2004-09-28 04:13:27 +02:00
|
|
|
FALSE,
|
2004-06-04 02:59:16 +02:00
|
|
|
DEBUG_PROCESS|DEBUG_ONLY_THIS_PROCESS|CREATE_NEW_CONSOLE,
|
2002-07-20 22:18:17 +02:00
|
|
|
NULL, NULL, &startup, &info))
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_printf("Couldn't start process '%s'\n", cmdLine);
|
2000-06-18 21:30:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-09-28 04:13:27 +02:00
|
|
|
if (!info.dwProcessId)
|
|
|
|
{
|
|
|
|
/* this happens when the program being run is not a Wine binary
|
|
|
|
* (for example, a shell wrapper around a WineLib app)
|
|
|
|
*/
|
|
|
|
/* Current fix: list running processes and let the user attach
|
|
|
|
* to one of them (sic)
|
|
|
|
* FIXME: implement a real fix => grab the process (from the
|
|
|
|
* running processes) from its name
|
|
|
|
*/
|
|
|
|
dbg_printf("Debuggee has been started (%s)\n"
|
|
|
|
"But WineDbg isn't attached to it. Maybe you're trying to debug a winelib wrapper ??\n"
|
|
|
|
"Try to attach to one of those processes:\n", cmdLine);
|
|
|
|
/* FIXME: (HACK) we need some time before the wrapper executes the winelib app */
|
|
|
|
Sleep(100);
|
|
|
|
info_win32_processes();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_pid = info.dwProcessId;
|
2005-05-24 13:46:25 +02:00
|
|
|
if (!(dbg_curr_process = dbg_add_process(dbg_curr_pid, 0))) return FALSE;
|
2000-06-18 21:30:24 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
void dbg_run_debuggee(const char* args)
|
2000-06-18 21:30:24 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (args)
|
|
|
|
{
|
|
|
|
WINE_FIXME("Re-running current program with %s as args is broken\n", args);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG_EVENT de;
|
|
|
|
|
|
|
|
if (!dbg_last_cmd_line)
|
|
|
|
{
|
|
|
|
dbg_printf("Cannot find previously used command line.\n");
|
2000-06-18 21:30:24 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_start_debuggee(dbg_last_cmd_line);
|
|
|
|
while (dbg_curr_process && WaitForDebugEvent(&de, INFINITE))
|
|
|
|
{
|
|
|
|
if (dbg_handle_debug_event(&de)) break;
|
|
|
|
}
|
|
|
|
source_list_from_addr(NULL, 0);
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
BOOL dbg_interrupt_debuggee(void)
|
2003-03-04 03:18:20 +01:00
|
|
|
{
|
2004-09-28 04:13:27 +02:00
|
|
|
if (!dbg_process_list) return FALSE;
|
2003-03-04 03:18:20 +01:00
|
|
|
/* FIXME: since we likely have a single process, signal the first process
|
|
|
|
* in list
|
|
|
|
*/
|
2004-09-28 04:13:27 +02:00
|
|
|
if (dbg_process_list->next) dbg_printf("Ctrl-C: only stopping the first process\n");
|
|
|
|
else dbg_printf("Ctrl-C: stopping debuggee\n");
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_process_list->continue_on_first_exception = FALSE;
|
2004-09-28 04:13:27 +02:00
|
|
|
return DebugBreakProcess(dbg_process_list->handle);
|
2003-03-04 03:18:20 +01:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static BOOL WINAPI ctrl_c_handler(DWORD dwCtrlType)
|
2002-06-02 23:20:02 +02:00
|
|
|
{
|
|
|
|
if (dwCtrlType == CTRL_C_EVENT)
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
return dbg_interrupt_debuggee();
|
2002-06-02 23:20:02 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static void dbg_init_console(void)
|
2001-11-24 00:10:08 +01:00
|
|
|
{
|
2002-06-02 23:20:02 +02:00
|
|
|
/* set our control-C handler */
|
2004-06-04 02:59:16 +02:00
|
|
|
SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
|
2002-09-04 20:42:13 +02:00
|
|
|
|
|
|
|
/* set our own title */
|
|
|
|
SetConsoleTitle("Wine Debugger");
|
2001-11-24 00:10:08 +01:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
static int dbg_winedbg_usage(void)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2005-11-16 12:23:07 +01:00
|
|
|
dbg_printf("Usage: winedbg [--command cmd|--file file|--auto] [--gdb [--no-start] [--with-xterm]] cmdline\n");
|
2002-07-20 22:18:17 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
struct backend_cpu* be_cpu;
|
2004-07-16 04:31:55 +02:00
|
|
|
#ifdef __i386__
|
2004-06-04 02:59:16 +02:00
|
|
|
extern struct backend_cpu be_i386;
|
2004-07-16 04:31:55 +02:00
|
|
|
#elif __powerpc__
|
|
|
|
extern struct backend_cpu be_ppc;
|
2004-10-18 23:27:52 +02:00
|
|
|
#elif __ALPHA__
|
|
|
|
extern struct backend_cpu be_alpha;
|
2004-07-16 04:31:55 +02:00
|
|
|
#else
|
|
|
|
# error CPU unknown
|
|
|
|
#endif
|
2004-06-04 02:59:16 +02:00
|
|
|
|
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;
|
2005-11-16 12:23:07 +01:00
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
2000-04-30 14:21:15 +02:00
|
|
|
|
2004-07-16 04:31:55 +02:00
|
|
|
#ifdef __i386__
|
2004-06-04 02:59:16 +02:00
|
|
|
be_cpu = &be_i386;
|
2004-07-16 04:31:55 +02:00
|
|
|
#elif __powerpc__
|
|
|
|
be_cpu = &be_ppc;
|
2004-10-18 23:27:52 +02:00
|
|
|
#elif __ALPHA__
|
|
|
|
be_cpu = &be_alpha;
|
2004-07-16 04:31:55 +02:00
|
|
|
#else
|
|
|
|
# error CPU unknown
|
|
|
|
#endif
|
2004-04-15 06:58:09 +02:00
|
|
|
/* Initialize the output */
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_houtput = GetStdHandle(STD_OUTPUT_HANDLE);
|
2002-07-30 02:03:34 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
/* Initialize internal vars */
|
|
|
|
if (!dbg_load_internal_vars()) 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
|
|
|
{
|
2004-06-23 02:10:02 +02:00
|
|
|
if (!strcmp(argv[1], "--command"))
|
|
|
|
{
|
2005-11-16 12:23:07 +01:00
|
|
|
char path[MAX_PATH], file[MAX_PATH];
|
|
|
|
DWORD w;
|
|
|
|
|
|
|
|
GetTempPath(sizeof(path), path);
|
|
|
|
GetTempFileName(path, "WD", 0, file);
|
|
|
|
argc--; argv++;
|
|
|
|
hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE|DELETE, FILE_SHARE_DELETE,
|
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
dbg_printf("Couldn't open temp file %s (%lu)\n", file, GetLastError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
WriteFile(hFile, argv[1], strlen(argv[1]), &w, 0);
|
|
|
|
WriteFile(hFile, "\nquit\n", 6, &w, 0);
|
|
|
|
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
|
|
|
|
|
2004-06-23 02:10:02 +02:00
|
|
|
argc--; argv++;
|
2005-11-16 12:23:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[1], "--file"))
|
|
|
|
{
|
|
|
|
argc--; argv++;
|
|
|
|
hFile = CreateFileA(argv[1], GENERIC_READ|DELETE, 0,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
dbg_printf("Couldn't open file %s (%lu)\n", argv[1], GetLastError());
|
|
|
|
return 1;
|
|
|
|
}
|
2004-06-23 02:10:02 +02:00
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!strcmp(argv[1], "--auto"))
|
2002-06-04 23:31:10 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_action_mode != none_mode) return dbg_winedbg_usage();
|
|
|
|
dbg_action_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++;
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_houtput = GetStdHandle(STD_ERROR_HANDLE);
|
2002-07-20 22:18:17 +02:00
|
|
|
continue;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!strcmp(argv[1], "--gdb"))
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_action_mode != none_mode) return dbg_winedbg_usage();
|
|
|
|
dbg_action_mode = gdb_mode;
|
2002-07-20 22:18:17 +02:00
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
if (strcmp(argv[1], "--no-start") == 0 && dbg_action_mode == gdb_mode)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
|
|
|
gdb_flags |= 1;
|
|
|
|
argc--; argv++; /* as we don't use argv[0] */
|
|
|
|
continue;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
if (strcmp(argv[1], "--with-xterm") == 0 && dbg_action_mode == gdb_mode)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
|
|
|
gdb_flags |= 2;
|
|
|
|
argc--; argv++; /* as we don't use argv[0] */
|
2002-06-04 23:31:10 +02:00
|
|
|
continue;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
return dbg_winedbg_usage();
|
2001-10-22 21:00:34 +02:00
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_action_mode == none_mode) dbg_action_mode = winedbg_mode;
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2003-02-11 23:05:06 +01:00
|
|
|
/* try the form <myself> pid */
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_pid == 0 && argc == 2)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
|
|
|
char* ptr;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_pid = strtol(argv[1], &ptr, 10);
|
2004-11-08 21:25:55 +01:00
|
|
|
if (dbg_curr_pid == 0 || ptr != argv[1] + strlen(argv[1]) ||
|
2005-11-16 12:23:07 +01:00
|
|
|
!dbg_attach_debuggee(dbg_curr_pid, FALSE, FALSE))
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_pid = 0;
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
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) */
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_pid == 0 && argc == 3)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
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)
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!dbg_attach_debuggee(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);
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_curr_pid = pid;
|
2000-05-11 23:43:43 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_curr_pid == 0 && argc > 1)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2000-06-18 21:30:24 +02:00
|
|
|
int i, len;
|
|
|
|
LPSTR cmdLine;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!(cmdLine = HeapAlloc(GetProcessHeap(), 0, len = 1))) goto oom_leave;
|
2000-06-18 21:30:24 +02:00
|
|
|
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;
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!(cmdLine = HeapReAlloc(GetProcessHeap(), 0, cmdLine, len)))
|
|
|
|
goto oom_leave;
|
2000-06-18 21:30:24 +02:00
|
|
|
strcat(cmdLine, argv[i]);
|
|
|
|
cmdLine[len - 2] = ' ';
|
|
|
|
cmdLine[len - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
if (!dbg_start_debuggee(cmdLine))
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_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
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_last_cmd_line = 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 */
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_action_mode == gdb_mode && dbg_curr_pid)
|
|
|
|
return gdb_remote(gdb_flags);
|
2000-04-30 14:21:15 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_init_console();
|
2002-07-20 22:18:17 +02:00
|
|
|
|
2005-05-23 11:51:44 +02:00
|
|
|
SymSetOptions((SymGetOptions() & ~(SYMOPT_UNDNAME)) |
|
2004-06-04 02:59:16 +02:00
|
|
|
SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS | SYMOPT_AUTO_PUBLICS);
|
|
|
|
|
2005-11-16 12:23:07 +01:00
|
|
|
retv = dbg_main_loop(hFile);
|
2002-07-20 22:18:17 +02:00
|
|
|
/* don't save modified variables in auto mode */
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_action_mode != automatic_mode) dbg_save_internal_vars();
|
2000-04-30 14:21:15 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
leave:
|
2000-04-30 14:21:15 +02:00
|
|
|
return retv;
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
oom_leave:
|
|
|
|
dbg_printf("Out of memory\n");
|
|
|
|
return retv;
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|