dbghelp: Implemented SymFunctionTableAccess.
[wine/testsucceed.git] / dlls / dbghelp / dbghelp_private.h
blob54b7272b2115fe2dd8027278d7361085289ab9b5
1 /*
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
24 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winver.h"
28 #include "dbghelp.h"
29 #include "objbase.h"
30 #include "oaidl.h"
31 #include "winnls.h"
32 #include "wine/list.h"
33 #include "wine/unicode.h"
35 #include "cvconst.h"
37 /* #define USE_STATS */
39 struct pool /* poor's man */
41 struct list arena_list;
42 struct list arena_full;
43 size_t arena_size;
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);
51 struct vector
53 void** buckets;
54 unsigned elt_size;
55 unsigned shift;
56 unsigned num_elts;
57 unsigned num_buckets;
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);
66 struct sparse_array
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);
77 struct hash_table_elt
79 const char* name;
80 struct hash_table_elt* next;
83 struct hash_table_bucket
85 struct hash_table_elt* first;
86 struct hash_table_elt* last;
89 struct hash_table
91 unsigned num_elts;
92 unsigned num_buckets;
93 struct hash_table_bucket* buckets;
94 struct pool* pool;
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;
106 int index;
107 int last;
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 */
136 struct location
138 unsigned kind : 8,
139 reg;
140 unsigned long offset;
143 struct symt
145 enum SymTagEnum tag;
148 struct symt_ht
150 struct symt symt;
151 struct hash_table_elt hash_elt; /* if global symbol or type */
154 /* lexical tree */
155 struct symt_block
157 struct symt symt;
158 unsigned long address;
159 unsigned long size;
160 struct symt* container; /* block, or func */
161 struct vector vchildren; /* sub-blocks & local variables */
164 struct symt_compiland
166 struct symt symt;
167 unsigned long address;
168 unsigned source;
169 struct vector vchildren; /* global variables & functions */
172 struct symt_data
174 struct symt symt;
175 struct hash_table_elt hash_elt; /* if global symbol */
176 enum DataKind kind;
177 struct symt* container;
178 struct symt* type;
179 union /* depends on kind */
181 /* DataIs{Global, FileStatic}:
182 * loc.kind is loc_absolute
183 * loc.offset is address
184 * DataIs{Local,Param}:
185 * with loc.kind
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
191 struct location var;
192 /* DataIs{Member} (all values are in bits, not bytes) */
193 struct
195 long offset;
196 unsigned long length;
197 } member;
198 /* DataIsConstant */
199 VARIANT value;
200 } u;
203 struct symt_function
205 struct symt symt;
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 */
210 unsigned long size;
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 */
220 struct location loc;
223 struct symt_public
225 struct symt symt;
226 struct hash_table_elt hash_elt;
227 struct symt* container; /* compiland */
228 unsigned long address;
229 unsigned long size;
232 struct symt_thunk
234 struct symt symt;
235 struct hash_table_elt hash_elt;
236 struct symt* container; /* compiland */
237 unsigned long address;
238 unsigned long size;
239 THUNK_ORDINAL ordinal; /* FIXME: doesn't seem to be accessible */
242 /* class tree */
243 struct symt_array
245 struct symt symt;
246 int start;
247 int end; /* end index if > 0, or -array_len (in bytes) if < 0 */
248 struct symt* base_type;
249 struct symt* index_type;
252 struct symt_basic
254 struct symt symt;
255 struct hash_table_elt hash_elt;
256 enum BasicType bt;
257 unsigned long size;
260 struct symt_enum
262 struct symt symt;
263 struct symt* base_type;
264 const char* name;
265 struct vector vchildren;
268 struct symt_function_signature
270 struct symt symt;
271 struct symt* rettype;
272 struct vector vchildren;
273 enum CV_call_e call_conv;
276 struct symt_function_arg_type
278 struct symt symt;
279 struct symt* arg_type;
280 struct symt* container;
283 struct symt_pointer
285 struct symt symt;
286 struct symt* pointsto;
289 struct symt_typedef
291 struct symt symt;
292 struct hash_table_elt hash_elt;
293 struct symt* type;
296 struct symt_udt
298 struct symt symt;
299 struct hash_table_elt hash_elt;
300 enum UdtKind kind;
301 int size;
302 struct vector vchildren;
305 enum module_type
307 DMT_UNKNOWN, /* for lookup, not actually used for a module */
308 DMT_ELF, /* a real ELF shared module */
309 DMT_PE, /* a native or builtin PE module */
310 DMT_MACHO, /* a real Mach-O shared module */
311 DMT_PDB, /* .PDB file */
312 DMT_DBG, /* .DBG file */
315 struct process;
316 struct module;
318 /* a module can be made of several debug information formats, so we have to
319 * support them all
321 enum format_info
323 DFI_ELF,
324 DFI_PE,
325 DFI_MACHO,
326 DFI_DWARF,
327 DFI_LAST
330 struct module_format
332 struct module* module;
333 void (*remove)(struct process* pcs, struct module_format* modfmt);
334 void (*loc_compute)(struct process* pcs,
335 const struct module_format* modfmt,
336 const struct symt_function* func,
337 struct location* loc);
338 union
340 struct elf_module_info* elf_info;
341 struct dwarf2_module_info_s* dwarf2_info;
342 struct pe_module_info* pe_info;
343 struct macho_module_info* macho_info;
344 } u;
347 struct module
349 IMAGEHLP_MODULEW64 module;
350 /* ANSI copy of module.ModuleName for efficiency */
351 char module_name[MAX_PATH];
352 struct module* next;
353 enum module_type type : 16;
354 unsigned short is_virtual : 1;
356 /* specific information for debug types */
357 struct module_format* format_info[DFI_LAST];
359 /* memory allocation pool */
360 struct pool pool;
362 /* symbols & symbol tables */
363 struct vector vsymt;
364 int sortlist_valid;
365 unsigned num_sorttab; /* number of symbols with addresses */
366 unsigned num_symbols;
367 unsigned sorttab_size;
368 struct symt_ht** addr_sorttab;
369 struct hash_table ht_symbols;
371 /* types */
372 struct hash_table ht_types;
373 struct vector vtypes;
375 /* source files */
376 unsigned sources_used;
377 unsigned sources_alloc;
378 char* sources;
381 struct process
383 struct process* next;
384 HANDLE handle;
385 WCHAR* search_path;
387 PSYMBOL_REGISTERED_CALLBACK64 reg_cb;
388 PSYMBOL_REGISTERED_CALLBACK reg_cb32;
389 BOOL reg_is_unicode;
390 DWORD64 reg_user;
392 struct module* lmodules;
393 unsigned long dbg_hdr_addr;
395 IMAGEHLP_STACK_FRAME ctx_frame;
397 unsigned buffer_size;
398 void* buffer;
401 struct line_info
403 unsigned long is_first : 1,
404 is_last : 1,
405 is_source_file : 1,
406 line_number;
407 union
409 unsigned long pc_offset; /* if is_source_file isn't set */
410 unsigned source_file; /* if is_source_file is set */
411 } u;
414 struct module_pair
416 struct process* pcs;
417 struct module* requested; /* in: to module_get_debug() */
418 struct module* effective; /* out: module with debug info */
421 enum pdb_kind {PDB_JG, PDB_DS};
423 struct pdb_lookup
425 const char* filename;
426 DWORD age;
427 enum pdb_kind kind;
428 union
430 struct
432 DWORD timestamp;
433 struct PDB_JG_TOC* toc;
434 } jg;
435 struct
437 GUID guid;
438 struct PDB_DS_TOC* toc;
439 } ds;
440 } u;
443 struct cpu_stack_walk
445 HANDLE hProcess;
446 HANDLE hThread;
447 BOOL is32;
448 union
450 struct
452 PREAD_PROCESS_MEMORY_ROUTINE f_read_mem;
453 PTRANSLATE_ADDRESS_ROUTINE f_xlat_adr;
454 PFUNCTION_TABLE_ACCESS_ROUTINE f_tabl_acs;
455 PGET_MODULE_BASE_ROUTINE f_modl_bas;
456 } s32;
457 struct
459 PREAD_PROCESS_MEMORY_ROUTINE64 f_read_mem;
460 PTRANSLATE_ADDRESS_ROUTINE64 f_xlat_adr;
461 PFUNCTION_TABLE_ACCESS_ROUTINE64 f_tabl_acs;
462 PGET_MODULE_BASE_ROUTINE64 f_modl_bas;
463 } s64;
464 } u;
467 enum cpu_addr {cpu_addr_pc, cpu_addr_stack, cpu_addr_frame};
468 struct cpu
470 DWORD machine;
471 DWORD word_size;
472 /* address manipulation */
473 unsigned (*get_addr)(HANDLE hThread, const CONTEXT* ctx,
474 enum cpu_addr, ADDRESS64* addr);
476 /* stack manipulation */
477 BOOL (*stack_walk)(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame);
479 /* module manipulation */
480 void* (*find_runtime_function)(struct module*, DWORD64 addr);
483 extern struct cpu* dbghelp_current_cpu;
485 /* dbghelp.c */
486 extern struct process* process_find_by_handle(HANDLE hProcess);
487 extern HANDLE hMsvcrt;
488 extern BOOL validate_addr64(DWORD64 addr);
489 extern BOOL pcs_callback(const struct process* pcs, ULONG action, void* data);
490 extern void* fetch_buffer(struct process* pcs, unsigned size);
491 extern const char* wine_dbgstr_addr(const ADDRESS64* addr);
492 extern struct cpu* cpu_find(DWORD);
494 /* crc32.c */
495 extern DWORD calc_crc32(int fd);
497 typedef BOOL (*enum_modules_cb)(const WCHAR*, unsigned long addr, void* user);
499 /* elf_module.c */
500 extern BOOL elf_enum_modules(HANDLE hProc, enum_modules_cb, void*);
501 extern BOOL elf_fetch_file_info(const WCHAR* name, DWORD* base, DWORD* size, DWORD* checksum);
502 struct image_file_map;
503 extern BOOL elf_load_debug_info(struct module* module, struct image_file_map* fmap);
504 extern struct module*
505 elf_load_module(struct process* pcs, const WCHAR* name, unsigned long);
506 extern BOOL elf_read_wine_loader_dbg_info(struct process* pcs);
507 extern BOOL elf_synchronize_module_list(struct process* pcs);
508 struct elf_thunk_area;
509 extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_thunk_area* thunks);
511 /* macho_module.c */
512 #define MACHO_NO_MAP ((const void*)-1)
513 extern BOOL macho_enum_modules(HANDLE hProc, enum_modules_cb, void*);
514 extern BOOL macho_fetch_file_info(const WCHAR* name, DWORD* base, DWORD* size, DWORD* checksum);
515 struct macho_file_map;
516 extern BOOL macho_load_debug_info(struct module* module, struct macho_file_map* fmap);
517 extern struct module*
518 macho_load_module(struct process* pcs, const WCHAR* name, unsigned long);
519 extern BOOL macho_read_wine_loader_dbg_info(struct process* pcs);
520 extern BOOL macho_synchronize_module_list(struct process* pcs);
522 /* module.c */
523 extern const WCHAR S_ElfW[];
524 extern const WCHAR S_WineLoaderW[];
525 extern const WCHAR S_WineW[];
526 extern const WCHAR S_SlashW[];
528 extern struct module*
529 module_find_by_addr(const struct process* pcs, unsigned long addr,
530 enum module_type type);
531 extern struct module*
532 module_find_by_nameA(const struct process* pcs,
533 const char* name);
534 extern struct module*
535 module_is_already_loaded(const struct process* pcs,
536 const WCHAR* imgname);
537 extern BOOL module_get_debug(struct module_pair*);
538 extern struct module*
539 module_new(struct process* pcs, const WCHAR* name,
540 enum module_type type, BOOL virtual,
541 DWORD64 addr, DWORD64 size,
542 unsigned long stamp, unsigned long checksum);
543 extern struct module*
544 module_get_containee(const struct process* pcs,
545 const struct module* inner);
546 extern enum module_type
547 module_get_type_by_name(const WCHAR* name);
548 extern void module_reset_debug_info(struct module* module);
549 extern BOOL module_remove(struct process* pcs,
550 struct module* module);
551 extern void module_set_module(struct module* module, const WCHAR* name);
553 /* msc.c */
554 extern BOOL pe_load_debug_directory(const struct process* pcs,
555 struct module* module,
556 const BYTE* mapping,
557 const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
558 const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg);
559 extern BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup);
561 /* path.c */
562 extern BOOL path_find_symbol_file(const struct process* pcs, PCSTR full_path,
563 const GUID* guid, DWORD dw1, DWORD dw2, PSTR buffer,
564 BOOL* is_unmatched);
566 /* pe_module.c */
567 extern BOOL pe_load_nt_header(HANDLE hProc, DWORD64 base, IMAGE_NT_HEADERS* nth);
568 extern struct module*
569 pe_load_native_module(struct process* pcs, const WCHAR* name,
570 HANDLE hFile, DWORD base, DWORD size);
571 extern struct module*
572 pe_load_builtin_module(struct process* pcs, const WCHAR* name,
573 DWORD64 base, DWORD64 size);
574 extern BOOL pe_load_debug_info(const struct process* pcs,
575 struct module* module);
576 extern const char* pe_map_directory(struct module* module, int dirno, DWORD* size);
577 extern void pe_unmap_directoy(struct module* module, int dirno);
579 /* source.c */
580 extern unsigned source_new(struct module* module, const char* basedir, const char* source);
581 extern const char* source_get(const struct module* module, unsigned idx);
583 /* stabs.c */
584 typedef void (*stabs_def_cb)(struct module* module, unsigned long load_offset,
585 const char* name, unsigned long offset,
586 BOOL is_public, BOOL is_global, unsigned char other,
587 struct symt_compiland* compiland, void* user);
588 extern BOOL stabs_parse(struct module* module, unsigned long load_offset,
589 const void* stabs, int stablen,
590 const char* strs, int strtablen,
591 stabs_def_cb callback, void* user);
593 /* dwarf.c */
594 extern BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
595 const struct elf_thunk_area* thunks,
596 struct image_file_map* fmap);
598 /* stack.c */
599 extern BOOL sw_read_mem(struct cpu_stack_walk* csw, DWORD64 addr, void* ptr, DWORD sz);
600 extern DWORD64 sw_xlat_addr(struct cpu_stack_walk* csw, ADDRESS64* addr);
601 extern void* sw_table_access(struct cpu_stack_walk* csw, DWORD64 addr);
602 extern DWORD64 sw_module_base(struct cpu_stack_walk* csw, DWORD64 addr);
604 /* symbol.c */
605 extern const char* symt_get_name(const struct symt* sym);
606 extern struct module* symt_cmp_addr_module;
607 extern int symt_cmp_addr(const void* p1, const void* p2);
608 extern void copy_symbolW(SYMBOL_INFOW* siw, const SYMBOL_INFO* si);
609 extern struct symt_ht*
610 symt_find_nearest(struct module* module, DWORD_PTR addr);
611 extern struct symt_compiland*
612 symt_new_compiland(struct module* module, unsigned long address,
613 unsigned src_idx);
614 extern struct symt_public*
615 symt_new_public(struct module* module,
616 struct symt_compiland* parent,
617 const char* typename,
618 unsigned long address, unsigned size);
619 extern struct symt_data*
620 symt_new_global_variable(struct module* module,
621 struct symt_compiland* parent,
622 const char* name, unsigned is_static,
623 unsigned long addr, unsigned long size,
624 struct symt* type);
625 extern struct symt_function*
626 symt_new_function(struct module* module,
627 struct symt_compiland* parent,
628 const char* name,
629 unsigned long addr, unsigned long size,
630 struct symt* type);
631 extern BOOL symt_normalize_function(struct module* module,
632 const struct symt_function* func);
633 extern void symt_add_func_line(struct module* module,
634 struct symt_function* func,
635 unsigned source_idx, int line_num,
636 unsigned long offset);
637 extern struct symt_data*
638 symt_add_func_local(struct module* module,
639 struct symt_function* func,
640 enum DataKind dt, const struct location* loc,
641 struct symt_block* block,
642 struct symt* type, const char* name);
643 extern struct symt_block*
644 symt_open_func_block(struct module* module,
645 struct symt_function* func,
646 struct symt_block* block,
647 unsigned pc, unsigned len);
648 extern struct symt_block*
649 symt_close_func_block(struct module* module,
650 const struct symt_function* func,
651 struct symt_block* block, unsigned pc);
652 extern struct symt_hierarchy_point*
653 symt_add_function_point(struct module* module,
654 struct symt_function* func,
655 enum SymTagEnum point,
656 const struct location* loc,
657 const char* name);
658 extern BOOL symt_fill_func_line_info(const struct module* module,
659 const struct symt_function* func,
660 DWORD64 addr, IMAGEHLP_LINE64* line);
661 extern BOOL symt_get_func_line_next(const struct module* module, PIMAGEHLP_LINE64 line);
662 extern struct symt_thunk*
663 symt_new_thunk(struct module* module,
664 struct symt_compiland* parent,
665 const char* name, THUNK_ORDINAL ord,
666 unsigned long addr, unsigned long size);
667 extern struct symt_data*
668 symt_new_constant(struct module* module,
669 struct symt_compiland* parent,
670 const char* name, struct symt* type,
671 const VARIANT* v);
672 extern struct symt_hierarchy_point*
673 symt_new_label(struct module* module,
674 struct symt_compiland* compiland,
675 const char* name, unsigned long address);
676 extern struct symt* symt_index2ptr(struct module* module, DWORD id);
677 extern DWORD symt_ptr2index(struct module* module, const struct symt* sym);
679 /* type.c */
680 extern void symt_init_basic(struct module* module);
681 extern BOOL symt_get_info(struct module* module, const struct symt* type,
682 IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo);
683 extern struct symt_basic*
684 symt_new_basic(struct module* module, enum BasicType,
685 const char* typename, unsigned size);
686 extern struct symt_udt*
687 symt_new_udt(struct module* module, const char* typename,
688 unsigned size, enum UdtKind kind);
689 extern BOOL symt_set_udt_size(struct module* module,
690 struct symt_udt* type, unsigned size);
691 extern BOOL symt_add_udt_element(struct module* module,
692 struct symt_udt* udt_type,
693 const char* name,
694 struct symt* elt_type, unsigned offset,
695 unsigned size);
696 extern struct symt_enum*
697 symt_new_enum(struct module* module, const char* typename,
698 struct symt* basetype);
699 extern BOOL symt_add_enum_element(struct module* module,
700 struct symt_enum* enum_type,
701 const char* name, int value);
702 extern struct symt_array*
703 symt_new_array(struct module* module, int min, int max,
704 struct symt* base, struct symt* index);
705 extern struct symt_function_signature*
706 symt_new_function_signature(struct module* module,
707 struct symt* ret_type,
708 enum CV_call_e call_conv);
709 extern BOOL symt_add_function_signature_parameter(struct module* module,
710 struct symt_function_signature* sig,
711 struct symt* param);
712 extern struct symt_pointer*
713 symt_new_pointer(struct module* module,
714 struct symt* ref_type);
715 extern struct symt_typedef*
716 symt_new_typedef(struct module* module, struct symt* ref,
717 const char* name);