rpcrt4/tests: Replace || by |.
[wine/multimedia.git] / dlls / dbghelp / module.c
blobec3c70c667d850e4405498621034615e13acacc8
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 = FALSE;
140 module->module.Publics = FALSE;
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, ImageName, ModuleName, (DWORD)BaseOfDll, DllSize);
479 /***********************************************************************
480 * SymLoadModuleExW (DBGHELP.@)
482 DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
483 PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD DllSize,
484 PMODLOAD_DATA Data, DWORD Flags)
486 LPSTR ImageName, ModuleName;
487 unsigned len;
488 BOOL ret;
490 if (wImageName)
492 len = WideCharToMultiByte(CP_ACP,0, wImageName, -1, NULL, 0, NULL, NULL);
493 ImageName = HeapAlloc(GetProcessHeap(), 0, len);
494 WideCharToMultiByte(CP_ACP,0, wImageName, -1, ImageName, len, NULL, NULL);
496 else ImageName = NULL;
497 if (wModuleName)
499 len = WideCharToMultiByte(CP_ACP,0, wModuleName, -1, NULL, 0, NULL, NULL);
500 ModuleName = HeapAlloc(GetProcessHeap(), 0, len);
501 WideCharToMultiByte(CP_ACP,0, wModuleName, -1, ModuleName, len, NULL, NULL);
503 else ModuleName = NULL;
505 ret = SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName,
506 BaseOfDll, DllSize, Data, Flags);
507 HeapFree(GetProcessHeap(), 0, ImageName);
508 HeapFree(GetProcessHeap(), 0, ModuleName);
509 return ret;
512 /***********************************************************************
513 * SymLoadModule64 (DBGHELP.@)
515 DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
516 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
518 if (!validate_addr64(BaseOfDll)) return FALSE;
519 return SymLoadModule(hProcess, hFile, ImageName, ModuleName, (DWORD)BaseOfDll, SizeOfDll);
522 /******************************************************************
523 * module_remove
526 BOOL module_remove(struct process* pcs, struct module* module)
528 struct module** p;
530 TRACE("%s (%p)\n", module->module.ModuleName, module);
531 hash_table_destroy(&module->ht_symbols);
532 hash_table_destroy(&module->ht_types);
533 HeapFree(GetProcessHeap(), 0, (char*)module->sources);
534 HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
535 pool_destroy(&module->pool);
536 /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
537 * so do we
539 for (p = &pcs->lmodules; *p; p = &(*p)->next)
541 if (*p == module)
543 *p = module->next;
544 HeapFree(GetProcessHeap(), 0, module);
545 return TRUE;
548 FIXME("This shouldn't happen\n");
549 return FALSE;
552 /******************************************************************
553 * SymUnloadModule (DBGHELP.@)
556 BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
558 struct process* pcs;
559 struct module* module;
561 pcs = process_find_by_handle(hProcess);
562 if (!pcs) return FALSE;
563 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
564 if (!module) return FALSE;
565 return module_remove(pcs, module);
568 /******************************************************************
569 * SymUnloadModule64 (DBGHELP.@)
572 BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
574 struct process* pcs;
575 struct module* module;
577 pcs = process_find_by_handle(hProcess);
578 if (!pcs) return FALSE;
579 if (!validate_addr64(BaseOfDll)) return FALSE;
580 module = module_find_by_addr(pcs, (DWORD)BaseOfDll, DMT_UNKNOWN);
581 if (!module) return FALSE;
582 return module_remove(pcs, module);
585 /******************************************************************
586 * SymEnumerateModules (DBGHELP.@)
589 BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
590 PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
591 PVOID UserContext)
593 struct process* pcs = process_find_by_handle(hProcess);
594 struct module* module;
596 if (!pcs) return FALSE;
598 for (module = pcs->lmodules; module; module = module->next)
600 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
601 continue;
602 if (!EnumModulesCallback(module->module.ModuleName,
603 module->module.BaseOfImage, UserContext))
604 break;
606 return TRUE;
609 /******************************************************************
610 * SymEnumerateModules64 (DBGHELP.@)
613 BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
614 PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
615 PVOID UserContext)
617 struct process* pcs = process_find_by_handle(hProcess);
618 struct module* module;
620 if (!pcs) return FALSE;
622 for (module = pcs->lmodules; module; module = module->next)
624 if (!(dbghelp_options & SYMOPT_WINE_WITH_ELF_MODULES) && module->type == DMT_ELF)
625 continue;
626 if (!EnumModulesCallback(module->module.ModuleName,
627 module->module.BaseOfImage, UserContext))
628 break;
630 return TRUE;
633 /******************************************************************
634 * EnumerateLoadedModules (DBGHELP.@)
637 BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
638 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
639 PVOID UserContext)
641 HMODULE* hMods;
642 char base[256], mod[256];
643 DWORD i, sz;
644 MODULEINFO mi;
646 hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
647 if (!hMods) return FALSE;
649 if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
651 /* hProcess should also be a valid process handle !! */
652 FIXME("If this happens, bump the number in mod\n");
653 HeapFree(GetProcessHeap(), 0, hMods);
654 return FALSE;
656 sz /= sizeof(HMODULE);
657 for (i = 0; i < sz; i++)
659 if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
660 !GetModuleBaseNameA(hProcess, hMods[i], base, sizeof(base)))
661 continue;
662 module_fill_module(base, mod, sizeof(mod));
663 EnumLoadedModulesCallback(mod, (DWORD)mi.lpBaseOfDll, mi.SizeOfImage,
664 UserContext);
666 HeapFree(GetProcessHeap(), 0, hMods);
668 return sz != 0 && i == sz;
671 /******************************************************************
672 * SymGetModuleInfo (DBGHELP.@)
675 BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
676 PIMAGEHLP_MODULE ModuleInfo)
678 struct process* pcs = process_find_by_handle(hProcess);
679 struct module* module;
680 IMAGEHLP_MODULE mod;
682 if (!pcs) return FALSE;
683 if (ModuleInfo->SizeOfStruct < sizeof(*ModuleInfo)) return FALSE;
684 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
685 if (!module) return FALSE;
687 mod.SizeOfStruct = ModuleInfo->SizeOfStruct;
688 mod.BaseOfImage = module->module.BaseOfImage;
689 mod.ImageSize = module->module.ImageSize;
690 mod.TimeDateStamp = module->module.TimeDateStamp;
691 mod.CheckSum = module->module.CheckSum;
692 mod.NumSyms = module->module.NumSyms;
693 mod.SymType = module->module.SymType;
694 strcpy(mod.ModuleName, module->module.ModuleName);
695 strcpy(mod.ImageName, module->module.ImageName);
696 strcpy(mod.LoadedImageName, module->module.LoadedImageName);
698 if (module->module.SymType == SymNone)
700 module = module_get_container(pcs, module);
701 if (module && module->module.SymType != SymNone)
703 mod.SymType = module->module.SymType;
704 mod.NumSyms = module->module.NumSyms;
707 memcpy(ModuleInfo, &mod, ModuleInfo->SizeOfStruct);
708 return TRUE;
711 /******************************************************************
712 * SymGetModuleInfoW (DBGHELP.@)
715 BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
716 PIMAGEHLP_MODULEW ModuleInfo)
718 IMAGEHLP_MODULE mi;
719 IMAGEHLP_MODULEW miw;
721 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
723 mi.SizeOfStruct = sizeof(mi);
724 if (!SymGetModuleInfo(hProcess, dwAddr, &mi)) return FALSE;
726 miw.SizeOfStruct = mi.SizeOfStruct;
727 miw.BaseOfImage = mi.BaseOfImage;
728 miw.ImageSize = mi.ImageSize;
729 miw.TimeDateStamp = mi.TimeDateStamp;
730 miw.CheckSum = mi.CheckSum;
731 miw.NumSyms = mi.NumSyms;
732 miw.SymType = mi.SymType;
733 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
734 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
735 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
736 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
737 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
738 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
739 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
741 return TRUE;
744 /******************************************************************
745 * SymGetModuleInfo64 (DBGHELP.@)
748 BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
749 PIMAGEHLP_MODULE64 ModuleInfo)
751 struct process* pcs = process_find_by_handle(hProcess);
752 struct module* module;
754 TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
756 if (!pcs) return FALSE;
757 if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
758 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
759 if (!module) return FALSE;
761 memcpy(ModuleInfo, &module->module, ModuleInfo->SizeOfStruct);
763 if (module->module.SymType == SymNone)
765 module = module_get_container(pcs, module);
766 if (module && module->module.SymType != SymNone)
768 ModuleInfo->SymType = module->module.SymType;
769 ModuleInfo->NumSyms = module->module.NumSyms;
772 return TRUE;
775 /******************************************************************
776 * SymGetModuleInfoW64 (DBGHELP.@)
779 BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
780 PIMAGEHLP_MODULEW64 ModuleInfo)
782 IMAGEHLP_MODULE64 mi;
783 IMAGEHLP_MODULEW64 miw;
785 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
787 mi.SizeOfStruct = sizeof(mi);
788 if (!SymGetModuleInfo64(hProcess, dwAddr, &mi)) return FALSE;
790 miw.SizeOfStruct = mi.SizeOfStruct;
791 miw.BaseOfImage = mi.BaseOfImage;
792 miw.ImageSize = mi.ImageSize;
793 miw.TimeDateStamp = mi.TimeDateStamp;
794 miw.CheckSum = mi.CheckSum;
795 miw.NumSyms = mi.NumSyms;
796 miw.SymType = mi.SymType;
797 MultiByteToWideChar(CP_ACP, 0, mi.ModuleName, -1,
798 miw.ModuleName, sizeof(miw.ModuleName) / sizeof(WCHAR));
799 MultiByteToWideChar(CP_ACP, 0, mi.ImageName, -1,
800 miw.ImageName, sizeof(miw.ImageName) / sizeof(WCHAR));
801 MultiByteToWideChar(CP_ACP, 0, mi.LoadedImageName, -1,
802 miw.LoadedImageName, sizeof(miw.LoadedImageName) / sizeof(WCHAR));
803 MultiByteToWideChar(CP_ACP, 0, mi.LoadedPdbName, -1,
804 miw.LoadedPdbName, sizeof(miw.LoadedPdbName) / sizeof(WCHAR));
806 miw.CVSig = mi.CVSig;
807 MultiByteToWideChar(CP_ACP, 0, mi.CVData, -1,
808 miw.CVData, sizeof(miw.CVData) / sizeof(WCHAR));
809 miw.PdbSig = mi.PdbSig;
810 miw.PdbSig70 = mi.PdbSig70;
811 miw.PdbAge = mi.PdbAge;
812 miw.PdbUnmatched = mi.PdbUnmatched;
813 miw.DbgUnmatched = mi.DbgUnmatched;
814 miw.LineNumbers = mi.LineNumbers;
815 miw.GlobalSymbols = mi.GlobalSymbols;
816 miw.TypeInfo = mi.TypeInfo;
817 miw.SourceIndexed = mi.SourceIndexed;
818 miw.Publics = mi.Publics;
820 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
822 return TRUE;
825 /***********************************************************************
826 * SymGetModuleBase (DBGHELP.@)
828 DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
830 struct process* pcs = process_find_by_handle(hProcess);
831 struct module* module;
833 if (!pcs) return 0;
834 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
835 if (!module) return 0;
836 return module->module.BaseOfImage;
839 /***********************************************************************
840 * SymGetModuleBase64 (DBGHELP.@)
842 DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
844 if (!validate_addr64(dwAddr)) return 0;
845 return SymGetModuleBase(hProcess, (DWORD)dwAddr);
848 /******************************************************************
849 * module_reset_debug_info
850 * Removes any debug information linked to a given module.
852 void module_reset_debug_info(struct module* module)
854 module->sortlist_valid = TRUE;
855 module->addr_sorttab = NULL;
856 hash_table_destroy(&module->ht_symbols);
857 module->ht_symbols.num_buckets = 0;
858 module->ht_symbols.buckets = NULL;
859 hash_table_destroy(&module->ht_types);
860 module->ht_types.num_buckets = 0;
861 module->ht_types.buckets = NULL;
862 module->vtypes.num_elts = 0;
863 hash_table_destroy(&module->ht_symbols);
864 module->sources_used = module->sources_alloc = 0;
865 module->sources = NULL;