2 * File dbghelp_private.h - dbghelp internal definitions
4 * Copyright (C) 1995, Alexandre Julliard
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999-2000, Ulrich Weigand.
7 * Copyright (C) 2004-2007, Eric Pouech.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/list.h"
33 #include "wine/unicode.h"
37 /* #define USE_STATS */
39 struct pool
/* poor's man */
41 struct list arena_list
;
42 struct list arena_full
;
46 void pool_init(struct pool
* a
, size_t arena_size
);
47 void pool_destroy(struct pool
* a
);
48 void* pool_alloc(struct pool
* a
, size_t len
);
49 char* pool_strdup(struct pool
* a
, const char* str
);
58 unsigned buckets_allocated
;
61 void vector_init(struct vector
* v
, unsigned elt_sz
, unsigned bucket_sz
);
62 unsigned vector_length(const struct vector
* v
);
63 void* vector_at(const struct vector
* v
, unsigned pos
);
64 void* vector_add(struct vector
* v
, struct pool
* pool
);
68 struct vector key2index
;
69 struct vector elements
;
72 void sparse_array_init(struct sparse_array
* sa
, unsigned elt_sz
, unsigned bucket_sz
);
73 void* sparse_array_find(const struct sparse_array
* sa
, unsigned long idx
);
74 void* sparse_array_add(struct sparse_array
* sa
, unsigned long key
, struct pool
* pool
);
75 unsigned sparse_array_length(const struct sparse_array
* sa
);
80 struct hash_table_elt
* next
;
87 struct hash_table_elt
** buckets
;
91 void hash_table_init(struct pool
* pool
, struct hash_table
* ht
,
92 unsigned num_buckets
);
93 void hash_table_destroy(struct hash_table
* ht
);
94 void hash_table_add(struct hash_table
* ht
, struct hash_table_elt
* elt
);
96 struct hash_table_iter
98 const struct hash_table
* ht
;
99 struct hash_table_elt
* element
;
104 void hash_table_iter_init(const struct hash_table
* ht
,
105 struct hash_table_iter
* hti
, const char* name
);
106 void* hash_table_iter_up(struct hash_table_iter
* hti
);
108 #define GET_ENTRY(__i, __t, __f) \
109 ((__t*)((char*)(__i) - FIELD_OFFSET(__t,__f)))
112 extern unsigned dbghelp_options
;
113 /* some more Wine extensions */
114 #define SYMOPT_WINE_WITH_NATIVE_MODULES 0x40000000
116 enum location_kind
{loc_error
, /* reg is the error code */
117 loc_absolute
, /* offset is the location */
118 loc_register
, /* reg is the location */
119 loc_regrel
, /* [reg+offset] is the location */
120 loc_user
, /* value is debug information dependent,
121 reg & offset can be used ad libidem */
124 enum location_error
{loc_err_internal
= -1, /* internal while computing */
125 loc_err_too_complex
= -2, /* couldn't compute location (even at runtime) */
126 loc_err_out_of_scope
= -3, /* variable isn't available at current address */
127 loc_err_cant_read
= -4, /* couldn't read memory at given address */
134 unsigned long offset
;
145 struct hash_table_elt hash_elt
; /* if global symbol or type */
152 unsigned long address
;
154 struct symt
* container
; /* block, or func */
155 struct vector vchildren
; /* sub-blocks & local variables */
158 struct symt_compiland
161 unsigned long address
;
163 struct vector vchildren
; /* global variables & functions */
169 struct hash_table_elt hash_elt
; /* if global symbol */
171 struct symt
* container
;
173 union /* depends on kind */
175 /* DataIs{Global, FileStatic}:
176 * loc.kind is loc_absolute
177 * loc.offset is address
178 * DataIs{Local,Param}:
180 * loc_absolute not supported
181 * loc_register location is in register loc.reg
182 * loc_regrel location is at address loc.reg + loc.offset
183 * >= loc_user ask debug info provider for resolution
186 /* DataIs{Member} (all values are in bits, not bytes) */
190 unsigned long length
;
200 struct hash_table_elt hash_elt
; /* if global symbol */
201 unsigned long address
;
202 struct symt
* container
; /* compiland */
203 struct symt
* type
; /* points to function_signature */
205 struct vector vlines
;
206 struct vector vchildren
; /* locals, params, blocks, start/end, labels */
209 struct symt_hierarchy_point
211 struct symt symt
; /* either SymTagFunctionDebugStart, SymTagFunctionDebugEnd, SymTagLabel */
212 struct hash_table_elt hash_elt
; /* if label (and in compiland's hash table if global) */
213 struct symt
* parent
; /* symt_function or symt_compiland */
220 struct hash_table_elt hash_elt
;
221 struct symt
* container
; /* compiland */
222 unsigned long address
;
224 unsigned in_code
: 1,
231 struct hash_table_elt hash_elt
;
232 struct symt
* container
; /* compiland */
233 unsigned long address
;
235 THUNK_ORDINAL ordinal
; /* FIXME: doesn't seem to be accessible */
244 struct symt
* base_type
;
245 struct symt
* index_type
;
251 struct hash_table_elt hash_elt
;
259 struct symt
* base_type
;
261 struct vector vchildren
;
264 struct symt_function_signature
267 struct symt
* rettype
;
268 struct vector vchildren
;
269 enum CV_call_e call_conv
;
272 struct symt_function_arg_type
275 struct symt
* arg_type
;
276 struct symt
* container
;
282 struct symt
* pointsto
;
288 struct hash_table_elt hash_elt
;
295 struct hash_table_elt hash_elt
;
298 struct vector vchildren
;
303 DMT_UNKNOWN
, /* for lookup, not actually used for a module */
304 DMT_ELF
, /* a real ELF shared module */
305 DMT_PE
, /* a native or builtin PE module */
306 DMT_MACHO
, /* a real Mach-O shared module */
307 DMT_PDB
, /* .PDB file */
308 DMT_DBG
, /* .DBG file */
315 IMAGEHLP_MODULEW64 module
;
316 /* ANSI copy of module.ModuleName for efficiency */
317 char module_name
[MAX_PATH
];
319 enum module_type type
: 16;
320 unsigned short is_virtual
: 1;
322 /* specific information for debug types */
323 struct elf_module_info
* elf_info
;
324 struct dwarf2_module_info_s
*dwarf2_info
;
326 struct macho_module_info
* macho_info
;
328 /* memory allocation pool */
331 /* symbols & symbol tables */
333 unsigned num_sorttab
; /* number of symbols with addresses */
334 struct symt_ht
** addr_sorttab
;
335 struct hash_table ht_symbols
;
336 void (*loc_compute
)(struct process
* pcs
,
337 const struct module
* module
,
338 const struct symt_function
* func
,
339 struct location
* loc
);
342 struct hash_table ht_types
;
343 struct vector vtypes
;
346 unsigned sources_used
;
347 unsigned sources_alloc
;
353 struct process
* next
;
357 PSYMBOL_REGISTERED_CALLBACK64 reg_cb
;
361 struct module
* lmodules
;
362 unsigned long dbg_hdr_addr
;
364 IMAGEHLP_STACK_FRAME ctx_frame
;
366 unsigned buffer_size
;
372 unsigned long is_first
: 1,
378 unsigned long pc_offset
; /* if is_source_file isn't set */
379 unsigned source_file
; /* if is_source_file is set */
386 struct module
* requested
; /* in: to module_get_debug() */
387 struct module
* effective
; /* out: module with debug info */
390 enum pdb_kind
{PDB_JG
, PDB_DS
};
394 const char* filename
;
402 struct PDB_JG_TOC
* toc
;
407 struct PDB_DS_TOC
* toc
;
413 extern struct process
* process_find_by_handle(HANDLE hProcess
);
414 extern HANDLE hMsvcrt
;
415 extern BOOL
validate_addr64(DWORD64 addr
);
416 extern BOOL
pcs_callback(const struct process
* pcs
, ULONG action
, void* data
);
417 extern void* fetch_buffer(struct process
* pcs
, unsigned size
);
420 extern DWORD
calc_crc32(int fd
);
422 typedef BOOL (*enum_modules_cb
)(const WCHAR
*, unsigned long addr
, void* user
);
425 #define ELF_NO_MAP ((const void*)-1)
426 extern BOOL
elf_enum_modules(HANDLE hProc
, enum_modules_cb
, void*);
427 extern BOOL
elf_fetch_file_info(const WCHAR
* name
, DWORD
* base
, DWORD
* size
, DWORD
* checksum
);
429 extern BOOL
elf_load_debug_info(struct module
* module
, struct elf_file_map
* fmap
);
430 extern struct module
*
431 elf_load_module(struct process
* pcs
, const WCHAR
* name
, unsigned long);
432 extern BOOL
elf_read_wine_loader_dbg_info(struct process
* pcs
);
433 extern BOOL
elf_synchronize_module_list(struct process
* pcs
);
434 struct elf_thunk_area
;
435 extern int elf_is_in_thunk_area(unsigned long addr
, const struct elf_thunk_area
* thunks
);
436 extern DWORD WINAPI
addr_to_linear(HANDLE hProcess
, HANDLE hThread
, ADDRESS
* addr
);
439 #define MACHO_NO_MAP ((const void*)-1)
440 extern BOOL
macho_enum_modules(HANDLE hProc
, enum_modules_cb
, void*);
441 extern BOOL
macho_fetch_file_info(const WCHAR
* name
, DWORD
* base
, DWORD
* size
, DWORD
* checksum
);
442 struct macho_file_map
;
443 extern BOOL
macho_load_debug_info(struct module
* module
, struct macho_file_map
* fmap
);
444 extern struct module
*
445 macho_load_module(struct process
* pcs
, const WCHAR
* name
, unsigned long);
446 extern BOOL
macho_read_wine_loader_dbg_info(struct process
* pcs
);
447 extern BOOL
macho_synchronize_module_list(struct process
* pcs
);
450 extern const WCHAR S_ElfW
[];
451 extern const WCHAR S_WineLoaderW
[];
452 extern const WCHAR S_WineW
[];
453 extern const WCHAR S_SlashW
[];
455 extern struct module
*
456 module_find_by_addr(const struct process
* pcs
, unsigned long addr
,
457 enum module_type type
);
458 extern struct module
*
459 module_find_by_nameA(const struct process
* pcs
,
461 extern struct module
*
462 module_is_already_loaded(const struct process
* pcs
,
463 const WCHAR
* imgname
);
464 extern BOOL
module_get_debug(struct module_pair
*);
465 extern struct module
*
466 module_new(struct process
* pcs
, const WCHAR
* name
,
467 enum module_type type
, BOOL
virtual,
468 unsigned long addr
, unsigned long size
,
469 unsigned long stamp
, unsigned long checksum
);
470 extern struct module
*
471 module_get_containee(const struct process
* pcs
,
472 const struct module
* inner
);
473 extern enum module_type
474 module_get_type_by_name(const WCHAR
* name
);
475 extern void module_reset_debug_info(struct module
* module
);
476 extern BOOL
module_remove(struct process
* pcs
,
477 struct module
* module
);
478 extern void module_set_module(struct module
* module
, const WCHAR
* name
);
481 extern BOOL
pe_load_debug_directory(const struct process
* pcs
,
482 struct module
* module
,
484 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
485 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
);
486 extern BOOL
pdb_fetch_file_info(struct pdb_lookup
* pdb_lookup
);
489 extern BOOL
path_find_symbol_file(const struct process
* pcs
, PCSTR full_path
,
490 const GUID
* guid
, DWORD dw1
, DWORD dw2
, PSTR buffer
,
494 extern BOOL
pe_load_nt_header(HANDLE hProc
, DWORD base
, IMAGE_NT_HEADERS
* nth
);
495 extern struct module
*
496 pe_load_native_module(struct process
* pcs
, const WCHAR
* name
,
497 HANDLE hFile
, DWORD base
, DWORD size
);
498 extern struct module
*
499 pe_load_builtin_module(struct process
* pcs
, const WCHAR
* name
,
500 DWORD base
, DWORD size
);
501 extern BOOL
pe_load_debug_info(const struct process
* pcs
,
502 struct module
* module
);
504 extern unsigned source_new(struct module
* module
, const char* basedir
, const char* source
);
505 extern const char* source_get(const struct module
* module
, unsigned idx
);
508 typedef void (*stabs_def_cb
)(struct module
* module
, unsigned long load_offset
,
509 const char* name
, unsigned long offset
,
510 BOOL is_public
, BOOL is_global
, unsigned char other
,
511 struct symt_compiland
* compiland
, void* user
);
512 extern BOOL
stabs_parse(struct module
* module
, unsigned long load_offset
,
513 const void* stabs
, int stablen
,
514 const char* strs
, int strtablen
,
515 stabs_def_cb callback
, void* user
);
518 extern BOOL
dwarf2_parse(struct module
* module
, unsigned long load_offset
,
519 const struct elf_thunk_area
* thunks
,
520 const unsigned char* debug
, unsigned int debug_size
,
521 const unsigned char* abbrev
, unsigned int abbrev_size
,
522 const unsigned char* str
, unsigned int str_size
,
523 const unsigned char* line
, unsigned int line_size
,
524 const unsigned char* loclist
, unsigned int loclist_size
);
527 extern const char* symt_get_name(const struct symt
* sym
);
528 extern int symt_cmp_addr(const void* p1
, const void* p2
);
529 extern void copy_symbolW(SYMBOL_INFOW
* siw
, const SYMBOL_INFO
* si
);
530 extern struct symt_ht
*
531 symt_find_nearest(struct module
* module
, DWORD addr
);
532 extern struct symt_compiland
*
533 symt_new_compiland(struct module
* module
, unsigned long address
,
535 extern struct symt_public
*
536 symt_new_public(struct module
* module
,
537 struct symt_compiland
* parent
,
538 const char* typename
,
539 unsigned long address
, unsigned size
,
540 BOOL in_code
, BOOL is_func
);
541 extern struct symt_data
*
542 symt_new_global_variable(struct module
* module
,
543 struct symt_compiland
* parent
,
544 const char* name
, unsigned is_static
,
545 unsigned long addr
, unsigned long size
,
547 extern struct symt_function
*
548 symt_new_function(struct module
* module
,
549 struct symt_compiland
* parent
,
551 unsigned long addr
, unsigned long size
,
553 extern BOOL
symt_normalize_function(struct module
* module
,
554 struct symt_function
* func
);
555 extern void symt_add_func_line(struct module
* module
,
556 struct symt_function
* func
,
557 unsigned source_idx
, int line_num
,
558 unsigned long offset
);
559 extern struct symt_data
*
560 symt_add_func_local(struct module
* module
,
561 struct symt_function
* func
,
562 enum DataKind dt
, const struct location
* loc
,
563 struct symt_block
* block
,
564 struct symt
* type
, const char* name
);
565 extern struct symt_block
*
566 symt_open_func_block(struct module
* module
,
567 struct symt_function
* func
,
568 struct symt_block
* block
,
569 unsigned pc
, unsigned len
);
570 extern struct symt_block
*
571 symt_close_func_block(struct module
* module
,
572 struct symt_function
* func
,
573 struct symt_block
* block
, unsigned pc
);
574 extern struct symt_hierarchy_point
*
575 symt_add_function_point(struct module
* module
,
576 struct symt_function
* func
,
577 enum SymTagEnum point
,
578 const struct location
* loc
,
580 extern BOOL
symt_fill_func_line_info(const struct module
* module
,
581 const struct symt_function
* func
,
582 DWORD addr
, IMAGEHLP_LINE
* line
);
583 extern BOOL
symt_get_func_line_next(const struct module
* module
, PIMAGEHLP_LINE line
);
584 extern struct symt_thunk
*
585 symt_new_thunk(struct module
* module
,
586 struct symt_compiland
* parent
,
587 const char* name
, THUNK_ORDINAL ord
,
588 unsigned long addr
, unsigned long size
);
589 extern struct symt_data
*
590 symt_new_constant(struct module
* module
,
591 struct symt_compiland
* parent
,
592 const char* name
, struct symt
* type
,
594 extern struct symt_hierarchy_point
*
595 symt_new_label(struct module
* module
,
596 struct symt_compiland
* compiland
,
597 const char* name
, unsigned long address
);
600 extern void symt_init_basic(struct module
* module
);
601 extern BOOL
symt_get_info(const struct symt
* type
,
602 IMAGEHLP_SYMBOL_TYPE_INFO req
, void* pInfo
);
603 extern struct symt_basic
*
604 symt_new_basic(struct module
* module
, enum BasicType
,
605 const char* typename
, unsigned size
);
606 extern struct symt_udt
*
607 symt_new_udt(struct module
* module
, const char* typename
,
608 unsigned size
, enum UdtKind kind
);
609 extern BOOL
symt_set_udt_size(struct module
* module
,
610 struct symt_udt
* type
, unsigned size
);
611 extern BOOL
symt_add_udt_element(struct module
* module
,
612 struct symt_udt
* udt_type
,
614 struct symt
* elt_type
, unsigned offset
,
616 extern struct symt_enum
*
617 symt_new_enum(struct module
* module
, const char* typename
,
618 struct symt
* basetype
);
619 extern BOOL
symt_add_enum_element(struct module
* module
,
620 struct symt_enum
* enum_type
,
621 const char* name
, int value
);
622 extern struct symt_array
*
623 symt_new_array(struct module
* module
, int min
, int max
,
624 struct symt
* base
, struct symt
* index
);
625 extern struct symt_function_signature
*
626 symt_new_function_signature(struct module
* module
,
627 struct symt
* ret_type
,
628 enum CV_call_e call_conv
);
629 extern BOOL
symt_add_function_signature_parameter(struct module
* module
,
630 struct symt_function_signature
* sig
,
632 extern struct symt_pointer
*
633 symt_new_pointer(struct module
* module
,
634 struct symt
* ref_type
);
635 extern struct symt_typedef
*
636 symt_new_typedef(struct module
* module
, struct symt
* ref
,