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, 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
34 /* #define USE_STATS */
36 struct pool /* poor's man */
38 struct pool_arena* first;
42 void pool_init(struct pool* a, unsigned arena_size);
43 void pool_destroy(struct pool* a);
44 void* pool_alloc(struct pool* a, unsigned len);
45 /* void* pool_realloc(struct pool* a, void* p,
46 unsigned old_size, unsigned new_size); */
47 char* pool_strdup(struct pool* a, const char* str);
58 void vector_init(struct vector* v, unsigned elt_sz, unsigned bucket_sz);
59 unsigned vector_length(const struct vector* v);
60 void* vector_at(const struct vector* v, unsigned pos);
61 void* vector_add(struct vector* v, struct pool* pool);
62 /*void vector_pool_normalize(struct vector* v, struct pool* pool); */
63 void* vector_iter_up(const struct vector* v, void* elt);
64 void* vector_iter_down(const struct vector* v, void* elt);
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;
86 struct hash_table_elt** buckets;
89 void hash_table_init(struct pool* pool, struct hash_table* ht,
90 unsigned num_buckets);
91 void hash_table_destroy(struct hash_table* ht);
92 void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt);
93 void* hash_table_find(const struct hash_table* ht, const char* name);
94 unsigned hash_table_hash(const char* name, unsigned num_buckets);
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) - (unsigned int)(&((__t*)0)->__f)))
112 extern unsigned dbghelp_options;
113 /* some more Wine extensions */
114 #define SYMOPT_WINE_WITH_ELF_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_function_point
211 struct symt symt; /* either SymTagFunctionDebugStart, SymTagFunctionDebugEnd, SymTagLabel */
212 struct symt_function* parent;
214 const char* name; /* for labels */
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;
260 struct vector vchildren;
263 struct symt_function_signature
266 struct symt* rettype;
267 struct vector vchildren;
268 enum CV_call_e call_conv;
271 struct symt_function_arg_type
274 struct symt* arg_type;
275 struct symt* container;
281 struct symt* pointsto;
287 struct hash_table_elt hash_elt;
294 struct hash_table_elt hash_elt;
297 struct vector vchildren;
302 DMT_UNKNOWN, /* for lookup, not actually used for a module */
303 DMT_ELF, /* a real ELF shared module */
304 DMT_PE, /* a native or builtin PE module */
305 DMT_PDB, /* PDB file */
312 IMAGEHLP_MODULE64 module;
314 enum module_type type : 16;
315 unsigned short is_virtual : 1;
316 struct elf_module_info* elf_info;
317 struct dwarf2_module_info_s*dwarf2_info;
319 /* memory allocation pool */
322 /* symbols & symbol tables */
324 struct symt_ht** addr_sorttab;
325 struct hash_table ht_symbols;
326 void (*loc_compute)(struct process* pcs,
327 const struct module* module,
328 const struct symt_function* func,
329 struct location* loc);
332 struct hash_table ht_types;
333 struct vector vtypes;
336 unsigned sources_used;
337 unsigned sources_alloc;
343 struct process* next;
347 PSYMBOL_REGISTERED_CALLBACK64 reg_cb;
351 struct module* lmodules;
352 unsigned long dbg_hdr_addr;
354 IMAGEHLP_STACK_FRAME ctx_frame;
356 unsigned buffer_size;
362 unsigned long is_first : 1,
368 unsigned long pc_offset; /* if is_source_file isn't set */
369 unsigned source_file; /* if is_source_file is set */
376 struct module* requested; /* in: to module_get_debug() */
377 struct module* effective; /* out: module with debug info */
380 enum pdb_kind {PDB_JG, PDB_DS};
384 const char* filename;
392 struct PDB_JG_TOC* toc;
397 struct PDB_DS_TOC* toc;
403 extern struct process* process_find_by_handle(HANDLE hProcess);
404 extern HANDLE hMsvcrt;
405 extern BOOL validate_addr64(DWORD64 addr);
406 extern BOOL pcs_callback(const struct process* pcs, ULONG action, void* data);
407 extern void* fetch_buffer(struct process* pcs, unsigned size);
410 #define ELF_NO_MAP ((const void*)0xffffffff)
411 typedef BOOL (*elf_enum_modules_cb)(const char*, unsigned long addr, void* user);
412 extern BOOL elf_enum_modules(HANDLE hProc, elf_enum_modules_cb, void*);
413 extern BOOL elf_fetch_file_info(const char* name, DWORD* base, DWORD* size, DWORD* checksum);
415 extern BOOL elf_load_debug_info(struct module* module, struct elf_file_map* fmap);
416 extern struct module*
417 elf_load_module(struct process* pcs, const char* name, unsigned long);
418 extern BOOL elf_read_wine_loader_dbg_info(struct process* pcs);
419 extern BOOL elf_synchronize_module_list(struct process* pcs);
420 struct elf_thunk_area;
421 extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_thunk_area* thunks);
422 extern DWORD WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS* addr);
425 extern int module_compute_num_syms(struct module* module);
426 extern struct module*
427 module_find_by_addr(const struct process* pcs, unsigned long addr,
428 enum module_type type);
429 extern struct module*
430 module_find_by_name(const struct process* pcs,
431 const char* name, enum module_type type);
432 extern BOOL module_get_debug(struct module_pair*);
433 extern struct module*
434 module_new(struct process* pcs, const char* name,
435 enum module_type type, BOOL virtual,
436 unsigned long addr, unsigned long size,
437 unsigned long stamp, unsigned long checksum);
438 extern struct module*
439 module_get_container(const struct process* pcs,
440 const struct module* inner);
441 extern struct module*
442 module_get_containee(const struct process* pcs,
443 const struct module* inner);
444 extern enum module_type
445 module_get_type_by_name(const char* name);
446 extern void module_reset_debug_info(struct module* module);
447 extern BOOL module_remove(struct process* pcs,
448 struct module* module);
450 extern BOOL pe_load_debug_directory(const struct process* pcs,
451 struct module* module,
453 const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
454 const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg);
455 extern BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup);
458 extern BOOL pe_load_nt_header(HANDLE hProc, DWORD base, IMAGE_NT_HEADERS* nth);
459 extern struct module*
460 pe_load_module(struct process* pcs, const char* name,
461 HANDLE hFile, DWORD base, DWORD size);
462 extern struct module*
463 pe_load_module_from_pcs(struct process* pcs, const char* name,
464 const char* mod_name, DWORD base, DWORD size);
465 extern BOOL pe_load_debug_info(const struct process* pcs,
466 struct module* module);
468 extern unsigned source_new(struct module* module, const char* basedir, const char* source);
469 extern const char* source_get(const struct module* module, unsigned idx);
472 extern BOOL stabs_parse(struct module* module, unsigned long load_offset,
473 const void* stabs, int stablen,
474 const char* strs, int strtablen);
477 extern BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
478 const struct elf_thunk_area* thunks,
479 const unsigned char* debug, unsigned int debug_size,
480 const unsigned char* abbrev, unsigned int abbrev_size,
481 const unsigned char* str, unsigned int str_size,
482 const unsigned char* line, unsigned int line_size,
483 const unsigned char* loclist, unsigned int loclist_size);
486 extern const char* symt_get_name(const struct symt* sym);
487 extern int symt_cmp_addr(const void* p1, const void* p2);
488 extern int symt_find_nearest(struct module* module, DWORD addr);
489 extern struct symt_compiland*
490 symt_new_compiland(struct module* module, unsigned long address,
492 extern struct symt_public*
493 symt_new_public(struct module* module,
494 struct symt_compiland* parent,
495 const char* typename,
496 unsigned long address, unsigned size,
497 BOOL in_code, BOOL is_func);
498 extern struct symt_data*
499 symt_new_global_variable(struct module* module,
500 struct symt_compiland* parent,
501 const char* name, unsigned is_static,
502 unsigned long addr, unsigned long size,
504 extern struct symt_function*
505 symt_new_function(struct module* module,
506 struct symt_compiland* parent,
508 unsigned long addr, unsigned long size,
510 extern BOOL symt_normalize_function(struct module* module,
511 struct symt_function* func);
512 extern void symt_add_func_line(struct module* module,
513 struct symt_function* func,
514 unsigned source_idx, int line_num,
515 unsigned long offset);
516 extern struct symt_data*
517 symt_add_func_local(struct module* module,
518 struct symt_function* func,
519 enum DataKind dt, const struct location* loc,
520 struct symt_block* block,
521 struct symt* type, const char* name);
522 extern struct symt_block*
523 symt_open_func_block(struct module* module,
524 struct symt_function* func,
525 struct symt_block* block,
526 unsigned pc, unsigned len);
527 extern struct symt_block*
528 symt_close_func_block(struct module* module,
529 struct symt_function* func,
530 struct symt_block* block, unsigned pc);
531 extern struct symt_function_point*
532 symt_add_function_point(struct module* module,
533 struct symt_function* func,
534 enum SymTagEnum point,
535 const struct location* loc,
537 extern BOOL symt_fill_func_line_info(struct module* module,
538 struct symt_function* func,
539 DWORD addr, IMAGEHLP_LINE* line);
540 extern BOOL symt_get_func_line_next(struct module* module, PIMAGEHLP_LINE line);
541 extern struct symt_thunk*
542 symt_new_thunk(struct module* module,
543 struct symt_compiland* parent,
544 const char* name, THUNK_ORDINAL ord,
545 unsigned long addr, unsigned long size);
548 extern void symt_init_basic(struct module* module);
549 extern BOOL symt_get_info(const struct symt* type,
550 IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo);
551 extern struct symt_basic*
552 symt_new_basic(struct module* module, enum BasicType,
553 const char* typename, unsigned size);
554 extern struct symt_udt*
555 symt_new_udt(struct module* module, const char* typename,
556 unsigned size, enum UdtKind kind);
557 extern BOOL symt_set_udt_size(struct module* module,
558 struct symt_udt* type, unsigned size);
559 extern BOOL symt_add_udt_element(struct module* module,
560 struct symt_udt* udt_type,
562 struct symt* elt_type, unsigned offset,
564 extern struct symt_enum*
565 symt_new_enum(struct module* module, const char* typename);
566 extern BOOL symt_add_enum_element(struct module* module,
567 struct symt_enum* enum_type,
568 const char* name, int value);
569 extern struct symt_array*
570 symt_new_array(struct module* module, int min, int max,
571 struct symt* base, struct symt* index);
572 extern struct symt_function_signature*
573 symt_new_function_signature(struct module* module,
574 struct symt* ret_type,
575 enum CV_call_e call_conv);
576 extern BOOL symt_add_function_signature_parameter(struct module* module,
577 struct symt_function_signature* sig,
579 extern struct symt_pointer*
580 symt_new_pointer(struct module* module,
581 struct symt* ref_type);
582 extern struct symt_typedef*
583 symt_new_typedef(struct module* module, struct symt* ref,