winex11.drv: Support multiple adapter display settings in registry.
[wine.git] / dlls / dbghelp / module.c
blob23e673901851705f77efb3e04729d401b3c10e8a
1 /*
2 * File module.c - module handling for the wine debugger
4 * Copyright (C) 1993, Eric Youngdale.
5 * 2000-2007, 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 <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <assert.h>
27 #include "dbghelp_private.h"
28 #include "image_private.h"
29 #include "psapi.h"
30 #include "winternl.h"
31 #include "wine/debug.h"
32 #include "wine/heap.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
36 #define NOTE_GNU_BUILD_ID 3
38 const WCHAR S_ElfW[] = {'<','e','l','f','>','\0'};
39 const WCHAR S_WineLoaderW[] = {'<','w','i','n','e','-','l','o','a','d','e','r','>','\0'};
40 static const WCHAR S_DotSoW[] = {'.','s','o','\0'};
41 const WCHAR S_SlashW[] = {'/','\0'};
43 static const WCHAR S_AcmW[] = {'.','a','c','m','\0'};
44 static const WCHAR S_DllW[] = {'.','d','l','l','\0'};
45 static const WCHAR S_DrvW[] = {'.','d','r','v','\0'};
46 static const WCHAR S_ExeW[] = {'.','e','x','e','\0'};
47 static const WCHAR S_OcxW[] = {'.','o','c','x','\0'};
48 static const WCHAR S_VxdW[] = {'.','v','x','d','\0'};
49 static const WCHAR * const ext[] = {S_AcmW, S_DllW, S_DrvW, S_ExeW, S_OcxW, S_VxdW, NULL};
51 static int match_ext(const WCHAR* ptr, size_t len)
53 const WCHAR* const *e;
54 size_t l;
56 for (e = ext; *e; e++)
58 l = lstrlenW(*e);
59 if (l >= len) return 0;
60 if (wcsnicmp(&ptr[len - l], *e, l)) continue;
61 return l;
63 return 0;
66 static const WCHAR* get_filename(const WCHAR* name, const WCHAR* endptr)
68 const WCHAR* ptr;
70 if (!endptr) endptr = name + lstrlenW(name);
71 for (ptr = endptr - 1; ptr >= name; ptr--)
73 if (*ptr == '/' || *ptr == '\\') break;
75 return ++ptr;
78 static BOOL is_wine_loader(const WCHAR *module)
80 static const WCHAR wineW[] = {'w','i','n','e',0};
81 static const WCHAR suffixW[] = {'6','4',0};
82 const WCHAR *filename = get_filename(module, NULL);
83 const char *ptr;
84 BOOL ret = FALSE;
85 WCHAR *buffer;
86 DWORD len;
88 if ((ptr = getenv("WINELOADER")))
90 ptr = file_nameA(ptr);
91 len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 );
92 buffer = heap_alloc( len * sizeof(WCHAR) );
93 MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len );
95 else
97 buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) );
98 lstrcpyW( buffer, wineW );
101 if (!wcscmp( filename, buffer ))
102 ret = TRUE;
104 lstrcatW( buffer, suffixW );
105 if (!wcscmp( filename, buffer ))
106 ret = TRUE;
108 heap_free( buffer );
109 return ret;
112 static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size)
114 const WCHAR *ptr, *endptr;
115 size_t len, l;
117 ptr = get_filename(in, endptr = in + lstrlenW(in));
118 len = min(endptr - ptr, size - 1);
119 memcpy(out, ptr, len * sizeof(WCHAR));
120 out[len] = '\0';
121 if (len > 4 && (l = match_ext(out, len)))
122 out[len - l] = '\0';
123 else if (is_wine_loader(out))
124 lstrcpynW(out, S_WineLoaderW, size);
125 else
127 if (len > 3 && !wcsicmp(&out[len - 3], S_DotSoW) &&
128 (l = match_ext(out, len - 3)))
129 lstrcpyW(&out[len - l - 3], S_ElfW);
131 while ((*out = towlower(*out))) out++;
134 void module_set_module(struct module* module, const WCHAR* name)
136 module_fill_module(name, module->module.ModuleName, ARRAY_SIZE(module->module.ModuleName));
137 module_fill_module(name, module->modulename, ARRAY_SIZE(module->modulename));
140 /* Returned string must be freed by caller */
141 WCHAR *get_wine_loader_name(struct process *pcs)
143 static const WCHAR wineW[] = {'w','i','n','e',0};
144 static const WCHAR suffixW[] = {'6','4',0};
145 WCHAR *buffer, *p;
146 const char *env;
148 /* All binaries are loaded with WINELOADER (if run from tree) or by the
149 * main executable
151 if ((env = getenv("WINELOADER")))
153 DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, env, -1, NULL, 0 );
154 buffer = heap_alloc( len * sizeof(WCHAR) );
155 MultiByteToWideChar( CP_UNIXCP, 0, env, -1, buffer, len );
157 else
159 buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) );
160 lstrcpyW( buffer, wineW );
163 p = buffer + lstrlenW( buffer ) - lstrlenW( suffixW );
164 if (p > buffer && !wcscmp( p, suffixW ))
165 *p = 0;
167 if (pcs->is_64bit)
168 lstrcatW(buffer, suffixW);
170 TRACE( "returning %s\n", debugstr_w(buffer) );
171 return buffer;
174 static const char* get_module_type(enum module_type type, BOOL virtual)
176 switch (type)
178 case DMT_ELF: return virtual ? "Virtual ELF" : "ELF";
179 case DMT_PE: return virtual ? "Virtual PE" : "PE";
180 case DMT_MACHO: return virtual ? "Virtual Mach-O" : "Mach-O";
181 default: return "---";
185 /***********************************************************************
186 * Creates and links a new module to a process
188 struct module* module_new(struct process* pcs, const WCHAR* name,
189 enum module_type type, BOOL virtual,
190 DWORD64 mod_addr, DWORD64 size,
191 ULONG_PTR stamp, ULONG_PTR checksum)
193 struct module* module;
194 unsigned i;
196 assert(type == DMT_ELF || type == DMT_PE || type == DMT_MACHO);
197 if (!(module = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*module))))
198 return NULL;
200 module->next = pcs->lmodules;
201 pcs->lmodules = module;
203 TRACE("=> %s %s-%s %s\n",
204 get_module_type(type, virtual),
205 wine_dbgstr_longlong(mod_addr), wine_dbgstr_longlong(mod_addr + size),
206 debugstr_w(name));
208 pool_init(&module->pool, 65536);
210 module->process = pcs;
211 module->module.SizeOfStruct = sizeof(module->module);
212 module->module.BaseOfImage = mod_addr;
213 module->module.ImageSize = size;
214 module_set_module(module, name);
215 module->module.ImageName[0] = '\0';
216 lstrcpynW(module->module.LoadedImageName, name, ARRAY_SIZE(module->module.LoadedImageName));
217 module->module.SymType = SymNone;
218 module->module.NumSyms = 0;
219 module->module.TimeDateStamp = stamp;
220 module->module.CheckSum = checksum;
222 memset(module->module.LoadedPdbName, 0, sizeof(module->module.LoadedPdbName));
223 module->module.CVSig = 0;
224 memset(module->module.CVData, 0, sizeof(module->module.CVData));
225 module->module.PdbSig = 0;
226 memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
227 module->module.PdbAge = 0;
228 module->module.PdbUnmatched = FALSE;
229 module->module.DbgUnmatched = FALSE;
230 module->module.LineNumbers = FALSE;
231 module->module.GlobalSymbols = FALSE;
232 module->module.TypeInfo = FALSE;
233 module->module.SourceIndexed = FALSE;
234 module->module.Publics = FALSE;
236 module->reloc_delta = 0;
237 module->type = type;
238 module->is_virtual = virtual;
239 for (i = 0; i < DFI_LAST; i++) module->format_info[i] = NULL;
240 module->sortlist_valid = FALSE;
241 module->sorttab_size = 0;
242 module->addr_sorttab = NULL;
243 module->num_sorttab = 0;
244 module->num_symbols = 0;
246 vector_init(&module->vsymt, sizeof(struct symt*), 128);
247 /* FIXME: this seems a bit too high (on a per module basis)
248 * need some statistics about this
250 hash_table_init(&module->pool, &module->ht_symbols, 4096);
251 hash_table_init(&module->pool, &module->ht_types, 4096);
252 vector_init(&module->vtypes, sizeof(struct symt*), 32);
254 module->sources_used = 0;
255 module->sources_alloc = 0;
256 module->sources = 0;
257 wine_rb_init(&module->sources_offsets_tree, source_rb_compare);
259 return module;
262 /***********************************************************************
263 * module_find_by_nameW
266 struct module* module_find_by_nameW(const struct process* pcs, const WCHAR* name)
268 struct module* module;
270 for (module = pcs->lmodules; module; module = module->next)
272 if (!wcsicmp(name, module->module.ModuleName)) return module;
274 SetLastError(ERROR_INVALID_NAME);
275 return NULL;
278 struct module* module_find_by_nameA(const struct process* pcs, const char* name)
280 WCHAR wname[MAX_PATH];
282 MultiByteToWideChar(CP_ACP, 0, name, -1, wname, ARRAY_SIZE(wname));
283 return module_find_by_nameW(pcs, wname);
286 /***********************************************************************
287 * module_is_already_loaded
290 struct module* module_is_already_loaded(const struct process* pcs, const WCHAR* name)
292 struct module* module;
293 const WCHAR* filename;
295 /* first compare the loaded image name... */
296 for (module = pcs->lmodules; module; module = module->next)
298 if (!wcsicmp(name, module->module.LoadedImageName))
299 return module;
301 /* then compare the standard filenames (without the path) ... */
302 filename = get_filename(name, NULL);
303 for (module = pcs->lmodules; module; module = module->next)
305 if (!wcsicmp(filename, get_filename(module->module.LoadedImageName, NULL)))
306 return module;
308 SetLastError(ERROR_INVALID_NAME);
309 return NULL;
312 /***********************************************************************
313 * module_get_container
316 static struct module* module_get_container(const struct process* pcs,
317 const struct module* inner)
319 struct module* module;
321 for (module = pcs->lmodules; module; module = module->next)
323 if (module != inner &&
324 module->module.BaseOfImage <= inner->module.BaseOfImage &&
325 module->module.BaseOfImage + module->module.ImageSize >=
326 inner->module.BaseOfImage + inner->module.ImageSize)
327 return module;
329 return NULL;
332 /***********************************************************************
333 * module_get_containee
336 struct module* module_get_containee(const struct process* pcs, const struct module* outer)
338 struct module* module;
340 for (module = pcs->lmodules; module; module = module->next)
342 if (module != outer &&
343 outer->module.BaseOfImage <= module->module.BaseOfImage &&
344 outer->module.BaseOfImage + outer->module.ImageSize >=
345 module->module.BaseOfImage + module->module.ImageSize)
346 return module;
348 return NULL;
351 /******************************************************************
352 * module_get_debug
354 * get the debug information from a module:
355 * - if the module's type is deferred, then force loading of debug info (and return
356 * the module itself)
357 * - if the module has no debug info and has an ELF container, then return the ELF
358 * container (and also force the ELF container's debug info loading if deferred)
359 * - otherwise return the module itself if it has some debug info
361 BOOL module_get_debug(struct module_pair* pair)
363 IMAGEHLP_DEFERRED_SYMBOL_LOADW64 idslW64;
365 if (!pair->requested) return FALSE;
366 /* for a PE builtin, always get info from container */
367 if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
368 pair->effective = pair->requested;
369 /* if deferred, force loading */
370 if (pair->effective->module.SymType == SymDeferred)
372 BOOL ret;
374 if (pair->effective->is_virtual) ret = FALSE;
375 else if (pair->effective->type == DMT_PE)
377 idslW64.SizeOfStruct = sizeof(idslW64);
378 idslW64.BaseOfImage = pair->effective->module.BaseOfImage;
379 idslW64.CheckSum = pair->effective->module.CheckSum;
380 idslW64.TimeDateStamp = pair->effective->module.TimeDateStamp;
381 memcpy(idslW64.FileName, pair->effective->module.ImageName,
382 sizeof(pair->effective->module.ImageName));
383 idslW64.Reparse = FALSE;
384 idslW64.hFile = INVALID_HANDLE_VALUE;
386 pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idslW64);
387 ret = pe_load_debug_info(pair->pcs, pair->effective);
388 pcs_callback(pair->pcs,
389 ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
390 &idslW64);
392 else ret = pair->pcs->loader->load_debug_info(pair->pcs, pair->effective);
394 if (!ret) pair->effective->module.SymType = SymNone;
395 assert(pair->effective->module.SymType != SymDeferred);
396 pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
398 return pair->effective->module.SymType != SymNone;
401 /***********************************************************************
402 * module_find_by_addr
404 * either the addr where module is loaded, or any address inside the
405 * module
407 struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr,
408 enum module_type type)
410 struct module* module;
412 if (type == DMT_UNKNOWN)
414 if ((module = module_find_by_addr(pcs, addr, DMT_PE)) ||
415 (module = module_find_by_addr(pcs, addr, DMT_ELF)) ||
416 (module = module_find_by_addr(pcs, addr, DMT_MACHO)))
417 return module;
419 else
421 for (module = pcs->lmodules; module; module = module->next)
423 if (type == module->type && addr >= module->module.BaseOfImage &&
424 addr < module->module.BaseOfImage + module->module.ImageSize)
425 return module;
428 SetLastError(ERROR_MOD_NOT_FOUND);
429 return module;
432 /******************************************************************
433 * module_is_container_loaded
435 * checks whether the native container, for a (supposed) PE builtin is
436 * already loaded
438 static BOOL module_is_container_loaded(const struct process* pcs,
439 const WCHAR* ImageName, DWORD64 base)
441 size_t len;
442 struct module* module;
443 PCWSTR filename, modname;
445 if (!base) return FALSE;
446 filename = get_filename(ImageName, NULL);
447 len = lstrlenW(filename);
449 for (module = pcs->lmodules; module; module = module->next)
451 if ((module->type == DMT_ELF || module->type == DMT_MACHO) &&
452 base >= module->module.BaseOfImage &&
453 base < module->module.BaseOfImage + module->module.ImageSize)
455 modname = get_filename(module->module.LoadedImageName, NULL);
456 if (!wcsnicmp(modname, filename, len) &&
457 !memcmp(modname + len, S_DotSoW, 3 * sizeof(WCHAR)))
459 return TRUE;
463 /* likely a native PE module */
464 WARN("Couldn't find container for %s\n", debugstr_w(ImageName));
465 return FALSE;
468 static BOOL image_check_debug_link(const WCHAR* file, struct image_file_map* fmap, DWORD link_crc)
470 DWORD read_bytes;
471 HANDLE handle;
472 WCHAR *path;
473 WORD magic;
474 BOOL ret;
476 path = get_dos_file_name(file);
477 handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
478 heap_free(path);
479 if (handle == INVALID_HANDLE_VALUE) return FALSE;
481 if (link_crc)
483 DWORD crc = calc_crc32(handle);
484 if (crc != link_crc)
486 WARN("Bad CRC for file %s (got %08x while expecting %08x)\n", debugstr_w(file), crc, link_crc);
487 CloseHandle(handle);
488 return FALSE;
492 SetFilePointer(handle, 0, 0, FILE_BEGIN);
493 if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE)
494 ret = pe_map_file(handle, fmap, DMT_PE);
495 else
496 ret = elf_map_handle(handle, fmap);
497 CloseHandle(handle);
498 return ret;
501 /******************************************************************
502 * image_locate_debug_link
504 * Locate a filename from a .gnu_debuglink section, using the same
505 * strategy as gdb:
506 * "If the full name of the directory containing the executable is
507 * execdir, and the executable has a debug link that specifies the
508 * name debugfile, then GDB will automatically search for the
509 * debugging information file in three places:
510 * - the directory containing the executable file (that is, it
511 * will look for a file named `execdir/debugfile',
512 * - a subdirectory of that directory named `.debug' (that is, the
513 * file `execdir/.debug/debugfile', and
514 * - a subdirectory of the global debug file directory that includes
515 * the executable's full path, and the name from the link (that is,
516 * the file `globaldebugdir/execdir/debugfile', where globaldebugdir
517 * is the global debug file directory, and execdir has been turned
518 * into a relative path)." (from GDB manual)
520 static BOOL image_locate_debug_link(const struct module* module, struct image_file_map* fmap, const char* filename, DWORD crc)
522 static const WCHAR globalDebugDirW[] = {'/','u','s','r','/','l','i','b','/','d','e','b','u','g','/'};
523 static const WCHAR dotDebugW[] = {'.','d','e','b','u','g','/'};
524 const size_t globalDebugDirLen = ARRAY_SIZE(globalDebugDirW);
525 size_t filename_len, path_len;
526 WCHAR* p = NULL;
527 WCHAR* slash;
528 WCHAR* slash2;
529 struct image_file_map* fmap_link = NULL;
531 fmap_link = HeapAlloc(GetProcessHeap(), 0, sizeof(*fmap_link));
532 if (!fmap_link) return FALSE;
534 filename_len = MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, NULL, 0);
535 path_len = lstrlenW(module->module.LoadedImageName);
536 if (module->real_path) path_len = max(path_len, lstrlenW(module->real_path));
537 p = HeapAlloc(GetProcessHeap(), 0,
538 (globalDebugDirLen + path_len + 6 + 1 + filename_len + 1) * sizeof(WCHAR));
539 if (!p) goto found;
541 /* we prebuild the string with "execdir" */
542 lstrcpyW(p, module->module.LoadedImageName);
543 slash = p;
544 if ((slash2 = wcsrchr(slash, '/'))) slash = slash2 + 1;
545 if ((slash2 = wcsrchr(slash, '\\'))) slash = slash2 + 1;
547 /* testing execdir/filename */
548 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
549 if (image_check_debug_link(p, fmap_link, crc)) goto found;
551 /* testing execdir/.debug/filename */
552 memcpy(slash, dotDebugW, sizeof(dotDebugW));
553 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash + ARRAY_SIZE(dotDebugW), filename_len);
554 if (image_check_debug_link(p, fmap_link, crc)) goto found;
556 if (module->real_path)
558 lstrcpyW(p, module->real_path);
559 slash = p;
560 if ((slash2 = wcsrchr(slash, '/'))) slash = slash2 + 1;
561 if ((slash2 = wcsrchr(slash, '\\'))) slash = slash2 + 1;
562 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
563 if (image_check_debug_link(p, fmap_link, crc)) goto found;
566 /* testing globaldebugdir/execdir/filename */
567 memmove(p + globalDebugDirLen, p, (slash - p) * sizeof(WCHAR));
568 memcpy(p, globalDebugDirW, globalDebugDirLen * sizeof(WCHAR));
569 slash += globalDebugDirLen;
570 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
571 if (image_check_debug_link(p, fmap_link, crc)) goto found;
573 /* finally testing filename */
574 if (image_check_debug_link(slash, fmap_link, crc)) goto found;
577 WARN("Couldn't locate or map %s\n", filename);
578 HeapFree(GetProcessHeap(), 0, p);
579 HeapFree(GetProcessHeap(), 0, fmap_link);
580 return FALSE;
582 found:
583 TRACE("Located debug information file %s at %s\n", filename, debugstr_w(p));
584 HeapFree(GetProcessHeap(), 0, p);
585 fmap->alternate = fmap_link;
586 return TRUE;
589 /******************************************************************
590 * image_locate_build_id_target
592 * Try to find the .so file containing the debug info out of the build-id note information
594 static BOOL image_locate_build_id_target(struct image_file_map* fmap, const BYTE* id, unsigned idlen)
596 static const WCHAR globalDebugDirW[] = {'/','u','s','r','/','l','i','b','/','d','e','b','u','g','/'};
597 static const WCHAR buildidW[] = {'.','b','u','i','l','d','-','i','d','/'};
598 static const WCHAR dotDebug0W[] = {'.','d','e','b','u','g',0};
599 struct image_file_map* fmap_link = NULL;
600 WCHAR* p;
601 WCHAR* z;
602 const BYTE* idend = id + idlen;
604 fmap_link = HeapAlloc(GetProcessHeap(), 0, sizeof(*fmap_link));
605 if (!fmap_link) return FALSE;
607 p = HeapAlloc(GetProcessHeap(), 0,
608 sizeof(globalDebugDirW) + sizeof(buildidW) +
609 (idlen * 2 + 1) * sizeof(WCHAR) + sizeof(dotDebug0W));
610 z = p;
611 memcpy(z, globalDebugDirW, sizeof(globalDebugDirW));
612 z += ARRAY_SIZE(globalDebugDirW);
613 memcpy(z, buildidW, sizeof(buildidW));
614 z += ARRAY_SIZE(buildidW);
616 if (id < idend)
618 *z++ = "0123456789abcdef"[*id >> 4 ];
619 *z++ = "0123456789abcdef"[*id & 0x0F];
620 id++;
622 if (id < idend)
623 *z++ = '/';
624 while (id < idend)
626 *z++ = "0123456789abcdef"[*id >> 4 ];
627 *z++ = "0123456789abcdef"[*id & 0x0F];
628 id++;
630 memcpy(z, dotDebug0W, sizeof(dotDebug0W));
631 TRACE("checking %s\n", wine_dbgstr_w(p));
633 if (image_check_debug_link(p, fmap_link, 0))
635 struct image_section_map buildid_sect;
636 if (image_find_section(fmap_link, ".note.gnu.build-id", &buildid_sect))
638 const UINT32* note;
640 note = (const UINT32*)image_map_section(&buildid_sect);
641 if (note != IMAGE_NO_MAP)
643 /* the usual ELF note structure: name-size desc-size type <name> <desc> */
644 if (note[2] == NOTE_GNU_BUILD_ID)
646 if (note[1] == idlen &&
647 !memcmp(note + 3 + ((note[0] + 3) >> 2), idend - idlen, idlen))
649 TRACE("Located debug information file at %s\n", debugstr_w(p));
650 HeapFree(GetProcessHeap(), 0, p);
651 fmap->alternate = fmap_link;
652 return TRUE;
654 WARN("mismatch in buildid information for %s\n", wine_dbgstr_w(p));
657 image_unmap_section(&buildid_sect);
659 image_unmap_file(fmap_link);
662 TRACE("not found\n");
663 HeapFree(GetProcessHeap(), 0, p);
664 HeapFree(GetProcessHeap(), 0, fmap_link);
665 return FALSE;
668 /******************************************************************
669 * image_check_alternate
671 * Load alternate files for a given image file, looking at either .note.gnu_build-id
672 * or .gnu_debuglink sections.
674 BOOL image_check_alternate(struct image_file_map* fmap, const struct module* module)
676 BOOL ret = FALSE;
677 BOOL found = FALSE;
678 struct image_section_map buildid_sect, debuglink_sect;
680 /* if present, add the .gnu_debuglink file as an alternate to current one */
681 if (image_find_section(fmap, ".note.gnu.build-id", &buildid_sect))
683 const UINT32* note;
685 found = TRUE;
686 note = (const UINT32*)image_map_section(&buildid_sect);
687 if (note != IMAGE_NO_MAP)
689 /* the usual ELF note structure: name-size desc-size type <name> <desc> */
690 if (note[2] == NOTE_GNU_BUILD_ID)
692 ret = image_locate_build_id_target(fmap, (const BYTE*)(note + 3 + ((note[0] + 3) >> 2)), note[1]);
695 image_unmap_section(&buildid_sect);
697 /* if present, add the .gnu_debuglink file as an alternate to current one */
698 if (!ret && image_find_section(fmap, ".gnu_debuglink", &debuglink_sect))
700 const char* dbg_link;
702 found = TRUE;
703 dbg_link = (const char*)image_map_section(&debuglink_sect);
704 if (dbg_link != IMAGE_NO_MAP)
706 /* The content of a debug link section is:
707 * 1/ a NULL terminated string, containing the file name for the
708 * debug info
709 * 2/ padding on 4 byte boundary
710 * 3/ CRC of the linked file
712 DWORD crc = *(const DWORD*)(dbg_link + ((DWORD_PTR)(strlen(dbg_link) + 4) & ~3));
713 ret = image_locate_debug_link(module, fmap, dbg_link, crc);
714 if (!ret)
715 WARN("Couldn't load linked debug file for %s\n",
716 debugstr_w(module->module.ModuleName));
718 image_unmap_section(&debuglink_sect);
720 return found ? ret : TRUE;
723 /***********************************************************************
724 * SymLoadModule (DBGHELP.@)
726 DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
727 PCSTR ModuleName, DWORD BaseOfDll, DWORD SizeOfDll)
729 return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll,
730 SizeOfDll, NULL, 0);
733 /***********************************************************************
734 * SymLoadModuleEx (DBGHELP.@)
736 DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
737 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize,
738 PMODLOAD_DATA Data, DWORD Flags)
740 PWSTR wImageName, wModuleName;
741 unsigned len;
742 DWORD64 ret;
744 TRACE("(%p %p %s %s %s %08x %p %08x)\n",
745 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
746 wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags);
748 if (ImageName)
750 len = MultiByteToWideChar(CP_ACP, 0, ImageName, -1, NULL, 0);
751 wImageName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
752 MultiByteToWideChar(CP_ACP, 0, ImageName, -1, wImageName, len);
754 else wImageName = NULL;
755 if (ModuleName)
757 len = MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, NULL, 0);
758 wModuleName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
759 MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, wModuleName, len);
761 else wModuleName = NULL;
763 ret = SymLoadModuleExW(hProcess, hFile, wImageName, wModuleName,
764 BaseOfDll, DllSize, Data, Flags);
765 HeapFree(GetProcessHeap(), 0, wImageName);
766 HeapFree(GetProcessHeap(), 0, wModuleName);
767 return ret;
770 /***********************************************************************
771 * SymLoadModuleExW (DBGHELP.@)
773 DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
774 PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll,
775 PMODLOAD_DATA Data, DWORD Flags)
777 struct process* pcs;
778 struct module* module = NULL;
780 TRACE("(%p %p %s %s %s %08x %p %08x)\n",
781 hProcess, hFile, debugstr_w(wImageName), debugstr_w(wModuleName),
782 wine_dbgstr_longlong(BaseOfDll), SizeOfDll, Data, Flags);
784 if (Data)
785 FIXME("Unsupported load data parameter %p for %s\n",
786 Data, debugstr_w(wImageName));
787 if (!validate_addr64(BaseOfDll)) return FALSE;
789 if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
791 if (Flags & SLMFLAG_VIRTUAL)
793 if (!wImageName) return FALSE;
794 module = module_new(pcs, wImageName, DMT_PE, TRUE, BaseOfDll, SizeOfDll, 0, 0);
795 if (!module) return FALSE;
796 if (wModuleName) module_set_module(module, wModuleName);
797 module->module.SymType = SymVirtual;
799 return TRUE;
801 if (Flags & ~(SLMFLAG_VIRTUAL))
802 FIXME("Unsupported Flags %08x for %s\n", Flags, debugstr_w(wImageName));
804 pcs->loader->synchronize_module_list(pcs);
806 /* this is a Wine extension to the API just to redo the synchronisation */
807 if (!wImageName && !hFile) return 0;
809 /* check if the module is already loaded, or if it's a builtin PE module with
810 * an containing ELF module
812 if (wImageName)
814 module = module_is_already_loaded(pcs, wImageName);
815 if (!module && module_is_container_loaded(pcs, wImageName, BaseOfDll))
817 /* force the loading of DLL as builtin */
818 module = pe_load_builtin_module(pcs, wImageName, BaseOfDll, SizeOfDll);
821 if (!module)
823 /* otherwise, try a regular PE module */
824 if (!(module = pe_load_native_module(pcs, wImageName, hFile, BaseOfDll, SizeOfDll)) &&
825 wImageName)
827 /* and finally an ELF or Mach-O module */
828 module = pcs->loader->load_module(pcs, wImageName, BaseOfDll);
831 if (!module)
833 WARN("Couldn't locate %s\n", debugstr_w(wImageName));
834 return 0;
836 module->module.NumSyms = module->ht_symbols.num_elts;
837 /* by default module_new fills module.ModuleName from a derivation
838 * of LoadedImageName. Overwrite it, if we have better information
840 if (wModuleName)
841 module_set_module(module, wModuleName);
842 if (wImageName)
843 lstrcpynW(module->module.ImageName, wImageName, ARRAY_SIZE(module->module.ImageName));
845 return module->module.BaseOfImage;
848 /***********************************************************************
849 * SymLoadModule64 (DBGHELP.@)
851 DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
852 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
854 return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll,
855 NULL, 0);
858 /******************************************************************
859 * module_remove
862 BOOL module_remove(struct process* pcs, struct module* module)
864 struct module_format*modfmt;
865 struct module** p;
866 unsigned i;
868 TRACE("%s (%p)\n", debugstr_w(module->module.ModuleName), module);
870 for (i = 0; i < DFI_LAST; i++)
872 if ((modfmt = module->format_info[i]) && modfmt->remove)
873 modfmt->remove(pcs, module->format_info[i]);
875 hash_table_destroy(&module->ht_symbols);
876 hash_table_destroy(&module->ht_types);
877 HeapFree(GetProcessHeap(), 0, module->sources);
878 HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
879 HeapFree(GetProcessHeap(), 0, module->real_path);
880 pool_destroy(&module->pool);
881 /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
882 * so do we
884 for (p = &pcs->lmodules; *p; p = &(*p)->next)
886 if (*p == module)
888 *p = module->next;
889 HeapFree(GetProcessHeap(), 0, module);
890 return TRUE;
893 FIXME("This shouldn't happen\n");
894 return FALSE;
897 /******************************************************************
898 * SymUnloadModule (DBGHELP.@)
901 BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
903 struct process* pcs;
904 struct module* module;
906 pcs = process_find_by_handle(hProcess);
907 if (!pcs) return FALSE;
908 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
909 if (!module) return FALSE;
910 return module_remove(pcs, module);
913 /******************************************************************
914 * SymUnloadModule64 (DBGHELP.@)
917 BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
919 struct process* pcs;
920 struct module* module;
922 pcs = process_find_by_handle(hProcess);
923 if (!pcs) return FALSE;
924 if (!validate_addr64(BaseOfDll)) return FALSE;
925 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
926 if (!module) return FALSE;
927 return module_remove(pcs, module);
930 /******************************************************************
931 * SymEnumerateModules (DBGHELP.@)
934 struct enum_modW64_32
936 PSYM_ENUMMODULES_CALLBACK cb;
937 PVOID user;
938 char module[MAX_PATH];
941 static BOOL CALLBACK enum_modW64_32(PCWSTR name, DWORD64 base, PVOID user)
943 struct enum_modW64_32* x = user;
945 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
946 return x->cb(x->module, (DWORD)base, x->user);
949 BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
950 PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
951 PVOID UserContext)
953 struct enum_modW64_32 x;
955 x.cb = EnumModulesCallback;
956 x.user = UserContext;
958 return SymEnumerateModulesW64(hProcess, enum_modW64_32, &x);
961 /******************************************************************
962 * SymEnumerateModules64 (DBGHELP.@)
965 struct enum_modW64_64
967 PSYM_ENUMMODULES_CALLBACK64 cb;
968 PVOID user;
969 char module[MAX_PATH];
972 static BOOL CALLBACK enum_modW64_64(PCWSTR name, DWORD64 base, PVOID user)
974 struct enum_modW64_64* x = user;
976 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
977 return x->cb(x->module, base, x->user);
980 BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
981 PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
982 PVOID UserContext)
984 struct enum_modW64_64 x;
986 x.cb = EnumModulesCallback;
987 x.user = UserContext;
989 return SymEnumerateModulesW64(hProcess, enum_modW64_64, &x);
992 /******************************************************************
993 * SymEnumerateModulesW64 (DBGHELP.@)
996 BOOL WINAPI SymEnumerateModulesW64(HANDLE hProcess,
997 PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback,
998 PVOID UserContext)
1000 struct process* pcs = process_find_by_handle(hProcess);
1001 struct module* module;
1003 if (!pcs) return FALSE;
1005 for (module = pcs->lmodules; module; module = module->next)
1007 if (!dbghelp_opt_native &&
1008 (module->type == DMT_ELF || module->type == DMT_MACHO))
1009 continue;
1010 if (!EnumModulesCallback(module->modulename,
1011 module->module.BaseOfImage, UserContext))
1012 break;
1014 return TRUE;
1017 /******************************************************************
1018 * EnumerateLoadedModules64 (DBGHELP.@)
1021 struct enum_load_modW64_64
1023 PENUMLOADED_MODULES_CALLBACK64 cb;
1024 PVOID user;
1025 char module[MAX_PATH];
1028 static BOOL CALLBACK enum_load_modW64_64(PCWSTR name, DWORD64 base, ULONG size,
1029 PVOID user)
1031 struct enum_load_modW64_64* x = user;
1033 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
1034 return x->cb(x->module, base, size, x->user);
1037 BOOL WINAPI EnumerateLoadedModules64(HANDLE hProcess,
1038 PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,
1039 PVOID UserContext)
1041 struct enum_load_modW64_64 x;
1043 x.cb = EnumLoadedModulesCallback;
1044 x.user = UserContext;
1046 return EnumerateLoadedModulesW64(hProcess, enum_load_modW64_64, &x);
1049 /******************************************************************
1050 * EnumerateLoadedModules (DBGHELP.@)
1053 struct enum_load_modW64_32
1055 PENUMLOADED_MODULES_CALLBACK cb;
1056 PVOID user;
1057 char module[MAX_PATH];
1060 static BOOL CALLBACK enum_load_modW64_32(PCWSTR name, DWORD64 base, ULONG size,
1061 PVOID user)
1063 struct enum_load_modW64_32* x = user;
1064 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
1065 return x->cb(x->module, (DWORD)base, size, x->user);
1068 BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
1069 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
1070 PVOID UserContext)
1072 struct enum_load_modW64_32 x;
1074 x.cb = EnumLoadedModulesCallback;
1075 x.user = UserContext;
1077 return EnumerateLoadedModulesW64(hProcess, enum_load_modW64_32, &x);
1080 /******************************************************************
1081 * EnumerateLoadedModulesW64 (DBGHELP.@)
1084 BOOL WINAPI EnumerateLoadedModulesW64(HANDLE hProcess,
1085 PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback,
1086 PVOID UserContext)
1088 HMODULE* hMods;
1089 WCHAR baseW[256], modW[256];
1090 DWORD i, sz;
1091 MODULEINFO mi;
1093 hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
1094 if (!hMods) return FALSE;
1096 if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
1098 /* hProcess should also be a valid process handle !! */
1099 FIXME("If this happens, bump the number in mod\n");
1100 HeapFree(GetProcessHeap(), 0, hMods);
1101 return FALSE;
1103 sz /= sizeof(HMODULE);
1104 for (i = 0; i < sz; i++)
1106 if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
1107 !GetModuleBaseNameW(hProcess, hMods[i], baseW, ARRAY_SIZE(baseW)))
1108 continue;
1109 module_fill_module(baseW, modW, ARRAY_SIZE(modW));
1110 EnumLoadedModulesCallback(modW, (DWORD_PTR)mi.lpBaseOfDll, mi.SizeOfImage,
1111 UserContext);
1113 HeapFree(GetProcessHeap(), 0, hMods);
1115 return sz != 0 && i == sz;
1118 static void dbghelp_str_WtoA(const WCHAR *src, char *dst, int dst_len)
1120 WideCharToMultiByte(CP_ACP, 0, src, -1, dst, dst_len - 1, NULL, NULL);
1121 dst[dst_len - 1] = 0;
1124 /******************************************************************
1125 * SymGetModuleInfo (DBGHELP.@)
1128 BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
1129 PIMAGEHLP_MODULE ModuleInfo)
1131 IMAGEHLP_MODULE mi;
1132 IMAGEHLP_MODULEW64 miw64;
1134 if (sizeof(mi) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
1136 miw64.SizeOfStruct = sizeof(miw64);
1137 if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
1139 mi.SizeOfStruct = ModuleInfo->SizeOfStruct;
1140 mi.BaseOfImage = miw64.BaseOfImage;
1141 mi.ImageSize = miw64.ImageSize;
1142 mi.TimeDateStamp = miw64.TimeDateStamp;
1143 mi.CheckSum = miw64.CheckSum;
1144 mi.NumSyms = miw64.NumSyms;
1145 mi.SymType = miw64.SymType;
1146 dbghelp_str_WtoA(miw64.ModuleName, mi.ModuleName, sizeof(mi.ModuleName));
1147 dbghelp_str_WtoA(miw64.ImageName, mi.ImageName, sizeof(mi.ImageName));
1148 dbghelp_str_WtoA(miw64.LoadedImageName, mi.LoadedImageName, sizeof(mi.LoadedImageName));
1150 memcpy(ModuleInfo, &mi, ModuleInfo->SizeOfStruct);
1152 return TRUE;
1155 /******************************************************************
1156 * SymGetModuleInfoW (DBGHELP.@)
1159 BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
1160 PIMAGEHLP_MODULEW ModuleInfo)
1162 IMAGEHLP_MODULEW64 miw64;
1163 IMAGEHLP_MODULEW miw;
1165 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
1167 miw64.SizeOfStruct = sizeof(miw64);
1168 if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
1170 miw.SizeOfStruct = ModuleInfo->SizeOfStruct;
1171 miw.BaseOfImage = miw64.BaseOfImage;
1172 miw.ImageSize = miw64.ImageSize;
1173 miw.TimeDateStamp = miw64.TimeDateStamp;
1174 miw.CheckSum = miw64.CheckSum;
1175 miw.NumSyms = miw64.NumSyms;
1176 miw.SymType = miw64.SymType;
1177 lstrcpyW(miw.ModuleName, miw64.ModuleName);
1178 lstrcpyW(miw.ImageName, miw64.ImageName);
1179 lstrcpyW(miw.LoadedImageName, miw64.LoadedImageName);
1180 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
1182 return TRUE;
1185 /******************************************************************
1186 * SymGetModuleInfo64 (DBGHELP.@)
1189 BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
1190 PIMAGEHLP_MODULE64 ModuleInfo)
1192 IMAGEHLP_MODULE64 mi64;
1193 IMAGEHLP_MODULEW64 miw64;
1195 if (sizeof(mi64) < ModuleInfo->SizeOfStruct)
1197 SetLastError(ERROR_MOD_NOT_FOUND); /* NOTE: native returns this error */
1198 WARN("Wrong size %u\n", ModuleInfo->SizeOfStruct);
1199 return FALSE;
1202 miw64.SizeOfStruct = sizeof(miw64);
1203 if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
1205 mi64.SizeOfStruct = ModuleInfo->SizeOfStruct;
1206 mi64.BaseOfImage = miw64.BaseOfImage;
1207 mi64.ImageSize = miw64.ImageSize;
1208 mi64.TimeDateStamp = miw64.TimeDateStamp;
1209 mi64.CheckSum = miw64.CheckSum;
1210 mi64.NumSyms = miw64.NumSyms;
1211 mi64.SymType = miw64.SymType;
1212 dbghelp_str_WtoA(miw64.ModuleName, mi64.ModuleName, sizeof(mi64.ModuleName));
1213 dbghelp_str_WtoA(miw64.ImageName, mi64.ImageName, sizeof(mi64.ImageName));
1214 dbghelp_str_WtoA(miw64.LoadedImageName, mi64.LoadedImageName, sizeof(mi64.LoadedImageName));
1215 dbghelp_str_WtoA(miw64.LoadedPdbName, mi64.LoadedPdbName, sizeof(mi64.LoadedPdbName));
1217 mi64.CVSig = miw64.CVSig;
1218 dbghelp_str_WtoA(miw64.CVData, mi64.CVData, sizeof(mi64.CVData));
1219 mi64.PdbSig = miw64.PdbSig;
1220 mi64.PdbSig70 = miw64.PdbSig70;
1221 mi64.PdbAge = miw64.PdbAge;
1222 mi64.PdbUnmatched = miw64.PdbUnmatched;
1223 mi64.DbgUnmatched = miw64.DbgUnmatched;
1224 mi64.LineNumbers = miw64.LineNumbers;
1225 mi64.GlobalSymbols = miw64.GlobalSymbols;
1226 mi64.TypeInfo = miw64.TypeInfo;
1227 mi64.SourceIndexed = miw64.SourceIndexed;
1228 mi64.Publics = miw64.Publics;
1230 memcpy(ModuleInfo, &mi64, ModuleInfo->SizeOfStruct);
1232 return TRUE;
1235 /******************************************************************
1236 * SymGetModuleInfoW64 (DBGHELP.@)
1239 BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
1240 PIMAGEHLP_MODULEW64 ModuleInfo)
1242 struct process* pcs = process_find_by_handle(hProcess);
1243 struct module* module;
1244 IMAGEHLP_MODULEW64 miw64;
1246 TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
1248 if (!pcs) return FALSE;
1249 if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
1250 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
1251 if (!module) return FALSE;
1253 miw64 = module->module;
1255 /* update debug information from container if any */
1256 if (module->module.SymType == SymNone)
1258 module = module_get_container(pcs, module);
1259 if (module && module->module.SymType != SymNone)
1261 miw64.SymType = module->module.SymType;
1262 miw64.NumSyms = module->module.NumSyms;
1265 memcpy(ModuleInfo, &miw64, ModuleInfo->SizeOfStruct);
1266 return TRUE;
1269 /***********************************************************************
1270 * SymGetModuleBase (DBGHELP.@)
1272 DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
1274 DWORD64 ret;
1276 ret = SymGetModuleBase64(hProcess, dwAddr);
1277 return validate_addr64(ret) ? ret : 0;
1280 /***********************************************************************
1281 * SymGetModuleBase64 (DBGHELP.@)
1283 DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
1285 struct process* pcs = process_find_by_handle(hProcess);
1286 struct module* module;
1288 if (!pcs) return 0;
1289 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
1290 if (!module) return 0;
1291 return module->module.BaseOfImage;
1294 /******************************************************************
1295 * module_reset_debug_info
1296 * Removes any debug information linked to a given module.
1298 void module_reset_debug_info(struct module* module)
1300 module->sortlist_valid = TRUE;
1301 module->sorttab_size = 0;
1302 module->addr_sorttab = NULL;
1303 module->num_sorttab = module->num_symbols = 0;
1304 hash_table_destroy(&module->ht_symbols);
1305 module->ht_symbols.num_buckets = 0;
1306 module->ht_symbols.buckets = NULL;
1307 hash_table_destroy(&module->ht_types);
1308 module->ht_types.num_buckets = 0;
1309 module->ht_types.buckets = NULL;
1310 module->vtypes.num_elts = 0;
1311 hash_table_destroy(&module->ht_symbols);
1312 module->sources_used = module->sources_alloc = 0;
1313 module->sources = NULL;
1316 /******************************************************************
1317 * SymRefreshModuleList (DBGHELP.@)
1319 BOOL WINAPI SymRefreshModuleList(HANDLE hProcess)
1321 struct process* pcs;
1323 TRACE("(%p)\n", hProcess);
1325 if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
1327 return pcs->loader->synchronize_module_list(pcs);
1330 /***********************************************************************
1331 * SymFunctionTableAccess (DBGHELP.@)
1333 PVOID WINAPI SymFunctionTableAccess(HANDLE hProcess, DWORD AddrBase)
1335 return SymFunctionTableAccess64(hProcess, AddrBase);
1338 /***********************************************************************
1339 * SymFunctionTableAccess64 (DBGHELP.@)
1341 PVOID WINAPI SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase)
1343 struct process* pcs = process_find_by_handle(hProcess);
1344 struct module* module;
1346 if (!pcs || !dbghelp_current_cpu->find_runtime_function) return NULL;
1347 module = module_find_by_addr(pcs, AddrBase, DMT_UNKNOWN);
1348 if (!module) return NULL;
1350 return dbghelp_current_cpu->find_runtime_function(module, AddrBase);
1353 static BOOL native_synchronize_module_list(struct process* pcs)
1355 return FALSE;
1358 static struct module* native_load_module(struct process* pcs, const WCHAR* name, ULONG_PTR addr)
1360 return NULL;
1363 static BOOL native_load_debug_info(struct process* process, struct module* module)
1365 return FALSE;
1368 static BOOL native_enum_modules(struct process *process, enum_modules_cb cb, void* user)
1370 return FALSE;
1373 static BOOL native_fetch_file_info(struct process* process, const WCHAR* name, ULONG_PTR load_addr, DWORD_PTR* base,
1374 DWORD* size, DWORD* checksum)
1376 return FALSE;
1379 const struct loader_ops no_loader_ops =
1381 native_synchronize_module_list,
1382 native_load_module,
1383 native_load_debug_info,
1384 native_enum_modules,
1385 native_fetch_file_info,