Ignore all output files.
[wine/multimedia.git] / debugger / debugger.h
blobd95ce57c6628f190be656c99d815174afa6a250a
1 /*
2 * Debugger definitions
4 * Copyright 1995 Alexandre Julliard
5 */
7 #ifndef __WINE_DEBUGGER_H
8 #define __WINE_DEBUGGER_H
10 #include <sys/types.h> /* u_long ... */
11 #include <assert.h>
12 #include "windef.h"
13 #include "winbase.h"
14 #include "wine/exception.h"
16 #ifdef __i386__
17 #define STEP_FLAG 0x00000100 /* single step flag */
18 #define V86_FLAG 0x00020000
19 #endif
21 #define SYM_FUNC 0x0
22 #define SYM_DATA 0x1
23 #define SYM_WIN32 0x2
24 #define SYM_WINE 0x4
25 #define SYM_INVALID 0x8
26 #define SYM_TRAMPOLINE 0x10
27 #define SYM_STEP_THROUGH 0x20
29 enum debug_type {DT_BASIC, DT_CONST, DT_POINTER, DT_ARRAY, DT_STRUCT, DT_ENUM, DT_TYPEDEF, DT_FUNC, DT_BITFIELD};
33 * Return values for DEBUG_CheckLinenoStatus. Used to determine
34 * what to do when the 'step' command is given.
36 #define FUNC_HAS_NO_LINES (0)
37 #define NOT_ON_LINENUMBER (1)
38 #define AT_LINENUMBER (2)
39 #define FUNC_IS_TRAMPOLINE (3)
42 * For constants generated by the parser, we use this datatype
44 extern struct datatype * DEBUG_TypeInt;
45 extern struct datatype * DEBUG_TypeIntConst;
46 extern struct datatype * DEBUG_TypeUSInt;
47 extern struct datatype * DEBUG_TypeString;
49 typedef struct
51 DWORD seg; /* 0xffffffff means current default segment (cs or ds) */
52 DWORD off;
53 } DBG_ADDR;
55 #define DV_TARGET 0xF00D
56 #define DV_HOST 0x50DA
58 typedef struct
60 struct datatype* type;
61 int cookie; /* DV_??? */
62 DBG_ADDR addr;
63 } DBG_VALUE;
65 struct list_id
67 char * sourcefile;
68 int line;
71 struct wine_lines {
72 unsigned long line_number;
73 DBG_ADDR pc_offset;
76 struct symbol_info
78 struct name_hash * sym;
79 struct list_id list;
82 typedef struct wine_lines WineLineNo;
85 * This structure holds information about stack variables, function
86 * parameters, and register variables, which are all local to this
87 * function.
89 struct wine_locals {
90 unsigned int regno:8; /* For register symbols */
91 signed int offset:24; /* offset from esp/ebp to symbol */
92 unsigned int pc_start; /* For RBRAC/LBRAC */
93 unsigned int pc_end; /* For RBRAC/LBRAC */
94 char * name; /* Name of symbol */
95 struct datatype * type; /* Datatype of symbol */
98 typedef struct wine_locals WineLocals;
100 enum exec_mode
102 EXEC_CONT, /* Continuous execution */
103 EXEC_PASS, /* Continue, passing exception to app */
104 EXEC_STEP_OVER, /* Stepping over a call to next source line */
105 EXEC_STEP_INSTR, /* Step to next source line, stepping in if needed */
106 EXEC_STEPI_OVER, /* Stepping over a call */
107 EXEC_STEPI_INSTR, /* Single-stepping an instruction */
108 EXEC_FINISH, /* Step until we exit current frame */
109 EXEC_STEP_OVER_TRAMPOLINE /* Step over trampoline. Requires that
110 * we dig the real return value off the stack
111 * and set breakpoint there - not at the
112 * instr just after the call.
116 #define DBG_BREAK 0
117 #define DBG_WATCH 1
119 typedef struct
121 DBG_ADDR addr;
122 WORD enabled : 1,
123 type : 1,
124 is32 : 1,
125 refcount : 13;
126 WORD skipcount;
127 union {
128 BYTE opcode;
129 struct {
130 BYTE rw : 1,
131 len : 2;
132 BYTE reg;
133 DWORD oldval;
134 } w;
135 } u;
136 struct expr * condition;
137 } BREAKPOINT;
139 typedef struct tagDBG_THREAD {
140 struct tagDBG_PROCESS* process;
141 HANDLE handle;
142 DWORD tid;
143 LPVOID start;
144 LPVOID teb;
145 int wait_for_first_exception;
146 int dbg_mode;
147 enum exec_mode dbg_exec_mode;
148 int dbg_exec_count;
149 BREAKPOINT stepOverBP;
150 struct tagDBG_THREAD* next;
151 struct tagDBG_THREAD* prev;
152 } DBG_THREAD;
154 typedef struct tagDBG_PROCESS {
155 HANDLE handle;
156 DWORD pid;
157 DBG_THREAD* threads;
158 int num_threads;
159 struct tagDBG_MODULE* modules;
161 * This is an index we use to keep track of the debug information
162 * when we have multiple sources. We use the same database to also
163 * allow us to do an 'info shared' type of deal, and we use the index
164 * to eliminate duplicates.
166 int next_index;
167 struct tagDBG_PROCESS* next;
168 struct tagDBG_PROCESS* prev;
169 } DBG_PROCESS;
171 extern DBG_PROCESS* DEBUG_CurrProcess;
172 extern DBG_THREAD* DEBUG_CurrThread;
173 extern CONTEXT DEBUG_context;
175 #define DEBUG_READ_MEM(addr, buf, len) \
176 (ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
178 #define DEBUG_WRITE_MEM(addr, buf, len) \
179 (WriteProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
181 #define DEBUG_READ_MEM_VERBOSE(addr, buf, len) \
182 (DEBUG_READ_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
184 #define DEBUG_WRITE_MEM_VERBOSE(addr, buf, len) \
185 (DEBUG_WRITE_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
187 typedef struct tagDBG_MODULE {
188 struct tagDBG_MODULE* next;
189 void* load_addr;
190 char* module_name;
191 char status;
192 char type;
193 short int dbg_index;
194 HMODULE handle;
195 void* extra_info;
196 } DBG_MODULE;
198 /* status field */
199 #define DM_STATUS_NEW 0
200 #define DM_STATUS_LOADED 1
201 #define DM_STATUS_ERROR 2
203 /* type field */
204 #define DM_TYPE_UNKNOWN 0
205 #define DM_TYPE_ELF 1
206 #define DM_TYPE_NE 2
207 #define DM_TYPE_PE 3
209 #ifdef __i386__
210 #ifdef REG_SP /* Some Sun includes define this */
211 #undef REG_SP
212 #endif
214 enum debug_regs
216 REG_EAX, REG_EBX, REG_ECX, REG_EDX, REG_ESI,
217 REG_EDI, REG_EBP, REG_EFL, REG_EIP, REG_ESP,
218 REG_AX, REG_BX, REG_CX, REG_DX, REG_SI,
219 REG_DI, REG_BP, REG_FL, REG_IP, REG_SP,
220 REG_CS, REG_DS, REG_ES, REG_SS, REG_FS, REG_GS
222 #endif
224 #define OFFSET_OF(__c,__f) ((int)(((char*)&(((__c*)0)->__f))-((char*)0)))
226 /* debugger/break.c */
227 extern void DEBUG_SetBreakpoints( BOOL set );
228 extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr );
229 extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
230 extern void DEBUG_DelBreakpoint( int num );
231 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
232 extern void DEBUG_InfoBreakpoints(void);
233 extern BOOL DEBUG_HandleTrap(void);
234 extern BOOL DEBUG_ShouldContinue( DWORD code, enum exec_mode mode, int * count );
235 extern void DEBUG_SuspendExecution( void );
236 extern enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count );
237 extern BOOL DEBUG_IsFctReturn(void);
238 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
240 /* debugger/db_disasm.c */
241 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
243 /* debugger/expr.c */
244 extern void DEBUG_FreeExprMem(void);
245 struct expr * DEBUG_RegisterExpr(enum debug_regs);
246 struct expr * DEBUG_SymbolExpr(const char * name);
247 struct expr * DEBUG_ConstExpr(int val);
248 struct expr * DEBUG_StringExpr(const char * str);
249 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
250 struct expr * DEBUG_USConstExpr(unsigned int val);
251 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
252 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
253 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
254 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
255 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
256 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
257 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
258 extern DBG_VALUE DEBUG_EvalExpr(struct expr *);
259 extern int DEBUG_DelDisplay(int displaynum);
260 extern struct expr * DEBUG_CloneExpr(const struct expr * exp);
261 extern int DEBUG_FreeExpr(struct expr * exp);
262 extern int DEBUG_DisplayExpr(const struct expr * exp);
264 /* debugger/display.c */
265 extern int DEBUG_DoDisplay(void);
266 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
267 extern int DEBUG_DoDisplay(void);
268 extern int DEBUG_DelDisplay(int displaynum);
269 extern int DEBUG_InfoDisplay(void);
271 /* debugger/hash.c */
272 extern struct name_hash * DEBUG_AddSymbol( const char *name,
273 const DBG_VALUE *addr,
274 const char *sourcefile,
275 int flags);
276 extern BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
277 DBG_VALUE *addr, int );
278 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
279 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
280 struct name_hash ** rtn,
281 unsigned int ebp,
282 struct list_id * source);
283 extern void DEBUG_ReadSymbolTable( const char * filename );
284 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num,
285 unsigned long offset );
286 extern struct wine_locals *
287 DEBUG_AddLocal( struct name_hash * func, int regno,
288 int offset,
289 int pc_start,
290 int pc_end,
291 char * name);
292 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
293 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file,
294 const char * func);
295 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
296 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
297 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
298 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
299 extern BOOL DEBUG_GetLineNumberAddr( struct name_hash *, const int lineno,
300 DBG_ADDR *addr, int bp_flag );
302 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym,
303 struct datatype * type);
304 extern BOOL DEBUG_Normalize(struct name_hash * nh );
306 /* debugger/info.c */
307 extern void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format );
308 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr,
309 int addrlen, int flag );
310 extern void DEBUG_Help(void);
311 extern void DEBUG_HelpInfo(void);
312 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr,
313 int addrlen,
314 unsigned int ebp,
315 int flag );
316 extern void DEBUG_InfoClass(const char* clsName);
317 extern void DEBUG_WalkClasses(void);
318 extern void DEBUG_WalkModref(DWORD p);
319 extern void DEBUG_DumpModule(DWORD mod);
320 extern void DEBUG_WalkModules(void);
321 extern void DEBUG_WalkProcess(void);
322 extern void DEBUG_DumpQueue(DWORD q);
323 extern void DEBUG_WalkQueues(void);
324 extern void DEBUG_InfoSegments(DWORD s, int v);
325 extern void DEBUG_InfoVirtual(void);
326 extern void DEBUG_InfoWindow(HWND hWnd);
327 extern void DEBUG_WalkWindows(HWND hWnd, int indent);
329 /* debugger/memory.c */
330 extern int DEBUG_ReadMemory( const DBG_ADDR *address );
331 extern void DEBUG_WriteMemory( const DBG_ADDR *address, int value );
332 extern void DEBUG_ExamineMemory( const DBG_VALUE *addr, int count, char format);
333 extern void DEBUG_InvalLinAddr( void* addr );
334 #ifdef __i386__
335 extern void DEBUG_GetCurrentAddress( DBG_ADDR * );
336 extern DWORD DEBUG_ToLinear( const DBG_ADDR *address );
337 extern void DEBUG_FixAddress( DBG_ADDR *address, DWORD def );
338 extern BOOL DEBUG_FixSegment( DBG_ADDR* addr );
339 extern int DEBUG_GetSelectorType( WORD sel );
340 extern int DEBUG_IsSelectorSystem( WORD sel );
341 #endif
343 /* debugger/module.c */
344 extern int DEBUG_LoadEntryPoints( const char * prefix );
345 extern void DEBUG_LoadModule32( const char* name, DWORD base );
346 extern DBG_MODULE* DEBUG_AddModule(const char* name, int type,
347 void* mod_addr, HMODULE hmod);
348 extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, int type);
349 extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, int type);
350 extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, const char* name);
351 extern DBG_MODULE* DEBUG_RegisterELFModule(u_long load_addr, const char* name);
352 extern int DEBUG_ProcessDeferredDebug(void);
353 extern void DEBUG_InfoShare(void);
355 /* debugger/msc.c */
356 extern int DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, void* nth, unsigned long nth_ofs);
357 extern int DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module, void* nth, unsigned long nth_ofs);
358 extern void DEBUG_InitCVDataTypes(void);
359 extern int DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module);
361 /* debugger/registers.c */
362 extern void DEBUG_SetRegister( enum debug_regs reg, int val );
363 extern int DEBUG_GetRegister( enum debug_regs reg );
364 extern void DEBUG_InfoRegisters(void);
365 extern BOOL DEBUG_ValidateRegisters(void);
366 extern int DEBUG_PrintRegister(enum debug_regs reg);
368 /* debugger/stack.c */
369 extern void DEBUG_InfoStack(void);
370 extern void DEBUG_BackTrace(BOOL noisy);
371 extern int DEBUG_InfoLocals(void);
372 extern int DEBUG_SetFrame(int newframe);
373 extern int DEBUG_GetCurrentFrame(struct name_hash ** name,
374 unsigned int * eip,
375 unsigned int * ebp);
377 /* debugger/stabs.c */
378 extern int DEBUG_ReadExecutableDbgInfo(void);
379 extern int DEBUG_ParseStabs(char * addr, unsigned int load_offset, unsigned int staboff,
380 int stablen, unsigned int strtaboff, int strtablen);
382 /* debugger/types.c */
383 extern int DEBUG_nchar;
384 extern void DEBUG_InitTypes(void);
385 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype,
386 const char * typename);
387 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype);
388 extern int DEBUG_AddStructElement(struct datatype * dt,
389 char * name, struct datatype * type,
390 int offset, int size);
391 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
392 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
393 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
394 struct datatype * dt2);
395 extern void DEBUG_Print( const DBG_VALUE *addr, int count, char format, int level );
396 extern unsigned int DEBUG_FindStructElement(DBG_VALUE * addr,
397 const char * ele_name, int * tmpbuf);
398 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
399 extern int DEBUG_GetObjectSize(struct datatype * dt);
400 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE * addr, DBG_VALUE * result, int index);
401 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
402 extern long long int DEBUG_GetExprValue(const DBG_VALUE * addr, char ** format);
403 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset,
404 int nbits, struct datatype * dt2);
405 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
406 extern enum debug_type DEBUG_GetType(struct datatype * dt);
407 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
408 extern int DEBUG_PrintTypeCast(const struct datatype *);
409 extern int DEBUG_PrintType( const DBG_VALUE* addr );
411 /* debugger/source.c */
412 extern void DEBUG_ShowDir(void);
413 extern void DEBUG_AddPath(const char * path);
414 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,
415 int delta);
416 extern void DEBUG_NukePath(void);
417 extern void DEBUG_Disassemble( const DBG_VALUE *, const DBG_VALUE*, int offset );
419 /* debugger/external.c */
420 extern void DEBUG_ExternalDebugger(void);
422 /* debugger/dbg.y */
423 extern void DEBUG_Exit( DWORD exit_code );
424 extern BOOL DEBUG_Main( BOOL is_debug, BOOL force, DWORD code );
426 /* Choose your allocator! */
427 #if 1
428 /* this one is libc's fast one */
429 extern void* DEBUG_XMalloc(size_t size);
430 extern void* DEBUG_XReAlloc(void *ptr, size_t size);
431 extern char* DEBUG_XStrDup(const char *str);
433 #define DBG_alloc(x) DEBUG_XMalloc(x)
434 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
435 #define DBG_free(x) free(x)
436 #define DBG_strdup(x) DEBUG_XStrDup(x)
437 #else
438 /* this one is slow (takes 5 minutes to load the debugger on my machine),
439 but is pretty crash-proof (can step through malloc() without problems,
440 malloc() arena (and other heaps) can be totally wasted and it'll still
441 work, etc... if someone could make optimized routines so it wouldn't
442 take so long to load, it could be made default) */
443 #include "heap.h"
444 #define DBG_alloc(x) HEAP_xalloc(dbg_heap,0,x)
445 #define DBG_realloc(x,y) HEAP_xrealloc(dbg_heap,0,x,y)
446 #define DBG_free(x) HeapFree(dbg_heap,0,x)
447 #define DBG_strdup(x) HEAP_strdupA(dbg_heap,0,x)
448 #define DBG_need_heap
449 extern HANDLE dbg_heap;
450 #endif
452 #define DEBUG_STATUS_OFFSET 0x80003000
453 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
454 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
455 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
456 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
458 #endif /* __WINE_DEBUGGER_H */