- implement SymUnDName and UndecorateSymbolName on top of
authorEric Pouech <pouech-eric@wanadoo.fr>
Fri, 19 Nov 2004 18:02:47 +0000 (18:02 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 19 Nov 2004 18:02:47 +0000 (18:02 +0000)
  msvcrt.__unDName
- implement SYMOPT_UNDNAME support

dlls/dbghelp/dbghelp.c
dlls/dbghelp/dbghelp_private.h
dlls/dbghelp/symbol.c

index d95e62827426b7422bd06de5613ba3db208be9fa..982956e5aeda70a24ea1c78d4512838fb5e9b791 100644 (file)
@@ -33,14 +33,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
  *      + funcargtype:s are (partly) wrong: they should be a specific struct (like
  *        typedef) pointing to the actual type (and not a direct access)
  *      + we should store the underlying type for an enum in the symt_enum struct
- *  - most options (dbghelp_options) are not used (loading lines, decoration...)
+ *      + for enums, we store the names & values (associated to the enum type), 
+ *        but those values are not directly usable from a debugger (that's why, I
+ *        assume, that we have also to define constants for enum values, as 
+ *        Codeview does BTW.
+ *  - most options (dbghelp_options) are not used (loading lines...)
  *  - in symbol lookup by name, we don't use RE everywhere we should. Moreover, when
  *    we're supposed to use RE, it doesn't make use of our hash tables. Therefore,
  *    we could use hash if name isn't a RE, and fall back to a full search when we
  *    get a full RE
- *  - (un)decoration is not handled (should make winedump's code a (.a) library
- *    and link it to winedump, and potentially to msvcrt and dbghelp (check best
- *    way not to duplicate code in msvcrt & dbghelp)
  *  - msc:
  *      + we should add parameters' types to the function's signature
  *        while processing a function's parameters
@@ -59,6 +60,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
  */
 
 unsigned   dbghelp_options = SYMOPT_UNDNAME;
+HANDLE     hMsvcrt = NULL;
 
 /***********************************************************************
  *           DllMain (DEBUGHLP.@)
@@ -68,7 +70,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
     switch (fdwReason)
     {
     case DLL_PROCESS_ATTACH:    break;
-    case DLL_PROCESS_DETACH:    break;
+    case DLL_PROCESS_DETACH:
+        if (hMsvcrt) FreeLibrary(hMsvcrt);
+        break;
     case DLL_THREAD_ATTACH:     break;
     case DLL_THREAD_DETACH:     break;
     default:                    break;
index f22d6af15545cc21d38003208721757b5057f336..8ac44c55fa1fb8b1c58761efa32222e0c4f45b5e 100644 (file)
@@ -99,6 +99,8 @@ void*    hash_table_iter_up(struct hash_table_iter* hti);
 
 
 extern unsigned dbghelp_options;
+/* some more Wine extensions */
+#define SYMOPT_WINE_WITH_ELF_MODULES 0x40000000
 
 struct symt
 {
@@ -288,6 +290,7 @@ struct process
 
 /* dbghelp.c */
 extern struct process* process_find_by_handle(HANDLE hProcess);
+extern HANDLE hMsvcrt;
 
 /* elf_module.c */
 extern BOOL         elf_load_debug_info(struct module* module);
@@ -443,7 +446,3 @@ extern struct symt_pointer*
 extern struct symt_typedef*
                     symt_new_typedef(struct module* module, struct symt* ref, 
                                      const char* name);
-
-
-/* some more Wine extensions */
-#define SYMOPT_WINE_WITH_ELF_MODULES 0x40000000
index 8b22ef878a806527a11515d1b34e3b7232649cd2..9776716c5b4c86898002f27c2177ab3e7f0d5138 100644 (file)
@@ -529,11 +529,16 @@ static void symt_fill_sym_info(const struct module* module,
     sym_info->Scope = 0; /* FIXME */
     sym_info->Tag = sym->tag;
     name = symt_get_name(sym);
-    sym_info->NameLen = strlen(name) + 1;
     if (sym_info->MaxNameLen)
     {
-        strncpy(sym_info->Name, name, min(sym_info->NameLen, sym_info->MaxNameLen));
-        sym_info->Name[sym_info->MaxNameLen - 1] = '\0';
+        if (sym->tag != SymTagPublicSymbol || !(dbghelp_options & SYMOPT_UNDNAME) ||
+            (sym_info->NameLen = UnDecorateSymbolName(sym_info->Name, sym_info->Name, 
+                                                      sym_info->MaxNameLen, UNDNAME_COMPLETE) == 0))
+        {
+            sym_info->NameLen = min(strlen(name), sym_info->MaxNameLen - 1);
+            strncpy(sym_info->Name, name, sym_info->NameLen);
+            sym_info->Name[sym_info->NameLen] = '\0';
+        }
     }
     TRACE_(dbghelp_symt)("%p => %s %lu %s\n",
                          sym, sym_info->Name, sym_info->Size,
@@ -1186,21 +1191,37 @@ PVOID WINAPI SymFunctionTableAccess(HANDLE hProcess, DWORD AddrBase)
  */
 BOOL WINAPI SymUnDName(PIMAGEHLP_SYMBOL sym, LPSTR UnDecName, DWORD UnDecNameLength)
 {
-    FIXME("(%p %s %lu): stub\n", sym, UnDecName, UnDecNameLength);
+    TRACE("(%p %s %lu): stub\n", sym, UnDecName, UnDecNameLength);
     return UnDecorateSymbolName(sym->Name, UnDecName, UnDecNameLength, 
-                                UNDNAME_COMPLETE);
+                                UNDNAME_COMPLETE) != 0;
 }
 
+static void* und_alloc(size_t len) { return HeapAlloc(GetProcessHeap(), 0, len); }
+static void  und_free (void* ptr)  { HeapFree(GetProcessHeap(), 0, ptr); }
+
 /***********************************************************************
  *             UnDecorateSymbolName (DBGHELP.@)
  */
 DWORD WINAPI UnDecorateSymbolName(LPCSTR DecoratedName, LPSTR UnDecoratedName,
                                   DWORD UndecoratedLength, DWORD Flags)
 {
-    FIXME("(%s, %p, %ld, 0x%08lx): stub\n",
+    /* undocumented from msvcrt */
+    static char* (*p_undname)(char*, const char*, int, void* (*)(size_t), void (*)(void*), unsigned short);
+    static WCHAR szMsvcrt[] = {'m','s','v','c','r','t','.','d','l','l',0};
+
+    TRACE("(%s, %p, %ld, 0x%08lx): stub\n",
           debugstr_a(DecoratedName), UnDecoratedName, UndecoratedLength, Flags);
 
-    strncpy(UnDecoratedName, DecoratedName, UndecoratedLength);
-    UnDecoratedName[UndecoratedLength - 1] = '\0';
-    return TRUE;
+    if (!p_undname)
+    {
+        if (!hMsvcrt) hMsvcrt = LoadLibraryW(szMsvcrt);
+        if (hMsvcrt) p_undname = (void*)GetProcAddress(hMsvcrt, "__unDName");
+        if (!p_undname) return 0;
+    }
+
+    if (!UnDecoratedName) return 0;
+    if (!p_undname(UnDecoratedName, DecoratedName, UndecoratedLength, 
+                   und_alloc, und_free, Flags))
+        return 0;
+    return strlen(UnDecoratedName);
 }