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
28 #include "dbghelp_private.h"
32 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
37 static const char* ext[] = {".acm", ".dll", ".drv", ".exe", ".ocx", ".vxd", NULL};
39 static int match_ext(const char* ptr, size_t len)
44 for (e = ext; *e; e++)
47 if (l >= len) return FALSE;
48 if (strncasecmp(&ptr[len - l], *e, l)) continue;
54 static void module_fill_module(const char* in, char* out, size_t size)
56 const char *ptr,*endptr;
59 endptr = in + strlen(in);
60 for (ptr = endptr - 1;
61 ptr >= in && *ptr != '/' && *ptr != '\\';
64 len = min(endptr-ptr,size-1);
65 memcpy(out, ptr, len);
67 if (len > 4 && (l = match_ext(out, len)))
70 (!strcasecmp(out + len - 12, "wine-pthread") ||
71 !strcasecmp(out + len - 12, "wine-kthread")))
72 lstrcpynA(out, "<wine-loader>", size);
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 static const char* get_module_type(enum module_type type, BOOL virtual)
86 case DMT_ELF: return virtual ? "Virtual ELF" : "ELF";
87 case DMT_PE: return virtual ? "Virtual PE" : "PE";
88 default: return "---";
92 /***********************************************************************
93 * Creates and links a new module to a process
95 struct module* module_new(struct process* pcs, const char* name,
96 enum module_type type, BOOL virtual,
97 unsigned long mod_addr, unsigned long size,
98 unsigned long stamp, unsigned long checksum)
100 struct module* module;
102 assert(type == DMT_ELF || type == DMT_PE);
103 if (!(module = HeapAlloc(GetProcessHeap(), 0, sizeof(*module))))
106 memset(module, 0, sizeof(*module));
108 module->next = pcs->lmodules;
109 pcs->lmodules = module;
111 TRACE("=> %s %08lx-%08lx %s\n",
112 get_module_type(type, virtual), mod_addr, mod_addr + size, name);
114 pool_init(&module->pool, 65536);
116 module->module.SizeOfStruct = sizeof(module->module);
117 module->module.BaseOfImage = mod_addr;
118 module->module.ImageSize = size;
119 module_fill_module(name, module->module.ModuleName,
120 sizeof(module->module.ModuleName));
121 module->module.ImageName[0] = '\0';
122 lstrcpynA(module->module.LoadedImageName, name, sizeof(module->module.LoadedImageName));
123 module->module.SymType = SymNone;
124 module->module.NumSyms = 0;
125 module->module.TimeDateStamp = stamp;
126 module->module.CheckSum = checksum;
128 memset(module->module.LoadedPdbName, 0, sizeof(module->module.CVData));
129 module->module.CVSig = 0;
130 memset(module->module.CVData, 0, sizeof(module->module.CVData));
131 module->module.PdbSig = 0;
132 memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
133 module->module.PdbAge = 0;
134 module->module.PdbUnmatched = FALSE;
135 module->module.DbgUnmatched = FALSE;
136 module->module.LineNumbers = FALSE;
137 module->module.GlobalSymbols = FALSE;
138 module->module.TypeInfo = FALSE;
139 module->module.SourceIndexed = FALSE;
140 module->module.Publics = FALSE;
143 module->is_virtual = virtual ? TRUE : FALSE;
144 module->sortlist_valid = FALSE;
145 module->addr_sorttab = NULL;
146 /* FIXME: this seems a bit too high (on a per module basis)
147 * need some statistics about this
149 hash_table_init(&module->pool, &module->ht_symbols, 4096);
150 hash_table_init(&module->pool, &module->ht_types, 4096);
151 vector_init(&module->vtypes, sizeof(struct symt*), 32);
153 module->sources_used = 0;
154 module->sources_alloc = 0;
160 /***********************************************************************
161 * module_find_by_name
164 struct module* module_find_by_name(const struct process* pcs,
165 const char* name, enum module_type type)
167 struct module* module;
169 if (type == DMT_UNKNOWN)
171 if ((module = module_find_by_name(pcs, name, DMT_PE)) ||
172 (module = module_find_by_name(pcs, name, DMT_ELF)))
177 char modname[MAX_PATH];
179 for (module = pcs->lmodules; module; module = module->next)
181 if (type == module->type &&
182 !strcasecmp(name, module->module.LoadedImageName))
185 module_fill_module(name, modname, sizeof(modname));
186 for (module = pcs->lmodules; module; module = module->next)
188 if (type == module->type &&
189 !strcasecmp(modname, module->module.ModuleName))
193 SetLastError(ERROR_INVALID_NAME);
197 /***********************************************************************
198 * module_get_container
201 struct module* module_get_container(const struct process* pcs,
202 const struct module* inner)
204 struct module* module;
206 for (module = pcs->lmodules; module; module = module->next)
208 if (module != inner &&
209 module->module.BaseOfImage <= inner->module.BaseOfImage &&
210 module->module.BaseOfImage + module->module.ImageSize >=
211 inner->module.BaseOfImage + inner->module.ImageSize)
217 /***********************************************************************
218 * module_get_containee
221 struct module* module_get_containee(const struct process* pcs,
222 const struct module* outter)
224 struct module* module;
226 for (module = pcs->lmodules; module; module = module->next)
228 if (module != outter &&
229 outter->module.BaseOfImage <= module->module.BaseOfImage &&
230 outter->module.BaseOfImage + outter->module.ImageSize >=
231 module->module.BaseOfImage + module->module.ImageSize)
237 /******************************************************************
240 * get the debug information from a module:
241 * - if the module's type is deferred, then force loading of debug info (and return
243 * - if the module has no debug info and has an ELF container, then return the ELF
244 * container (and also force the ELF container's debug info loading if deferred)
245 * - otherwise return the module itself if it has some debug info
247 BOOL module_get_debug(struct module_pair* pair)
249 IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl64;
251 if (!pair->requested) return FALSE;
252 /* for a PE builtin, always get info from container */
253 if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
254 pair->effective = pair->requested;
255 /* if deferred, force loading */
256 if (pair->effective->module.SymType == SymDeferred)
260 if (pair->effective->is_virtual) ret = FALSE;
261 else switch (pair->effective->type)
264 ret = elf_load_debug_info(pair->effective, NULL);
267 idsl64.SizeOfStruct = sizeof(idsl64);
268 idsl64.BaseOfImage = pair->effective->module.BaseOfImage;
269 idsl64.CheckSum = pair->effective->module.CheckSum;
270 idsl64.TimeDateStamp = pair->effective->module.TimeDateStamp;
271 strcpy(idsl64.FileName, pair->effective->module.ImageName);
272 idsl64.Reparse = FALSE;
273 idsl64.hFile = INVALID_HANDLE_VALUE;
275 pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64);
276 ret = pe_load_debug_info(pair->pcs, pair->effective);
277 pcs_callback(pair->pcs,
278 ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
285 if (!ret) pair->effective->module.SymType = SymNone;
286 assert(pair->effective->module.SymType != SymDeferred);
287 pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
289 return pair->effective->module.SymType != SymNone;
292 /***********************************************************************
293 * module_find_by_addr
295 * either the addr where module is loaded, or any address inside the
298 struct module* module_find_by_addr(const struct process* pcs, unsigned long addr,
299 enum module_type type)
301 struct module* module;
303 if (type == DMT_UNKNOWN)
305 if ((module = module_find_by_addr(pcs, addr, DMT_PE)) ||
306 (module = module_find_by_addr(pcs, addr, DMT_ELF)))
311 for (module = pcs->lmodules; module; module = module->next)
313 if (type == module->type && addr >= module->module.BaseOfImage &&
314 addr < module->module.BaseOfImage + module->module.ImageSize)
318 SetLastError(ERROR_INVALID_ADDRESS);
322 static BOOL module_is_elf_container_loaded(struct process* pcs, const char* ImageName,
323 const char* ModuleName)
325 char buffer[MAX_PATH];
327 struct module* module;
331 module_fill_module(ImageName, buffer, sizeof(buffer));
334 len = strlen(ModuleName);
335 for (module = pcs->lmodules; module; module = module->next)
337 if (!strncasecmp(module->module.ModuleName, ModuleName, len) &&
338 module->type == DMT_ELF &&
339 !strcmp(module->module.ModuleName + len, "<elf>"))
345 /******************************************************************
346 * module_get_type_by_name
348 * Guesses a filename type from its extension
350 enum module_type module_get_type_by_name(const char* name)
353 int len = strlen(name);
355 /* check for terminating .so or .so.[digit] */
356 ptr = strrchr(name, '.');
359 if (!strcmp(ptr, ".so") ||
360 (isdigit(ptr[1]) && !ptr[2] && ptr >= name + 3 && !memcmp(ptr - 3, ".so", 3)))
362 else if (!strcasecmp(ptr, ".pdb"))
365 /* wine-[kp]thread is also an ELF module */
366 else if (((len > 12 && name[len - 13] == '/') || len == 12) &&
367 (!strcasecmp(name + len - 12, "wine-pthread") ||
368 !strcasecmp(name + len - 12, "wine-kthread")))
375 /***********************************************************************
376 * SymLoadModule (DBGHELP.@)
378 DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, const char* ImageName,
379 const char* ModuleName, DWORD BaseOfDll, DWORD SizeOfDll)
382 struct module* module = NULL;
384 TRACE("(%p %p %s %s %08x %08x)\n",
385 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
386 BaseOfDll, SizeOfDll);
388 pcs = process_find_by_handle(hProcess);
389 if (!pcs) return FALSE;
391 /* force transparent ELF loading / unloading */
392 elf_synchronize_module_list(pcs);
394 /* this is a Wine extension to the API just to redo the synchronisation */
395 if (!ImageName && !hFile) return 0;
397 if (module_is_elf_container_loaded(pcs, ImageName, ModuleName))
399 /* force the loading of DLL as builtin */
400 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
401 BaseOfDll, SizeOfDll)))
403 WARN("Couldn't locate %s\n", ImageName);
406 TRACE("Assuming %s as native DLL\n", ImageName);
407 if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll)))
409 if (module_get_type_by_name(ImageName) == DMT_ELF &&
410 (module = elf_load_module(pcs, ImageName, BaseOfDll)))
412 FIXME("Should have successfully loaded debug information for image %s\n",
414 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
415 BaseOfDll, SizeOfDll)))
417 WARN("Couldn't locate %s\n", ImageName);
420 module->module.NumSyms = module->ht_symbols.num_elts;
422 /* by default pe_load_module fills module.ModuleName from a derivation
423 * of ImageName. Overwrite it, if we have better information
426 lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
427 lstrcpynA(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
429 return module->module.BaseOfImage;
432 /***********************************************************************
433 * SymLoadModuleEx (DBGHELP.@)
435 DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
436 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize,
437 PMODLOAD_DATA Data, DWORD Flags)
439 TRACE("(%p %p %s %s %s %08x %p %08x)\n",
440 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
441 wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags);
444 FIXME("Unsupported load data parameter %p for %s\n", Data, ImageName);
445 if (!validate_addr64(BaseOfDll)) return FALSE;
446 if (Flags & SLMFLAG_VIRTUAL)
448 struct process* pcs = process_find_by_handle(hProcess);
449 struct module* module;
450 if (!pcs) return FALSE;
452 module = module_new(pcs, ImageName, module_get_type_by_name(ImageName), TRUE,
453 (DWORD)BaseOfDll, DllSize, 0, 0);
454 if (!module) return FALSE;
456 lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
457 module->module.SymType = SymVirtual;
461 if (Flags & ~(SLMFLAG_VIRTUAL))
462 FIXME("Unsupported Flags %08x for %s\n", Flags, ImageName);
464 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, DllSize);
467 /***********************************************************************
468 * SymLoadModuleExW (DBGHELP.@)
470 DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
471 PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD DllSize,
472 PMODLOAD_DATA Data, DWORD Flags)
474 LPSTR ImageName, ModuleName;
480 len = WideCharToMultiByte(CP_ACP,0, wImageName, -1, NULL, 0, NULL, NULL);
481 ImageName = HeapAlloc(GetProcessHeap(), 0, len);
482 WideCharToMultiByte(CP_ACP,0, wImageName, -1, ImageName, len, NULL, NULL);
484 else ImageName = NULL;
487 len = WideCharToMultiByte(CP_ACP,0, wModuleName, -1, NULL, 0, NULL, NULL);
488 ModuleName = HeapAlloc(GetProcessHeap(), 0, len);
489 WideCharToMultiByte(CP_ACP,0, wModuleName, -1, ModuleName, len, NULL, NULL);
491 else ModuleName = NULL;
493 ret = SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName,
494 BaseOfDll, DllSize, Data, Flags);
495 HeapFree(GetProcessHeap(), 0, ImageName);
496 HeapFree(GetProcessHeap(), 0, ModuleName);
500 /***********************************************************************
501 * SymLoadModule64 (DBGHELP.@)
503 DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
504 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
506 if (!validate_addr64(BaseOfDll)) return FALSE;
507 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, SizeOfDll);
510 /******************************************************************
514 BOOL module_remove(struct process* pcs, struct module* module)
518 TRACE("%s (%p)\n", module->module.ModuleName, module);
519 hash_table_destroy(&module->ht_symbols);
520 hash_table_destroy(&module->ht_types);
521 HeapFree(GetProcessHeap(), 0, (char*)module->sources);
522 HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
523 HeapFree(GetProcessHeap(), 0, module->dwarf2_info);
524 pool_destroy(&module->pool);
525 /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
528 for (p = &pcs->lmodules; *p; p = &(*p)->next)
533 HeapFree(GetProcessHeap(), 0, module);
537 FIXME("This shouldn't happen\n");
541 /******************************************************************
542 * SymUnloadModule (DBGHELP.@)
545 BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
548 struct module* module;
550 pcs = process_find_by_handle(hProcess);
551 if (!pcs) return FALSE;
552 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
553 if (!module) return FALSE;
554 return module_remove(pcs, module);
557 /******************************************************************
558 * SymUnloadModule64 (DBGHELP.@)
561 BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
564 struct module* module;
566 pcs = process_find_by_handle(hProcess);
567 if (!pcs) return FALSE;
568 if (!validate_addr64(BaseOfDll)) return FALSE;
569 module = module_find_by_addr(pcs, (DWORD)BaseOfDll, DMT_UNKNOWN);
570 if (!module) return FALSE;
571 return module_remove(pcs, module);
574 /******************************************************************
575 * SymEnumerateModules (DBGHELP.@)
578 BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
579 PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
582 struct process* pcs = process_find_by_handle(hProcess);
583 struct module* module;
585 if (!pcs) return FALSE;
587 for (module = pcs->lmodules; module; module = module->next)
589 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
591 if (!EnumModulesCallback(module->module.ModuleName,
592 module->module.BaseOfImage, UserContext))
598 /******************************************************************
599 * SymEnumerateModules64 (DBGHELP.@)
602 BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
603 PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
606 struct process* pcs = process_find_by_handle(hProcess);
607 struct module* module;
609 if (!pcs) return FALSE;
611 for (module = pcs->lmodules; module; module = module->next)
613 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
615 if (!EnumModulesCallback(module->module.ModuleName,
616 module->module.BaseOfImage, UserContext))
622 /******************************************************************
623 * EnumerateLoadedModules (DBGHELP.@)
626 BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
627 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
631 char base[256], mod[256];
635 hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
636 if (!hMods) return FALSE;
638 if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
640 /* hProcess should also be a valid process handle !! */
641 FIXME("If this happens, bump the number in mod\n");
642 HeapFree(GetProcessHeap(), 0, hMods);
645 sz /= sizeof(HMODULE);
646 for (i = 0; i < sz; i++)
648 if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
649 !GetModuleBaseNameA(hProcess, hMods[i], base, sizeof(base)))
651 module_fill_module(base, mod, sizeof(mod));
652 EnumLoadedModulesCallback(mod, (DWORD)mi.lpBaseOfDll, mi.SizeOfImage,
655 HeapFree(GetProcessHeap(), 0, hMods);
657 return sz != 0 && i == sz;
660 /******************************************************************
661 * SymGetModuleInfo (DBGHELP.@)
664 BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
665 PIMAGEHLP_MODULE ModuleInfo)
667 struct process* pcs = process_find_by_handle(hProcess);
668 struct module* module;
671 if (!pcs) return FALSE;
672 if (ModuleInfo->SizeOfStruct < sizeof(*ModuleInfo)) return FALSE;
673 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
674 if (!module) return FALSE;
676 mod.SizeOfStruct = ModuleInfo->SizeOfStruct;
677 mod.BaseOfImage = module->module.BaseOfImage;
678 mod.ImageSize = module->module.ImageSize;
679 mod.TimeDateStamp = module->module.TimeDateStamp;
680 mod.CheckSum = module->module.CheckSum;
681 mod.NumSyms = module->module.NumSyms;
682 mod.SymType = module->module.SymType;
683 strcpy(mod.ModuleName, module->module.ModuleName);
684 strcpy(mod.ImageName, module->module.ImageName);
685 strcpy(mod.LoadedImageName, module->module.LoadedImageName);
687 if (module->module.SymType == SymNone)
689 module = module_get_container(pcs, module);
690 if (module && module->module.SymType != SymNone)
692 mod.SymType = module->module.SymType;
693 mod.NumSyms = module->module.NumSyms;
696 memcpy(ModuleInfo, &mod, ModuleInfo->SizeOfStruct);
700 /******************************************************************
701 * SymGetModuleInfoW (DBGHELP.@)
704 BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
705 PIMAGEHLP_MODULEW ModuleInfo)
708 IMAGEHLP_MODULEW miw;
710 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
712 mi.SizeOfStruct = sizeof(mi);
713 if (!SymGetModuleInfo(hProcess, dwAddr, &mi)) return FALSE;
715 miw.SizeOfStruct = mi.SizeOfStruct;
716 miw.BaseOfImage = mi.BaseOfImage;
717 miw.ImageSize = mi.ImageSize;
718 miw.TimeDateStamp = mi.TimeDateStamp;
719 miw.CheckSum = mi.CheckSum;
720 miw.NumSyms = mi.NumSyms;
721 miw.SymType = mi.SymType;
722 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
723 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
724 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
725 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
726 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
727 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
728 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
733 /******************************************************************
734 * SymGetModuleInfo64 (DBGHELP.@)
737 BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
738 PIMAGEHLP_MODULE64 ModuleInfo)
740 struct process* pcs = process_find_by_handle(hProcess);
741 struct module* module;
743 TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
745 if (!pcs) return FALSE;
746 if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
747 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
748 if (!module) return FALSE;
750 memcpy(ModuleInfo, &module->module, ModuleInfo->SizeOfStruct);
752 if (module->module.SymType == SymNone)
754 module = module_get_container(pcs, module);
755 if (module && module->module.SymType != SymNone)
757 ModuleInfo->SymType = module->module.SymType;
758 ModuleInfo->NumSyms = module->module.NumSyms;
764 /******************************************************************
765 * SymGetModuleInfoW64 (DBGHELP.@)
768 BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
769 PIMAGEHLP_MODULEW64 ModuleInfo)
771 IMAGEHLP_MODULE64 mi;
772 IMAGEHLP_MODULEW64 miw;
774 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
776 mi.SizeOfStruct = sizeof(mi);
777 if (!SymGetModuleInfo64(hProcess, dwAddr, &mi)) return FALSE;
779 miw.SizeOfStruct = mi.SizeOfStruct;
780 miw.BaseOfImage = mi.BaseOfImage;
781 miw.ImageSize = mi.ImageSize;
782 miw.TimeDateStamp = mi.TimeDateStamp;
783 miw.CheckSum = mi.CheckSum;
784 miw.NumSyms = mi.NumSyms;
785 miw.SymType = mi.SymType;
786 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
787 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
788 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
789 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
790 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
791 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
792 MultiByteToWideChar(CP_ACP, 0, mi.LoadedPdbName, -1,
793 miw.LoadedPdbName, sizeof(miw.LoadedPdbName) / sizeof(WCHAR));
795 miw.CVSig = mi.CVSig;
796 MultiByteToWideChar(CP_ACP, 0, mi.CVData, -1,
797 miw.CVData, sizeof(miw.CVData) / sizeof(WCHAR));
798 miw.PdbSig = mi.PdbSig;
799 miw.PdbSig70 = mi.PdbSig70;
800 miw.PdbAge = mi.PdbAge;
801 miw.PdbUnmatched = mi.PdbUnmatched;
802 miw.DbgUnmatched = mi.DbgUnmatched;
803 miw.LineNumbers = mi.LineNumbers;
804 miw.GlobalSymbols = mi.GlobalSymbols;
805 miw.TypeInfo = mi.TypeInfo;
806 miw.SourceIndexed = mi.SourceIndexed;
807 miw.Publics = mi.Publics;
809 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
814 /***********************************************************************
815 * SymGetModuleBase (DBGHELP.@)
817 DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
819 struct process* pcs = process_find_by_handle(hProcess);
820 struct module* module;
823 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
824 if (!module) return 0;
825 return module->module.BaseOfImage;
828 /***********************************************************************
829 * SymGetModuleBase64 (DBGHELP.@)
831 DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
833 if (!validate_addr64(dwAddr)) return 0;
834 return SymGetModuleBase(hProcess, (DWORD)dwAddr);
837 /******************************************************************
838 * module_reset_debug_info
839 * Removes any debug information linked to a given module.
841 void module_reset_debug_info(struct module* module)
843 module->sortlist_valid = TRUE;
844 module->addr_sorttab = NULL;
845 hash_table_destroy(&module->ht_symbols);
846 module->ht_symbols.num_buckets = 0;
847 module->ht_symbols.buckets = NULL;
848 hash_table_destroy(&module->ht_types);
849 module->ht_types.num_buckets = 0;
850 module->ht_types.buckets = NULL;
851 module->vtypes.num_elts = 0;
852 hash_table_destroy(&module->ht_symbols);
853 module->sources_used = module->sources_alloc = 0;
854 module->sources = NULL;