Eric Pouech : winedbg: Added a command to allow loading mismatched modules.

Alexandre Julliard julliard at winehq.org
Mon Oct 20 08:01:01 CDT 2008


Module: wine
Branch: master
Commit: cbb84fdb738a8c8f9bde50d0c91d49f8e7953131
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cbb84fdb738a8c8f9bde50d0c91d49f8e7953131

Author: Eric Pouech <eric.pouech at orange.fr>
Date:   Sat Oct 18 09:15:19 2008 +0200

winedbg: Added a command to allow loading mismatched modules.

---

 programs/winedbg/dbg.y          |    2 ++
 programs/winedbg/debugger.h     |    2 ++
 programs/winedbg/gdbproxy.c     |    9 ++++-----
 programs/winedbg/tgt_active.c   |    8 ++++----
 programs/winedbg/tgt_minidump.c |   12 ++++++------
 programs/winedbg/tgt_module.c   |   16 +++++++++++++++-
 programs/winedbg/winedbg.c      |   25 +++++++++++++++++++++++++
 7 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/programs/winedbg/dbg.y b/programs/winedbg/dbg.y
index 1d0eba3..190c106 100644
--- a/programs/winedbg/dbg.y
+++ b/programs/winedbg/dbg.y
@@ -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:
diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h
index aae0c0c..d7ea3c9 100644
--- a/programs/winedbg/debugger.h
+++ b/programs/winedbg/debugger.h
@@ -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[]);
diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c
index 7799148..9026b37 100644
--- a/programs/winedbg/gdbproxy.c
+++ b/programs/winedbg/gdbproxy.c
@@ -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:
diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c
index af1bc91..9cb0a56 100644
--- a/programs/winedbg/tgt_active.c
+++ b/programs/winedbg/tgt_active.c
@@ -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);
diff --git a/programs/winedbg/tgt_minidump.c b/programs/winedbg/tgt_minidump.c
index f6b7c35..a9f92db 100644
--- a/programs/winedbg/tgt_minidump.c
+++ b/programs/winedbg/tgt_minidump.c
@@ -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);
diff --git a/programs/winedbg/tgt_module.c b/programs/winedbg/tgt_module.c
index 044e312..5341726 100644
--- a/programs/winedbg/tgt_module.c
+++ b/programs/winedbg/tgt_module.c
@@ -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)
     {
diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c
index 575c829..ab66148 100644
--- a/programs/winedbg/winedbg.c
+++ b/programs/winedbg/winedbg.c
@@ -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;




More information about the wine-cvs mailing list