wined3d: Print real unhandled D3DCMPFUNC value.
[wine/hacks.git] / dlls / dbghelp / module.c
bloba08cf125f14eaaee5d299abe96372c07b7d95d70
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* ext[] = {".acm", ".dll", ".drv", ".exe", ".ocx", ".vxd", NULL};
39 static int match_ext(const char* ptr, size_t len)
41 const char**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 static const char* get_module_type(enum module_type type, BOOL virtual)
84 switch (type)
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))))
104 return NULL;
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 = 0;
140 module->module.Publics = 0;
142 module->type = type;
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;
155 module->sources = 0;
157 return module;
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)))
173 return module;
175 else
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))
183 return module;
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))
190 return module;
193 SetLastError(ERROR_INVALID_NAME);
194 return NULL;
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)
212 return module;
214 return NULL;
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)
232 return module;
234 return NULL;
237 /******************************************************************
238 * module_get_debug
240 * get the debug information from a module:
241 * - if the module's type is deferred, then force loading of debug info (and return
242 * the module itself)
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(const struct process* pcs, 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(pcs, pair->requested)))
254 pair->effective = pair->requested;
255 /* if deferred, force loading */
256 if (pair->effective->module.SymType == SymDeferred)
258 BOOL ret;
260 if (pair->effective->is_virtual) ret = FALSE;
261 else switch (pair->effective->type)
263 case DMT_ELF:
264 ret = elf_load_debug_info(pair->effective, NULL);
265 break;
266 case DMT_PE:
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(pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64);
276 ret = pe_load_debug_info(pcs, pair->effective);
277 pcs_callback(pcs,
278 ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
279 &idsl64);
280 break;
281 default:
282 ret = FALSE;
283 break;
285 if (!ret) pair->effective->module.SymType = SymNone;
286 assert(pair->effective->module.SymType != SymDeferred);
287 module_compute_num_syms(pair->effective);
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
296 * module
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)))
307 return module;
309 else
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)
315 return module;
318 SetLastError(ERROR_INVALID_ADDRESS);
319 return module;
322 static BOOL module_is_elf_container_loaded(struct process* pcs, const char* ImageName,
323 const char* ModuleName)
325 char buffer[MAX_PATH];
326 size_t len;
327 struct module* module;
329 if (!ModuleName)
331 module_fill_module(ImageName, buffer, sizeof(buffer));
332 ModuleName = 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>"))
340 return TRUE;
342 return FALSE;
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)
352 const char* ptr;
353 int len = strlen(name);
355 /* check for terminating .so or .so.[digit] */
356 ptr = strrchr(name, '.');
357 if (ptr)
359 if (!strcmp(ptr, ".so") ||
360 (isdigit(ptr[1]) && !ptr[2] && ptr >= name + 3 && !memcmp(ptr - 3, ".so", 3)))
361 return DMT_ELF;
362 else if (!strcasecmp(ptr, ".pdb"))
363 return DMT_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")))
370 return DMT_ELF;
372 return DMT_PE;
375 int module_compute_num_syms(struct module* module)
377 struct hash_table_iter hti;
378 void* ptr;
380 module->module.NumSyms = 0;
381 hash_table_iter_init(&module->ht_symbols, &hti, NULL);
382 while ((ptr = hash_table_iter_up(&hti)))
383 module->module.NumSyms++;
384 return module->module.NumSyms;
387 /***********************************************************************
388 * SymLoadModule (DBGHELP.@)
390 DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, const char* ImageName,
391 const char* ModuleName, DWORD BaseOfDll, DWORD SizeOfDll)
393 struct process* pcs;
394 struct module* module = NULL;
396 TRACE("(%p %p %s %s %08lx %08lx)\n",
397 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
398 BaseOfDll, SizeOfDll);
400 pcs = process_find_by_handle(hProcess);
401 if (!pcs) return FALSE;
403 /* force transparent ELF loading / unloading */
404 elf_synchronize_module_list(pcs);
406 /* this is a Wine extension to the API just to redo the synchronisation */
407 if (!ImageName && !hFile) return 0;
409 if (module_is_elf_container_loaded(pcs, ImageName, ModuleName))
411 /* force the loading of DLL as builtin */
412 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
413 BaseOfDll, SizeOfDll)))
414 goto done;
415 WARN("Couldn't locate %s\n", ImageName);
416 return 0;
418 TRACE("Assuming %s as native DLL\n", ImageName);
419 if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll)))
421 if (module_get_type_by_name(ImageName) == DMT_ELF &&
422 (module = elf_load_module(pcs, ImageName, BaseOfDll)))
423 goto done;
424 FIXME("Should have successfully loaded debug information for image %s\n",
425 ImageName);
426 if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName,
427 BaseOfDll, SizeOfDll)))
428 goto done;
429 WARN("Couldn't locate %s\n", ImageName);
430 return 0;
432 module_compute_num_syms(module);
433 done:
434 /* by default pe_load_module fills module.ModuleName from a derivation
435 * of ImageName. Overwrite it, if we have better information
437 if (ModuleName)
438 lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
439 lstrcpynA(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
441 return module->module.BaseOfImage;
444 /***********************************************************************
445 * SymLoadModuleEx (DBGHELP.@)
447 DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
448 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize,
449 PMODLOAD_DATA Data, DWORD Flags)
451 TRACE("(%p %p %s %s %s %08lx %p %08lx)\n",
452 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
453 wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags);
455 if (Data)
456 FIXME("Unsupported load data parameter %p for %s\n", Data, ImageName);
457 if (!validate_addr64(BaseOfDll)) return FALSE;
458 if (Flags & SLMFLAG_VIRTUAL)
460 struct process* pcs = process_find_by_handle(hProcess);
461 struct module* module;
462 if (!pcs) return FALSE;
464 module = module_new(pcs, ImageName, module_get_type_by_name(ImageName), TRUE,
465 (DWORD)BaseOfDll, DllSize, 0, 0);
466 if (!module) return FALSE;
467 if (ModuleName)
468 lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
469 module->module.SymType = SymVirtual;
471 return TRUE;
473 if (Flags & ~(SLMFLAG_VIRTUAL))
474 FIXME("Unsupported Flags %08lx for %s\n", Flags, ImageName);
476 return SymLoadModule(hProcess, hFile, (char*)ImageName, (char*)ModuleName,
477 (DWORD)BaseOfDll, DllSize);
480 /***********************************************************************
481 * SymLoadModuleExW (DBGHELP.@)
483 DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
484 PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD DllSize,
485 PMODLOAD_DATA Data, DWORD Flags)
487 LPSTR ImageName, ModuleName;
488 unsigned len;
489 BOOL ret;
491 if (wImageName)
493 len = WideCharToMultiByte(CP_ACP,0, wImageName, -1, NULL, 0, NULL, NULL);
494 ImageName = HeapAlloc(GetProcessHeap(), 0, len);
495 WideCharToMultiByte(CP_ACP,0, wImageName, -1, ImageName, len, NULL, NULL);
497 else ImageName = NULL;
498 if (wModuleName)
500 len = WideCharToMultiByte(CP_ACP,0, wModuleName, -1, NULL, 0, NULL, NULL);
501 ModuleName = HeapAlloc(GetProcessHeap(), 0, len);
502 WideCharToMultiByte(CP_ACP,0, wModuleName, -1, ModuleName, len, NULL, NULL);
504 else ModuleName = NULL;
506 ret = SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName,
507 BaseOfDll, DllSize, Data, Flags);
508 HeapFree(GetProcessHeap(), 0, ImageName);
509 HeapFree(GetProcessHeap(), 0, ModuleName);
510 return ret;
513 /***********************************************************************
514 * SymLoadModule64 (DBGHELP.@)
516 DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
517 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
519 if (!validate_addr64(BaseOfDll)) return FALSE;
520 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, SizeOfDll);
523 /******************************************************************
524 * module_remove
527 BOOL module_remove(struct process* pcs, struct module* module)
529 struct module** p;
531 TRACE("%s (%p)\n", module->module.ModuleName, module);
532 hash_table_destroy(&module->ht_symbols);
533 hash_table_destroy(&module->ht_types);
534 HeapFree(GetProcessHeap(), 0, (char*)module->sources);
535 HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
536 pool_destroy(&module->pool);
537 /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
538 * so do we
540 for (p = &pcs->lmodules; *p; p = &(*p)->next)
542 if (*p == module)
544 *p = module->next;
545 HeapFree(GetProcessHeap(), 0, module);
546 return TRUE;
549 FIXME("This shouldn't happen\n");
550 return FALSE;
553 /******************************************************************
554 * SymUnloadModule (DBGHELP.@)
557 BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
559 struct process* pcs;
560 struct module* module;
562 pcs = process_find_by_handle(hProcess);
563 if (!pcs) return FALSE;
564 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
565 if (!module) return FALSE;
566 return module_remove(pcs, module);
569 /******************************************************************
570 * SymUnloadModule64 (DBGHELP.@)
573 BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
575 struct process* pcs;
576 struct module* module;
578 pcs = process_find_by_handle(hProcess);
579 if (!pcs) return FALSE;
580 if (!validate_addr64(BaseOfDll)) return FALSE;
581 module = module_find_by_addr(pcs, (DWORD)BaseOfDll, DMT_UNKNOWN);
582 if (!module) return FALSE;
583 return module_remove(pcs, module);
586 /******************************************************************
587 * SymEnumerateModules (DBGHELP.@)
590 BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
591 PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
592 PVOID UserContext)
594 struct process* pcs = process_find_by_handle(hProcess);
595 struct module* module;
597 if (!pcs) return FALSE;
599 for (module = pcs->lmodules; module; module = module->next)
601 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
602 continue;
603 if (!EnumModulesCallback(module->module.ModuleName,
604 module->module.BaseOfImage, UserContext))
605 break;
607 return TRUE;
610 /******************************************************************
611 * SymEnumerateModules64 (DBGHELP.@)
614 BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
615 PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
616 PVOID UserContext)
618 struct process* pcs = process_find_by_handle(hProcess);
619 struct module* module;
621 if (!pcs) return FALSE;
623 for (module = pcs->lmodules; module; module = module->next)
625 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
626 continue;
627 if (!EnumModulesCallback(module->module.ModuleName,
628 module->module.BaseOfImage, UserContext))
629 break;
631 return TRUE;
634 /******************************************************************
635 * EnumerateLoadedModules (DBGHELP.@)
638 BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
639 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
640 PVOID UserContext)
642 HMODULE* hMods;
643 char base[256], mod[256];
644 DWORD i, sz;
645 MODULEINFO mi;
647 hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
648 if (!hMods) return FALSE;
650 if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
652 /* hProcess should also be a valid process handle !! */
653 FIXME("If this happens, bump the number in mod\n");
654 HeapFree(GetProcessHeap(), 0, hMods);
655 return FALSE;
657 sz /= sizeof(HMODULE);
658 for (i = 0; i < sz; i++)
660 if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
661 !GetModuleBaseNameA(hProcess, hMods[i], base, sizeof(base)))
662 continue;
663 module_fill_module(base, mod, sizeof(mod));
664 EnumLoadedModulesCallback(mod, (DWORD)mi.lpBaseOfDll, mi.SizeOfImage,
665 UserContext);
667 HeapFree(GetProcessHeap(), 0, hMods);
669 return sz != 0 && i == sz;
672 /******************************************************************
673 * SymGetModuleInfo (DBGHELP.@)
676 BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
677 PIMAGEHLP_MODULE ModuleInfo)
679 struct process* pcs = process_find_by_handle(hProcess);
680 struct module* module;
681 IMAGEHLP_MODULE mod;
683 if (!pcs) return FALSE;
684 if (ModuleInfo->SizeOfStruct < sizeof(*ModuleInfo)) return FALSE;
685 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
686 if (!module) return FALSE;
688 mod.SizeOfStruct = ModuleInfo->SizeOfStruct;
689 mod.BaseOfImage = module->module.BaseOfImage;
690 mod.ImageSize = module->module.ImageSize;
691 mod.TimeDateStamp = module->module.TimeDateStamp;
692 mod.CheckSum = module->module.CheckSum;
693 mod.NumSyms = module->module.NumSyms;
694 mod.SymType = module->module.SymType;
695 strcpy(mod.ModuleName, module->module.ModuleName);
696 strcpy(mod.ImageName, module->module.ImageName);
697 strcpy(mod.LoadedImageName, module->module.LoadedImageName);
699 if (module->module.SymType == SymNone)
701 module = module_get_container(pcs, module);
702 if (module && module->module.SymType != SymNone)
704 mod.SymType = module->module.SymType;
705 mod.NumSyms = module->module.NumSyms;
708 memcpy(ModuleInfo, &mod, ModuleInfo->SizeOfStruct);
709 return TRUE;
712 /******************************************************************
713 * SymGetModuleInfoW (DBGHELP.@)
716 BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
717 PIMAGEHLP_MODULEW ModuleInfo)
719 IMAGEHLP_MODULE mi;
720 IMAGEHLP_MODULEW miw;
722 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
724 mi.SizeOfStruct = sizeof(mi);
725 if (!SymGetModuleInfo(hProcess, dwAddr, &mi)) return FALSE;
727 miw.SizeOfStruct = mi.SizeOfStruct;
728 miw.BaseOfImage = mi.BaseOfImage;
729 miw.ImageSize = mi.ImageSize;
730 miw.TimeDateStamp = mi.TimeDateStamp;
731 miw.CheckSum = mi.CheckSum;
732 miw.NumSyms = mi.NumSyms;
733 miw.SymType = mi.SymType;
734 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
735 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
736 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
737 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
738 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
739 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
740 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
742 return TRUE;
745 /******************************************************************
746 * SymGetModuleInfo64 (DBGHELP.@)
749 BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
750 PIMAGEHLP_MODULE64 ModuleInfo)
752 struct process* pcs = process_find_by_handle(hProcess);
753 struct module* module;
755 TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
757 if (!pcs) return FALSE;
758 if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
759 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
760 if (!module) return FALSE;
762 memcpy(ModuleInfo, &module->module, ModuleInfo->SizeOfStruct);
764 if (module->module.SymType == SymNone)
766 module = module_get_container(pcs, module);
767 if (module && module->module.SymType != SymNone)
769 ModuleInfo->SymType = module->module.SymType;
770 ModuleInfo->NumSyms = module->module.NumSyms;
773 return TRUE;
776 /******************************************************************
777 * SymGetModuleInfoW64 (DBGHELP.@)
780 BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
781 PIMAGEHLP_MODULEW64 ModuleInfo)
783 IMAGEHLP_MODULE64 mi;
784 IMAGEHLP_MODULEW64 miw;
786 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
788 mi.SizeOfStruct = sizeof(mi);
789 if (!SymGetModuleInfo64(hProcess, dwAddr, &mi)) return FALSE;
791 miw.SizeOfStruct = mi.SizeOfStruct;
792 miw.BaseOfImage = mi.BaseOfImage;
793 miw.ImageSize = mi.ImageSize;
794 miw.TimeDateStamp = mi.TimeDateStamp;
795 miw.CheckSum = mi.CheckSum;
796 miw.NumSyms = mi.NumSyms;
797 miw.SymType = mi.SymType;
798 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
799 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
800 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
801 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
802 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
803 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
804 MultiByteToWideChar(CP_ACP, 0, mi.LoadedPdbName, -1,
805 miw.LoadedPdbName, sizeof(miw.LoadedPdbName) / sizeof(WCHAR));
807 miw.CVSig = mi.CVSig;
808 MultiByteToWideChar(CP_ACP, 0, mi.CVData, -1,
809 miw.CVData, sizeof(miw.CVData) / sizeof(WCHAR));
810 miw.PdbSig = mi.PdbSig;
811 miw.PdbSig70 = mi.PdbSig70;
812 miw.PdbAge = mi.PdbAge;
813 miw.PdbUnmatched = mi.PdbUnmatched;
814 miw.DbgUnmatched = mi.DbgUnmatched;
815 miw.LineNumbers = mi.LineNumbers;
816 miw.GlobalSymbols = mi.GlobalSymbols;
817 miw.TypeInfo = mi.TypeInfo;
818 miw.SourceIndexed = mi.SourceIndexed;
819 miw.Publics = mi.Publics;
821 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
823 return TRUE;
826 /***********************************************************************
827 * SymGetModuleBase (DBGHELP.@)
829 DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
831 struct process* pcs = process_find_by_handle(hProcess);
832 struct module* module;
834 if (!pcs) return 0;
835 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
836 if (!module) return 0;
837 return module->module.BaseOfImage;
840 /***********************************************************************
841 * SymGetModuleBase64 (DBGHELP.@)
843 DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
845 if (!validate_addr64(dwAddr)) return 0;
846 return SymGetModuleBase(hProcess, (DWORD)dwAddr);
849 /******************************************************************
850 * module_reset_debug_info
851 * Removes any debug information linked to a given module.
853 void module_reset_debug_info(struct module* module)
855 module->sortlist_valid = TRUE;
856 module->addr_sorttab = NULL;
857 hash_table_destroy(&module->ht_symbols);
858 module->ht_symbols.num_buckets = 0;
859 module->ht_symbols.buckets = NULL;
860 hash_table_destroy(&module->ht_types);
861 module->ht_types.num_buckets = 0;
862 module->ht_types.buckets = NULL;
863 module->vtypes.num_elts = 0;
864 hash_table_destroy(&module->ht_symbols);
865 module->sources_used = module->sources_alloc = 0;
866 module->sources = NULL;