winedbg: Added a command to allow loading mismatched modules.

This commit is contained in:
Eric Pouech 2008-10-18 09:15:19 +02:00 committed by Alexandre Julliard
parent 5c8ad49158
commit cbb84fdb73
7 changed files with 58 additions and 16 deletions

View File

@ -209,6 +209,8 @@ set_command:
| tSET '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, NULL, $3); }
| tSET tIDENTIFIER '+' tIDENTIFIER { info_wine_dbg_channel(TRUE, $2, $4); }
| tSET tIDENTIFIER '-' tIDENTIFIER { info_wine_dbg_channel(FALSE, $2, $4); }
| tSET '!' tIDENTIFIER '+' { dbg_set_option($3, TRUE); }
| tSET '!' tIDENTIFIER '-' { dbg_set_option($3, FALSE); }
;
x_command:

View File

@ -448,7 +448,9 @@ struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid, HANDLE h, vo
extern struct dbg_thread* dbg_get_thread(struct dbg_process* p, DWORD tid);
extern void dbg_del_thread(struct dbg_thread* t);
extern BOOL dbg_init(HANDLE hProc, const WCHAR* in, BOOL invade);
extern BOOL dbg_load_module(HANDLE hProc, HANDLE hFile, const WCHAR* name, DWORD base, DWORD size);
extern BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE* imh_mod);
extern void dbg_set_option(const char*, BOOL);
/* gdbproxy.c */
extern int gdb_main(int argc, char* argv[]);

View File

@ -63,7 +63,6 @@
#include "windef.h"
#include "winbase.h"
#include "tlhelp32.h"
#include "wine/debug.h"
#define GDBPXY_TRC_LOWLEVEL 0x01
#define GDBPXY_TRC_PACKET 0x02
@ -537,16 +536,16 @@ static void handle_debug_event(struct gdb_context* gdbctx, DEBUG_EVENT* de)
de->u.LoadDll.lpBaseOfDll,
de->u.LoadDll.dwDebugInfoFileOffset,
de->u.LoadDll.nDebugInfoSize);
SymLoadModuleExW(gdbctx->process->handle, de->u.LoadDll.hFile, u.buffer, NULL,
(unsigned long)de->u.LoadDll.lpBaseOfDll, 0, NULL, 0);
dbg_load_module(gdbctx->process->handle, de->u.LoadDll.hFile, u.buffer,
(DWORD_PTR)de->u.LoadDll.lpBaseOfDll, 0);
break;
case UNLOAD_DLL_DEBUG_EVENT:
if (gdbctx->trace & GDBPXY_TRC_WIN32_EVENT)
fprintf(stderr, "%08x:%08x: unload DLL @%p\n",
de->dwProcessId, de->dwThreadId, de->u.UnloadDll.lpBaseOfDll);
SymUnloadModule(gdbctx->process->handle,
(unsigned long)de->u.UnloadDll.lpBaseOfDll);
SymUnloadModule(gdbctx->process->handle,
(DWORD_PTR)de->u.UnloadDll.lpBaseOfDll);
break;
case EXCEPTION_DEBUG_EVENT:

View File

@ -519,8 +519,8 @@ static unsigned dbg_handle_debug_event(DEBUG_EVENT* de)
if (!dbg_init(dbg_curr_process->handle, u.buffer, FALSE))
dbg_printf("Couldn't initiate DbgHelp\n");
if (!SymLoadModuleExW(dbg_curr_process->handle, de->u.CreateProcessInfo.hFile, u.buffer, NULL,
(unsigned long)de->u.CreateProcessInfo.lpBaseOfImage, 0, NULL, 0))
if (!dbg_load_module(dbg_curr_process->handle, de->u.CreateProcessInfo.hFile, u.buffer,
(DWORD_PTR)de->u.CreateProcessInfo.lpBaseOfImage, 0))
dbg_printf("couldn't load main module (%u)\n", GetLastError());
WINE_TRACE("%04x:%04x: create thread I @%p\n",
@ -608,8 +608,8 @@ static unsigned dbg_handle_debug_event(DEBUG_EVENT* de)
wine_dbgstr_w(u.buffer), de->u.LoadDll.lpBaseOfDll,
de->u.LoadDll.dwDebugInfoFileOffset,
de->u.LoadDll.nDebugInfoSize);
SymLoadModuleExW(dbg_curr_process->handle, de->u.LoadDll.hFile, u.buffer, NULL,
(unsigned long)de->u.LoadDll.lpBaseOfDll, 0, NULL, 0);
dbg_load_module(dbg_curr_process->handle, de->u.LoadDll.hFile, u.buffer,
(DWORD_PTR)de->u.LoadDll.lpBaseOfDll, 0);
break_set_xpoints(FALSE);
break_check_delayed_bp();
break_set_xpoints(TRUE);

