msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / dbghelp / dbghelp_private.h
blob880aed9a86b6c25bdb95a5350f7dd99d30222e7d
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/unicode.h"
34 #include "cvconst.h"
36 /* #define USE_STATS */
38 struct pool /* poor's man */
40 struct pool_arena* first;
41 unsigned arena_size;
44 void pool_init(struct pool* a, unsigned arena_size);
45 void pool_destroy(struct pool* a);
46 void* pool_alloc(struct pool* a, unsigned len);
47 char* pool_strdup(struct pool* a, const char* str);
49 struct vector
51 void** buckets;
52 unsigned elt_size;
53 unsigned shift;
54 unsigned num_elts;
55 unsigned num_buckets;
56 unsigned buckets_allocated;
59 void vector_init(struct vector* v, unsigned elt_sz, unsigned bucket_sz);
60 unsigned vector_length(const struct vector* v);
61 void* vector_at(const struct vector* v, unsigned pos);
62 void* vector_add(struct vector* v, struct pool* pool);
64 struct sparse_array
66 struct vector key2index;
67 struct vector elements;
70 void sparse_array_init(struct sparse_array* sa, unsigned elt_sz, unsigned bucket_sz);
71 void* sparse_array_find(const struct sparse_array* sa, unsigned long idx);
72 void* sparse_array_add(struct sparse_array* sa, unsigned long key, struct pool* pool);
73 unsigned sparse_array_length(const struct sparse_array* sa);
75 struct hash_table_elt
77 const char* name;
78 struct hash_table_elt* next;
81 struct hash_table
83 unsigned num_elts;
84 unsigned num_buckets;
85 struct hash_table_elt** buckets;
86 struct pool* pool;
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);
95 struct hash_table_iter
97 const struct hash_table* ht;
98 struct hash_table_elt* element;
99 int index;
100 int last;
103 void hash_table_iter_init(const struct hash_table* ht,
104 struct hash_table_iter* hti, const char* name);
105 void* hash_table_iter_up(struct hash_table_iter* hti);
107 #define GET_ENTRY(__i, __t, __f) \
108 ((__t*)((char*)(__i) - FIELD_OFFSET(__t,__f)))
111 extern unsigned dbghelp_options;
112 /* some more Wine extensions */
113 #define SYMOPT_WINE_WITH_ELF_MODULES 0x40000000
115 enum location_kind {loc_error, /* reg is the error code */
116 loc_absolute, /* offset is the location */
117 loc_register, /* reg is the location */
118 loc_regrel, /* [reg+offset] is the location */
119 loc_user, /* value is debug information dependent,
120 reg & offset can be used ad libidem */
123 enum location_error {loc_err_internal = -1, /* internal while computing */
124 loc_err_too_complex = -2, /* couldn't compute location (even at runtime) */
125 loc_err_out_of_scope = -3, /* variable isn't available at current address */
126 loc_err_cant_read = -4, /* couldn't read memory at given address */
129 struct location
131 unsigned kind : 8,
132 reg;
133 unsigned long offset;
136 struct symt
138 enum SymTagEnum tag;
141 struct symt_ht
143 struct symt symt;
144 struct hash_table_elt hash_elt; /* if global symbol or type */
147 /* lexical tree */
148 struct symt_block
150 struct symt symt;
151 unsigned long address;
152 unsigned long size;
153 struct symt* container; /* block, or func */
154 struct vector vchildren; /* sub-blocks & local variables */
157 struct symt_compiland
159 struct symt symt;
160 unsigned long address;
161 unsigned source;
162 struct vector vchildren; /* global variables & functions */
165 struct symt_data
167 struct symt symt;
168 struct hash_table_elt hash_elt; /* if global symbol */
169 enum DataKind kind;
170 struct symt* container;
171 struct symt* type;
172 union /* depends on kind */
174 /* DataIs{Global, FileStatic}:
175 * loc.kind is loc_absolute
176 * loc.offset is address
177 * DataIs{Local,Param}:
178 * with loc.kind
179 * loc_absolute not supported
180 * loc_register location is in register loc.reg
181 * loc_regrel location is at address loc.reg + loc.offset
182 * >= loc_user ask debug info provider for resolution
184 struct location var;
185 /* DataIs{Member} (all values are in bits, not bytes) */
186 struct
188 long offset;
189 unsigned long length;
190 } member;
191 /* DataIsConstant */
192 VARIANT value;
193 } u;
196 struct symt_function
198 struct symt symt;
199 struct hash_table_elt hash_elt; /* if global symbol */
200 unsigned long address;
201 struct symt* container; /* compiland */
202 struct symt* type; /* points to function_signature */
203 unsigned long size;
204 struct vector vlines;
205 struct vector vchildren; /* locals, params, blocks, start/end, labels */
208 struct symt_hierarchy_point
210 struct symt symt; /* either SymTagFunctionDebugStart, SymTagFunctionDebugEnd, SymTagLabel */
211 struct hash_table_elt hash_elt; /* if label (and in compiland's hash table if global) */
212 struct symt* parent; /* symt_function or symt_compiland */
213 struct location loc;
216 struct symt_public
218 struct symt symt;
219 struct hash_table_elt hash_elt;
220 struct symt* container; /* compiland */
221 unsigned long address;
222 unsigned long size;
223 unsigned in_code : 1,
224 is_function : 1;
227 struct symt_thunk
229 struct symt symt;
230 struct hash_table_elt hash_elt;
231 struct symt* container; /* compiland */
232 unsigned long address;
233 unsigned long size;
234 THUNK_ORDINAL ordinal; /* FIXME: doesn't seem to be accessible */
237 /* class tree */
238 struct symt_array
240 struct symt symt;
241 int start;
242 int end;
243 struct symt* base_type;
244 struct symt* index_type;
247 struct symt_basic
249 struct symt symt;
250 struct hash_table_elt hash_elt;
251 enum BasicType bt;
252 unsigned long size;
255 struct symt_enum
257 struct symt symt;
258 struct symt* base_type;
259 const char* name;
260 struct vector vchildren;
263 struct symt_function_signature
265 struct symt symt;
266 struct symt* rettype;
267 struct vector vchildren;
268 enum CV_call_e call_conv;
271 struct symt_function_arg_type
273 struct symt symt;
274 struct symt* arg_type;
275 struct symt* container;
278 struct symt_pointer
280 struct symt symt;
281 struct symt* pointsto;
284 struct symt_typedef
286 struct symt symt;
287 struct hash_table_elt hash_elt;
288 struct symt* type;
291 struct symt_udt
293 struct symt symt;
294 struct hash_table_elt hash_elt;
295 enum UdtKind kind;
296 int size;
297 struct vector vchildren;
300 enum module_type
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 */
306 DMT_DBG, /* .DBG file */
309 struct process;
311 struct module
313 IMAGEHLP_MODULEW64 module;
314 /* ANSI copy of module.ModuleName for efficiency */
315 char module_name[MAX_PATH];
316 struct module* next;
317 enum module_type type : 16;
318 unsigned short is_virtual : 1;
320 /* specific information for debug types */
321 struct elf_module_info* elf_info;
322 struct dwarf2_module_info_s*dwarf2_info;
324 /* memory allocation pool */
325 struct pool pool;
327 /* symbols & symbol tables */
328 int sortlist_valid;
329 unsigned num_sorttab; /* number of symbols with addresses */
330 struct symt_ht** addr_sorttab;
331 struct hash_table ht_symbols;
332 void (*loc_compute)(struct process* pcs,
333 const struct module* module,
334 const struct symt_function* func,
335 struct location* loc);
337 /* types */
338 struct hash_table ht_types;
339 struct vector vtypes;
341 /* source files */
342 unsigned sources_used;
343 unsigned sources_alloc;
344 char* sources;
347 struct process
349 struct process* next;
350 HANDLE handle;
351 WCHAR* search_path;
353 PSYMBOL_REGISTERED_CALLBACK64 reg_cb;
354 BOOL reg_is_unicode;
355 DWORD64 reg_user;
357 struct module* lmodules;
358 unsigned long dbg_hdr_addr;
360 IMAGEHLP_STACK_FRAME ctx_frame;
362 unsigned buffer_size;
363 void* buffer;
366 struct line_info
368 unsigned long is_first : 1,
369 is_last : 1,
370 is_source_file : 1,
371 line_number;
372 union
374 unsigned long pc_offset; /* if is_source_file isn't set */
375 unsigned source_file; /* if is_source_file is set */
376 } u;
379 struct module_pair
381 struct process* pcs;
382 struct module* requested; /* in: to module_get_debug() */
383 struct module* effective; /* out: module with debug info */
386 enum pdb_kind {PDB_JG, PDB_DS};
388 struct pdb_lookup
390 const char* filename;
391 DWORD age;
392 enum pdb_kind kind;
393 union
395 struct
397 DWORD timestamp;
398 struct PDB_JG_TOC* toc;
399 } jg;
400 struct
402 GUID guid;
403 struct PDB_DS_TOC* toc;
404 } ds;
405 } u;
408 /* dbghelp.c */
409 extern struct process* process_find_by_handle(HANDLE hProcess);
410 extern HANDLE hMsvcrt;
411 extern BOOL validate_addr64(DWORD64 addr);
412 extern BOOL pcs_callback(const struct process* pcs, ULONG action, void* data);
413 extern void* fetch_buffer(struct process* pcs, unsigned size);
415 /* elf_module.c */
416 #define ELF_NO_MAP ((const void*)0xffffffff)
417 typedef BOOL (*elf_enum_modules_cb)(const WCHAR*, unsigned long addr, void* user);
418 extern BOOL elf_enum_modules(HANDLE hProc, elf_enum_modules_cb, void*);
419 extern BOOL elf_fetch_file_info(const WCHAR* name, DWORD* base, DWORD* size, DWORD* checksum);
420 struct elf_file_map;
421 extern BOOL elf_load_debug_info(struct module* module, struct elf_file_map* fmap);
422 extern struct module*
423 elf_load_module(struct process* pcs, const WCHAR* name, unsigned long);
424 extern BOOL elf_read_wine_loader_dbg_info(struct process* pcs);
425 extern BOOL elf_synchronize_module_list(struct process* pcs);
426 struct elf_thunk_area;
427 extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_thunk_area* thunks);
428 extern DWORD WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS* addr);
430 /* module.c */
431 extern const WCHAR S_ElfW[];
432 extern const WCHAR S_WineLoaderW[];
433 extern const WCHAR S_WinePThreadW[];
434 extern const WCHAR S_WineKThreadW[];
435 extern const WCHAR S_SlashW[];
437 extern struct module*
438 module_find_by_addr(const struct process* pcs, unsigned long addr,
439 enum module_type type);
440 extern struct module*
441 module_find_by_nameA(const struct process* pcs,
442 const char* name);
443 extern struct module*
444 module_is_already_loaded(const struct process* pcs,
445 const WCHAR* imgname);
446 extern BOOL module_get_debug(struct module_pair*);
447 extern struct module*
448 module_new(struct process* pcs, const WCHAR* name,
449 enum module_type type, BOOL virtual,
450 unsigned long addr, unsigned long size,
451 unsigned long stamp, unsigned long checksum);
452 extern struct module*
453 module_get_containee(const struct process* pcs,
454 const struct module* inner);
455 extern enum module_type
456 module_get_type_by_name(const WCHAR* name);
457 extern void module_reset_debug_info(struct module* module);
458 extern BOOL module_remove(struct process* pcs,
459 struct module* module);
460 extern void module_set_module(struct module* module, const WCHAR* name);
462 /* msc.c */
463 extern BOOL pe_load_debug_directory(const struct process* pcs,
464 struct module* module,
465 const BYTE* mapping,
466 const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
467 const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg);
468 extern BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup);
470 /* path.c */
471 extern BOOL path_find_symbol_file(const struct process* pcs, PCSTR full_path,
472 const GUID* guid, DWORD dw1, DWORD dw2, PSTR buffer,
473 BOOL* is_unmatched);
475 /* pe_module.c */
476 extern BOOL pe_load_nt_header(HANDLE hProc, DWORD base, IMAGE_NT_HEADERS* nth);
477 extern struct module*
478 pe_load_native_module(struct process* pcs, const WCHAR* name,
479 HANDLE hFile, DWORD base, DWORD size);
480 extern struct module*
481 pe_load_builtin_module(struct process* pcs, const WCHAR* name,
482 DWORD base, DWORD size);
483 extern BOOL pe_load_debug_info(const struct process* pcs,
484 struct module* module);
485 /* source.c */
486 extern unsigned source_new(struct module* module, const char* basedir, const char* source);
487 extern const char* source_get(const struct module* module, unsigned idx);
489 /* stabs.c */
490 extern BOOL stabs_parse(struct module* module, unsigned long load_offset,
491 const void* stabs, int stablen,
492 const char* strs, int strtablen);
494 /* dwarf.c */
495 extern BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
496 const struct elf_thunk_area* thunks,
497 const unsigned char* debug, unsigned int debug_size,
498 const unsigned char* abbrev, unsigned int abbrev_size,
499 const unsigned char* str, unsigned int str_size,
500 const unsigned char* line, unsigned int line_size,
501 const unsigned char* loclist, unsigned int loclist_size);
503 /* symbol.c */
504 extern const char* symt_get_name(const struct symt* sym);
505 extern int symt_cmp_addr(const void* p1, const void* p2);
506 extern void copy_symbolW(SYMBOL_INFOW* siw, const SYMBOL_INFO* si);
507 extern struct symt_ht*
508 symt_find_nearest(struct module* module, DWORD addr);
509 extern struct symt_compiland*
510 symt_new_compiland(struct module* module, unsigned long address,
511 unsigned src_idx);
512 extern struct symt_public*
513 symt_new_public(struct module* module,
514 struct symt_compiland* parent,
515 const char* typename,
516 unsigned long address, unsigned size,
517 BOOL in_code, BOOL is_func);
518 extern struct symt_data*
519 symt_new_global_variable(struct module* module,
520 struct symt_compiland* parent,
521 const char* name, unsigned is_static,
522 unsigned long addr, unsigned long size,
523 struct symt* type);
524 extern struct symt_function*
525 symt_new_function(struct module* module,
526 struct symt_compiland* parent,
527 const char* name,
528 unsigned long addr, unsigned long size,
529 struct symt* type);
530 extern BOOL symt_normalize_function(struct module* module,
531 struct symt_function* func);
532 extern void symt_add_func_line(struct module* module,
533 struct symt_function* func,
534 unsigned source_idx, int line_num,
535 unsigned long offset);
536 extern struct symt_data*
537 symt_add_func_local(struct module* module,
538 struct symt_function* func,
539 enum DataKind dt, const struct location* loc,
540 struct symt_block* block,
541 struct symt* type, const char* name);
542 extern struct symt_block*
543 symt_open_func_block(struct module* module,
544 struct symt_function* func,
545 struct symt_block* block,
546 unsigned pc, unsigned len);
547 extern struct symt_block*
548 symt_close_func_block(struct module* module,
549 struct symt_function* func,
550 struct symt_block* block, unsigned pc);
551 extern struct symt_hierarchy_point*
552 symt_add_function_point(struct module* module,
553 struct symt_function* func,
554 enum SymTagEnum point,
555 const struct location* loc,
556 const char* name);
557 extern BOOL symt_fill_func_line_info(const struct module* module,
558 const struct symt_function* func,
559 DWORD addr, IMAGEHLP_LINE* line);
560 extern BOOL symt_get_func_line_next(const struct module* module, PIMAGEHLP_LINE line);
561 extern struct symt_thunk*
562 symt_new_thunk(struct module* module,
563 struct symt_compiland* parent,
564 const char* name, THUNK_ORDINAL ord,
565 unsigned long addr, unsigned long size);
566 extern struct symt_data*
567 symt_new_constant(struct module* module,
568 struct symt_compiland* parent,
569 const char* name, struct symt* type,
570 const VARIANT* v);
571 extern struct symt_hierarchy_point*
572 symt_new_label(struct module* module,
573 struct symt_compiland* compiland,
574 const char* name, unsigned long address);
576 /* type.c */
577 extern void symt_init_basic(struct module* module);
578 extern BOOL symt_get_info(const struct symt* type,
579 IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo);
580 extern struct symt_basic*
581 symt_new_basic(struct module* module, enum BasicType,
582 const char* typename, unsigned size);
583 extern struct symt_udt*
584 symt_new_udt(struct module* module, const char* typename,
585 unsigned size, enum UdtKind kind);
586 extern BOOL symt_set_udt_size(struct module* module,
587 struct symt_udt* type, unsigned size);
588 extern BOOL symt_add_udt_element(struct module* module,
589 struct symt_udt* udt_type,
590 const char* name,
591 struct symt* elt_type, unsigned offset,
592 unsigned size);
593 extern struct symt_enum*
594 symt_new_enum(struct module* module, const char* typename,
595 struct symt* basetype);
596 extern BOOL symt_add_enum_element(struct module* module,
597 struct symt_enum* enum_type,
598 const char* name, int value);
599 extern struct symt_array*
600 symt_new_array(struct module* module, int min, int max,
601 struct symt* base, struct symt* index);
602 extern struct symt_function_signature*
603 symt_new_function_signature(struct module* module,
604 struct symt* ret_type,
605 enum CV_call_e call_conv);
606 extern BOOL symt_add_function_signature_parameter(struct module* module,
607 struct symt_function_signature* sig,
608 struct symt* param);
609 extern struct symt_pointer*
610 symt_new_pointer(struct module* module,
611 struct symt* ref_type);
612 extern struct symt_typedef*
613 symt_new_typedef(struct module* module, struct symt* ref,
614 const char* name);