kernel32: Update Italian translation.
[wine/multimedia.git] / dlls / dbghelp / dbghelp_private.h
blob531a74048a09eb1b012bacbc6903d5552f547caf
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_unavailable, /* location is not available */
124 loc_absolute, /* offset is the location */
125 loc_register, /* reg is the location */
126 loc_regrel, /* [reg+offset] is the location */
127 loc_user, /* value is debug information dependent,
128 reg & offset can be used ad libidem */
131 enum location_error {loc_err_internal = -1, /* internal while computing */
132 loc_err_too_complex = -2, /* couldn't compute location (even at runtime) */
133 loc_err_out_of_scope = -3, /* variable isn't available at current address */
134 loc_err_cant_read = -4, /* couldn't read memory at given address */
135 loc_err_no_location = -5, /* likely optimized away (by compiler) */
138 struct location
140 unsigned kind : 8,
141 reg;
142 unsigned long offset;
145 struct symt
147 enum SymTagEnum tag;
150 struct symt_ht
152 struct symt symt;
153 struct hash_table_elt hash_elt; /* if global symbol or type */
156 /* lexical tree */
157 struct symt_block
159 struct symt symt;
160 unsigned long address;
161 unsigned long size;
162 struct symt* container; /* block, or func */
163 struct vector vchildren; /* sub-blocks & local variables */
166 struct symt_compiland
168 struct symt symt;
169 unsigned long address;
170 unsigned source;
171 struct vector vchildren; /* global variables & functions */
174 struct symt_data
176 struct symt symt;
177 struct hash_table_elt hash_elt; /* if global symbol */
178 enum DataKind kind;
179 struct symt* container;
180 struct symt* type;
181 union /* depends on kind */
183 /* DataIs{Global, FileStatic}:
184 * loc.kind is loc_absolute
185 * loc.offset is address
186 * DataIs{Local,Param}:
187 * with loc.kind
188 * loc_absolute not supported
189 * loc_register location is in register loc.reg
190 * loc_regrel location is at address loc.reg + loc.offset
191 * >= loc_user ask debug info provider for resolution
193 struct location var;
194 /* DataIs{Member} (all values are in bits, not bytes) */
195 struct
197 long offset;
198 unsigned long length;
199 } member;
200 /* DataIsConstant */
201 VARIANT value;
202 } u;
205 struct symt_function
207 struct symt symt;
208 struct hash_table_elt hash_elt; /* if global symbol */
209 unsigned long address;
210 struct symt* container; /* compiland */
211 struct symt* type; /* points to function_signature */
212 unsigned long size;
213 struct vector vlines;
214 struct vector vchildren; /* locals, params, blocks, start/end, labels */
217 struct symt_hierarchy_point
219 struct symt symt; /* either SymTagFunctionDebugStart, SymTagFunctionDebugEnd, SymTagLabel */
220 struct hash_table_elt hash_elt; /* if label (and in compiland's hash table if global) */
221 struct symt* parent; /* symt_function or symt_compiland */
222 struct location loc;
225 struct symt_public
227 struct symt symt;
228 struct hash_table_elt hash_elt;
229 struct symt* container; /* compiland */
230 unsigned long address;
231 unsigned long size;
234 struct symt_thunk
236 struct symt symt;
237 struct hash_table_elt hash_elt;
238 struct symt* container; /* compiland */
239 unsigned long address;
240 unsigned long size;
241 THUNK_ORDINAL ordinal; /* FIXME: doesn't seem to be accessible */
244 /* class tree */
245 struct symt_array
247 struct symt symt;
248 int start;
249 int end; /* end index if > 0, or -array_len (in bytes) if < 0 */
250 struct symt* base_type;
251 struct symt* index_type;
254 struct symt_basic
256 struct symt symt;
257 struct hash_table_elt hash_elt;
258 enum BasicType bt;
259 unsigned long size;
262 struct symt_enum
264 struct symt symt;
265 struct symt* base_type;
266 const char* name;
267 struct vector vchildren;
270 struct symt_function_signature
272 struct symt symt;
273 struct symt* rettype;
274 struct vector vchildren;
275 enum CV_call_e call_conv;
278 struct symt_function_arg_type
280 struct symt symt;
281 struct symt* arg_type;
282 struct symt* container;
285 struct symt_pointer
287 struct symt symt;
288 struct symt* pointsto;
291 struct symt_typedef
293 struct symt symt;
294 struct hash_table_elt hash_elt;
295 struct symt* type;
298 struct symt_udt
300 struct symt symt;
301 struct hash_table_elt hash_elt;
302 enum UdtKind kind;
303 int size;
304 struct vector vchildren;
307 enum module_type
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 */
317 struct process;
318 struct module;
320 /* a module can be made of several debug information formats, so we have to
321 * support them all
323 enum format_info
325 DFI_ELF,
326 DFI_PE,
327 DFI_MACHO,
328 DFI_DWARF,
329 DFI_LAST
332 struct module_format
334 struct module* module;
335 void (*remove)(struct process* pcs, struct module_format* modfmt);
336 void (*loc_compute)(struct process* pcs,
337 const struct module_format* modfmt,
338 const struct symt_function* func,
339 struct location* loc);
340 union
342 struct elf_module_info* elf_info;
343 struct dwarf2_module_info_s* dwarf2_info;
344 struct pe_module_info* pe_info;
345 struct macho_module_info* macho_info;
346 } u;
349 struct module
351 struct process* process;
352 IMAGEHLP_MODULEW64 module;
353 /* ANSI copy of module.ModuleName for efficiency */
354 char module_name[MAX_PATH];
355 struct module* next;
356 enum module_type type : 16;
357 unsigned short is_virtual : 1;
358 DWORD64 reloc_delta;
360 /* specific information for debug types */
361 struct module_format* format_info[DFI_LAST];
363 /* memory allocation pool */
364 struct pool pool;
366 /* symbols & symbol tables */
367 struct vector vsymt;
368 int sortlist_valid;
369 unsigned num_sorttab; /* number of symbols with addresses */
370 unsigned num_symbols;
371 unsigned sorttab_size;
372 struct symt_ht** addr_sorttab;
373 struct hash_table ht_symbols;
375 /* types */
376 struct hash_table ht_types;
377 struct vector vtypes;
379 /* source files */
380 unsigned sources_used;
381 unsigned sources_alloc;
382 char* sources;
385 struct process
387 struct process* next;
388 HANDLE handle;
389 WCHAR* search_path;
391 PSYMBOL_REGISTERED_CALLBACK64 reg_cb;
392 PSYMBOL_REGISTERED_CALLBACK reg_cb32;
393 BOOL reg_is_unicode;
394 DWORD64 reg_user;
396 struct module* lmodules;
397 unsigned long dbg_hdr_addr;
399 IMAGEHLP_STACK_FRAME ctx_frame;
401 unsigned buffer_size;
402 void* buffer;
405 struct line_info
407 unsigned long is_first : 1,
408 is_last : 1,
409 is_source_file : 1,
410 line_number;
411 union
413 unsigned long pc_offset; /* if is_source_file isn't set */
414 unsigned source_file; /* if is_source_file is set */
415 } u;
418 struct module_pair
420 struct process* pcs;
421 struct module* requested; /* in: to module_get_debug() */
422 struct module* effective; /* out: module with debug info */
425 enum pdb_kind {PDB_JG, PDB_DS};
427 struct pdb_lookup
429 const char* filename;
430 DWORD age;
431 enum pdb_kind kind;
432 union
434 struct
436 DWORD timestamp;
437 struct PDB_JG_TOC* toc;
438 } jg;
439 struct
441 GUID guid;
442 struct PDB_DS_TOC* toc;
443 } ds;
444 } u;
447 struct cpu_stack_walk
449 HANDLE hProcess;
450 HANDLE hThread;
451 BOOL is32;
452 union
454 struct
456 PREAD_PROCESS_MEMORY_ROUTINE f_read_mem;
457 PTRANSLATE_ADDRESS_ROUTINE f_xlat_adr;
458 PFUNCTION_TABLE_ACCESS_ROUTINE f_tabl_acs;
459 PGET_MODULE_BASE_ROUTINE f_modl_bas;
460 } s32;
461 struct
463 PREAD_PROCESS_MEMORY_ROUTINE64 f_read_mem;
464 PTRANSLATE_ADDRESS_ROUTINE64 f_xlat_adr;
465 PFUNCTION_TABLE_ACCESS_ROUTINE64 f_tabl_acs;
466 PGET_MODULE_BASE_ROUTINE64 f_modl_bas;
467 } s64;
468 } u;
471 enum cpu_addr {cpu_addr_pc, cpu_addr_stack, cpu_addr_frame};
472 struct cpu
474 DWORD machine;
475 DWORD word_size;
476 /* address manipulation */
477 unsigned (*get_addr)(HANDLE hThread, const CONTEXT* ctx,
478 enum cpu_addr, ADDRESS64* addr);
480 /* stack manipulation */
481 BOOL (*stack_walk)(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame, CONTEXT* context);
483 /* module manipulation */
484 void* (*find_runtime_function)(struct module*, DWORD64 addr);
486 /* dwarf dedicated information */
487 unsigned (*map_dwarf_register)(unsigned regno);
489 /* context related maniputation */
490 void* (*fetch_context_reg)(CONTEXT* context, unsigned regno, unsigned* size);
491 const char* (*fetch_regname)(unsigned regno);
494 extern struct cpu* dbghelp_current_cpu;
496 /* dbghelp.c */
497 extern struct process* process_find_by_handle(HANDLE hProcess);
498 extern HANDLE hMsvcrt;
499 extern BOOL validate_addr64(DWORD64 addr);
500 extern BOOL pcs_callback(const struct process* pcs, ULONG action, void* data);
501 extern void* fetch_buffer(struct process* pcs, unsigned size);
502 extern const char* wine_dbgstr_addr(const ADDRESS64* addr);
503 extern struct cpu* cpu_find(DWORD);
505 /* crc32.c */
506 extern DWORD calc_crc32(int fd);
508 typedef BOOL (*enum_modules_cb)(const WCHAR*, unsigned long addr, void* user);
510 /* elf_module.c */
511 extern BOOL elf_enum_modules(HANDLE hProc, enum_modules_cb, void*);
512 extern BOOL elf_fetch_file_info(const WCHAR* name, DWORD* base, DWORD* size, DWORD* checksum);
513 struct image_file_map;
514 extern BOOL elf_load_debug_info(struct module* module, struct image_file_map* fmap);
515 extern struct module*
516 elf_load_module(struct process* pcs, const WCHAR* name, unsigned long);
517 extern BOOL elf_read_wine_loader_dbg_info(struct process* pcs);
518 extern BOOL elf_synchronize_module_list(struct process* pcs);
519 struct elf_thunk_area;
520 extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_thunk_area* thunks);
522 /* macho_module.c */
523 #define MACHO_NO_MAP ((const void*)-1)
524 extern BOOL macho_enum_modules(HANDLE hProc, enum_modules_cb, void*);
525 extern BOOL macho_fetch_file_info(const WCHAR* name, DWORD* base, DWORD* size, DWORD* checksum);
526 struct macho_file_map;
527 extern BOOL macho_load_debug_info(struct module* module, struct macho_file_map* fmap);
528 extern struct module*
529 macho_load_module(struct process* pcs, const WCHAR* name, unsigned long);
530 extern BOOL macho_read_wine_loader_dbg_info(struct process* pcs);
531 extern BOOL macho_synchronize_module_list(struct process* pcs);
533 /* module.c */
534 extern const WCHAR S_ElfW[];
535 extern const WCHAR S_WineLoaderW[];
536 extern const WCHAR S_WineW[];
537 extern const WCHAR S_SlashW[];
539 extern struct module*
540 module_find_by_addr(const struct process* pcs, unsigned long addr,
541 enum module_type type);
542 extern struct module*
543 module_find_by_nameA(const struct process* pcs,
544 const char* name);
545 extern struct module*
546 module_is_already_loaded(const struct process* pcs,
547 const WCHAR* imgname);
548 extern BOOL module_get_debug(struct module_pair*);
549 extern struct module*
550 module_new(struct process* pcs, const WCHAR* name,
551 enum module_type type, BOOL virtual,
552 DWORD64 addr, DWORD64 size,
553 unsigned long stamp, unsigned long checksum);
554 extern struct module*
555 module_get_containee(const struct process* pcs,
556 const struct module* inner);
557 extern enum module_type
558 module_get_type_by_name(const WCHAR* name);
559 extern void module_reset_debug_info(struct module* module);
560 extern BOOL module_remove(struct process* pcs,
561 struct module* module);
562 extern void module_set_module(struct module* module, const WCHAR* name);
564 /* msc.c */
565 extern BOOL pe_load_debug_directory(const struct process* pcs,
566 struct module* module,
567 const BYTE* mapping,
568 const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
569 const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg);
570 extern BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup);
572 /* path.c */
573 extern BOOL path_find_symbol_file(const struct process* pcs, PCSTR full_path,
574 const GUID* guid, DWORD dw1, DWORD dw2, PSTR buffer,
575 BOOL* is_unmatched);
577 /* pe_module.c */
578 extern BOOL pe_load_nt_header(HANDLE hProc, DWORD64 base, IMAGE_NT_HEADERS* nth);
579 extern struct module*
580 pe_load_native_module(struct process* pcs, const WCHAR* name,
581 HANDLE hFile, DWORD base, DWORD size);
582 extern struct module*
583 pe_load_builtin_module(struct process* pcs, const WCHAR* name,
584 DWORD64 base, DWORD64 size);
585 extern BOOL pe_load_debug_info(const struct process* pcs,
586 struct module* module);
587 extern const char* pe_map_directory(struct module* module, int dirno, DWORD* size);
588 extern void pe_unmap_directoy(struct module* module, int dirno);
590 /* source.c */
591 extern unsigned source_new(struct module* module, const char* basedir, const char* source);
592 extern const char* source_get(const struct module* module, unsigned idx);
594 /* stabs.c */
595 typedef void (*stabs_def_cb)(struct module* module, unsigned long load_offset,
596 const char* name, unsigned long offset,
597 BOOL is_public, BOOL is_global, unsigned char other,
598 struct symt_compiland* compiland, void* user);
599 extern BOOL stabs_parse(struct module* module, unsigned long load_offset,
600 const void* stabs, int stablen,
601 const char* strs, int strtablen,
602 stabs_def_cb callback, void* user);
604 /* dwarf.c */
605 extern BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
606 const struct elf_thunk_area* thunks,
607 struct image_file_map* fmap);
608 extern BOOL dwarf2_virtual_unwind(struct cpu_stack_walk* csw, DWORD_PTR ip,
609 CONTEXT* context, ULONG_PTR* cfa);
611 /* stack.c */
612 extern BOOL sw_read_mem(struct cpu_stack_walk* csw, DWORD64 addr, void* ptr, DWORD sz);
613 extern DWORD64 sw_xlat_addr(struct cpu_stack_walk* csw, ADDRESS64* addr);
614 extern void* sw_table_access(struct cpu_stack_walk* csw, DWORD64 addr);
615 extern DWORD64 sw_module_base(struct cpu_stack_walk* csw, DWORD64 addr);
617 /* symbol.c */
618 extern const char* symt_get_name(const struct symt* sym);
619 extern struct module* symt_cmp_addr_module;
620 extern int symt_cmp_addr(const void* p1, const void* p2);
621 extern void copy_symbolW(SYMBOL_INFOW* siw, const SYMBOL_INFO* si);
622 extern struct symt_ht*
623 symt_find_nearest(struct module* module, DWORD_PTR addr);
624 extern struct symt_compiland*
625 symt_new_compiland(struct module* module, unsigned long address,
626 unsigned src_idx);
627 extern struct symt_public*
628 symt_new_public(struct module* module,
629 struct symt_compiland* parent,
630 const char* typename,
631 unsigned long address, unsigned size);
632 extern struct symt_data*
633 symt_new_global_variable(struct module* module,
634 struct symt_compiland* parent,
635 const char* name, unsigned is_static,
636 unsigned long addr, unsigned long size,
637 struct symt* type);
638 extern struct symt_function*
639 symt_new_function(struct module* module,
640 struct symt_compiland* parent,
641 const char* name,
642 unsigned long addr, unsigned long size,
643 struct symt* type);
644 extern BOOL symt_normalize_function(struct module* module,
645 const struct symt_function* func);
646 extern void symt_add_func_line(struct module* module,
647 struct symt_function* func,
648 unsigned source_idx, int line_num,
649 unsigned long offset);
650 extern struct symt_data*
651 symt_add_func_local(struct module* module,
652 struct symt_function* func,
653 enum DataKind dt, const struct location* loc,
654 struct symt_block* block,
655 struct symt* type, const char* name);
656 extern struct symt_block*
657 symt_open_func_block(struct module* module,
658 struct symt_function* func,
659 struct symt_block* block,
660 unsigned pc, unsigned len);
661 extern struct symt_block*
662 symt_close_func_block(struct module* module,
663 const struct symt_function* func,
664 struct symt_block* block, unsigned pc);
665 extern struct symt_hierarchy_point*
666 symt_add_function_point(struct module* module,
667 struct symt_function* func,
668 enum SymTagEnum point,
669 const struct location* loc,
670 const char* name);
671 extern BOOL symt_fill_func_line_info(const struct module* module,
672 const struct symt_function* func,
673 DWORD64 addr, IMAGEHLP_LINE64* line);
674 extern BOOL symt_get_func_line_next(const struct module* module, PIMAGEHLP_LINE64 line);
675 extern struct symt_thunk*
676 symt_new_thunk(struct module* module,
677 struct symt_compiland* parent,
678 const char* name, THUNK_ORDINAL ord,
679 unsigned long addr, unsigned long size);
680 extern struct symt_data*
681 symt_new_constant(struct module* module,
682 struct symt_compiland* parent,
683 const char* name, struct symt* type,
684 const VARIANT* v);
685 extern struct symt_hierarchy_point*
686 symt_new_label(struct module* module,
687 struct symt_compiland* compiland,
688 const char* name, unsigned long address);
689 extern struct symt* symt_index2ptr(struct module* module, DWORD id);
690 extern DWORD symt_ptr2index(struct module* module, const struct symt* sym);
692 /* type.c */
693 extern void symt_init_basic(struct module* module);
694 extern BOOL symt_get_info(struct module* module, const struct symt* type,
695 IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo);
696 extern struct symt_basic*
697 symt_new_basic(struct module* module, enum BasicType,
698 const char* typename, unsigned size);
699 extern struct symt_udt*
700 symt_new_udt(struct module* module, const char* typename,
701 unsigned size, enum UdtKind kind);
702 extern BOOL symt_set_udt_size(struct module* module,
703 struct symt_udt* type, unsigned size);
704 extern BOOL symt_add_udt_element(struct module* module,
705 struct symt_udt* udt_type,
706 const char* name,
707 struct symt* elt_type, unsigned offset,
708 unsigned size);
709 extern struct symt_enum*
710 symt_new_enum(struct module* module, const char* typename,
711 struct symt* basetype);
712 extern BOOL symt_add_enum_element(struct module* module,
713 struct symt_enum* enum_type,
714 const char* name, int value);
715 extern struct symt_array*
716 symt_new_array(struct module* module, int min, int max,
717 struct symt* base, struct symt* index);
718 extern struct symt_function_signature*
719 symt_new_function_signature(struct module* module,
720 struct symt* ret_type,
721 enum CV_call_e call_conv);
722 extern BOOL symt_add_function_signature_parameter(struct module* module,
723 struct symt_function_signature* sig,
724 struct symt* param);
725 extern struct symt_pointer*
726 symt_new_pointer(struct module* module,
727 struct symt* ref_type);
728 extern struct symt_typedef*
729 symt_new_typedef(struct module* module, struct symt* ref,
730 const char* name);