4 * Copyright 1995 Alexandre Julliard
7 #ifndef __WINE_DEBUGGER_H
8 #define __WINE_DEBUGGER_H
10 #include <sys/types.h> /* u_long ... */
14 #include "wine/exception.h"
17 #define STEP_FLAG 0x00000100 /* single step flag */
18 #define V86_FLAG 0x00020000
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_TypeShortUInt;
45 extern struct datatype * DEBUG_TypeInt;
46 extern struct datatype * DEBUG_TypeIntConst;
47 extern struct datatype * DEBUG_TypeUSInt;
48 extern struct datatype * DEBUG_TypeString;
52 DWORD seg; /* 0xffffffff means current default segment (cs or ds) */
56 #define DV_TARGET 0xF00D
57 #define DV_HOST 0x50DA
61 struct datatype* type;
62 int cookie; /* DV_??? */
73 unsigned long line_number;
79 struct name_hash * sym;
83 typedef struct wine_lines WineLineNo;
86 * This structure holds information about stack variables, function
87 * parameters, and register variables, which are all local to this
91 unsigned int regno:8; /* For register symbols */
92 signed int offset:24; /* offset from esp/ebp to symbol */
93 unsigned int pc_start; /* For RBRAC/LBRAC */
94 unsigned int pc_end; /* For RBRAC/LBRAC */
95 char * name; /* Name of symbol */
96 struct datatype * type; /* Datatype of symbol */
99 typedef struct wine_locals WineLocals;
103 EXEC_CONT, /* Continuous execution */
104 EXEC_PASS, /* Continue, passing exception to app */
105 EXEC_STEP_OVER, /* Stepping over a call to next source line */
106 EXEC_STEP_INSTR, /* Step to next source line, stepping in if needed */
107 EXEC_STEPI_OVER, /* Stepping over a call */
108 EXEC_STEPI_INSTR, /* Single-stepping an instruction */
109 EXEC_FINISH, /* Step until we exit current frame */
110 EXEC_STEP_OVER_TRAMPOLINE, /* Step over trampoline. Requires that
111 * we dig the real return value off the stack
112 * and set breakpoint there - not at the
113 * instr just after the call.
115 EXEC_KILL /* terminate debugging session */
141 struct expr * condition;
144 typedef struct tagDBG_THREAD {
145 struct tagDBG_PROCESS* process;
150 int wait_for_first_exception;
152 enum exec_mode dbg_exec_mode;
154 DBG_BREAKPOINT stepOverBP;
155 struct tagDBG_THREAD* next;
156 struct tagDBG_THREAD* prev;
159 typedef struct tagDBG_PROCESS {
164 unsigned continue_on_first_exception;
165 struct tagDBG_MODULE* modules;
166 unsigned long dbg_hdr_addr;
168 * This is an index we use to keep track of the debug information
169 * when we have multiple sources. We use the same database to also
170 * allow us to do an 'info shared' type of deal, and we use the index
171 * to eliminate duplicates.
174 struct tagDBG_PROCESS* next;
175 struct tagDBG_PROCESS* prev;
178 extern DBG_PROCESS* DEBUG_CurrProcess;
179 extern DBG_THREAD* DEBUG_CurrThread;
180 extern DWORD DEBUG_CurrTid;
181 extern DWORD DEBUG_CurrPid;
182 extern CONTEXT DEBUG_context;
184 #define DEBUG_READ_MEM(addr, buf, len) \
185 (ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
187 #define DEBUG_WRITE_MEM(addr, buf, len) \
188 (WriteProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
190 #define DEBUG_READ_MEM_VERBOSE(addr, buf, len) \
191 (DEBUG_READ_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
193 #define DEBUG_WRITE_MEM_VERBOSE(addr, buf, len) \
194 (DEBUG_WRITE_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
196 typedef struct tagDBG_MODULE {
197 struct tagDBG_MODULE* next;
208 #define DM_STATUS_NEW 0
209 #define DM_STATUS_LOADED 1
210 #define DM_STATUS_ERROR 2
213 #define DM_TYPE_UNKNOWN 0
214 #define DM_TYPE_ELF 1
222 struct datatype* type;
225 #define OFFSET_OF(__c,__f) ((int)(((char*)&(((__c*)0)->__f))-((char*)0)))
230 # define GET_IP(context) ((DWORD)(context)->Eip)
233 # define GET_IP(context) ((DWORD)(context)->pc)
237 # error You must define GET_IP for this CPU
241 /* debugger/break.c */
242 extern void DEBUG_SetBreakpoints( BOOL set );
243 extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) );
244 extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
245 extern void DEBUG_DelBreakpoint( int num );
246 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
247 extern void DEBUG_InfoBreakpoints(void);
248 extern BOOL DEBUG_HandleTrap(void);
249 extern BOOL DEBUG_ShouldContinue( DWORD code, enum exec_mode mode, int * count );
250 extern void DEBUG_SuspendExecution( void );
251 extern enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count );
252 extern BOOL DEBUG_IsFctReturn(void);
253 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
255 /* debugger/db_disasm.c */
256 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
259 extern BOOL DEBUG_Main( BOOL is_debug, BOOL force, DWORD code );
260 extern void DEBUG_Exit( DWORD );
262 /* debugger/debug.l */
263 extern void flush_symbols(void);
265 /* debugger/display.c */
266 extern int DEBUG_DoDisplay(void);
267 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
268 extern int DEBUG_DoDisplay(void);
269 extern int DEBUG_DelDisplay(int displaynum);
270 extern int DEBUG_InfoDisplay(void);
272 /* debugger/editline.c */
273 extern char * readline(const char *);
274 extern void add_history(char *);
276 /* debugger/expr.c */
277 extern void DEBUG_FreeExprMem(void);
278 struct expr * DEBUG_IntVarExpr(const char* name);
279 struct expr * DEBUG_SymbolExpr(const char * name);
280 struct expr * DEBUG_ConstExpr(int val);
281 struct expr * DEBUG_StringExpr(const char * str);
282 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
283 struct expr * DEBUG_USConstExpr(unsigned int val);
284 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
285 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
286 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
287 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
288 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
289 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
290 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
291 extern DBG_VALUE DEBUG_EvalExpr(struct expr *);
292 extern int DEBUG_DelDisplay(int displaynum);
293 extern struct expr * DEBUG_CloneExpr(const struct expr * exp);
294 extern int DEBUG_FreeExpr(struct expr * exp);
295 extern int DEBUG_DisplayExpr(const struct expr * exp);
297 /* debugger/external.c */
298 extern void DEBUG_ExternalDebugger(void);
300 /* debugger/hash.c */
301 extern struct name_hash * DEBUG_AddSymbol( const char *name,
302 const DBG_VALUE *addr,
303 const char *sourcefile,
305 extern BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
306 DBG_VALUE *addr, int );
307 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
308 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
309 struct name_hash ** rtn,
311 struct list_id * source);
312 extern void DEBUG_ReadSymbolTable( const char * filename );
313 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num,
314 unsigned long offset );
315 extern struct wine_locals *
316 DEBUG_AddLocal( struct name_hash * func, int regno,
321 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
322 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file,
324 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
325 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
326 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
327 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
328 extern BOOL DEBUG_GetLineNumberAddr( struct name_hash *, const int lineno,
329 DBG_ADDR *addr, int bp_flag );
331 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym,
332 struct datatype * type);
333 extern BOOL DEBUG_Normalize(struct name_hash * nh );
335 /* debugger/info.c */
336 extern void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format );
337 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr,
338 int addrlen, int flag );
339 extern void DEBUG_Help(void);
340 extern void DEBUG_HelpInfo(void);
341 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr,
345 extern void DEBUG_InfoClass(const char* clsName);
346 extern void DEBUG_WalkClasses(void);
347 extern void DEBUG_WalkModref(DWORD p);
348 extern void DEBUG_DumpModule(DWORD mod);
349 extern void DEBUG_WalkModules(void);
350 extern void DEBUG_WalkProcess(void);
351 extern void DEBUG_WalkThreads(void);
352 extern void DEBUG_DumpQueue(DWORD q);
353 extern void DEBUG_WalkQueues(void);
354 extern void DEBUG_InfoSegments(DWORD s, int v);
355 extern void DEBUG_InfoVirtual(void);
356 extern void DEBUG_InfoWindow(HWND hWnd);
357 extern void DEBUG_WalkWindows(HWND hWnd, int indent);
359 /* debugger/memory.c */
360 extern int DEBUG_ReadMemory( const DBG_VALUE* value );
361 extern void DEBUG_WriteMemory( const DBG_VALUE* val, int value );
362 extern void DEBUG_ExamineMemory( const DBG_VALUE *addr, int count, char format);
363 extern void DEBUG_InvalAddr( const DBG_ADDR* addr );
364 extern void DEBUG_InvalLinAddr( void* addr );
365 extern DWORD DEBUG_ToLinear( const DBG_ADDR *address );
366 extern void DEBUG_GetCurrentAddress( DBG_ADDR * );
368 extern void DEBUG_FixAddress( DBG_ADDR *address, DWORD def );
369 extern BOOL DEBUG_FixSegment( DBG_ADDR* addr );
370 extern int DEBUG_GetSelectorType( WORD sel );
371 extern int DEBUG_IsSelectorSystem( WORD sel );
374 /* debugger/module.c */
375 extern int DEBUG_LoadEntryPoints( const char * prefix );
376 extern void DEBUG_LoadModule32( const char* name, HANDLE hFile, DWORD base );
377 extern DBG_MODULE* DEBUG_AddModule(const char* name, int type,
378 void* mod_addr, HMODULE hmod);
379 extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, int type);
380 extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, int type);
381 extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, const char* name);
382 extern DBG_MODULE* DEBUG_RegisterELFModule(u_long load_addr, const char* name);
383 extern void DEBUG_InfoShare(void);
386 extern int DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile, void* nth, unsigned long nth_ofs);
387 extern int DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module, HANDLE hFile, void* nth, unsigned long nth_ofs);
388 extern void DEBUG_InitCVDataTypes(void);
390 /* debugger/registers.c */
391 extern void DEBUG_InfoRegisters(void);
392 extern BOOL DEBUG_ValidateRegisters(void);
394 /* debugger/stack.c */
395 extern void DEBUG_InfoStack(void);
396 extern void DEBUG_BackTrace(BOOL noisy);
397 extern int DEBUG_InfoLocals(void);
398 extern int DEBUG_SetFrame(int newframe);
399 extern int DEBUG_GetCurrentFrame(struct name_hash ** name,
403 /* debugger/stabs.c */
404 extern int DEBUG_ReadExecutableDbgInfo(const char* exe_name);
405 extern int DEBUG_ProcessElfObject(const char* filename, unsigned int load_offset);
406 extern int DEBUG_ParseStabs(char * addr, unsigned int load_offset, unsigned int staboff,
407 int stablen, unsigned int strtaboff, int strtablen);
409 /* debugger/types.c */
410 extern int DEBUG_nchar;
411 extern void DEBUG_InitTypes(void);
412 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype,
413 const char * typename);
414 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype);
415 extern int DEBUG_AddStructElement(struct datatype * dt,
416 char * name, struct datatype * type,
417 int offset, int size);
418 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
419 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
420 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
421 struct datatype * dt2);
422 extern void DEBUG_Print( const DBG_VALUE *addr, int count, char format, int level );
423 extern unsigned int DEBUG_FindStructElement(DBG_VALUE * addr,
424 const char * ele_name, int * tmpbuf);
425 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
426 extern int DEBUG_GetObjectSize(struct datatype * dt);
427 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE * addr, DBG_VALUE * result, int index);
428 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
429 extern long long int DEBUG_GetExprValue(const DBG_VALUE * addr, char ** format);
430 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset,
431 int nbits, struct datatype * dt2);
432 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
433 extern enum debug_type DEBUG_GetType(struct datatype * dt);
434 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
435 extern int DEBUG_PrintTypeCast(const struct datatype *);
436 extern int DEBUG_PrintType( const DBG_VALUE* addr );
438 /* debugger/source.c */
439 extern void DEBUG_ShowDir(void);
440 extern void DEBUG_AddPath(const char * path);
441 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,
443 extern void DEBUG_NukePath(void);
444 extern void DEBUG_Disassemble( const DBG_VALUE *, const DBG_VALUE*, int offset );
446 /* debugger/winedbg.c */
447 #define DBG_CHN_MESG 1
448 #define DBG_CHN_ERR 2
449 #define DBG_CHN_WARN 4
450 #define DBG_CHN_FIXME 8
451 #define DBG_CHN_TRACE 16
452 extern void DEBUG_Output(int chn, const char* buffer, int len);
454 extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__((format (printf,2,3)));
456 extern int DEBUG_Printf(int chn, const char* format, ...);
458 extern DBG_INTVAR* DEBUG_GetIntVar(const char*);
460 /* Choose your allocator! */
462 /* this one is libc's fast one */
463 extern void* DEBUG_XMalloc(size_t size);
464 extern void* DEBUG_XReAlloc(void *ptr, size_t size);
465 extern char* DEBUG_XStrDup(const char *str);
467 #define DBG_alloc(x) DEBUG_XMalloc(x)
468 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
469 #define DBG_free(x) free(x)
470 #define DBG_strdup(x) DEBUG_XStrDup(x)
472 /* this one is slow (takes 5 minutes to load the debugger on my machine),
473 but is pretty crash-proof (can step through malloc() without problems,
474 malloc() arena (and other heaps) can be totally wasted and it'll still
475 work, etc... if someone could make optimized routines so it wouldn't
476 take so long to load, it could be made default) */
478 #define DBG_alloc(x) HeapAlloc(dbg_heap,0,x)
479 #define DBG_realloc(x,y) HeapRealloc(dbg_heap,0,x,y)
480 #define DBG_free(x) HeapFree(dbg_heap,0,x)
481 #define DBG_strdup(x) HEAP_strdupA(dbg_heap,0,x)
482 #define DBG_need_heap
483 extern HANDLE dbg_heap;
486 #define DEBUG_STATUS_OFFSET 0x80003000
487 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
488 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
489 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
490 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
492 extern DBG_INTVAR DEBUG_IntVars[];
494 #define DBG_IVARNAME(_var) DEBUG_IV_##_var
495 #define DBG_IVARSTRUCT(_var) DEBUG_IntVars[DBG_IVARNAME(_var)]
496 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
497 #define INTERNAL_VAR(_var,_val,_ref,_typ) DBG_IVARNAME(_var),
504 #endif /* __WINE_DEBUGGER_H */