dbghelp: Use local NOTE_GNU_BUILD_ID declaration.
[wine.git] / dlls / dbghelp / module.c
blobbf7f105bf0b526eefc6ed4ae4fc08432cda2f486
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 "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 "image_private.h"
30 #include "psapi.h"
31 #include "winternl.h"
32 #include "wine/debug.h"
33 #include "wine/heap.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
37 #define NOTE_GNU_BUILD_ID 3
39 const WCHAR S_ElfW[] = {'<','e','l','f','>','\0'};
40 const WCHAR S_WineLoaderW[] = {'<','w','i','n','e','-','l','o','a','d','e','r','>','\0'};
41 static const WCHAR S_DotSoW[] = {'.','s','o','\0'};
42 const WCHAR S_SlashW[] = {'/','\0'};
44 static const WCHAR S_AcmW[] = {'.','a','c','m','\0'};
45 static const WCHAR S_DllW[] = {'.','d','l','l','\0'};
46 static const WCHAR S_DrvW[] = {'.','d','r','v','\0'};
47 static const WCHAR S_ExeW[] = {'.','e','x','e','\0'};
48 static const WCHAR S_OcxW[] = {'.','o','c','x','\0'};
49 static const WCHAR S_VxdW[] = {'.','v','x','d','\0'};
50 static const WCHAR * const ext[] = {S_AcmW, S_DllW, S_DrvW, S_ExeW, S_OcxW, S_VxdW, NULL};
52 static int match_ext(const WCHAR* ptr, size_t len)
54 const WCHAR* const *e;
55 size_t l;
57 for (e = ext; *e; e++)
59 l = strlenW(*e);
60 if (l >= len) return 0;
61 if (strncmpiW(&ptr[len - l], *e, l)) continue;
62 return l;
64 return 0;
67 static const WCHAR* get_filename(const WCHAR* name, const WCHAR* endptr)
69 const WCHAR* ptr;
71 if (!endptr) endptr = name + strlenW(name);
72 for (ptr = endptr - 1; ptr >= name; ptr--)
74 if (*ptr == '/' || *ptr == '\\') break;
76 return ++ptr;
79 static BOOL is_wine_loader(const WCHAR *module)
81 static const WCHAR wineW[] = {'w','i','n','e',0};
82 static const WCHAR suffixW[] = {'6','4',0};
83 const WCHAR *filename = get_filename(module, NULL);
84 const char *ptr;
85 BOOL ret = FALSE;
86 WCHAR *buffer;
87 DWORD len;
89 if ((ptr = getenv("WINELOADER")))
91 ptr = file_nameA(ptr);
92 len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 );
93 buffer = heap_alloc( len * sizeof(WCHAR) );
94 MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len );
96 else
98 buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) );
99 strcpyW( buffer, wineW );
102 if (!strcmpW( filename, buffer ))
103 ret = TRUE;
105 strcatW( buffer, suffixW );
106 if (!strcmpW( filename, buffer ))
107 ret = TRUE;
109 heap_free( buffer );
110 return ret;
113 static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size)
115 const WCHAR *ptr, *endptr;
116 size_t len, l;
118 ptr = get_filename(in, endptr = in + strlenW(in));
119 len = min(endptr - ptr, size - 1);
120 memcpy(out, ptr, len * sizeof(WCHAR));
121 out[len] = '\0';
122 if (len > 4 && (l = match_ext(out, len)))
123 out[len - l] = '\0';
124 else if (is_wine_loader(out))
125 lstrcpynW(out, S_WineLoaderW, size);
126 else
128 if (len > 3 && !strcmpiW(&out[len - 3], S_DotSoW) &&
129 (l = match_ext(out, len - 3)))
130 strcpyW(&out[len - l - 3], S_ElfW);
132 while ((*out = tolowerW(*out))) out++;
135 void module_set_module(struct module* module, const WCHAR* name)
137 module_fill_module(name, module->module.ModuleName, ARRAY_SIZE(module->module.ModuleName));
138 module_fill_module(name, module->modulename, ARRAY_SIZE(module->modulename));
141 /* Returned string must be freed by caller */
142 WCHAR *get_wine_loader_name(struct process *pcs)
144 static const WCHAR wineW[] = {'w','i','n','e',0};
145 static const WCHAR suffixW[] = {'6','4',0};
146 WCHAR *buffer, *p;
147 const char *env;
149 /* All binaries are loaded with WINELOADER (if run from tree) or by the
150 * main executable
152 if ((env = getenv("WINELOADER")))
154 DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, env, -1, NULL, 0 );
155 buffer = heap_alloc( len * sizeof(WCHAR) );
156 MultiByteToWideChar( CP_UNIXCP, 0, env, -1, buffer, len );
158 else
160 buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) );
161 strcpyW( buffer, wineW );
164 p = buffer + strlenW( buffer ) - strlenW( suffixW );
165 if (p > buffer && !strcmpW( p, suffixW ))
166 *p = 0;
168 if (pcs->is_64bit)
169 strcatW(buffer, suffixW);
171 TRACE( "returning %s\n", debugstr_w(buffer) );
172 return buffer;
175 static const char* get_module_type(enum module_type type, BOOL virtual)
177 switch (type)
179 case DMT_ELF: return virtual ? "Virtual ELF" : "ELF";
180 case DMT_PE: return virtual ? "Virtual PE" : "PE";
181 case DMT_MACHO: return virtual ? "Virtual Mach-O" : "Mach-O";
182 default: return "---";
186 /***********************************************************************
187 * Creates and links a new module to a process
189 struct module* module_new(struct process* pcs, const WCHAR* name,
190 enum module_type type, BOOL virtual,
191 DWORD64 mod_addr, DWORD64 size,
192 ULONG_PTR stamp, ULONG_PTR checksum)
194 struct module* module;
195 unsigned i;
197 assert(type == DMT_ELF || type == DMT_PE || type == DMT_MACHO);
198 if (!(module = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*module))))
199 return NULL;
201 module->next = pcs->lmodules;
202 pcs->lmodules = module;
204 TRACE("=> %s %s-%s %s\n",
205 get_module_type(type, virtual),
206 wine_dbgstr_longlong(mod_addr), wine_dbgstr_longlong(mod_addr + size),
207 debugstr_w(name));
209 pool_init(&module->pool, 65536);
211 module->process = pcs;
212 module->module.SizeOfStruct = sizeof(module->module);
213 module->module.BaseOfImage = mod_addr;
214 module->module.ImageSize = size;
215 module_set_module(module, name);
216 module->module.ImageName[0] = '\0';
217 lstrcpynW(module->module.LoadedImageName, name, ARRAY_SIZE(module->module.LoadedImageName));
218 module->module.SymType = SymNone;
219 module->module.NumSyms = 0;
220 module->module.TimeDateStamp = stamp;
221 module->module.CheckSum = checksum;
223 memset(module->module.LoadedPdbName, 0, sizeof(module->module.LoadedPdbName));
224 module->module.CVSig = 0;
225 memset(module->module.CVData, 0, sizeof(module->module.CVData));
226 module->module.PdbSig = 0;
227 memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
228 module->module.PdbAge = 0;
229 module->module.PdbUnmatched = FALSE;
230 module->module.DbgUnmatched = FALSE;
231 module->module.LineNumbers = FALSE;
232 module->module.GlobalSymbols = FALSE;
233 module->module.TypeInfo = FALSE;
234 module->module.SourceIndexed = FALSE;
235 module->module.Publics = FALSE;
237 module->reloc_delta = 0;
238 module->type = type;
239 module->is_virtual = virtual;
240 for (i = 0; i < DFI_LAST; i++) module->format_info[i] = NULL;
241 module->sortlist_valid = FALSE;
242 module->sorttab_size = 0;
243 module->addr_sorttab = NULL;
244 module->num_sorttab = 0;
245 module->num_symbols = 0;
247 vector_init(&module->vsymt, sizeof(struct symt*), 128);
248 /* FIXME: this seems a bit too high (on a per module basis)
249 * need some statistics about this
251 hash_table_init(&module->pool, &module->ht_symbols, 4096);
252 hash_table_init(&module->pool, &module->ht_types, 4096);
253 vector_init(&module->vtypes, sizeof(struct symt*), 32);
255 module->sources_used = 0;
256 module->sources_alloc = 0;
257 module->sources = 0;
258 wine_rb_init(&module->sources_offsets_tree, source_rb_compare);
260 return module;
263 /***********************************************************************
264 * module_find_by_nameW
267 struct module* module_find_by_nameW(const struct process* pcs, const WCHAR* name)
269 struct module* module;
271 for (module = pcs->lmodules; module; module = module->next)
273 if (!strcmpiW(name, module->module.ModuleName)) return module;
275 SetLastError(ERROR_INVALID_NAME);
276 return NULL;
279 struct module* module_find_by_nameA(const struct process* pcs, const char* name)
281 WCHAR wname[MAX_PATH];
283 MultiByteToWideChar(CP_ACP, 0, name, -1, wname, ARRAY_SIZE(wname));
284 return module_find_by_nameW(pcs, wname);
287 /***********************************************************************
288 * module_is_already_loaded
291 struct module* module_is_already_loaded(const struct process* pcs, const WCHAR* name)
293 struct module* module;
294 const WCHAR* filename;
296 /* first compare the loaded image name... */
297 for (module = pcs->lmodules; module; module = module->next)
299 if (!strcmpiW(name, module->module.LoadedImageName))
300 return module;
302 /* then compare the standard filenames (without the path) ... */
303 filename = get_filename(name, NULL);
304 for (module = pcs->lmodules; module; module = module->next)
306 if (!strcmpiW(filename, get_filename(module->module.LoadedImageName, NULL)))
307 return module;
309 SetLastError(ERROR_INVALID_NAME);
310 return NULL;
313 /***********************************************************************
314 * module_get_container
317 static struct module* module_get_container(const struct process* pcs,
318 const struct module* inner)
320 struct module* module;
322 for (module = pcs->lmodules; module; module = module->next)
324 if (module != inner &&
325 module->module.BaseOfImage <= inner->module.BaseOfImage &&
326 module->module.BaseOfImage + module->module.ImageSize >=
327 inner->module.BaseOfImage + inner->module.ImageSize)
328 return module;
330 return NULL;
333 /***********************************************************************
334 * module_get_containee
337 struct module* module_get_containee(const struct process* pcs, const struct module* outer)
339 struct module* module;
341 for (module = pcs->lmodules; module; module = module->next)
343 if (module != outer &&
344 outer->module.BaseOfImage <= module->module.BaseOfImage &&
345 outer->module.BaseOfImage + outer->module.ImageSize >=
346 module->module.BaseOfImage + module->module.ImageSize)
347 return module;
349 return NULL;
352 /******************************************************************
353 * module_get_debug
355 * get the debug information from a module:
356 * - if the module's type is deferred, then force loading of debug info (and return
357 * the module itself)
358 * - if the module has no debug info and has an ELF container, then return the ELF
359 * container (and also force the ELF container's debug info loading if deferred)
360 * - otherwise return the module itself if it has some debug info
362 BOOL module_get_debug(struct module_pair* pair)
364 IMAGEHLP_DEFERRED_SYMBOL_LOADW64 idslW64;
366 if (!pair->requested) return FALSE;
367 /* for a PE builtin, always get info from container */
368 if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
369 pair->effective = pair->requested;
370 /* if deferred, force loading */
371 if (pair->effective->module.SymType == SymDeferred)
373 BOOL ret;
375 if (pair->effective->is_virtual) ret = FALSE;
376 else if (pair->effective->type == DMT_PE)
378 idslW64.SizeOfStruct = sizeof(idslW64);
379 idslW64.BaseOfImage = pair->effective->module.BaseOfImage;
380 idslW64.CheckSum = pair->effective->module.CheckSum;
381 idslW64.TimeDateStamp = pair->effective->module.TimeDateStamp;
382 memcpy(idslW64.FileName, pair->effective->module.ImageName,
383 sizeof(pair->effective->module.ImageName));
384 idslW64.Reparse = FALSE;
385 idslW64.hFile = INVALID_HANDLE_VALUE;
387 pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idslW64);
388 ret = pe_load_debug_info(pair->pcs, pair->effective);
389 pcs_callback(pair->pcs,
390 ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
391 &idslW64);
393 else ret = pair->pcs->loader->load_debug_info(pair->pcs, pair->effective);
395 if (!ret) pair->effective->module.SymType = SymNone;
396 assert(pair->effective->module.SymType != SymDeferred);
397 pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
399 return pair->effective->module.SymType != SymNone;
402 /***********************************************************************
403 * module_find_by_addr
405 * either the addr where module is loaded, or any address inside the
406 * module
408 struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr,
409 enum module_type type)
411 struct module* module;
413 if (type == DMT_UNKNOWN)
415 if ((module = module_find_by_addr(pcs, addr, DMT_PE)) ||
416 (module = module_find_by_addr(pcs, addr, DMT_ELF)) ||
417 (module = module_find_by_addr(pcs, addr, DMT_MACHO)))
418 return module;
420 else
422 for (module = pcs->lmodules; module; module = module->next)
424 if (type == module->type && addr >= module->module.BaseOfImage &&
425 addr < module->module.BaseOfImage + module->module.ImageSize)
426 return module;
429 SetLastError(ERROR_MOD_NOT_FOUND);
430 return module;
433 /******************************************************************
434 * module_is_container_loaded
436 * checks whether the native container, for a (supposed) PE builtin is
437 * already loaded
439 static BOOL module_is_container_loaded(const struct process* pcs,
440 const WCHAR* ImageName, DWORD64 base)
442 size_t len;
443 struct module* module;
444 PCWSTR filename, modname;
446 if (!base) return FALSE;
447 filename = get_filename(ImageName, NULL);
448 len = strlenW(filename);
450 for (module = pcs->lmodules; module; module = module->next)
452 if ((module->type == DMT_ELF || module->type == DMT_MACHO) &&
453 base >= module->module.BaseOfImage &&
454 base < module->module.BaseOfImage + module->module.ImageSize)
456 modname = get_filename(module->module.LoadedImageName, NULL);
457 if (!strncmpiW(modname, filename, len) &&
458 !memcmp(modname + len, S_DotSoW, 3 * sizeof(WCHAR)))
460 return TRUE;
464 /* likely a native PE module */
465 WARN("Couldn't find container for %s\n", debugstr_w(ImageName));
466 return FALSE;
469 static BOOL image_check_debug_link(const WCHAR* file, struct image_file_map* fmap, DWORD link_crc)
471 DWORD read_bytes;
472 HANDLE handle;
473 WCHAR *path;
474 WORD magic;
475 BOOL ret;
477 path = get_dos_file_name(file);
478 handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
479 heap_free(path);
480 if (handle == INVALID_HANDLE_VALUE) return FALSE;
482 if (link_crc)
484 DWORD crc = calc_crc32(handle);
485 if (crc != link_crc)
487 WARN("Bad CRC for file %s (got %08x while expecting %08x)\n", debugstr_w(file), crc, link_crc);
488 CloseHandle(handle);
489 return FALSE;
493 SetFilePointer(handle, 0, 0, FILE_BEGIN);
494 if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE)
495 ret = pe_map_file(handle, fmap, DMT_PE);
496 else
497 ret = elf_map_handle(handle, fmap);
498 CloseHandle(handle);
499 return ret;
502 /******************************************************************
503 * image_locate_debug_link
505 * Locate a filename from a .gnu_debuglink section, using the same
506 * strategy as gdb:
507 * "If the full name of the directory containing the executable is
508 * execdir, and the executable has a debug link that specifies the
509 * name debugfile, then GDB will automatically search for the
510 * debugging information file in three places:
511 * - the directory containing the executable file (that is, it
512 * will look for a file named `execdir/debugfile',
513 * - a subdirectory of that directory named `.debug' (that is, the
514 * file `execdir/.debug/debugfile', and
515 * - a subdirectory of the global debug file directory that includes
516 * the executable's full path, and the name from the link (that is,
517 * the file `globaldebugdir/execdir/debugfile', where globaldebugdir
518 * is the global debug file directory, and execdir has been turned
519 * into a relative path)." (from GDB manual)
521 static BOOL image_locate_debug_link(const struct module* module, struct image_file_map* fmap, const char* filename, DWORD crc)
523 static const WCHAR globalDebugDirW[] = {'/','u','s','r','/','l','i','b','/','d','e','b','u','g','/'};
524 static const WCHAR dotDebugW[] = {'.','d','e','b','u','g','/'};
525 const size_t globalDebugDirLen = ARRAY_SIZE(globalDebugDirW);
526 size_t filename_len, path_len;
527 WCHAR* p = NULL;
528 WCHAR* slash;
529 WCHAR* slash2;
530 struct image_file_map* fmap_link = NULL;
532 fmap_link = HeapAlloc(GetProcessHeap(), 0, sizeof(*fmap_link));
533 if (!fmap_link) return FALSE;
535 filename_len = MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, NULL, 0);
536 path_len = strlenW(module->module.LoadedImageName);
537 if (module->real_path) path_len = max(path_len, strlenW(module->real_path));
538 p = HeapAlloc(GetProcessHeap(), 0,
539 (globalDebugDirLen + path_len + 6 + 1 + filename_len + 1) * sizeof(WCHAR));
540 if (!p) goto found;
542 /* we prebuild the string with "execdir" */
543 strcpyW(p, module->module.LoadedImageName);
544 slash = p;
545 if ((slash2 = strrchrW(slash, '/'))) slash = slash2 + 1;
546 if ((slash2 = strrchrW(slash, '\\'))) slash = slash2 + 1;
548 /* testing execdir/filename */
549 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
550 if (image_check_debug_link(p, fmap_link, crc)) goto found;
552 /* testing execdir/.debug/filename */
553 memcpy(slash, dotDebugW, sizeof(dotDebugW));
554 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash + ARRAY_SIZE(dotDebugW), filename_len);
555 if (image_check_debug_link(p, fmap_link, crc)) goto found;
557 if (module->real_path)
559 strcpyW(p, module->real_path);
560 slash = p;
561 if ((slash2 = strrchrW(slash, '/'))) slash = slash2 + 1;
562 if ((slash2 = strrchrW(slash, '\\'))) slash = slash2 + 1;
563 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
564 if (image_check_debug_link(p, fmap_link, crc)) goto found;
567 /* testing globaldebugdir/execdir/filename */
568 memmove(p + globalDebugDirLen, p, (slash - p) * sizeof(WCHAR));
569 memcpy(p, globalDebugDirW, globalDebugDirLen * sizeof(WCHAR));
570 slash += globalDebugDirLen;
571 MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
572 if (image_check_debug_link(p, fmap_link, crc)) goto found;
574 /* finally testing filename */
575 if (image_check_debug_link(slash, fmap_link, crc)) goto found;
578 WARN("Couldn't locate or map %s\n", filename);
579 HeapFree(GetProcessHeap(), 0, p);
580 HeapFree(GetProcessHeap(), 0, fmap_link);
581 return FALSE;
583 found:
584 TRACE("Located debug information file %s at %s\n", filename, debugstr_w(p));
585 HeapFree(GetProcessHeap(), 0, p);
586 fmap->alternate = fmap_link;
587 return TRUE;
590 /******************************************************************
591 * image_locate_build_id_target
593 * Try to find the .so file containing the debug info out of the build-id note information
595 static BOOL image_locate_build_id_target(struct image_file_map* fmap, const BYTE* id, unsigned idlen)
597 static const WCHAR globalDebugDirW[] = {'/','u','s','r','/','l','i','b','/','d','e','b','u','g','/'};
598 static const WCHAR buildidW[] = {'.','b','u','i','l','d','-','i','d','/'};
599 static const WCHAR dotDebug0W[] = {'.','d','e','b','u','g',0};
600 struct image_file_map* fmap_link = NULL;
601 WCHAR* p;
602 WCHAR* z;
603 const BYTE* idend = id + idlen;
605 fmap_link = HeapAlloc(GetProcessHeap(), 0, sizeof(*fmap_link));
606 if (!fmap_link) return FALSE;
608 p = HeapAlloc(GetProcessHeap(), 0,
609 sizeof(globalDebugDirW) + sizeof(buildidW) +
610 (idlen * 2 + 1) * sizeof(WCHAR) + sizeof(dotDebug0W));
611 z = p;
612 memcpy(z, globalDebugDirW, sizeof(globalDebugDirW));
613 z += ARRAY_SIZE(globalDebugDirW);
614 memcpy(z, buildidW, sizeof(buildidW));
615 z += ARRAY_SIZE(buildidW);
617 if (id < idend)
619 *z++ = "0123456789abcdef"[*id >> 4 ];
620 *z++ = "0123456789abcdef"[*id & 0x0F];
621 id++;
623 if (id < idend)
624 *z++ = '/';
625 while (id < idend)
627 *z++ = "0123456789abcdef"[*id >> 4 ];
628 *z++ = "0123456789abcdef"[*id & 0x0F];
629 id++;
631 memcpy(z, dotDebug0W, sizeof(dotDebug0W));
632 TRACE("checking %s\n", wine_dbgstr_w(p));
634 if (image_check_debug_link(p, fmap_link, 0))
636 struct image_section_map buildid_sect;
637 if (image_find_section(fmap_link, ".note.gnu.build-id", &buildid_sect))
639 const UINT32* note;
641 note = (const UINT32*)image_map_section(&buildid_sect);
642 if (note != IMAGE_NO_MAP)
644 /* the usual ELF note structure: name-size desc-size type <name> <desc> */
645 if (note[2] == NOTE_GNU_BUILD_ID)
647 if (note[1] == idlen &&
648 !memcmp(note + 3 + ((note[0] + 3) >> 2), idend - idlen, idlen))
650 TRACE("Located debug information file at %s\n", debugstr_w(p));
651 HeapFree(GetProcessHeap(), 0, p);
652 fmap->alternate = fmap_link;
653 return TRUE;
655 WARN("mismatch in buildid information for %s\n", wine_dbgstr_w(p));
658 image_unmap_section(&buildid_sect);
660 image_unmap_file(fmap_link);
663 TRACE("not found\n");
664 HeapFree(GetProcessHeap(), 0, p);
665 HeapFree(GetProcessHeap(), 0, fmap_link);
666 return FALSE;
669 /******************************************************************
670 * image_check_alternate
672 * Load alternate files for a given image file, looking at either .note.gnu_build-id
673 * or .gnu_debuglink sections.
675 BOOL image_check_alternate(struct image_file_map* fmap, const struct module* module)
677 BOOL ret = FALSE;
678 BOOL found = FALSE;
679 struct image_section_map buildid_sect, debuglink_sect;
681 /* if present, add the .gnu_debuglink file as an alternate to current one */
682 if (image_find_section(fmap, ".note.gnu.build-id", &buildid_sect))
684 const UINT32* note;
686 found = TRUE;
687 note = (const UINT32*)image_map_section(&buildid_sect);
688 if (note != IMAGE_NO_MAP)
690 /* the usual ELF note structure: name-size desc-size type <name> <desc> */
691 if (note[2] == NOTE_GNU_BUILD_ID)
693 ret = image_locate_build_id_target(fmap, (const BYTE*)(note + 3 + ((note[0] + 3) >> 2)), note[1]);
696 image_unmap_section(&buildid_sect);
698 /* if present, add the .gnu_debuglink file as an alternate to current one */
699 if (!ret && image_find_section(fmap, ".gnu_debuglink", &debuglink_sect))
701 const char* dbg_link;
703 found = TRUE;
704 dbg_link = (const char*)image_map_section(&debuglink_sect);
705 if (dbg_link != IMAGE_NO_MAP)
707 /* The content of a debug link section is:
708 * 1/ a NULL terminated string, containing the file name for the
709 * debug info
710 * 2/ padding on 4 byte boundary
711 * 3/ CRC of the linked file
713 DWORD crc = *(const DWORD*)(dbg_link + ((DWORD_PTR)(strlen(dbg_link) + 4) & ~3));
714 ret = image_locate_debug_link(module, fmap, dbg_link, crc);
715 if (!ret)
716 WARN("Couldn't load linked debug file for %s\n",
717 debugstr_w(module->module.ModuleName));
719 image_unmap_section(&debuglink_sect);
721 return found ? ret : TRUE;
724 /***********************************************************************
725 * SymLoadModule (DBGHELP.@)
727 DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
728 PCSTR ModuleName, DWORD BaseOfDll, DWORD SizeOfDll)
730 return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll,
731 SizeOfDll, NULL, 0);
734 /***********************************************************************
735 * SymLoadModuleEx (DBGHELP.@)
737 DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
738 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize,
739 PMODLOAD_DATA Data, DWORD Flags)
741 PWSTR wImageName, wModuleName;
742 unsigned len;
743 DWORD64 ret;
745 TRACE("(%p %p %s %s %s %08x %p %08x)\n",
746 hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
747 wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags);
749 if (ImageName)
751 len = MultiByteToWideChar(CP_ACP, 0, ImageName, -1, NULL, 0);
752 wImageName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
753 MultiByteToWideChar(CP_ACP, 0, ImageName, -1, wImageName, len);
755 else wImageName = NULL;
756 if (ModuleName)
758 len = MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, NULL, 0);
759 wModuleName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
760 MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, wModuleName, len);
762 else wModuleName = NULL;
764 ret = SymLoadModuleExW(hProcess, hFile, wImageName, wModuleName,
765 BaseOfDll, DllSize, Data, Flags);
766 HeapFree(GetProcessHeap(), 0, wImageName);
767 HeapFree(GetProcessHeap(), 0, wModuleName);
768 return ret;
771 /***********************************************************************
772 * SymLoadModuleExW (DBGHELP.@)
774 DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
775 PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll,
776 PMODLOAD_DATA Data, DWORD Flags)
778 struct process* pcs;
779 struct module* module = NULL;
781 TRACE("(%p %p %s %s %s %08x %p %08x)\n",
782 hProcess, hFile, debugstr_w(wImageName), debugstr_w(wModuleName),
783 wine_dbgstr_longlong(BaseOfDll), SizeOfDll, Data, Flags);
785 if (Data)
786 FIXME("Unsupported load data parameter %p for %s\n",
787 Data, debugstr_w(wImageName));
788 if (!validate_addr64(BaseOfDll)) return FALSE;
790 if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
792 if (Flags & SLMFLAG_VIRTUAL)
794 if (!wImageName) return FALSE;
795 module = module_new(pcs, wImageName, DMT_PE, TRUE, BaseOfDll, SizeOfDll, 0, 0);
796 if (!module) return FALSE;
797 if (wModuleName) module_set_module(module, wModuleName);
798 module->module.SymType = SymVirtual;
800 return TRUE;
802 if (Flags & ~(SLMFLAG_VIRTUAL))
803 FIXME("Unsupported Flags %08x for %s\n", Flags, debugstr_w(wImageName));
805 pcs->loader->synchronize_module_list(pcs);
807 /* this is a Wine extension to the API just to redo the synchronisation */
808 if (!wImageName && !hFile) return 0;
810 /* check if the module is already loaded, or if it's a builtin PE module with
811 * an containing ELF module
813 if (wImageName)
815 module = module_is_already_loaded(pcs, wImageName);
816 if (!module && module_is_container_loaded(pcs, wImageName, BaseOfDll))
818 /* force the loading of DLL as builtin */
819 module = pe_load_builtin_module(pcs, wImageName, BaseOfDll, SizeOfDll);
822 if (!module)
824 /* otherwise, try a regular PE module */
825 if (!(module = pe_load_native_module(pcs, wImageName, hFile, BaseOfDll, SizeOfDll)) &&
826 wImageName)
828 /* and finally an ELF or Mach-O module */
829 module = pcs->loader->load_module(pcs, wImageName, BaseOfDll);
832 if (!module)
834 WARN("Couldn't locate %s\n", debugstr_w(wImageName));
835 return 0;
837 module->module.NumSyms = module->ht_symbols.num_elts;
838 /* by default module_new fills module.ModuleName from a derivation
839 * of LoadedImageName. Overwrite it, if we have better information
841 if (wModuleName)
842 module_set_module(module, wModuleName);
843 if (wImageName)
844 lstrcpynW(module->module.ImageName, wImageName, ARRAY_SIZE(module->module.ImageName));
846 return module->module.BaseOfImage;
849 /***********************************************************************
850 * SymLoadModule64 (DBGHELP.@)
852 DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
853 PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
855 return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll,
856 NULL, 0);
859 /******************************************************************
860 * module_remove
863 BOOL module_remove(struct process* pcs, struct module* module)
865 struct module_format*modfmt;
866 struct module** p;
867 unsigned i;
869 TRACE("%s (%p)\n", debugstr_w(module->module.ModuleName), module);
871 for (i = 0; i < DFI_LAST; i++)
873 if ((modfmt = module->format_info[i]) && modfmt->remove)
874 modfmt->remove(pcs, module->format_info[i]);
876 hash_table_destroy(&module->ht_symbols);
877 hash_table_destroy(&module->ht_types);
878 HeapFree(GetProcessHeap(), 0, module->sources);
879 HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
880 HeapFree(GetProcessHeap(), 0, module->real_path);
881 pool_destroy(&module->pool);
882 /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
883 * so do we
885 for (p = &pcs->lmodules; *p; p = &(*p)->next)
887 if (*p == module)
889 *p = module->next;
890 HeapFree(GetProcessHeap(), 0, module);
891 return TRUE;
894 FIXME("This shouldn't happen\n");
895 return FALSE;
898 /******************************************************************
899 * SymUnloadModule (DBGHELP.@)
902 BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
904 struct process* pcs;
905 struct module* module;
907 pcs = process_find_by_handle(hProcess);
908 if (!pcs) return FALSE;
909 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
910 if (!module) return FALSE;
911 return module_remove(pcs, module);
914 /******************************************************************
915 * SymUnloadModule64 (DBGHELP.@)
918 BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
920 struct process* pcs;
921 struct module* module;
923 pcs = process_find_by_handle(hProcess);
924 if (!pcs) return FALSE;
925 if (!validate_addr64(BaseOfDll)) return FALSE;
926 module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
927 if (!module) return FALSE;
928 return module_remove(pcs, module);
931 /******************************************************************
932 * SymEnumerateModules (DBGHELP.@)
935 struct enum_modW64_32
937 PSYM_ENUMMODULES_CALLBACK cb;
938 PVOID user;
939 char module[MAX_PATH];
942 static BOOL CALLBACK enum_modW64_32(PCWSTR name, DWORD64 base, PVOID user)
944 struct enum_modW64_32* x = user;
946 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
947 return x->cb(x->module, (DWORD)base, x->user);
950 BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
951 PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
952 PVOID UserContext)
954 struct enum_modW64_32 x;
956 x.cb = EnumModulesCallback;
957 x.user = UserContext;
959 return SymEnumerateModulesW64(hProcess, enum_modW64_32, &x);
962 /******************************************************************
963 * SymEnumerateModules64 (DBGHELP.@)
966 struct enum_modW64_64
968 PSYM_ENUMMODULES_CALLBACK64 cb;
969 PVOID user;
970 char module[MAX_PATH];
973 static BOOL CALLBACK enum_modW64_64(PCWSTR name, DWORD64 base, PVOID user)
975 struct enum_modW64_64* x = user;
977 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
978 return x->cb(x->module, base, x->user);
981 BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
982 PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
983 PVOID UserContext)
985 struct enum_modW64_64 x;
987 x.cb = EnumModulesCallback;
988 x.user = UserContext;
990 return SymEnumerateModulesW64(hProcess, enum_modW64_64, &x);
993 /******************************************************************
994 * SymEnumerateModulesW64 (DBGHELP.@)
997 BOOL WINAPI SymEnumerateModulesW64(HANDLE hProcess,
998 PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback,
999 PVOID UserContext)
1001 struct process* pcs = process_find_by_handle(hProcess);
1002 struct module* module;
1004 if (!pcs) return FALSE;
1006 for (module = pcs->lmodules; module; module = module->next)
1008 if (!dbghelp_opt_native &&
1009 (module->type == DMT_ELF || module->type == DMT_MACHO))
1010 continue;
1011 if (!EnumModulesCallback(module->modulename,
1012 module->module.BaseOfImage, UserContext))
1013 break;
1015 return TRUE;
1018 /******************************************************************
1019 * EnumerateLoadedModules64 (DBGHELP.@)
1022 struct enum_load_modW64_64
1024 PENUMLOADED_MODULES_CALLBACK64 cb;
1025 PVOID user;
1026 char module[MAX_PATH];
1029 static BOOL CALLBACK enum_load_modW64_64(PCWSTR name, DWORD64 base, ULONG size,
1030 PVOID user)
1032 struct enum_load_modW64_64* x = user;
1034 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
1035 return x->cb(x->module, base, size, x->user);
1038 BOOL WINAPI EnumerateLoadedModules64(HANDLE hProcess,
1039 PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,
1040 PVOID UserContext)
1042 struct enum_load_modW64_64 x;
1044 x.cb = EnumLoadedModulesCallback;
1045 x.user = UserContext;
1047 return EnumerateLoadedModulesW64(hProcess, enum_load_modW64_64, &x);
1050 /******************************************************************
1051 * EnumerateLoadedModules (DBGHELP.@)
1054 struct enum_load_modW64_32
1056 PENUMLOADED_MODULES_CALLBACK cb;
1057 PVOID user;
1058 char module[MAX_PATH];
1061 static BOOL CALLBACK enum_load_modW64_32(PCWSTR name, DWORD64 base, ULONG size,
1062 PVOID user)
1064 struct enum_load_modW64_32* x = user;
1065 WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
1066 return x->cb(x->module, (DWORD)base, size, x->user);
1069 BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
1070 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
1071 PVOID UserContext)
1073 struct enum_load_modW64_32 x;
1075 x.cb = EnumLoadedModulesCallback;
1076 x.user = UserContext;
1078 return EnumerateLoadedModulesW64(hProcess, enum_load_modW64_32, &x);
1081 /******************************************************************
1082 * EnumerateLoadedModulesW64 (DBGHELP.@)
1085 BOOL WINAPI EnumerateLoadedModulesW64(HANDLE hProcess,
1086 PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback,
1087 PVOID UserContext)
1089 HMODULE* hMods;
1090 WCHAR baseW[256], modW[256];
1091 DWORD i, sz;
1092 MODULEINFO mi;
1094 hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
1095 if (!hMods) return FALSE;
1097 if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
1099 /* hProcess should also be a valid process handle !! */
1100 FIXME("If this happens, bump the number in mod\n");
1101 HeapFree(GetProcessHeap(), 0, hMods);
1102 return FALSE;
1104 sz /= sizeof(HMODULE);
1105 for (i = 0; i < sz; i++)
1107 if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
1108 !GetModuleBaseNameW(hProcess, hMods[i], baseW, ARRAY_SIZE(baseW)))
1109 continue;
1110 module_fill_module(baseW, modW, ARRAY_SIZE(modW));
1111 EnumLoadedModulesCallback(modW, (DWORD_PTR)mi.lpBaseOfDll, mi.SizeOfImage,
1112 UserContext);
1114 HeapFree(GetProcessHeap(), 0, hMods);
1116 return sz != 0 && i == sz;
1119 static void dbghelp_str_WtoA(const WCHAR *src, char *dst, int dst_len)
1121 WideCharToMultiByte(CP_ACP, 0, src, -1, dst, dst_len - 1, NULL, NULL);
1122 dst[dst_len - 1] = 0;
1125 /******************************************************************
1126 * SymGetModuleInfo (DBGHELP.@)
1129 BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
1130 PIMAGEHLP_MODULE ModuleInfo)
1132 IMAGEHLP_MODULE mi;
1133 IMAGEHLP_MODULEW64 miw64;
1135 if (sizeof(mi) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
1137 miw64.SizeOfStruct = sizeof(miw64);
1138 if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
1140 mi.SizeOfStruct = ModuleInfo->SizeOfStruct;
1141 mi.BaseOfImage = miw64.BaseOfImage;
1142 mi.ImageSize = miw64.ImageSize;
1143 mi.TimeDateStamp = miw64.TimeDateStamp;
1144 mi.CheckSum = miw64.CheckSum;
1145 mi.NumSyms = miw64.NumSyms;
1146 mi.SymType = miw64.SymType;
1147 dbghelp_str_WtoA(miw64.ModuleName, mi.ModuleName, sizeof(mi.ModuleName));
1148 dbghelp_str_WtoA(miw64.ImageName, mi.ImageName, sizeof(mi.ImageName));
1149 dbghelp_str_WtoA(miw64.LoadedImageName, mi.LoadedImageName, sizeof(mi.LoadedImageName));
1151 memcpy(ModuleInfo, &mi, ModuleInfo->SizeOfStruct);
1153 return TRUE;
1156 /******************************************************************
1157 * SymGetModuleInfoW (DBGHELP.@)
1160 BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
1161 PIMAGEHLP_MODULEW ModuleInfo)
1163 IMAGEHLP_MODULEW64 miw64;
1164 IMAGEHLP_MODULEW miw;
1166 if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
1168 miw64.SizeOfStruct = sizeof(miw64);
1169 if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
1171 miw.SizeOfStruct = ModuleInfo->SizeOfStruct;
1172 miw.BaseOfImage = miw64.BaseOfImage;
1173 miw.ImageSize = miw64.ImageSize;
1174 miw.TimeDateStamp = miw64.TimeDateStamp;
1175 miw.CheckSum = miw64.CheckSum;
1176 miw.NumSyms = miw64.NumSyms;
1177 miw.SymType = miw64.SymType;
1178 strcpyW(miw.ModuleName, miw64.ModuleName);
1179 strcpyW(miw.ImageName, miw64.ImageName);
1180 strcpyW(miw.LoadedImageName, miw64.LoadedImageName);
1181 memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
1183 return TRUE;
1186 /******************************************************************
1187 * SymGetModuleInfo64 (DBGHELP.@)
1190 BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
1191 PIMAGEHLP_MODULE64 ModuleInfo)
1193 IMAGEHLP_MODULE64 mi64;
1194 IMAGEHLP_MODULEW64 miw64;
1196 if (sizeof(mi64) < ModuleInfo->SizeOfStruct)
1198 SetLastError(ERROR_MOD_NOT_FOUND); /* NOTE: native returns this error */
1199 WARN("Wrong size %u\n", ModuleInfo->SizeOfStruct);
1200 return FALSE;
1203 miw64.SizeOfStruct = sizeof(miw64);
1204 if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
1206 mi64.SizeOfStruct = ModuleInfo->SizeOfStruct;
1207 mi64.BaseOfImage = miw64.BaseOfImage;
1208 mi64.ImageSize = miw64.ImageSize;
1209 mi64.TimeDateStamp = miw64.TimeDateStamp;
1210 mi64.CheckSum = miw64.CheckSum;
1211 mi64.NumSyms = miw64.NumSyms;
1212 mi64.SymType = miw64.SymType;
1213 dbghelp_str_WtoA(miw64.ModuleName, mi64.ModuleName, sizeof(mi64.ModuleName));
1214 dbghelp_str_WtoA(miw64.ImageName, mi64.ImageName, sizeof(mi64.ImageName));
1215 dbghelp_str_WtoA(miw64.LoadedImageName, mi64.LoadedImageName, sizeof(mi64.LoadedImageName));
1216 dbghelp_str_WtoA(miw64.LoadedPdbName, mi64.LoadedPdbName, sizeof(mi64.LoadedPdbName));
1218 mi64.CVSig = miw64.CVSig;
1219 dbghelp_str_WtoA(miw64.CVData, mi64.CVData, sizeof(mi64.CVData));
1220 mi64.PdbSig = miw64.PdbSig;
1221 mi64.PdbSig70 = miw64.PdbSig70;
1222 mi64.PdbAge = miw64.PdbAge;
1223 mi64.PdbUnmatched = miw64.PdbUnmatched;
1224 mi64.DbgUnmatched = miw64.DbgUnmatched;
1225 mi64.LineNumbers = miw64.LineNumbers;
1226 mi64.GlobalSymbols = miw64.GlobalSymbols;
1227 mi64.TypeInfo = miw64.TypeInfo;
1228 mi64.SourceIndexed = miw64.SourceIndexed;
1229 mi64.Publics = miw64.Publics;
1231 memcpy(ModuleInfo, &mi64, ModuleInfo->SizeOfStruct);
1233 return TRUE;
1236 /******************************************************************
1237 * SymGetModuleInfoW64 (DBGHELP.@)
1240 BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
1241 PIMAGEHLP_MODULEW64 ModuleInfo)
1243 struct process* pcs = process_find_by_handle(hProcess);
1244 struct module* module;
1245 IMAGEHLP_MODULEW64 miw64;
1247 TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
1249 if (!pcs) return FALSE;
1250 if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
1251 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
1252 if (!module) return FALSE;
1254 miw64 = module->module;
1256 /* update debug information from container if any */
1257 if (module->module.SymType == SymNone)
1259 module = module_get_container(pcs, module);
1260 if (module && module->module.SymType != SymNone)
1262 miw64.SymType = module->module.SymType;
1263 miw64.NumSyms = module->module.NumSyms;
1266 memcpy(ModuleInfo, &miw64, ModuleInfo->SizeOfStruct);
1267 return TRUE;
1270 /***********************************************************************
1271 * SymGetModuleBase (DBGHELP.@)
1273 DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
1275 DWORD64 ret;
1277 ret = SymGetModuleBase64(hProcess, dwAddr);
1278 return validate_addr64(ret) ? ret : 0;
1281 /***********************************************************************
1282 * SymGetModuleBase64 (DBGHELP.@)
1284 DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
1286 struct process* pcs = process_find_by_handle(hProcess);
1287 struct module* module;
1289 if (!pcs) return 0;
1290 module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
1291 if (!module) return 0;
1292 return module->module.BaseOfImage;
1295 /******************************************************************
1296 * module_reset_debug_info
1297 * Removes any debug information linked to a given module.
1299 void module_reset_debug_info(struct module* module)
1301 module->sortlist_valid = TRUE;
1302 module->sorttab_size = 0;
1303 module->addr_sorttab = NULL;
1304 module->num_sorttab = module->num_symbols = 0;
1305 hash_table_destroy(&module->ht_symbols);
1306 module->ht_symbols.num_buckets = 0;
1307 module->ht_symbols.buckets = NULL;
1308 hash_table_destroy(&module->ht_types);
1309 module->ht_types.num_buckets = 0;
1310 module->ht_types.buckets = NULL;
1311 module->vtypes.num_elts = 0;
1312 hash_table_destroy(&module->ht_symbols);
1313 module->sources_used = module->sources_alloc = 0;
1314 module->sources = NULL;
1317 /******************************************************************
1318 * SymRefreshModuleList (DBGHELP.@)
1320 BOOL WINAPI SymRefreshModuleList(HANDLE hProcess)
1322 struct process* pcs;
1324 TRACE("(%p)\n", hProcess);
1326 if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
1328 return pcs->loader->synchronize_module_list(pcs);
1331 /***********************************************************************
1332 * SymFunctionTableAccess (DBGHELP.@)
1334 PVOID WINAPI SymFunctionTableAccess(HANDLE hProcess, DWORD AddrBase)
1336 return SymFunctionTableAccess64(hProcess, AddrBase);
1339 /***********************************************************************
1340 * SymFunctionTableAccess64 (DBGHELP.@)
1342 PVOID WINAPI SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase)
1344 struct process* pcs = process_find_by_handle(hProcess);
1345 struct module* module;
1347 if (!pcs || !dbghelp_current_cpu->find_runtime_function) return NULL;
1348 module = module_find_by_addr(pcs, AddrBase, DMT_UNKNOWN);
1349 if (!module) return NULL;
1351 return dbghelp_current_cpu->find_runtime_function(module, AddrBase);
1354 static BOOL native_synchronize_module_list(struct process* pcs)
1356 return FALSE;
1359 static struct module* native_load_module(struct process* pcs, const WCHAR* name, ULONG_PTR addr)
1361 return NULL;
1364 static BOOL native_load_debug_info(struct process* process, struct module* module)
1366 return FALSE;
1369 static BOOL native_enum_modules(struct process *process, enum_modules_cb cb, void* user)
1371 return FALSE;
1374 static BOOL native_fetch_file_info(struct process* process, const WCHAR* name, ULONG_PTR load_addr, DWORD_PTR* base,
1375 DWORD* size, DWORD* checksum)
1377 return FALSE;
1380 const struct loader_ops no_loader_ops =
1382 native_synchronize_module_list,
1383 native_load_module,
1384 native_load_debug_info,
1385 native_enum_modules,
1386 native_fetch_file_info,