View File

@ -331,8 +331,8 @@ static enum dbg_start minidump_do_reload(struct tgt_process_minidump_data* data)
nameW[mds->Length / sizeof(WCHAR)] = 0;
if (SymFindFileInPathW(hProc, NULL, nameW, (void*)(DWORD_PTR)mm->CheckSum,
0, 0, SSRVOPT_DWORD, buffer, validate_file, NULL))
SymLoadModuleExW(hProc, NULL, buffer, NULL, get_addr64(mm->BaseOfImage),
mm->SizeOfImage, NULL, 0);
dbg_load_module(hProc, NULL, buffer, get_addr64(mm->BaseOfImage),
mm->SizeOfImage);
else
SymLoadModuleExW(hProc, NULL, nameW, NULL, get_addr64(mm->BaseOfImage),
mm->SizeOfImage, NULL, SLMFLAG_VIRTUAL);
@ -350,11 +350,11 @@ static enum dbg_start minidump_do_reload(struct tgt_process_minidump_data* data)
nameW[mds->Length / sizeof(WCHAR)] = 0;
if (SymFindFileInPathW(hProc, NULL, nameW, (void*)(DWORD_PTR)mm->TimeDateStamp,
mm->SizeOfImage, 0, SSRVOPT_DWORD, buffer, validate_file, NULL))
SymLoadModuleExW(hProc, NULL, buffer, NULL, get_addr64(mm->BaseOfImage),
mm->SizeOfImage, NULL, 0);
dbg_load_module(hProc, NULL, buffer, get_addr64(mm->BaseOfImage),
mm->SizeOfImage);
else if (is_pe_module_embedded(data, mm))
SymLoadModuleExW(hProc, NULL, nameW, NULL, get_addr64(mm->BaseOfImage),
mm->SizeOfImage, NULL, 0);
dbg_load_module(hProc, NULL, nameW, get_addr64(mm->BaseOfImage),
mm->SizeOfImage);
else
SymLoadModuleExW(hProc, NULL, nameW, NULL, get_addr64(mm->BaseOfImage),
mm->SizeOfImage, NULL, SLMFLAG_VIRTUAL);

View File

@ -52,16 +52,30 @@ enum dbg_start tgt_module_load(const char* name, BOOL keep)
DWORD opts = SymGetOptions();
HANDLE hDummy = (HANDLE)0x87654321;
enum dbg_start ret = start_ok;
WCHAR* nameW;
unsigned len;
SymSetOptions((opts & ~(SYMOPT_UNDNAME|SYMOPT_DEFERRED_LOADS)) |
SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS | 0x40000000);
if (!dbg_init(hDummy, NULL, FALSE))
return start_error_init;
if (!SymLoadModule(hDummy, NULL, name, NULL, 0, 0))
len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!nameW)
{
ret = start_error_init;
keep = FALSE;
}
else
{
len = MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, len);
if (!dbg_load_module(hDummy, NULL, nameW, 0, 0))
{
ret = start_error_init;
keep = FALSE;
}
HeapFree(GetProcessHeap(), 0, nameW);
}
if (keep)
{

View File

@ -435,6 +435,19 @@ BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE* imh_mod)
return imh_mod->BaseOfImage != 0;
}
BOOL dbg_load_module(HANDLE hProc, HANDLE hFile, const WCHAR* name, DWORD base, DWORD size)
{
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;
}
struct dbg_thread* dbg_get_thread(struct dbg_process* p, DWORD tid)
{
struct dbg_thread* t;
@ -488,6 +501,18 @@ void dbg_del_thread(struct dbg_thread* t)
HeapFree(GetProcessHeap(), 0, t);
}
void dbg_set_option(const char* option, BOOL enable)
{
if (!strcmp(option, "module"))
{
DWORD opt = SymGetOptions();
if (enable) opt |= SYMOPT_LOAD_ANYTHING;
else opt &= ~SYMOPT_LOAD_ANYTHING;
SymSetOptions(opt);
}
else dbg_printf("Unknown option '%s'\n", option);
}
BOOL dbg_interrupt_debuggee(void)
{
if (!dbg_process_list) return FALSE;