TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / tools / winedump / winedump.h
blob339cee32f09abb6cfd1e85419a8461993aef979c
1 /*
2 * Winedump - A Wine DLL tool
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * References:
21 * DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
23 * Option processing shamelessly cadged from winebuild.
25 * All the cool functionality (prototyping, call tracing, forwarding)
26 * relies on Patrik Stridvall's 'function_grep.pl' script to work.
28 * http://www.kegel.com/mangle.html
29 * Gives information on the name mangling scheme used by MS compilers,
30 * used as the starting point for the code here. Contains a few
31 * mistakes and some incorrect assumptions, but the lists of types
32 * are pure gold.
34 #ifndef __WINE_WINEDUMP_H
35 #define __WINE_WINEDUMP_H
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <ctype.h>
41 #include <errno.h>
42 #include <assert.h>
43 #include <stdarg.h>
45 #include "windef.h"
46 #include "winbase.h"
48 /* Argument type constants */
49 #define MAX_FUNCTION_ARGS 32
51 #define ARG_VOID 0x0
52 #define ARG_STRING 0x1
53 #define ARG_WIDE_STRING 0x2
54 #define ARG_POINTER 0x3
55 #define ARG_LONG 0x4
56 #define ARG_DOUBLE 0x5
57 #define ARG_STRUCT 0x6 /* By value */
58 #define ARG_FLOAT 0x7
59 #define ARG_VARARGS 0x8
61 /* Compound type flags */
62 #define CT_BY_REFERENCE 0x1
63 #define CT_VOLATILE 0x2
64 #define CT_CONST 0x4
65 #define CT_EXTENDED 0x8
67 /* symbol flags */
68 #define SYM_CDECL 0x1
69 #define SYM_STDCALL 0x2
70 #define SYM_THISCALL 0x4
71 #define SYM_DATA 0x8 /* Data, not a function */
73 typedef enum {NONE, DMGL, SPEC, DUMP} Mode;
75 /* Structure holding a parsed symbol */
76 typedef struct __parsed_symbol
78 char *symbol;
79 int ordinal;
80 char *return_text;
81 char return_type;
82 char *function_name;
83 int varargs;
84 unsigned int argc;
85 unsigned int flags;
86 char arg_type [MAX_FUNCTION_ARGS];
87 char arg_flag [MAX_FUNCTION_ARGS];
88 char *arg_text [MAX_FUNCTION_ARGS];
89 char *arg_name [MAX_FUNCTION_ARGS];
90 } parsed_symbol;
92 /* FIXME: Replace with some hash such as GHashTable */
93 typedef struct __search_symbol
95 struct __search_symbol *next;
96 BOOL found;
97 char symbolname[1]; /* static string, be ANSI C compliant by [1] */
98 } search_symbol;
100 /* All globals */
101 typedef struct __globals
103 Mode mode; /* SPEC, DEMANGLE or DUMP */
105 /* Options: generic */
106 BOOL do_quiet; /* -q */
107 BOOL do_verbose; /* -v */
109 /* Option arguments: generic */
110 const char *input_name; /* */
111 const char *input_module; /* input module name generated after input_name according mode */
113 /* Options: spec mode */
114 BOOL do_code; /* -c, -t, -f */
115 BOOL do_trace; /* -t, -f */
116 BOOL do_cdecl; /* -C */
117 BOOL do_documentation; /* -D */
119 /* Options: dump mode */
120 BOOL do_demangle; /* -d */
121 BOOL do_dumpheader; /* -f */
122 BOOL do_dump_rawdata; /* -x */
123 BOOL do_debug; /* -G == 1, -g == 2 */
124 BOOL do_symbol_table; /* -t */
126 /* Option arguments: spec mode */
127 int start_ordinal; /* -s */
128 int end_ordinal; /* -e */
129 search_symbol *search_symbol; /* -S */
130 char *directory; /* -I */
131 const char *forward_dll; /* -f */
132 const char *dll_name; /* -o */
133 const char *uc_dll_name; /* -o */
135 /* Option arguments: dump mode */
136 const char *dumpsect; /* -j */
137 } _globals;
139 extern _globals globals;
141 /* Names to use for output DLL */
142 #define OUTPUT_DLL_NAME \
143 (globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
144 #define OUTPUT_UC_DLL_NAME globals.uc_dll_name
146 /* Verbosity levels */
147 #define QUIET (globals.do_quiet)
148 #define NORMAL (!QUIET)
149 #define VERBOSE (globals.do_verbose)
151 /* Default calling convention */
152 #define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
154 /* Image functions */
155 void dump_file(const char* name);
157 /* DLL functions */
158 BOOL dll_open (const char *dll_name);
160 BOOL dll_next_symbol (parsed_symbol * sym);
162 /* Symbol functions */
163 void symbol_init(parsed_symbol* symbol, const char* name);
165 BOOL symbol_demangle (parsed_symbol *symbol);
167 BOOL symbol_search (parsed_symbol *symbol);
169 void symbol_clear(parsed_symbol *sym);
171 BOOL symbol_is_valid_c(const parsed_symbol *sym);
173 const char *symbol_get_call_convention(const parsed_symbol *sym);
175 const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);
177 void symbol_clean_string (char *string);
179 int symbol_get_type (const char *string);
181 /* Output functions */
182 void output_spec_preamble (void);
184 void output_spec_symbol (const parsed_symbol *sym);
186 void output_header_preamble (void);
188 void output_header_symbol (const parsed_symbol *sym);
190 void output_c_preamble (void);
192 void output_c_symbol (const parsed_symbol *sym);
194 void output_prototype (FILE *file, const parsed_symbol *sym);
196 void output_makefile (void);
198 /* Misc functions */
199 char *str_create (size_t num_str, ...);
201 char *str_create_num (size_t num_str, int num, ...);
203 char *str_substring(const char *start, const char *end);
205 char *str_replace (char *str, const char *oldstr, const char *newstr);
207 const char *str_match (const char *str, const char *match, BOOL *found);
209 const char *str_find_set (const char *str, const char *findset);
211 char *str_toupper (char *str);
213 const char *get_machine_str(int mach);
215 /* file dumping functions */
216 enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_PE, SIG_DBG, SIG_PDB, SIG_NE, SIG_LE, SIG_MDMP, SIG_COFFLIB, SIG_LNK,
217 SIG_EMF, SIG_FNT, SIG_MSFT};
219 const void* PRD(unsigned long prd, unsigned long len);
220 unsigned long Offset(const void* ptr);
222 typedef void (*file_dumper)(void);
223 BOOL dump_analysis(const char*, file_dumper, enum FileSig);
225 void dump_data( const unsigned char *ptr, unsigned int size, const char *prefix );
226 const char* get_time_str( unsigned long );
227 unsigned int strlenW( const unsigned short *str );
228 void dump_unicode_str( const unsigned short *str, int len );
229 const char* get_guid_str(const GUID* guid);
230 const char* get_symbol_str(const char* symname);
231 void dump_file_header(const IMAGE_FILE_HEADER *);
232 void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *, UINT);
233 void dump_section(const IMAGE_SECTION_HEADER *, const char* strtable);
235 enum FileSig get_kind_exec(void);
236 void dos_dump( void );
237 void pe_dump( void );
238 void ne_dump( void );
239 void le_dump( void );
240 enum FileSig get_kind_mdmp(void);
241 void mdmp_dump( void );
242 enum FileSig get_kind_lib(void);
243 void lib_dump( void );
244 enum FileSig get_kind_dbg(void);
245 void dbg_dump( void );
246 enum FileSig get_kind_lnk(void);
247 void lnk_dump( void );
248 enum FileSig get_kind_emf(void);
249 void emf_dump( void );
250 enum FileSig get_kind_pdb(void);
251 void pdb_dump(void);
252 enum FileSig get_kind_fnt(void);
253 void fnt_dump( void );
254 enum FileSig get_kind_msft(void);
255 void msft_dump(void);
257 BOOL codeview_dump_symbols(const void* root, unsigned long size);
258 BOOL codeview_dump_types_from_offsets(const void* table, const DWORD* offsets, unsigned num_types);
259 BOOL codeview_dump_types_from_block(const void* table, unsigned long len);
260 void codeview_dump_linetab(const char* linetab, BOOL pascal_str, const char* pfx);
261 void codeview_dump_linetab2(const char* linetab, DWORD size, const char* strimage, DWORD strsize, const char* pfx);
263 void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
264 void dump_codeview(unsigned long ptr, unsigned long len);
265 void dump_coff(unsigned long coffbase, unsigned long len,
266 const IMAGE_SECTION_HEADER *sectHead);
267 void dump_coff_symbol_table(const IMAGE_SYMBOL *coff_symbols, unsigned num_sym,
268 const IMAGE_SECTION_HEADER *sectHead);
269 void dump_frame_pointer_omission(unsigned long base, unsigned long len);
271 FILE *open_file (const char *name, const char *ext, const char *mode);
273 #ifdef __GNUC__
274 void do_usage (const char *arg) __attribute__ ((noreturn));
275 void fatal (const char *message) __attribute__ ((noreturn));
276 #else
277 void do_usage (const char *arg);
278 void fatal (const char *message);
279 #endif
283 #endif /* __WINE_WINEDUMP_H */