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
;
83 struct hash_table_bucket
85 struct hash_table_elt
* first
;
86 struct hash_table_elt
* last
;
93 struct hash_table_bucket
* buckets
;
97 void hash_table_init(struct pool
* pool
, struct hash_table
* ht
,
98 unsigned num_buckets
);
99 void hash_table_destroy(struct hash_table
* ht
);
100 void hash_table_add(struct hash_table
* ht
, struct hash_table_elt
* elt
);
102 struct hash_table_iter
104 const struct hash_table
* ht
;
105 struct hash_table_elt
* element
;
110 void hash_table_iter_init(const struct hash_table
* ht
,
111 struct hash_table_iter
* hti
, const char* name
);
112 void* hash_table_iter_up(struct hash_table_iter
* hti
);
114 #define GET_ENTRY(__i, __t, __f) \
115 ((__t*)((char*)(__i) - FIELD_OFFSET(__t,__f)))
118 extern unsigned dbghelp_options
;
119 /* some more Wine extensions */
120 #define SYMOPT_WINE_WITH_NATIVE_MODULES 0x40000000
122 enum location_kind
{loc_error
, /* reg is the error code */
123 loc_absolute
, /* offset is the location */
124 loc_register
, /* reg is the location */
125 loc_regrel
, /* [reg+offset] is the location */
126 loc_user
, /* value is debug information dependent,
127 reg & offset can be used ad libidem */
130 enum location_error
{loc_err_internal
= -1, /* internal while computing */
131 loc_err_too_complex
= -2, /* couldn't compute location (even at runtime) */
132 loc_err_out_of_scope
= -3, /* variable isn't available at current address */
133 loc_err_cant_read
= -4, /* couldn't read memory at given address */
140 unsigned long offset
;
151 struct hash_table_elt hash_elt
; /* if global symbol or type */
158 unsigned long address
;
160 struct symt
* container
; /* block, or func */
161 struct vector vchildren
; /* sub-blocks & local variables */
164 struct symt_compiland
167 unsigned long address
;
169 struct vector vchildren
; /* global variables & functions */
175 struct hash_table_elt hash_elt
; /* if global symbol */
177 struct symt
* container
;
179 union /* depends on kind */
181 /* DataIs{Global, FileStatic}:
182 * loc.kind is loc_absolute
183 * loc.offset is address
184 * DataIs{Local,Param}:
186 * loc_absolute not supported
187 * loc_register location is in register loc.reg
188 * loc_regrel location is at address loc.reg + loc.offset
189 * >= loc_user ask debug info provider for resolution
192 /* DataIs{Member} (all values are in bits, not bytes) */
196 unsigned long length
;
206 struct hash_table_elt hash_elt
; /* if global symbol */
207 unsigned long address
;
208 struct symt
* container
; /* compiland */
209 struct symt
* type
; /* points to function_signature */
211 struct vector vlines
;
212 struct vector vchildren
; /* locals, params, blocks, start/end, labels */
215 struct symt_hierarchy_point
217 struct symt symt
; /* either SymTagFunctionDebugStart, SymTagFunctionDebugEnd, SymTagLabel */
218 struct hash_table_elt hash_elt
; /* if label (and in compiland's hash table if global) */
219 struct symt
* parent
; /* symt_function or symt_compiland */
226 struct hash_table_elt hash_elt
;
227 struct symt
* container
; /* compiland */
228 unsigned long address
;
230 unsigned in_code
: 1,
237 struct hash_table_elt hash_elt
;
238 struct symt
* container
; /* compiland */
239 unsigned long address
;
241 THUNK_ORDINAL ordinal
; /* FIXME: doesn't seem to be accessible */
249 int end
; /* end index if > 0, or -array_len (in bytes) if < 0 */
250 struct symt
* base_type
;
251 struct symt
* index_type
;
257 struct hash_table_elt hash_elt
;
265 struct symt
* base_type
;
267 struct vector vchildren
;
270 struct symt_function_signature
273 struct symt
* rettype
;
274 struct vector vchildren
;
275 enum CV_call_e call_conv
;
278 struct symt_function_arg_type
281 struct symt
* arg_type
;
282 struct symt
* container
;
288 struct symt
* pointsto
;
294 struct hash_table_elt hash_elt
;
301 struct hash_table_elt hash_elt
;
304 struct vector vchildren
;
309 DMT_UNKNOWN
, /* for lookup, not actually used for a module */
310 DMT_ELF
, /* a real ELF shared module */
311 DMT_PE
, /* a native or builtin PE module */
312 DMT_MACHO
, /* a real Mach-O shared module */
313 DMT_PDB
, /* .PDB file */
314 DMT_DBG
, /* .DBG file */
321 IMAGEHLP_MODULEW64 module
;
322 /* ANSI copy of module.ModuleName for efficiency */
323 char module_name
[MAX_PATH
];
325 enum module_type type
: 16;
326 unsigned short is_virtual
: 1;
328 /* specific information for debug types */
329 struct elf_module_info
* elf_info
;
330 struct dwarf2_module_info_s
*dwarf2_info
;
332 struct macho_module_info
* macho_info
;
334 /* memory allocation pool */
337 /* symbols & symbol tables */
340 unsigned num_sorttab
; /* number of symbols with addresses */
341 unsigned num_symbols
;
342 unsigned sorttab_size
;
343 struct symt_ht
** addr_sorttab
;
344 struct hash_table ht_symbols
;
345 void (*loc_compute
)(struct process
* pcs
,
346 const struct module
* module
,
347 const struct symt_function
* func
,
348 struct location
* loc
);
351 struct hash_table ht_types
;
352 struct vector vtypes
;
355 unsigned sources_used
;
356 unsigned sources_alloc
;
362 struct process
* next
;
366 PSYMBOL_REGISTERED_CALLBACK64 reg_cb
;
367 PSYMBOL_REGISTERED_CALLBACK reg_cb32
;
371 struct module
* lmodules
;
372 unsigned long dbg_hdr_addr
;
374 IMAGEHLP_STACK_FRAME ctx_frame
;
376 unsigned buffer_size
;
382 unsigned long is_first
: 1,
388 unsigned long pc_offset
; /* if is_source_file isn't set */
389 unsigned source_file
; /* if is_source_file is set */
396 struct module
* requested
; /* in: to module_get_debug() */
397 struct module
* effective
; /* out: module with debug info */
400 enum pdb_kind
{PDB_JG
, PDB_DS
};
404 const char* filename
;
412 struct PDB_JG_TOC
* toc
;
417 struct PDB_DS_TOC
* toc
;
422 struct cpu_stack_walk
431 PREAD_PROCESS_MEMORY_ROUTINE f_read_mem
;
432 PTRANSLATE_ADDRESS_ROUTINE f_xlat_adr
;
433 PFUNCTION_TABLE_ACCESS_ROUTINE f_tabl_acs
;
434 PGET_MODULE_BASE_ROUTINE f_modl_bas
;
438 PREAD_PROCESS_MEMORY_ROUTINE64 f_read_mem
;
439 PTRANSLATE_ADDRESS_ROUTINE64 f_xlat_adr
;
440 PFUNCTION_TABLE_ACCESS_ROUTINE64 f_tabl_acs
;
441 PGET_MODULE_BASE_ROUTINE64 f_modl_bas
;
446 enum cpu_addr
{cpu_addr_pc
, cpu_addr_stack
, cpu_addr_frame
};
451 /* address manipulation */
452 unsigned (*get_addr
)(HANDLE hThread
, const CONTEXT
* ctx
,
453 enum cpu_addr
, ADDRESS64
* addr
);
455 /* stack manipulation */
456 BOOL (*stack_walk
)(struct cpu_stack_walk
* csw
, LPSTACKFRAME64 frame
);
459 extern struct cpu
* dbghelp_current_cpu
;
462 extern struct process
* process_find_by_handle(HANDLE hProcess
);
463 extern HANDLE hMsvcrt
;
464 extern BOOL
validate_addr64(DWORD64 addr
);
465 extern BOOL
pcs_callback(const struct process
* pcs
, ULONG action
, void* data
);
466 extern void* fetch_buffer(struct process
* pcs
, unsigned size
);
467 extern const char* wine_dbgstr_addr(const ADDRESS64
* addr
);
468 extern struct cpu
* cpu_find(DWORD
);
471 extern DWORD
calc_crc32(int fd
);
473 typedef BOOL (*enum_modules_cb
)(const WCHAR
*, unsigned long addr
, void* user
);
476 #define ELF_NO_MAP ((const void*)-1)
477 extern BOOL
elf_enum_modules(HANDLE hProc
, enum_modules_cb
, void*);
478 extern BOOL
elf_fetch_file_info(const WCHAR
* name
, DWORD
* base
, DWORD
* size
, DWORD
* checksum
);
480 extern BOOL
elf_load_debug_info(struct module
* module
, struct elf_file_map
* fmap
);
481 extern struct module
*
482 elf_load_module(struct process
* pcs
, const WCHAR
* name
, unsigned long);
483 extern BOOL
elf_read_wine_loader_dbg_info(struct process
* pcs
);
484 extern BOOL
elf_synchronize_module_list(struct process
* pcs
);
485 struct elf_thunk_area
;
486 extern int elf_is_in_thunk_area(unsigned long addr
, const struct elf_thunk_area
* thunks
);
489 #define MACHO_NO_MAP ((const void*)-1)
490 extern BOOL
macho_enum_modules(HANDLE hProc
, enum_modules_cb
, void*);
491 extern BOOL
macho_fetch_file_info(const WCHAR
* name
, DWORD
* base
, DWORD
* size
, DWORD
* checksum
);
492 struct macho_file_map
;
493 extern BOOL
macho_load_debug_info(struct module
* module
, struct macho_file_map
* fmap
);
494 extern struct module
*
495 macho_load_module(struct process
* pcs
, const WCHAR
* name
, unsigned long);
496 extern BOOL
macho_read_wine_loader_dbg_info(struct process
* pcs
);
497 extern BOOL
macho_synchronize_module_list(struct process
* pcs
);
500 extern const WCHAR S_ElfW
[];
501 extern const WCHAR S_WineLoaderW
[];
502 extern const WCHAR S_WineW
[];
503 extern const WCHAR S_SlashW
[];
505 extern struct module
*
506 module_find_by_addr(const struct process
* pcs
, unsigned long addr
,
507 enum module_type type
);
508 extern struct module
*
509 module_find_by_nameA(const struct process
* pcs
,
511 extern struct module
*
512 module_is_already_loaded(const struct process
* pcs
,
513 const WCHAR
* imgname
);
514 extern BOOL
module_get_debug(struct module_pair
*);
515 extern struct module
*
516 module_new(struct process
* pcs
, const WCHAR
* name
,
517 enum module_type type
, BOOL
virtual,
518 DWORD64 addr
, DWORD64 size
,
519 unsigned long stamp
, unsigned long checksum
);
520 extern struct module
*
521 module_get_containee(const struct process
* pcs
,
522 const struct module
* inner
);
523 extern enum module_type
524 module_get_type_by_name(const WCHAR
* name
);
525 extern void module_reset_debug_info(struct module
* module
);
526 extern BOOL
module_remove(struct process
* pcs
,
527 struct module
* module
);
528 extern void module_set_module(struct module
* module
, const WCHAR
* name
);
531 extern BOOL
pe_load_debug_directory(const struct process
* pcs
,
532 struct module
* module
,
534 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
535 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
);
536 extern BOOL
pdb_fetch_file_info(struct pdb_lookup
* pdb_lookup
);
539 extern BOOL
path_find_symbol_file(const struct process
* pcs
, PCSTR full_path
,
540 const GUID
* guid
, DWORD dw1
, DWORD dw2
, PSTR buffer
,
544 extern BOOL
pe_load_nt_header(HANDLE hProc
, DWORD64 base
, IMAGE_NT_HEADERS
* nth
);
545 extern struct module
*
546 pe_load_native_module(struct process
* pcs
, const WCHAR
* name
,
547 HANDLE hFile
, DWORD base
, DWORD size
);
548 extern struct module
*
549 pe_load_builtin_module(struct process
* pcs
, const WCHAR
* name
,
550 DWORD64 base
, DWORD64 size
);
551 extern BOOL
pe_load_debug_info(const struct process
* pcs
,
552 struct module
* module
);
554 extern unsigned source_new(struct module
* module
, const char* basedir
, const char* source
);
555 extern const char* source_get(const struct module
* module
, unsigned idx
);
558 typedef void (*stabs_def_cb
)(struct module
* module
, unsigned long load_offset
,
559 const char* name
, unsigned long offset
,
560 BOOL is_public
, BOOL is_global
, unsigned char other
,
561 struct symt_compiland
* compiland
, void* user
);
562 extern BOOL
stabs_parse(struct module
* module
, unsigned long load_offset
,
563 const void* stabs
, int stablen
,
564 const char* strs
, int strtablen
,
565 stabs_def_cb callback
, void* user
);
568 extern BOOL
dwarf2_parse(struct module
* module
, unsigned long load_offset
,
569 const struct elf_thunk_area
* thunks
,
570 const unsigned char* debug
, unsigned int debug_size
,
571 const unsigned char* abbrev
, unsigned int abbrev_size
,
572 const unsigned char* str
, unsigned int str_size
,
573 const unsigned char* line
, unsigned int line_size
,
574 const unsigned char* loclist
, unsigned int loclist_size
);
577 extern BOOL
sw_read_mem(struct cpu_stack_walk
* csw
, DWORD64 addr
, void* ptr
, DWORD sz
);
578 extern DWORD64
sw_xlat_addr(struct cpu_stack_walk
* csw
, ADDRESS64
* addr
);
579 extern void* sw_table_access(struct cpu_stack_walk
* csw
, DWORD64 addr
);
580 extern DWORD64
sw_module_base(struct cpu_stack_walk
* csw
, DWORD64 addr
);
583 extern const char* symt_get_name(const struct symt
* sym
);
584 extern struct module
* symt_cmp_addr_module
;
585 extern int symt_cmp_addr(const void* p1
, const void* p2
);
586 extern void copy_symbolW(SYMBOL_INFOW
* siw
, const SYMBOL_INFO
* si
);
587 extern struct symt_ht
*
588 symt_find_nearest(struct module
* module
, DWORD_PTR addr
);
589 extern struct symt_compiland
*
590 symt_new_compiland(struct module
* module
, unsigned long address
,
592 extern struct symt_public
*
593 symt_new_public(struct module
* module
,
594 struct symt_compiland
* parent
,
595 const char* typename
,
596 unsigned long address
, unsigned size
,
597 BOOL in_code
, BOOL is_func
);
598 extern struct symt_data
*
599 symt_new_global_variable(struct module
* module
,
600 struct symt_compiland
* parent
,
601 const char* name
, unsigned is_static
,
602 unsigned long addr
, unsigned long size
,
604 extern struct symt_function
*
605 symt_new_function(struct module
* module
,
606 struct symt_compiland
* parent
,
608 unsigned long addr
, unsigned long size
,
610 extern BOOL
symt_normalize_function(struct module
* module
,
611 const struct symt_function
* func
);
612 extern void symt_add_func_line(struct module
* module
,
613 struct symt_function
* func
,
614 unsigned source_idx
, int line_num
,
615 unsigned long offset
);
616 extern struct symt_data
*
617 symt_add_func_local(struct module
* module
,
618 struct symt_function
* func
,
619 enum DataKind dt
, const struct location
* loc
,
620 struct symt_block
* block
,
621 struct symt
* type
, const char* name
);
622 extern struct symt_block
*
623 symt_open_func_block(struct module
* module
,
624 struct symt_function
* func
,
625 struct symt_block
* block
,
626 unsigned pc
, unsigned len
);
627 extern struct symt_block
*
628 symt_close_func_block(struct module
* module
,
629 const struct symt_function
* func
,
630 struct symt_block
* block
, unsigned pc
);
631 extern struct symt_hierarchy_point
*
632 symt_add_function_point(struct module
* module
,
633 struct symt_function
* func
,
634 enum SymTagEnum point
,
635 const struct location
* loc
,
637 extern BOOL
symt_fill_func_line_info(const struct module
* module
,
638 const struct symt_function
* func
,
639 DWORD64 addr
, IMAGEHLP_LINE64
* line
);
640 extern BOOL
symt_get_func_line_next(const struct module
* module
, PIMAGEHLP_LINE64 line
);
641 extern struct symt_thunk
*
642 symt_new_thunk(struct module
* module
,
643 struct symt_compiland
* parent
,
644 const char* name
, THUNK_ORDINAL ord
,
645 unsigned long addr
, unsigned long size
);
646 extern struct symt_data
*
647 symt_new_constant(struct module
* module
,
648 struct symt_compiland
* parent
,
649 const char* name
, struct symt
* type
,
651 extern struct symt_hierarchy_point
*
652 symt_new_label(struct module
* module
,
653 struct symt_compiland
* compiland
,
654 const char* name
, unsigned long address
);
655 extern struct symt
* symt_index2ptr(struct module
* module
, DWORD id
);
656 extern DWORD
symt_ptr2index(struct module
* module
, const struct symt
* sym
);
659 extern void symt_init_basic(struct module
* module
);
660 extern BOOL
symt_get_info(struct module
* module
, const struct symt
* type
,
661 IMAGEHLP_SYMBOL_TYPE_INFO req
, void* pInfo
);
662 extern struct symt_basic
*
663 symt_new_basic(struct module
* module
, enum BasicType
,
664 const char* typename
, unsigned size
);
665 extern struct symt_udt
*
666 symt_new_udt(struct module
* module
, const char* typename
,
667 unsigned size
, enum UdtKind kind
);
668 extern BOOL
symt_set_udt_size(struct module
* module
,
669 struct symt_udt
* type
, unsigned size
);
670 extern BOOL
symt_add_udt_element(struct module
* module
,
671 struct symt_udt
* udt_type
,
673 struct symt
* elt_type
, unsigned offset
,
675 extern struct symt_enum
*
676 symt_new_enum(struct module
* module
, const char* typename
,
677 struct symt
* basetype
);
678 extern BOOL
symt_add_enum_element(struct module
* module
,
679 struct symt_enum
* enum_type
,
680 const char* name
, int value
);
681 extern struct symt_array
*
682 symt_new_array(struct module
* module
, int min
, int max
,
683 struct symt
* base
, struct symt
* index
);
684 extern struct symt_function_signature
*
685 symt_new_function_signature(struct module
* module
,
686 struct symt
* ret_type
,
687 enum CV_call_e call_conv
);
688 extern BOOL
symt_add_function_signature_parameter(struct module
* module
,
689 struct symt_function_signature
* sig
,
691 extern struct symt_pointer
*
692 symt_new_pointer(struct module
* module
,
693 struct symt
* ref_type
);
694 extern struct symt_typedef
*
695 symt_new_typedef(struct module
* module
, struct symt
* ref
,