dbghelp: Added an ANSI copy of the module name (useful for next patches).
[wine/multimedia.git] / dlls / dbghelp / module.c
blobebee8d919fcc00cd5af89490fff1307fed702ffc
1 /*
2 * File module.c - module handling for the wine debugger
4 * Copyright (C) 1993, Eric Youngdale.
5 * 2000-2004, Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <assert.h>
28 #include "dbghelp_private.h"
29 #include "psapi.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "wine/debug.h"
33 #include "winnls.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
37 static const char * const ext[] = {".acm", ".dll", ".drv", ".exe", ".ocx", ".vxd", NULL};
39 static int match_ext(const char* ptr, size_t len)
41 const char * const *e;
42 size_t l;
44 for (e = ext; *e; e++)
46 l = strlen(*e);
47 if (l >= len) return FALSE;
48 if (strncasecmp(&ptr[len - l], *e, l)) continue;
49 return l;
51 return 0;
54 static void module_fill_module(const char* in, char* out, size_t size)
56 const char *ptr,*endptr;
57 size_t len, l;
59 endptr = in + strlen(in);
60 for (ptr = endptr - 1;
61 ptr >= in && *ptr != '/' && *ptr != '\\';
62 ptr--);
63 ptr++;
64 len = min(endptr-ptr,size-1);
65 memcpy(out, ptr, len);
66 out[len] = '\0';
67 if (len > 4 && (l = match_ext(out, len)))
68 out[len - l] = '\0';
69 else if (len > 12 &&
70 (!strcasecmp(out + len - 12, "wine-pthread") ||
71 !strcasecmp(out + len - 12, "wine-kthread")))
72 lstrcpynA(out, "<wine-loader>", size);
73 else
75 if (len > 3 && !strcasecmp(&out[len - 3], ".so") &&
76 (l = match_ext(out, len - 3)))
77 strcpy(&out[len - l - 3], "<elf>");
79 while ((*out = tolower(*out))) out++;
82 void module_set_module(struct module* module, const char* name)
84 module_fill_module(name, module->module.ModuleName, sizeof(module->module.ModuleName));
85 strcpy(module->module_name, module->module.ModuleName);
88 static const char* get_module_type(enum module_type type, BOOL virtual)
90 switch (type)
92 case DMT_ELF: return virtual ? "Virtual ELF" : "ELF";
93 case DMT_PE: return virtual ? "Virtual PE" : "PE";
94 default: return "---";
98 /***********************************************************************
99 * Creates and links a new module to a process
101 struct module* module_new(struct process* pcs, const char* name,
102 enum module_type type, BOOL virtual,
103 unsigned long mod_addr, unsigned long size,
104 unsigned long stamp, unsigned long checksum)
106 struct module* module;
108 assert(type == DMT_ELF || type == DMT_PE);
109 if (!(module = HeapAlloc(GetProcessHeap(), 0, sizeof(*module))))
110 return NULL;
112 memset(module, 0, sizeof(*module));
114 module->next = pcs->lmodules;
115 pcs->lmodules = module;
117 TRACE("=> %s %08lx-%08lx %s\n",
118 get_module_type(type, virtual), mod_addr, mod_addr + size, name);
120 pool_init(&module->pool, 65536);
122 module->module.SizeOfStruct = sizeof(module->module);
123 module->module.BaseOfImage = mod_addr;
124 module->module.ImageSize = size;
125 module_set_module(module, name);
126 module->module.ImageName[0] = '\0';
127 lstrcpynA(module->module.LoadedImageName, name, sizeof(module->module.LoadedImageName));
128 module->module.SymType = SymNone;
129 module->module.NumSyms = 0;
130 module->module.TimeDateStamp = stamp;
131 module->module.CheckSum = checksum;
133 memset(module->module.LoadedPdbName, 0, sizeof(module->module.CVData));
134 module->module.CVSig = 0;
135 memset(module->module.CVData, 0, sizeof(module->module.CVData));
136 module->module.PdbSig = 0;
137 memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
138 module->module.PdbAge = 0;
139 module->module.PdbUnmatched = FALSE;
140 module->module.DbgUnmatched = FALSE;
141 module->module.LineNumbers = FALSE;
142 module->module.GlobalSymbols = FALSE;
143 module->module.TypeInfo = FALSE;
144 module->module.SourceIndexed = FALSE;
145 module->module.Publics = FALSE;
147 module->type = type;
148 module->is_virtual = virtual ? TRUE : FALSE;
149 module->sortlist_valid = FALSE;
150 module->addr_sorttab = NULL;
151 /* FIXME: this seems a bit too high (on a per module basis)
152 * need some statistics about this
154 hash_table_init(&module->pool, &module->ht_symbols, 4096);
155 hash_table_init(&module->pool, &module->ht_types, 4096);
156 vector_init(&module->vtypes, sizeof(struct symt*), 32);
158 module->sources_used = 0;
159 module->sources_alloc = 0;
160 module->sources = 0;
162 return module;
165 /***********************************************************************
166 * module_find_by_name
169 struct module* module_find_by_name(const struct process* pcs,
170 const char* name, enum module_type type)
172 struct module* module;
174 if (type == DMT_UNKNOWN)
176 if ((module = module_find_by_name(pcs, name, DMT_PE)) ||
177 (module = module_find_by_name(pcs, name, DMT_ELF)))
178 return module;
180 else
182 char modname[MAX_PATH];
184 for (module = pcs->lmodules; module; module = module->next)
186 if (type == module->type &&
187 !strcasecmp(name, module->module.LoadedImageName))
188 return module;
190 module_fill_module(name, modname, sizeof(modname));
191 for (module = pcs->lmodules; module; module = module->next)
193 if (type == module->type &&
194 !strcasecmp(modname, module->module.ModuleName))
195 return module;
198 SetLastError(ERROR_INVALID_NAME);
199 return NULL;
202 /***********************************************************************
203 * module_get_container
206 struct module* module_get_container(const struct process* pcs,
207 const struct module* inner)
209 struct module* module;
211 for (module = pcs->lmodules; module; module = module->next)
213 if (module != inner &&
214 module->module.BaseOfImage <= inner->module.BaseOfImage &&
215 module->module.BaseOfImage + module->module.ImageSize >=
216 inner->module.BaseOfImage + inner->module.ImageSize)
217 return module;
219 return NULL;
222 /***********************************************************************
223 * module_get_containee
226 struct module* module_get_containee(const struct process* pcs,
227 const struct module* outter)
229 struct module* module;
231 for (module = pcs->lmodules; module; module = module->next)
233 if (module != outter &&
234 outter->module.BaseOfImage <= module->module.BaseOfImage &&
235 outter->module.BaseOfImage + outter->module.ImageSize >=
236 module->module.BaseOfImage + module->module.ImageSize)
237 return module;
239 return NULL;
242 /******************************************************************
243 * module_get_debug
245 * get the debug information from a module:
246 * - if the module's type is deferred, then force loading of debug info (and return
247 * the module itself)
248 * - if the module has no debug info and has an ELF container, then return the ELF
249 * container (and also force the ELF container's debug info loading if deferred)
250 * - otherwise return the module itself if it has some debug info
252 BOOL module_get_debug(struct module_pair* pair)
254 IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl64;
256 if (!pair->requested) return FALSE;
257 /* for a PE builtin, always get info from container */
258 if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
259 pair->effective = pair->requested;
260 /* if deferred, force loading */
261 if (pair->effective->module.SymType == SymDeferred)
263 BOOL ret;
265 if (pair->effective->is_virtual) ret = FALSE;
266 else switch (pair->effective->type)
268 case DMT_ELF:
269 ret = elf_load_debug_info(pair->effective, NULL);
270 break;
271 case DMT_PE:
272 idsl64.SizeOfStruct = sizeof(idsl64);
273 idsl64.BaseOfImage = pair->effective->module.BaseOfImage;
274 idsl64.CheckSum = pair->effective->module.CheckSum;
275 idsl64.TimeDateStamp = pair->effective->module.TimeDateStamp;
276 strcpy(idsl64.FileName, pair->effective->module.ImageName);
277 idsl64.Reparse = FALSE;
278 idsl64.hFile = INVALID_HANDLE_VALUE;
280 pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64);
281 ret = pe_load_debug_info(pair->pcs, pair->effective);
282 pcs_callback(pair->pcs,
283 ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
284 &idsl64);
285 break;
286 default:
287 ret = FALSE;
288 break;
290 if (!ret) pair->effective->module.SymType = SymNone;
291 assert(pair->effective->module.SymType != SymDeferred);
292 pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
294 return pair->effective->module.SymType != SymNone;
297 /***********************************************************************
298 * module_find_by_addr
300 * either the addr where module is loaded, or any address inside the
301 * module
303 struct module* module_find_by_addr(const struct process* pcs, unsigned long addr,
304 enum module_type type)
306 struct module* module;
308 if (type == DMT_UNKNOWN)
310 if ((module = module_find_by_addr(pcs, addr, DMT_PE)) ||
311 (module = module_find_by_addr(pcs, addr, DMT_ELF)))
312 return module;
314 else
316 for (module = pcs->lmodules; module; module = module->next)
318 if (type == module->type && addr >= module->module.BaseOfImage &&
319 addr < module->module.BaseOfImage + module->module.ImageSize)
320 return module;
323 SetLastError(ERROR_INVALID_ADDRESS);
324 return module;
327 static BOOL module_is_elf_container_loaded(struct process* pcs, const char* ImageName,
328 const char* ModuleName)
330 char buffer[MAX_PATH];
331 size_t len;
332 struct module* module;
334 if (!ModuleName)
336 module_fill_module(ImageName, buffer, sizeof(buffer));
337 ModuleName = buffer;
339 len = strlen(ModuleName);
340 for (module = pcs->lmodules; module; module = module->next)
342 if (!strncasecmp(module->module.ModuleName, ModuleName, len) &&
343 module->type == DMT_ELF &&
344 !strcmp(module->module.ModuleName + len, "<elf>"))
345 return TRUE;
347 return FALSE;
350 /******************************************************************
351 * module_get_type_by_name
353 * Guesses a filename type from its extension
355 enum module_type module_get_type_by_name(const char* name)
357 const char* ptr;
358 int len = strlen(name);
360 /* check for terminating .so or .so.[digit] */
361 ptr = strrchr(name, '.');
362 if (ptr)
364 if (!strcmp(ptr, ".so") ||
365 (isdigit(ptr[1]) && !ptr[2] && ptr >= name + 3 && !memcmp(ptr - 3, ".so", 3)))
366 return DMT_ELF;
367 else if (!strcasecmp(ptr, ".pdb"))
368 return DMT_PDB;
370 /* wine-[kp]thread is also an ELF module */
371 else if (((len > 12 && name[len - 13] == '/') || len == 12) &&
372 (!strcasecmp(name + len - 12, "wine-pthread") ||
373 !strcasecmp(name + len - 12, "wine-kthread")))
375 return DMT_ELF;
377 return DMT_PE;
380 /***********************************************************************
381 * SymLoadModule (DBGHELP.@)
383 DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, const char* ImageName,
384 const char* ModuleName, DWORD BaseOfDll, DWORD SizeOfDll)
386 struct process* pcs;
387 struct module* module = NULL;
389 TRACE("(%p %p %s %s %08x %08x)\n",
390 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
391 BaseOfDll, SizeOfDll);
393 pcs = process_find_by_handle(hProcess);
394 if (!pcs) return FALSE;
396 /* force transparent ELF loading / unloading */
397 elf_synchronize_module_list(pcs);
399 /* this is a Wine extension to the API just to redo the synchronisation */
400 if (!ImageName && !hFile) return 0;
402 if (module_is_elf_container_loaded(pcs, ImageName, ModuleName))
404 /* force the loading of DLL as builtin */
405 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
406 BaseOfDll, SizeOfDll)))
407 goto done;
408 WARN("Couldn't locate %s\n", ImageName);
409 return 0;
411 TRACE("Assuming %s as native DLL\n", ImageName);
412 if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll)))
414 if (module_get_type_by_name(ImageName) == DMT_ELF &&
415 (module = elf_load_module(pcs, ImageName, BaseOfDll)))
416 goto done;
417 FIXME("Should have successfully loaded debug information for image %s\n",
418 ImageName);
419 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
420 BaseOfDll, SizeOfDll)))
421 goto done;
422 WARN("Couldn't locate %s\n", ImageName);
423 return 0;
425 module->module.NumSyms = module->ht_symbols.num_elts;
426 done:
427 /* by default pe_load_module fills module.ModuleName from a derivation
428 * of ImageName. Overwrite it, if we have better information
430 if (ModuleName)
431 module_set_module(module, ModuleName);
432 lstrcpynA(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
434 return module->module.BaseOfImage;
437 /***********************************************************************
438 * SymLoadModuleEx (DBGHELP.@)
440 DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
441 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize,
442 PMODLOAD_DATA Data, DWORD Flags)
444 TRACE("(%p %p %s %s %s %08x %p %08x)\n",
445 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
446 wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags);
448 if (Data)
449 FIXME("Unsupported load data parameter %p for %s\n", Data, ImageName);
450 if (!validate_addr64(BaseOfDll)) return FALSE;
451 if (Flags & SLMFLAG_VIRTUAL)
453 struct process* pcs = process_find_by_handle(hProcess);
454 struct module* module;
455 if (!pcs) return FALSE;
457 module = module_new(pcs, ImageName, module_get_type_by_name(ImageName), TRUE,
458 (DWORD)BaseOfDll, DllSize, 0, 0);
459 if (!module) return FALSE;
460 if (ModuleName)
461 module_set_module(module, ModuleName);
462 module->module.SymType = SymVirtual;
464 return TRUE;
466 if (Flags & ~(SLMFLAG_VIRTUAL))
467 FIXME("Unsupported Flags %08x for %s\n", Flags, ImageName);
469 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, DllSize);
472 /***********************************************************************
473 * SymLoadModuleExW (DBGHELP.@)
475 DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
476 PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD DllSize,
477 PMODLOAD_DATA Data, DWORD Flags)
479 LPSTR ImageName, ModuleName;
480 unsigned len;
481 BOOL ret;
483 if (wImageName)
485 len = WideCharToMultiByte(CP_ACP,0, wImageName, -1, NULL, 0, NULL, NULL);
486 ImageName = HeapAlloc(GetProcessHeap(), 0, len);
487 WideCharToMultiByte(CP_ACP,0, wImageName, -1, ImageName, len, NULL, NULL);
489 else ImageName = NULL;
490 if (wModuleName)
492 len = WideCharToMultiByte(CP_ACP,0, wModuleName, -1, NULL, 0, NULL, NULL);
493 ModuleName = HeapAlloc(GetProcessHeap(), 0, len);
494 WideCharToMultiByte(CP_ACP,0, wModuleName, -1, ModuleName, len, NULL, NULL);
496 else ModuleName = NULL;
498 ret = SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName,
499 BaseOfDll, DllSize, Data, Flags);
500 HeapFree(GetProcessHeap(), 0, ImageName);
501 HeapFree(GetProcessHeap(), 0, ModuleName);
502 return ret;
505 /***********************************************************************
506 * SymLoadModule64 (DBGHELP.@)
508 DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
509 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
511 if (!validate_addr64(BaseOfDll)) return FALSE;
512 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, SizeOfDll);
515 /******************************************************************
516 * module_remove
519 BOOL module_remove(struct process* pcs, struct module* module)
521 struct module** p;
523 TRACE("%s (%p)\n", module->module_name, module);
524 hash_table_destroy(&module->ht_symbols);
525 hash_table_destroy(&module->ht_types);
526 HeapFree(GetProcessHeap(), 0, (char*)module->sources);
527 HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
528 HeapFree(GetProcessHeap(), 0, module->dwarf2_info);
529 pool_destroy(&module->pool);
530 /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
531 * so do we
533 for (p = &pcs->lmodules; *p; p = &(*p)->next)
535 if (*p == module)
537 *p = module->next;
538 HeapFree(GetProcessHeap(), 0, module);
539 return TRUE;
542 FIXME("This shouldn't happen\n");
543 return FALSE;
546 /******************************************************************
547 * SymUnloadModule (DBGHELP.@)
550 BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
552 struct process* pcs;
553 struct module* module;
555 pcs = process_find_by_handle(hProcess);
556 if (!pcs) return FALSE;
557 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
558 if (!module) return FALSE;
559 return module_remove(pcs, module);
562 /******************************************************************
563 * SymUnloadModule64 (DBGHELP.@)
566 BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
568 struct process* pcs;
569 struct module* module;
571 pcs = process_find_by_handle(hProcess);
572 if (!pcs) return FALSE;
573 if (!validate_addr64(BaseOfDll)) return FALSE;
574 module = module_find_by_addr(pcs, (DWORD)BaseOfDll, DMT_UNKNOWN);
575 if (!module) return FALSE;
576 return module_remove(pcs, module);
579 /******************************************************************
580 * SymEnumerateModules (DBGHELP.@)
583 BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
584 PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
585 PVOID UserContext)
587 struct process* pcs = process_find_by_handle(hProcess);
588 struct module* module;
590 if (!pcs) return FALSE;
592 for (module = pcs->lmodules; module; module = module->next)
594 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
595 continue;
596 if (!EnumModulesCallback(module->module_name,
597 module->module.BaseOfImage, UserContext))
598 break;
600 return TRUE;
603 /******************************************************************
604 * SymEnumerateModules64 (DBGHELP.@)
607 BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
608 PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
609 PVOID UserContext)
611 struct process* pcs = process_find_by_handle(hProcess);
612 struct module* module;
614 if (!pcs) return FALSE;
616 for (module = pcs->lmodules; module; module = module->next)
618 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
619 continue;
620 if (!EnumModulesCallback(module->module_name,
621 module->module.BaseOfImage, UserContext))
622 break;
624 return TRUE;
627 /******************************************************************
628 * EnumerateLoadedModules64 (DBGHELP.@)
631 BOOL WINAPI EnumerateLoadedModules64(HANDLE hProcess,
632 PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,
633 PVOID UserContext)
635 HMODULE* hMods;
636 char base[256], mod[256];
637 DWORD i, sz;
638 MODULEINFO mi;
640 hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
641 if (!hMods) return FALSE;
643 if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
645 /* hProcess should also be a valid process handle !! */
646 FIXME("If this happens, bump the number in mod\n");
647 HeapFree(GetProcessHeap(), 0, hMods);
648 return FALSE;
650 sz /= sizeof(HMODULE);
651 for (i = 0; i < sz; i++)
653 if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
654 !GetModuleBaseNameA(hProcess, hMods[i], base, sizeof(base)))
655 continue;
656 module_fill_module(base, mod, sizeof(mod));
657 EnumLoadedModulesCallback(mod, (DWORD_PTR)mi.lpBaseOfDll, mi.SizeOfImage,
658 UserContext);
660 HeapFree(GetProcessHeap(), 0, hMods);
662 return sz != 0 && i == sz;
665 /******************************************************************
666 * EnumerateLoadedModules (DBGHELP.@)
669 struct enum_load_mod64_32
671 PENUMLOADED_MODULES_CALLBACK cb;
672 PVOID user;
675 static BOOL CALLBACK enum_load_mod64_32(PSTR name, DWORD64 base, ULONG size,
676 PVOID user)
678 struct enum_load_mod64_32* x = user;
679 return x->cb(name, (DWORD)base, size, x->user);
682 BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
683 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
684 PVOID UserContext)
686 struct enum_load_mod64_32 x;
688 x.cb = EnumLoadedModulesCallback;
689 x.user = UserContext;
691 return EnumerateLoadedModules64(hProcess, enum_load_mod64_32, &x);
694 /******************************************************************
695 * EnumerateLoadedModulesW64 (DBGHELP.@)
698 struct enum_load_mod64_W64
700 PENUMLOADED_MODULES_CALLBACKW64 cb;
701 PVOID user;
702 WCHAR module[MAX_PATH];
705 static BOOL CALLBACK enum_load_mod64_W64(PSTR name, DWORD64 base, ULONG size,
706 PVOID user)
708 struct enum_load_mod64_W64* x = user;
710 MultiByteToWideChar(CP_ACP, 0, name, -1,
711 x->module, sizeof(x->module) / sizeof(WCHAR));
712 return x->cb(x->module, base, size, x->user);
715 BOOL WINAPI EnumerateLoadedModulesW64(HANDLE hProcess,
716 PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback,
717 PVOID UserContext)
719 struct enum_load_mod64_W64 x;
721 x.cb = EnumLoadedModulesCallback;
722 x.user = UserContext;
724 return EnumerateLoadedModules64(hProcess, enum_load_mod64_W64, &x);
727 /******************************************************************
728 * SymGetModuleInfo (DBGHELP.@)
731 BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
732 PIMAGEHLP_MODULE ModuleInfo)
734 struct process* pcs = process_find_by_handle(hProcess);
735 struct module* module;
736 IMAGEHLP_MODULE mod;
738 if (!pcs) return FALSE;
739 if (ModuleInfo->SizeOfStruct < sizeof(*ModuleInfo)) return FALSE;
740 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
741 if (!module) return FALSE;
743 mod.SizeOfStruct = ModuleInfo->SizeOfStruct;
744 mod.BaseOfImage = module->module.BaseOfImage;
745 mod.ImageSize = module->module.ImageSize;
746 mod.TimeDateStamp = module->module.TimeDateStamp;
747 mod.CheckSum = module->module.CheckSum;
748 mod.NumSyms = module->module.NumSyms;
749 mod.SymType = module->module.SymType;
750 strcpy(mod.ModuleName, module->module.ModuleName);
751 strcpy(mod.ImageName, module->module.ImageName);
752 strcpy(mod.LoadedImageName, module->module.LoadedImageName);
754 if (module->module.SymType == SymNone)
756 module = module_get_container(pcs, module);
757 if (module && module->module.SymType != SymNone)
759 mod.SymType = module->module.SymType;
760 mod.NumSyms = module->module.NumSyms;
763 memcpy(ModuleInfo, &mod, ModuleInfo->SizeOfStruct);
764 return TRUE;
767 /******************************************************************
768 * SymGetModuleInfoW (DBGHELP.@)
771 BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
772 PIMAGEHLP_MODULEW ModuleInfo)
774 IMAGEHLP_MODULE mi;
775 IMAGEHLP_MODULEW miw;
777 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
779 mi.SizeOfStruct = sizeof(mi);
780 if (!SymGetModuleInfo(hProcess, dwAddr, &mi)) return FALSE;
782 miw.SizeOfStruct = mi.SizeOfStruct;
783 miw.BaseOfImage = mi.BaseOfImage;
784 miw.ImageSize = mi.ImageSize;
785 miw.TimeDateStamp = mi.TimeDateStamp;
786 miw.CheckSum = mi.CheckSum;
787 miw.NumSyms = mi.NumSyms;
788 miw.SymType = mi.SymType;
789 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
790 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
791 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
792 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
793 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
794 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
795 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
797 return TRUE;
800 /******************************************************************
801 * SymGetModuleInfo64 (DBGHELP.@)
804 BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
805 PIMAGEHLP_MODULE64 ModuleInfo)
807 struct process* pcs = process_find_by_handle(hProcess);
808 struct module* module;
810 TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
812 if (!pcs) return FALSE;
813 if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
814 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
815 if (!module) return FALSE;
817 memcpy(ModuleInfo, &module->module, ModuleInfo->SizeOfStruct);
819 if (module->module.SymType == SymNone)
821 module = module_get_container(pcs, module);
822 if (module && module->module.SymType != SymNone)
824 ModuleInfo->SymType = module->module.SymType;
825 ModuleInfo->NumSyms = module->module.NumSyms;
828 return TRUE;
831 /******************************************************************
832 * SymGetModuleInfoW64 (DBGHELP.@)
835 BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
836 PIMAGEHLP_MODULEW64 ModuleInfo)
838 IMAGEHLP_MODULE64 mi;
839 IMAGEHLP_MODULEW64 miw;
841 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
843 mi.SizeOfStruct = sizeof(mi);
844 if (!SymGetModuleInfo64(hProcess, dwAddr, &mi)) return FALSE;
846 miw.SizeOfStruct = mi.SizeOfStruct;
847 miw.BaseOfImage = mi.BaseOfImage;
848 miw.ImageSize = mi.ImageSize;
849 miw.TimeDateStamp = mi.TimeDateStamp;
850 miw.CheckSum = mi.CheckSum;
851 miw.NumSyms = mi.NumSyms;
852 miw.SymType = mi.SymType;
853 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
854 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
855 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
856 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
857 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
858 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
859 MultiByteToWideChar(CP_ACP, 0, mi.LoadedPdbName, -1,
860 miw.LoadedPdbName, sizeof(miw.LoadedPdbName) / sizeof(WCHAR));
862 miw.CVSig = mi.CVSig;
863 MultiByteToWideChar(CP_ACP, 0, mi.CVData, -1,
864 miw.CVData, sizeof(miw.CVData) / sizeof(WCHAR));
865 miw.PdbSig = mi.PdbSig;
866 miw.PdbSig70 = mi.PdbSig70;
867 miw.PdbAge = mi.PdbAge;
868 miw.PdbUnmatched = mi.PdbUnmatched;
869 miw.DbgUnmatched = mi.DbgUnmatched;
870 miw.LineNumbers = mi.LineNumbers;
871 miw.GlobalSymbols = mi.GlobalSymbols;
872 miw.TypeInfo = mi.TypeInfo;
873 miw.SourceIndexed = mi.SourceIndexed;
874 miw.Publics = mi.Publics;
876 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
878 return TRUE;
881 /***********************************************************************
882 * SymGetModuleBase (DBGHELP.@)
884 DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
886 struct process* pcs = process_find_by_handle(hProcess);
887 struct module* module;
889 if (!pcs) return 0;
890 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
891 if (!module) return 0;
892 return module->module.BaseOfImage;
895 /***********************************************************************
896 * SymGetModuleBase64 (DBGHELP.@)
898 DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
900 if (!validate_addr64(dwAddr)) return 0;
901 return SymGetModuleBase(hProcess, (DWORD)dwAddr);
904 /******************************************************************
905 * module_reset_debug_info
906 * Removes any debug information linked to a given module.
908 void module_reset_debug_info(struct module* module)
910 module->sortlist_valid = TRUE;
911 module->addr_sorttab = NULL;
912 hash_table_destroy(&module->ht_symbols);
913 module->ht_symbols.num_buckets = 0;
914 module->ht_symbols.buckets = NULL;
915 hash_table_destroy(&module->ht_types);
916 module->ht_types.num_buckets = 0;
917 module->ht_types.buckets = NULL;
918 module->vtypes.num_elts = 0;
919 hash_table_destroy(&module->ht_symbols);
920 module->sources_used = module->sources_alloc = 0;
921 module->sources = NULL;