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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
|
2006-03-01 21:05:35 +01:00
|
|
|
* + ensure that all commands work as expected in minidump reload function
|
|
|
|
* (and reenable parser usager)
|
2004-06-04 02:59:16 +02:00
|
|
|
* - 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
|
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)
|
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;
|
2009-12-10 15:23:45 +01:00
|
|
|
DWORD_PTR dbg_curr_tid = 0;
|
|
|
|
DWORD_PTR dbg_curr_pid = 0;
|
2004-06-04 02:59:16 +02:00
|
|
|
CONTEXT dbg_context;
|
|
|
|
BOOL dbg_interactiveP = FALSE;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2010-04-12 21:18:31 +02:00
|
|
|
static struct list dbg_process_list = LIST_INIT(dbg_process_list);
|
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];
|
|
|
|
static HANDLE dbg_houtput;
|
2000-04-13 21:31:58 +02:00
|
|
|
|
2009-01-20 09:13:23 +01:00
|
|
|
static 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
|
|
|
|
2008-10-18 09:15:10 +02:00
|
|
|
const char* dbg_W2A(const WCHAR* buffer, unsigned len)
|
2002-05-25 23:18:34 +02:00
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
static unsigned ansilen;
|
|
|
|
static char* ansi;
|
|
|
|
unsigned newlen;
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
newlen = WideCharToMultiByte(CP_ACP, 0, buffer, len, NULL, 0, NULL, NULL);
|
2008-10-18 09:15:10 +02:00
|
|
|
if (newlen > ansilen)
|
2004-06-04 02:59:16 +02:00
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
static char* newansi;
|
|
|
|
if (ansi)
|
|
|
|
newansi = HeapReAlloc(GetProcessHeap(), 0, ansi, newlen);
|
|
|
|
else
|
|
|
|
newansi = HeapAlloc(GetProcessHeap(), 0, newlen);
|
|
|
|
if (!newansi) return NULL;
|
|
|
|
ansilen = newlen;
|
|
|
|
ansi = newansi;
|
2004-06-04 02:59:16 +02:00
|
|
|
}
|
2008-10-18 09:15:10 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, buffer, len, ansi, newlen, NULL, NULL);
|
|
|
|
return ansi;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dbg_outputW(const WCHAR* buffer, int len)
|
|
|
|
{
|
|
|
|
const char* ansi = dbg_W2A(buffer, len);
|
|
|
|
if (ansi) dbg_outputA(ansi, strlen(ansi));
|
|
|
|
/* FIXME: should CP_ACP be GetConsoleCP()? */
|
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)
|
|
|
|
{
|
2009-12-09 18:14:07 +01:00
|
|
|
if (!RegQueryValueExA(hkey, dbg_internal_vars[i].name, 0,
|
|
|
|
&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);
|
2010-03-27 09:08:20 +01:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
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++)
|
|
|
|
{
|
2008-04-07 13:01:02 +02:00
|
|
|
/* FIXME: type should be inferred from basic type -if any- of intvar */
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_internal_vars[i].pval == &dbg_internal_vars[i].val)
|
2010-04-06 20:38:55 +02:00
|
|
|
{
|
|
|
|
DWORD val = dbg_internal_vars[i].val;
|
|
|
|
RegSetValueExA(hkey, dbg_internal_vars[i].name, 0, REG_DWORD, (BYTE *)&val, sizeof(val));
|
|
|
|
}
|
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
|
|
|
}
|
2010-03-27 09:08:20 +01:00
|
|
|
for (div = be_cpu->context_vars; div->name; div++)
|
2004-06-04 02:59:16 +02:00
|
|
|
{
|
2010-03-27 09:08:20 +01:00
|
|
|
if (!strcasecmp(div->name, name))
|
|
|
|
{
|
|
|
|
struct dbg_internal_var* ret = (void*)lexeme_alloc_size(sizeof(*ret));
|
|
|
|
/* relocate register's field against current context */
|
|
|
|
*ret = *div;
|
|
|
|
ret->pval = (DWORD_PTR*)((char*)&dbg_context + (DWORD_PTR)div->pval);
|
|
|
|
return ret;
|
|
|
|
}
|
2004-06-04 02:59:16 +02:00
|
|
|
}
|
|
|
|
|
2000-04-30 14:21:15 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-02-10 10:48:52 +01:00
|
|
|
unsigned dbg_num_processes(void)
|
|
|
|
{
|
2010-04-12 21:18:31 +02:00
|
|
|
return list_count(&dbg_process_list);
|
2007-02-10 10:48:52 +01: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
|
|
|
|
2010-04-12 21:18:31 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(p, &dbg_process_list, struct dbg_process, entry)
|
|
|
|
if (p->pid == pid) return p;
|
|
|
|
return NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
2006-03-01 21:05:35 +01:00
|
|
|
struct dbg_process* dbg_get_process_h(HANDLE h)
|
|
|
|
{
|
|
|
|
struct dbg_process* p;
|
|
|
|
|
2010-04-12 21:18:31 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(p, &dbg_process_list, struct dbg_process, entry)
|
|
|
|
if (p->handle == h) return p;
|
|
|
|
return NULL;
|
2006-03-01 21:05:35 +01:00
|
|
|
}
|
|
|
|
|
2006-03-01 21:05:31 +01:00
|
|
|
struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid, HANDLE h)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
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)
|
|
|
|
{
|
2006-12-20 14:17:27 +01:00
|
|
|
WINE_ERR("Process (%04x) is already defined\n", pid);
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p->handle = h;
|
2006-03-01 21:05:31 +01:00
|
|
|
p->process_io = pio;
|
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;
|
2006-03-01 21:05:31 +01:00
|
|
|
p->process_io = pio;
|
2006-03-01 21:05:35 +01:00
|
|
|
p->pio_data = NULL;
|
2005-05-24 13:46:25 +02:00
|
|
|
p->imageName = NULL;
|
2010-04-12 21:18:37 +02:00
|
|
|
list_init(&p->threads);
|
2000-05-05 20:14:34 +02:00
|
|
|
p->continue_on_first_exception = FALSE;
|
2006-09-25 22:45:24 +02:00
|
|
|
p->active_debuggee = 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;
|
2008-04-30 21:26:57 +02:00
|
|
|
p->source_ofiles = NULL;
|
|
|
|
p->search_path = NULL;
|
|
|
|
p->source_current_file[0] = '\0';
|
|
|
|
p->source_start_line = -1;
|
|
|
|
p->source_end_line = -1;
|
2000-03-08 17:44:54 +01:00
|
|
|
|
2010-04-12 21:18:31 +02:00
|
|
|
list_add_head(&dbg_process_list, &p->entry);
|
2000-03-08 17:44:54 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2008-10-18 09:15:10 +02:00
|
|
|
void dbg_set_process_name(struct dbg_process* p, const WCHAR* imageName)
|
2005-05-24 13:46:25 +02:00
|
|
|
{
|
|
|
|
assert(p->imageName == NULL);
|
|
|
|
if (imageName)
|
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
WCHAR* tmp = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(imageName) + 1) * sizeof(WCHAR));
|
|
|
|
if (tmp) p->imageName = lstrcpyW(tmp, imageName);
|
2005-05-24 13:46:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
void dbg_del_process(struct dbg_process* p)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2010-04-12 21:18:37 +02:00
|
|
|
struct dbg_thread* t;
|
|
|
|
struct dbg_thread* t2;
|
2001-05-21 20:33:15 +02:00
|
|
|
int i;
|
|
|
|
|
2010-04-12 21:18:37 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(t, t2, &p->threads, struct dbg_thread, entry)
|
|
|
|
dbg_del_thread(t);
|
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);
|
2008-04-30 21:26:57 +02:00
|
|
|
source_nuke_path(p);
|
|
|
|
source_free_files(p);
|
2010-04-12 21:18:31 +02:00
|
|
|
list_remove(&p->entry);
|
2004-06-04 02:59:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-08-30 08:44:48 +02:00
|
|
|
/******************************************************************
|
|
|
|
* dbg_init
|
|
|
|
*
|
|
|
|
* Initializes the dbghelp library, and also sets the application directory
|
|
|
|
* as a place holder for symbol searches.
|
|
|
|
*/
|
2008-10-18 09:15:10 +02:00
|
|
|
BOOL dbg_init(HANDLE hProc, const WCHAR* in, BOOL invade)
|
2008-08-30 08:44:48 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = SymInitialize(hProc, NULL, invade);
|
|
|
|
if (ret && in)
|
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
const WCHAR* last;
|
2008-08-30 08:44:48 +02:00
|
|
|
|
2008-10-18 09:15:10 +02:00
|
|
|
for (last = in + lstrlenW(in) - 1; last >= in; last--)
|
2008-08-30 08:44:48 +02:00
|
|
|
{
|
|
|
|
if (*last == '/' || *last == '\\')
|
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
WCHAR* tmp;
|
|
|
|
tmp = HeapAlloc(GetProcessHeap(), 0, (1024 + 1 + (last - in) + 1) * sizeof(WCHAR));
|
|
|
|
if (tmp && SymGetSearchPathW(hProc, tmp, 1024))
|
2008-08-30 08:44:48 +02:00
|
|
|
{
|
2008-10-18 09:15:10 +02:00
|
|
|
WCHAR* x = tmp + lstrlenW(tmp);
|
2008-08-30 08:44:48 +02:00
|
|
|
|
|
|
|
*x++ = ';';
|
2008-10-18 09:15:10 +02:00
|
|
|
memcpy(x, in, (last - in) * sizeof(WCHAR));
|
2008-08-30 08:44:48 +02:00
|
|
|
x[last - in] = '\0';
|
2008-10-18 09:15:10 +02:00
|
|
|
ret = SymSetSearchPathW(hProc, tmp);
|
2008-08-30 08:44:48 +02:00
|
|
|
}
|
|
|
|
else ret = FALSE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, tmp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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;
|
2009-12-12 12:19:23 +01:00
|
|
|
IMAGEHLP_MODULE64* imh_mod;
|
2004-06-04 02:59:16 +02:00
|
|
|
};
|
2000-03-10 23:25:07 +01:00
|
|
|
|
2009-12-10 15:23:45 +01:00
|
|
|
static BOOL CALLBACK mod_loader_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
|
2000-03-08 17:44:54 +01:00
|
|
|
{
|
2009-04-21 09:59:59 +02:00
|
|
|
struct mod_loader_info* mli = 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
|
|
|
{
|
2009-12-12 12:19:23 +01:00
|
|
|
if (SymGetModuleInfo64(mli->handle, base, mli->imh_mod))
|
2004-06-04 02:59:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-12-12 12:19:23 +01:00
|
|
|
BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE64* 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);
|
2009-12-10 15:23:45 +01:00
|
|
|
SymEnumerateModules64(hProcess, mod_loader_cb, (void*)&mli);
|
2004-06-04 02:59:16 +02:00
|
|
|
SymSetOptions(opt);
|
|
|
|
|
|
|
|
return imh_mod->BaseOfImage != 0;
|
|
|
|
}
|
|
|
|
|
2009-12-10 15:23:45 +01:00
|
|
|
BOOL dbg_load_module(HANDLE hProc, HANDLE hFile, const WCHAR* name, DWORD_PTR base, DWORD size)
|
2008-10-18 09:15:19 +02:00
|
|
|
{
|
|
|
|
BOOL ret = SymLoadModuleExW(hProc, NULL, name, NULL, base, size, NULL, 0);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
IMAGEHLP_MODULEW64 ihm;
|
|
|
|
ihm.SizeOfStruct = sizeof(ihm);
|
|
|
|
if (SymGetModuleInfoW64(hProc, base, &ihm) && (ihm.PdbUnmatched || ihm.DbgUnmatched))
|
|
|
|
dbg_printf("Loaded unmatched debug information for %s\n", wine_dbgstr_w(name));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
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;
|
2010-04-12 21:18:37 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(t, &p->threads, struct dbg_thread, entry)
|
|
|
|
if (t->tid == tid) return t;
|
|
|
|
return NULL;
|
2000-03-08 17:44:54 +01:00
|
|
|
}
|
|
|
|
|
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;
|
2006-01-27 16:17:22 +01:00
|
|
|
t->stopped_xpoint = -1;
|
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;
|
2006-02-16 12:06:43 +01:00
|
|
|
t->addr_mode = AddrModeFlat;
|
2002-04-01 23:03:13 +02:00
|
|
|
|
2006-12-20 14:17:27 +01:00
|
|
|
snprintf(t->name, sizeof(t->name), "%04x", tid);
|
2000-03-26 15:37:39 +02:00
|
|
|
|
2010-04-12 21:18:37 +02:00
|
|
|
list_add_head(&p->threads, &t->entry);
|
2000-03-08 17:44:54 +01:00
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
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);
|
2010-04-12 21:18:37 +02:00
|
|
|
list_remove(&t->entry);
|
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
|
|
|
}
|
|
|
|
|
2008-11-10 15:03:02 +01:00
|
|
|
void dbg_set_option(const char* option, const char* val)
|
2008-10-18 09:15:19 +02:00
|
|
|
{
|
2008-11-10 15:03:02 +01:00
|
|
|
if (!strcasecmp(option, "module_load_mismatched"))
|
2008-10-18 09:15:19 +02:00
|
|
|
{
|
|
|
|
DWORD opt = SymGetOptions();
|
2008-11-10 15:03:02 +01:00
|
|
|
if (!val)
|
|
|
|
dbg_printf("Option: module_load_mismatched %s\n", opt & SYMOPT_LOAD_ANYTHING ? "true" : "false");
|
|
|
|
else if (!strcasecmp(val, "true")) opt |= SYMOPT_LOAD_ANYTHING;
|
|
|
|
else if (!strcasecmp(val, "false")) opt &= ~SYMOPT_LOAD_ANYTHING;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dbg_printf("Syntax: module_load_mismatched [true|false]\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-10-18 09:15:19 +02:00
|
|
|
SymSetOptions(opt);
|
|
|
|
}
|
2008-11-10 15:03:10 +01:00
|
|
|
else if (!strcasecmp(option, "symbol_picker"))
|
|
|
|
{
|
|
|
|
if (!val)
|
|
|
|
dbg_printf("Option: symbol_picker %s\n",
|
|
|
|
symbol_current_picker == symbol_picker_interactive ? "interactive" : "scoped");
|
|
|
|
else if (!strcasecmp(val, "interactive"))
|
|
|
|
symbol_current_picker = symbol_picker_interactive;
|
|
|
|
else if (!strcasecmp(val, "scoped"))
|
|
|
|
symbol_current_picker = symbol_picker_scoped;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dbg_printf("Syntax: symbol_picker [interactive|scoped]\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-10-18 09:15:19 +02:00
|
|
|
else dbg_printf("Unknown option '%s'\n", option);
|
|
|
|
}
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
BOOL dbg_interrupt_debuggee(void)
|
2003-03-04 03:18:20 +01:00
|
|
|
{
|
2010-04-12 21:18:31 +02:00
|
|
|
struct dbg_process* p;
|
|
|
|
if (list_empty(&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
|
|
|
|
*/
|
2010-04-12 21:18:31 +02:00
|
|
|
p = LIST_ENTRY(list_head(&dbg_process_list), struct dbg_process, entry);
|
|
|
|
if (list_next(&dbg_process_list, &p->entry)) dbg_printf("Ctrl-C: only stopping the first process\n");
|
2004-09-28 04:13:27 +02:00
|
|
|
else dbg_printf("Ctrl-C: stopping debuggee\n");
|
2010-04-12 21:18:31 +02:00
|
|
|
p->continue_on_first_exception = FALSE;
|
|
|
|
return DebugBreakProcess(p->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;
|
|
|
|
}
|
|
|
|
|
2008-12-21 22:28:32 +01:00
|
|
|
void dbg_init_console(void)
|
2001-11-24 00:10:08 +01:00
|
|
|
{
|
2008-12-21 22:28:32 +01:00
|
|
|
/* set the output handle */
|
|
|
|
dbg_houtput = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
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 */
|
2009-12-09 18:14:07 +01:00
|
|
|
SetConsoleTitleA("Wine Debugger");
|
2001-11-24 00:10:08 +01:00
|
|
|
}
|
|
|
|
|
2006-03-01 21:05:39 +01:00
|
|
|
static int dbg_winedbg_usage(BOOL advanced)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2006-03-01 21:05:39 +01:00
|
|
|
if (advanced)
|
|
|
|
{
|
|
|
|
dbg_printf("Usage:\n"
|
|
|
|
" winedbg cmdline launch process 'cmdline' (as if you were starting\n"
|
|
|
|
" it with wine) and run WineDbg on it\n"
|
|
|
|
" winedbg <num> attach to running process of pid <num> and run\n"
|
|
|
|
" WineDbg on it\n"
|
|
|
|
" winedbg --gdb cmdline launch process 'cmdline' (as if you were starting\n"
|
|
|
|
" wine) and run gdb (proxied) on it\n"
|
|
|
|
" winedbg --gdb <num> attach to running process of pid <num> and run\n"
|
|
|
|
" gdb (proxied) on it\n"
|
|
|
|
" winedbg file.mdmp reload the minidump file.mdmp into memory and run\n"
|
|
|
|
" WineDbg on it\n"
|
|
|
|
" winedbg --help prints advanced options\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dbg_printf("Usage:\n\twinedbg [ [ --gdb ] [ prog-name [ prog-args ] | <num> | file.mdmp | --help ]\n");
|
2009-06-25 04:35:21 +02:00
|
|
|
return 0;
|
2002-07-20 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
2008-12-21 22:28:32 +01:00
|
|
|
void dbg_start_interactive(HANDLE hFile)
|
|
|
|
{
|
2010-04-12 21:18:31 +02:00
|
|
|
struct dbg_process* p;
|
|
|
|
struct dbg_process* p2;
|
|
|
|
|
2008-12-21 22:28:32 +01:00
|
|
|
if (dbg_curr_process)
|
|
|
|
{
|
2009-12-10 15:23:45 +01:00
|
|
|
dbg_printf("WineDbg starting on pid %04lx\n", dbg_curr_pid);
|
2008-12-21 22:28:32 +01:00
|
|
|
if (dbg_curr_process->active_debuggee) dbg_active_wait_for_first_exception();
|
|
|
|
}
|
|
|
|
|
|
|
|
dbg_interactiveP = TRUE;
|
|
|
|
parser_handle(hFile);
|
|
|
|
|
2010-04-12 21:18:31 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(p, p2, &dbg_process_list, struct dbg_process, entry)
|
|
|
|
p->process_io->close_process(p, FALSE);
|
2008-12-21 22:28:32 +01:00
|
|
|
|
|
|
|
dbg_save_internal_vars();
|
|
|
|
}
|
|
|
|
|
2010-10-26 12:55:53 +02:00
|
|
|
static LONG CALLBACK top_filter( EXCEPTION_POINTERS *ptr )
|
|
|
|
{
|
|
|
|
dbg_printf( "winedbg: Internal crash at %p\n", ptr->ExceptionRecord->ExceptionAddress );
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
|
|
|
|
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;
|
2009-12-23 00:36:44 +01:00
|
|
|
#elif defined(__powerpc__)
|
2004-07-16 04:31:55 +02:00
|
|
|
extern struct backend_cpu be_ppc;
|
2009-12-23 00:36:44 +01:00
|
|
|
#elif defined(__ALPHA__)
|
2004-10-18 23:27:52 +02:00
|
|
|
extern struct backend_cpu be_alpha;
|
2009-12-23 00:36:44 +01:00
|
|
|
#elif defined(__x86_64__)
|
2006-06-20 09:34:43 +02:00
|
|
|
extern struct backend_cpu be_x86_64;
|
2010-08-25 22:15:46 +02:00
|
|
|
#elif defined(__sparc__)
|
|
|
|
extern struct backend_cpu be_sparc;
|
2010-09-18 18:02:38 +02:00
|
|
|
#elif defined(__arm__)
|
|
|
|
extern struct backend_cpu be_arm;
|
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
|
|
|
{
|
2006-02-24 22:15:08 +01:00
|
|
|
int retv = 0;
|
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
|
|
|
enum dbg_start ds;
|
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;
|
2009-12-26 00:31:11 +01:00
|
|
|
#elif defined(__powerpc__)
|
2004-07-16 04:31:55 +02:00
|
|
|
be_cpu = &be_ppc;
|
2009-12-26 00:31:11 +01:00
|
|
|
#elif defined(__ALPHA__)
|
2004-10-18 23:27:52 +02:00
|
|
|
be_cpu = &be_alpha;
|
2009-12-26 00:31:11 +01:00
|
|
|
#elif defined(__x86_64__)
|
2006-06-20 09:34:43 +02:00
|
|
|
be_cpu = &be_x86_64;
|
2010-08-25 22:15:46 +02:00
|
|
|
#elif defined(__sparc__)
|
|
|
|
be_cpu = &be_sparc;
|
2010-09-18 18:02:38 +02:00
|
|
|
#elif defined(__arm__)
|
|
|
|
be_cpu = &be_arm;
|
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
|
|
|
|
2010-10-26 12:55:53 +02:00
|
|
|
SetUnhandledExceptionFilter( top_filter );
|
|
|
|
|
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
|
|
|
|
2006-02-24 22:14:05 +01:00
|
|
|
/* as we don't care about exec name */
|
|
|
|
argc--; argv++;
|
|
|
|
|
2006-03-01 21:05:39 +01:00
|
|
|
if (argc && !strcmp(argv[0], "--help"))
|
|
|
|
return dbg_winedbg_usage(TRUE);
|
|
|
|
|
2006-02-24 22:14:36 +01:00
|
|
|
if (argc && !strcmp(argv[0], "--gdb"))
|
|
|
|
{
|
|
|
|
retv = gdb_main(argc, argv);
|
2006-03-01 21:05:39 +01:00
|
|
|
if (retv == -1) dbg_winedbg_usage(FALSE);
|
2006-02-24 22:14:36 +01:00
|
|
|
return retv;
|
|
|
|
}
|
2006-02-24 22:15:08 +01:00
|
|
|
dbg_init_console();
|
2006-02-24 22:14:36 +01:00
|
|
|
|
2006-02-24 22:15:08 +01:00
|
|
|
SymSetOptions((SymGetOptions() & ~(SYMOPT_UNDNAME)) |
|
|
|
|
SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS | SYMOPT_AUTO_PUBLICS);
|
|
|
|
|
2006-02-27 21:50:39 +01:00
|
|
|
if (argc && (!strcmp(argv[0], "--auto") || !strcmp(argv[0], "--minidump")))
|
2006-02-24 22:15:08 +01:00
|
|
|
{
|
|
|
|
/* force some internal variables */
|
|
|
|
DBG_IVAR(BreakOnDllLoad) = 0;
|
|
|
|
dbg_houtput = GetStdHandle(STD_ERROR_HANDLE);
|
2006-02-27 21:50:36 +01:00
|
|
|
switch (dbg_active_auto(argc, argv))
|
|
|
|
{
|
|
|
|
case start_ok: return 0;
|
2006-03-01 21:05:39 +01:00
|
|
|
case start_error_parse: return dbg_winedbg_usage(FALSE);
|
2006-02-27 21:50:36 +01:00
|
|
|
case start_error_init: return -1;
|
|
|
|
}
|
2006-02-24 22:15:08 +01:00
|
|
|
}
|
2006-02-27 21:50:36 +01:00
|
|
|
/* parse options */
|
|
|
|
while (argc > 0 && argv[0][0] == '-')
|
2001-10-22 21:00:34 +02:00
|
|
|
{
|
2006-02-27 21:50:36 +01:00
|
|
|
if (!strcmp(argv[0], "--command"))
|
2004-06-23 02:10:02 +02:00
|
|
|
{
|
2006-02-27 21:50:36 +01:00
|
|
|
argc--; argv++;
|
|
|
|
hFile = parser_generate_command_file(argv[0], NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
2005-11-16 12:23:07 +01:00
|
|
|
{
|
2006-12-20 14:17:27 +01:00
|
|
|
dbg_printf("Couldn't open temp file (%u)\n", GetLastError());
|
2006-02-27 21:50:36 +01:00
|
|
|
return 1;
|
2005-11-16 12:23:07 +01:00
|
|
|
}
|
2006-02-27 21:50:36 +01:00
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[0], "--file"))
|
|
|
|
{
|
|
|
|
argc--; argv++;
|
|
|
|
hFile = CreateFileA(argv[0], GENERIC_READ|DELETE, 0,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
2005-11-16 12:23:07 +01:00
|
|
|
{
|
2006-12-20 14:17:27 +01:00
|
|
|
dbg_printf("Couldn't open file %s (%u)\n", argv[0], GetLastError());
|
2006-02-27 21:50:36 +01:00
|
|
|
return 1;
|
2005-11-16 12:23:07 +01:00
|
|
|
}
|
2006-02-27 21:50:36 +01:00
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
2004-06-23 02:10:02 +02:00
|
|
|
}
|
2006-02-27 21:50:36 +01:00
|
|
|
if (!strcmp(argv[0], "--"))
|
|
|
|
{
|
|
|
|
argc--; argv++;
|
|
|
|
break;
|
|
|
|
}
|
2006-03-01 21:05:39 +01:00
|
|
|
return dbg_winedbg_usage(FALSE);
|
2001-10-22 21:00:34 +02:00
|
|
|
}
|
2006-02-27 21:50:36 +01:00
|
|
|
if (!argc) ds = start_ok;
|
2006-03-01 21:05:35 +01:00
|
|
|
else if ((ds = dbg_active_attach(argc, argv)) == start_error_parse &&
|
|
|
|
(ds = minidump_reload(argc, argv)) == start_error_parse)
|
2006-02-27 21:50:36 +01:00
|
|
|
ds = dbg_active_launch(argc, argv);
|
2006-02-24 22:15:08 +01:00
|
|
|
switch (ds)
|
2002-07-20 22:18:17 +02:00
|
|
|
{
|
2006-02-24 22:15:08 +01:00
|
|
|
case start_ok: break;
|
2006-03-01 21:05:39 +01:00
|
|
|
case start_error_parse: return dbg_winedbg_usage(FALSE);
|
2006-02-24 22:15:08 +01:00
|
|
|
case start_error_init: return -1;
|
2000-05-11 23:43:43 +02:00
|
|
|
}
|
2006-02-27 21:50:36 +01:00
|
|
|
|
2008-12-21 22:28:32 +01:00
|
|
|
dbg_start_interactive(hFile);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-03-01 21:05:28 +01:00
|
|
|
return 0;
|
2000-06-18 21:30:24 +02:00
|
|
|
}
|