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)))
227 /* debugger/break.c */
228 extern void DEBUG_SetBreakpoints( BOOL set
);
229 extern void DEBUG_AddBreakpoint( const DBG_VALUE
*addr
, BOOL (*func
)(void) );
230 extern void DEBUG_AddWatchpoint( const DBG_VALUE
*addr
, int is_write
);
231 extern void DEBUG_DelBreakpoint( int num
);
232 extern void DEBUG_EnableBreakpoint( int num
, BOOL enable
);
233 extern void DEBUG_InfoBreakpoints(void);
234 extern BOOL
DEBUG_HandleTrap(void);
235 extern BOOL
DEBUG_ShouldContinue( DWORD code
, enum exec_mode mode
, int * count
);
236 extern void DEBUG_SuspendExecution( void );
237 extern enum exec_mode
DEBUG_RestartExecution( enum exec_mode mode
, int count
);
238 extern BOOL
DEBUG_IsFctReturn(void);
239 extern int DEBUG_AddBPCondition(int bpnum
, struct expr
* exp
);
241 /* debugger/db_disasm.c */
242 extern void DEBUG_Disasm( DBG_ADDR
*addr
, int display
);
245 extern BOOL
DEBUG_Main( BOOL is_debug
, BOOL force
, DWORD code
);
246 extern void DEBUG_Exit( DWORD
);
248 /* debugger/debug.l */
249 extern void flush_symbols(void);
251 /* debugger/display.c */
252 extern int DEBUG_DoDisplay(void);
253 extern int DEBUG_AddDisplay(struct expr
* exp
, int count
, char format
);
254 extern int DEBUG_DoDisplay(void);
255 extern int DEBUG_DelDisplay(int displaynum
);
256 extern int DEBUG_InfoDisplay(void);
258 /* debugger/editline.c */
259 extern char * readline(const char *);
260 extern void add_history(char *);
262 /* debugger/expr.c */
263 extern void DEBUG_FreeExprMem(void);
264 struct expr
* DEBUG_IntVarExpr(const char* name
);
265 struct expr
* DEBUG_SymbolExpr(const char * name
);
266 struct expr
* DEBUG_ConstExpr(int val
);
267 struct expr
* DEBUG_StringExpr(const char * str
);
268 struct expr
* DEBUG_SegAddr(struct expr
*, struct expr
*);
269 struct expr
* DEBUG_USConstExpr(unsigned int val
);
270 struct expr
* DEBUG_BinopExpr(int oper
, struct expr
*, struct expr
*);
271 struct expr
* DEBUG_UnopExpr(int oper
, struct expr
*);
272 struct expr
* DEBUG_StructPExpr(struct expr
*, const char * element
);
273 struct expr
* DEBUG_StructExpr(struct expr
*, const char * element
);
274 struct expr
* DEBUG_ArrayExpr(struct expr
*, struct expr
* index
);
275 struct expr
* DEBUG_CallExpr(const char *, int nargs
, ...);
276 struct expr
* DEBUG_TypeCastExpr(struct datatype
*, struct expr
*);
277 extern DBG_VALUE
DEBUG_EvalExpr(struct expr
*);
278 extern int DEBUG_DelDisplay(int displaynum
);
279 extern struct expr
* DEBUG_CloneExpr(const struct expr
* exp
);
280 extern int DEBUG_FreeExpr(struct expr
* exp
);
281 extern int DEBUG_DisplayExpr(const struct expr
* exp
);
283 /* debugger/external.c */
284 extern void DEBUG_ExternalDebugger(void);
286 /* debugger/hash.c */
287 extern struct name_hash
* DEBUG_AddSymbol( const char *name
,
288 const DBG_VALUE
*addr
,
289 const char *sourcefile
,
291 extern BOOL
DEBUG_GetSymbolValue( const char * name
, const int lineno
,
292 DBG_VALUE
*addr
, int );
293 extern BOOL
DEBUG_SetSymbolValue( const char * name
, const DBG_VALUE
*addr
);
294 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR
*addr
, int flag
,
295 struct name_hash
** rtn
,
297 struct list_id
* source
);
298 extern void DEBUG_ReadSymbolTable( const char * filename
);
299 extern void DEBUG_AddLineNumber( struct name_hash
* func
, int line_num
,
300 unsigned long offset
);
301 extern struct wine_locals
*
302 DEBUG_AddLocal( struct name_hash
* func
, int regno
,
307 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR
*addr
);
308 extern void DEBUG_GetFuncInfo(struct list_id
* ret
, const char * file
,
310 extern int DEBUG_SetSymbolSize(struct name_hash
* sym
, unsigned int len
);
311 extern int DEBUG_SetSymbolBPOff(struct name_hash
* sym
, unsigned int len
);
312 extern int DEBUG_GetSymbolAddr(struct name_hash
* sym
, DBG_ADDR
* addr
);
313 extern int DEBUG_cmp_sym(const void * p1
, const void * p2
);
314 extern BOOL
DEBUG_GetLineNumberAddr( struct name_hash
*, const int lineno
,
315 DBG_ADDR
*addr
, int bp_flag
);
317 extern int DEBUG_SetLocalSymbolType(struct wine_locals
* sym
,
318 struct datatype
* type
);
319 extern BOOL
DEBUG_Normalize(struct name_hash
* nh
);
321 /* debugger/info.c */
322 extern void DEBUG_PrintBasic( const DBG_VALUE
* value
, int count
, char format
);
323 extern struct symbol_info
DEBUG_PrintAddress( const DBG_ADDR
*addr
,
324 int addrlen
, int flag
);
325 extern void DEBUG_Help(void);
326 extern void DEBUG_HelpInfo(void);
327 extern struct symbol_info
DEBUG_PrintAddressAndArgs( const DBG_ADDR
*addr
,
331 extern void DEBUG_InfoClass(const char* clsName
);
332 extern void DEBUG_WalkClasses(void);
333 extern void DEBUG_WalkModref(DWORD p
);
334 extern void DEBUG_DumpModule(DWORD mod
);
335 extern void DEBUG_WalkModules(void);
336 extern void DEBUG_WalkProcess(void);
337 extern void DEBUG_WalkThreads(void);
338 extern void DEBUG_DumpQueue(DWORD q
);
339 extern void DEBUG_WalkQueues(void);
340 extern void DEBUG_InfoSegments(DWORD s
, int v
);
341 extern void DEBUG_InfoVirtual(void);
342 extern void DEBUG_InfoWindow(HWND hWnd
);
343 extern void DEBUG_WalkWindows(HWND hWnd
, int indent
);
345 /* debugger/memory.c */
346 extern int DEBUG_ReadMemory( const DBG_VALUE
* value
);
347 extern void DEBUG_WriteMemory( const DBG_VALUE
* val
, int value
);
348 extern void DEBUG_ExamineMemory( const DBG_VALUE
*addr
, int count
, char format
);
349 extern void DEBUG_InvalAddr( const DBG_ADDR
* addr
);
350 extern void DEBUG_InvalLinAddr( void* addr
);
352 extern void DEBUG_GetCurrentAddress( DBG_ADDR
* );
353 extern DWORD
DEBUG_ToLinear( const DBG_ADDR
*address
);
354 extern void DEBUG_FixAddress( DBG_ADDR
*address
, DWORD def
);
355 extern BOOL
DEBUG_FixSegment( DBG_ADDR
* addr
);
356 extern int DEBUG_GetSelectorType( WORD sel
);
357 extern int DEBUG_IsSelectorSystem( WORD sel
);
360 /* debugger/module.c */
361 extern int DEBUG_LoadEntryPoints( const char * prefix
);
362 extern void DEBUG_LoadModule32( const char* name
, HANDLE hFile
, DWORD base
);
363 extern DBG_MODULE
* DEBUG_AddModule(const char* name
, int type
,
364 void* mod_addr
, HMODULE hmod
);
365 extern DBG_MODULE
* DEBUG_FindModuleByName(const char* name
, int type
);
366 extern DBG_MODULE
* DEBUG_FindModuleByHandle(HANDLE handle
, int type
);
367 extern DBG_MODULE
* DEBUG_RegisterPEModule(HMODULE
, u_long load_addr
, const char* name
);
368 extern DBG_MODULE
* DEBUG_RegisterELFModule(u_long load_addr
, const char* name
);
369 extern void DEBUG_InfoShare(void);
372 extern int DEBUG_RegisterMSCDebugInfo(DBG_MODULE
* module
, HANDLE hFile
, void* nth
, unsigned long nth_ofs
);
373 extern int DEBUG_RegisterStabsDebugInfo(DBG_MODULE
* module
, HANDLE hFile
, void* nth
, unsigned long nth_ofs
);
374 extern void DEBUG_InitCVDataTypes(void);
376 /* debugger/registers.c */
377 extern void DEBUG_InfoRegisters(void);
378 extern BOOL
DEBUG_ValidateRegisters(void);
380 /* debugger/stack.c */
381 extern void DEBUG_InfoStack(void);
382 extern void DEBUG_BackTrace(BOOL noisy
);
383 extern int DEBUG_InfoLocals(void);
384 extern int DEBUG_SetFrame(int newframe
);
385 extern int DEBUG_GetCurrentFrame(struct name_hash
** name
,
389 /* debugger/stabs.c */
390 extern int DEBUG_ReadExecutableDbgInfo(const char* exe_name
);
391 extern int DEBUG_ProcessElfObject(const char* filename
, unsigned int load_offset
);
392 extern int DEBUG_ParseStabs(char * addr
, unsigned int load_offset
, unsigned int staboff
,
393 int stablen
, unsigned int strtaboff
, int strtablen
);
395 /* debugger/types.c */
396 extern int DEBUG_nchar
;
397 extern void DEBUG_InitTypes(void);
398 extern struct datatype
* DEBUG_NewDataType(enum debug_type xtype
,
399 const char * typename
);
400 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE
*value
, struct datatype
** newtype
);
401 extern int DEBUG_AddStructElement(struct datatype
* dt
,
402 char * name
, struct datatype
* type
,
403 int offset
, int size
);
404 extern int DEBUG_SetStructSize(struct datatype
* dt
, int size
);
405 extern int DEBUG_SetPointerType(struct datatype
* dt
, struct datatype
* dt2
);
406 extern int DEBUG_SetArrayParams(struct datatype
* dt
, int min
, int max
,
407 struct datatype
* dt2
);
408 extern void DEBUG_Print( const DBG_VALUE
*addr
, int count
, char format
, int level
);
409 extern unsigned int DEBUG_FindStructElement(DBG_VALUE
* addr
,
410 const char * ele_name
, int * tmpbuf
);
411 extern struct datatype
* DEBUG_GetPointerType(struct datatype
* dt
);
412 extern int DEBUG_GetObjectSize(struct datatype
* dt
);
413 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE
* addr
, DBG_VALUE
* result
, int index
);
414 extern struct datatype
* DEBUG_FindOrMakePointerType(struct datatype
* reftype
);
415 extern long long int DEBUG_GetExprValue(const DBG_VALUE
* addr
, char ** format
);
416 extern int DEBUG_SetBitfieldParams(struct datatype
* dt
, int offset
,
417 int nbits
, struct datatype
* dt2
);
418 extern int DEBUG_CopyFieldlist(struct datatype
* dt
, struct datatype
* dt2
);
419 extern enum debug_type
DEBUG_GetType(struct datatype
* dt
);
420 extern struct datatype
* DEBUG_TypeCast(enum debug_type
, const char *);
421 extern int DEBUG_PrintTypeCast(const struct datatype
*);
422 extern int DEBUG_PrintType( const DBG_VALUE
* addr
);
424 /* debugger/source.c */
425 extern void DEBUG_ShowDir(void);
426 extern void DEBUG_AddPath(const char * path
);
427 extern void DEBUG_List(struct list_id
* line1
, struct list_id
* line2
,
429 extern void DEBUG_NukePath(void);
430 extern void DEBUG_Disassemble( const DBG_VALUE
*, const DBG_VALUE
*, int offset
);
432 /* debugger/winedbg.c */
433 #define DBG_CHN_MESG 1
434 #define DBG_CHN_ERR 2
435 #define DBG_CHN_WARN 4
436 #define DBG_CHN_FIXME 8
437 #define DBG_CHN_TRACE 16
438 extern void DEBUG_Output(int chn
, const char* buffer
, int len
);
440 extern int DEBUG_Printf(int chn
, const char* format
, ...) __attribute__((format (printf
,2,3)));
442 extern int DEBUG_Printf(int chn
, const char* format
, ...);
444 extern DBG_INTVAR
* DEBUG_GetIntVar(const char*);
446 /* Choose your allocator! */
448 /* this one is libc's fast one */
449 extern void* DEBUG_XMalloc(size_t size
);
450 extern void* DEBUG_XReAlloc(void *ptr
, size_t size
);
451 extern char* DEBUG_XStrDup(const char *str
);
453 #define DBG_alloc(x) DEBUG_XMalloc(x)
454 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
455 #define DBG_free(x) free(x)
456 #define DBG_strdup(x) DEBUG_XStrDup(x)
458 /* this one is slow (takes 5 minutes to load the debugger on my machine),
459 but is pretty crash-proof (can step through malloc() without problems,
460 malloc() arena (and other heaps) can be totally wasted and it'll still
461 work, etc... if someone could make optimized routines so it wouldn't
462 take so long to load, it could be made default) */
464 #define DBG_alloc(x) HeapAlloc(dbg_heap,0,x)
465 #define DBG_realloc(x,y) HeapRealloc(dbg_heap,0,x,y)
466 #define DBG_free(x) HeapFree(dbg_heap,0,x)
467 #define DBG_strdup(x) HEAP_strdupA(dbg_heap,0,x)
468 #define DBG_need_heap
469 extern HANDLE dbg_heap
;
472 #define DEBUG_STATUS_OFFSET 0x80003000
473 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
474 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
475 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
476 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
478 extern DBG_INTVAR DEBUG_IntVars
[];
480 #define DBG_IVARNAME(_var) DEBUG_IV_##_var
481 #define DBG_IVARSTRUCT(_var) DEBUG_IntVars[DBG_IVARNAME(_var)]
482 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
483 #define INTERNAL_VAR(_var,_val,_ref,_typ) DBG_IVARNAME(_var),
490 #endif /* __WINE_DEBUGGER_H */