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
27 #include "dbghelp_private.h"
28 #include "image_private.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
;
56 for (e
= ext
; *e
; e
++)
59 if (l
>= len
) return 0;
60 if (wcsnicmp(&ptr
[len
- l
], *e
, l
)) continue;
66 static const WCHAR
* get_filename(const WCHAR
* name
, const WCHAR
* endptr
)
70 if (!endptr
) endptr
= name
+ lstrlenW(name
);
71 for (ptr
= endptr
- 1; ptr
>= name
; ptr
--)
73 if (*ptr
== '/' || *ptr
== '\\') break;
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
);
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
);
97 buffer
= heap_alloc( sizeof(wineW
) + 2 * sizeof(WCHAR
) );
98 lstrcpyW( buffer
, wineW
);
101 if (!wcscmp( filename
, buffer
))
104 lstrcatW( buffer
, suffixW
);
105 if (!wcscmp( filename
, buffer
))
112 static void module_fill_module(const WCHAR
* in
, WCHAR
* out
, size_t size
)
114 const WCHAR
*ptr
, *endptr
;
117 ptr
= get_filename(in
, endptr
= in
+ lstrlenW(in
));
118 len
= min(endptr
- ptr
, size
- 1);
119 memcpy(out
, ptr
, len
* sizeof(WCHAR
));
121 if (len
> 4 && (l
= match_ext(out
, len
)))
123 else if (is_wine_loader(out
))
124 lstrcpynW(out
, S_WineLoaderW
, size
);
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};
148 /* All binaries are loaded with WINELOADER (if run from tree) or by the
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
);
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
))
168 lstrcatW(buffer
, suffixW
);
170 TRACE( "returning %s\n", debugstr_w(buffer
) );
174 static const char* get_module_type(enum module_type type
, BOOL
virtual)
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
;
196 assert(type
== DMT_ELF
|| type
== DMT_PE
|| type
== DMT_MACHO
);
197 if (!(module
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*module
))))
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
),
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;
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;
257 wine_rb_init(&module
->sources_offsets_tree
, source_rb_compare
);
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
);
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
))
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
)))
308 SetLastError(ERROR_INVALID_NAME
);
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
)
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
)
351 /******************************************************************
354 * get the debug information from a module:
355 * - if the module's type is deferred, then force loading of debug info (and return
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
)
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
,
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
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
)))
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
)
428 SetLastError(ERROR_MOD_NOT_FOUND
);
432 /******************************************************************
433 * module_is_container_loaded
435 * checks whether the native container, for a (supposed) PE builtin is
438 static BOOL
module_is_container_loaded(const struct process
* pcs
,
439 const WCHAR
* ImageName
, DWORD64 base
)
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
)))
463 /* likely a native PE module */
464 WARN("Couldn't find container for %s\n", debugstr_w(ImageName
));
468 static BOOL
image_check_debug_link(const WCHAR
* file
, struct image_file_map
* fmap
, DWORD link_crc
)
476 path
= get_dos_file_name(file
);
477 handle
= CreateFileW(path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
479 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
483 DWORD crc
= calc_crc32(handle
);
486 WARN("Bad CRC for file %s (got %08x while expecting %08x)\n", debugstr_w(file
), crc
, link_crc
);
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
);
496 ret
= elf_map_handle(handle
, fmap
);
501 /******************************************************************
502 * image_locate_debug_link
504 * Locate a filename from a .gnu_debuglink section, using the same
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
;
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
));
541 /* we prebuild the string with "execdir" */
542 lstrcpyW(p
, module
->module
.LoadedImageName
);
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
);
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
);
583 TRACE("Located debug information file %s at %s\n", filename
, debugstr_w(p
));
584 HeapFree(GetProcessHeap(), 0, p
);
585 fmap
->alternate
= fmap_link
;
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
;
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
));
611 memcpy(z
, globalDebugDirW
, sizeof(globalDebugDirW
));
612 z
+= ARRAY_SIZE(globalDebugDirW
);
613 memcpy(z
, buildidW
, sizeof(buildidW
));
614 z
+= ARRAY_SIZE(buildidW
);
618 *z
++ = "0123456789abcdef"[*id
>> 4 ];
619 *z
++ = "0123456789abcdef"[*id
& 0x0F];
626 *z
++ = "0123456789abcdef"[*id
>> 4 ];
627 *z
++ = "0123456789abcdef"[*id
& 0x0F];
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
))
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
;
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
);
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
)
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
))
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
;
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
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
);
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
,
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
;
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
);
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
;
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
);
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
)
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
);
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
;
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
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
);
823 /* otherwise, try a regular PE module */
824 if (!(module
= pe_load_native_module(pcs
, wImageName
, hFile
, BaseOfDll
, SizeOfDll
)) &&
827 /* and finally an ELF or Mach-O module */
828 module
= pcs
->loader
->load_module(pcs
, wImageName
, BaseOfDll
);
833 WARN("Couldn't locate %s\n", debugstr_w(wImageName
));
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
841 module_set_module(module
, wModuleName
);
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
,
858 /******************************************************************
862 BOOL
module_remove(struct process
* pcs
, struct module
* module
)
864 struct module_format
*modfmt
;
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
884 for (p
= &pcs
->lmodules
; *p
; p
= &(*p
)->next
)
889 HeapFree(GetProcessHeap(), 0, module
);
893 FIXME("This shouldn't happen\n");
897 /******************************************************************
898 * SymUnloadModule (DBGHELP.@)
901 BOOL WINAPI
SymUnloadModule(HANDLE hProcess
, DWORD BaseOfDll
)
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
)
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
;
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
,
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
;
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
,
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
,
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
))
1010 if (!EnumModulesCallback(module
->modulename
,
1011 module
->module
.BaseOfImage
, UserContext
))
1017 /******************************************************************
1018 * EnumerateLoadedModules64 (DBGHELP.@)
1021 struct enum_load_modW64_64
1023 PENUMLOADED_MODULES_CALLBACK64 cb
;
1025 char module
[MAX_PATH
];
1028 static BOOL CALLBACK
enum_load_modW64_64(PCWSTR name
, DWORD64 base
, ULONG size
,
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
,
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
;
1057 char module
[MAX_PATH
];
1060 static BOOL CALLBACK
enum_load_modW64_32(PCWSTR name
, DWORD64 base
, ULONG size
,
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
,
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
,
1089 WCHAR baseW
[256], modW
[256];
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
);
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
)))
1109 module_fill_module(baseW
, modW
, ARRAY_SIZE(modW
));
1110 EnumLoadedModulesCallback(modW
, (DWORD_PTR
)mi
.lpBaseOfDll
, mi
.SizeOfImage
,
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
)
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
);
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
);
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
);
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
);
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
);
1269 /***********************************************************************
1270 * SymGetModuleBase (DBGHELP.@)
1272 DWORD WINAPI
SymGetModuleBase(HANDLE hProcess
, DWORD dwAddr
)
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
;
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
)
1358 static struct module
* native_load_module(struct process
* pcs
, const WCHAR
* name
, ULONG_PTR addr
)
1363 static BOOL
native_load_debug_info(struct process
* process
, struct module
* module
)
1368 static BOOL
native_enum_modules(struct process
*process
, enum_modules_cb cb
, void* user
)
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
)
1379 const struct loader_ops no_loader_ops
=
1381 native_synchronize_module_list
,
1383 native_load_debug_info
,
1384 native_enum_modules
,
1385 native_fetch_file_info
,