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
58 #define DV_INVALID 0x0000
62 struct datatype* type;
63 int cookie; /* DV_??? */
74 unsigned long line_number;
80 struct name_hash * sym;
84 typedef struct wine_lines WineLineNo;
87 * This structure holds information about stack variables, function
88 * parameters, and register variables, which are all local to this
92 unsigned int regno:8; /* For register symbols */
93 signed int offset:24; /* offset from esp/ebp to symbol */
94 unsigned int pc_start; /* For RBRAC/LBRAC */
95 unsigned int pc_end; /* For RBRAC/LBRAC */
96 char * name; /* Name of symbol */
97 struct datatype * type; /* Datatype of symbol */
100 typedef struct wine_locals WineLocals;
104 EXEC_CONT, /* Continuous execution */
105 EXEC_PASS, /* Continue, passing exception to app */
106 EXEC_STEP_OVER, /* Stepping over a call to next source line */
107 EXEC_STEP_INSTR, /* Step to next source line, stepping in if needed */
108 EXEC_STEPI_OVER, /* Stepping over a call */
109 EXEC_STEPI_INSTR, /* Single-stepping an instruction */
110 EXEC_FINISH, /* Step until we exit current frame */
111 EXEC_STEP_OVER_TRAMPOLINE, /* Step over trampoline. Requires that
112 * we dig the real return value off the stack
113 * and set breakpoint there - not at the
114 * instr just after the call.
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 /* from winelib.so */
228 extern void DEBUG_ExternalDebugger(void);
230 /* debugger/break.c */
231 extern void DEBUG_SetBreakpoints( BOOL set );
232 extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) );
233 extern void DEBUG_AddBreakpointFromId( const char *name, int lineno );
234 extern void DEBUG_AddBreakpointFromLineno( int lineno );
235 extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
236 extern void DEBUG_AddWatchpointFromId( const char *name, int lineno );
237 extern void DEBUG_DelBreakpoint( int num );
238 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
239 extern void DEBUG_InfoBreakpoints(void);
240 extern BOOL DEBUG_HandleTrap(void);
241 extern BOOL DEBUG_ShouldContinue( DWORD code, enum exec_mode mode, int * count );
242 extern void DEBUG_SuspendExecution( void );
243 extern enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count );
244 extern BOOL DEBUG_IsFctReturn(void);
245 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
247 /* debugger/db_disasm.c */
248 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
251 extern BOOL DEBUG_Parser(void);
252 extern void DEBUG_Exit( DWORD );
254 /* debugger/debug.l */
255 extern void DEBUG_FlushSymbols(void);
257 /* debugger/display.c */
258 extern int DEBUG_DoDisplay(void);
259 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
260 extern int DEBUG_DoDisplay(void);
261 extern int DEBUG_DelDisplay(int displaynum);
262 extern int DEBUG_InfoDisplay(void);
264 /* debugger/editline.c */
265 extern char * readline(const char *);
266 extern void add_history(char *);
268 /* debugger/expr.c */
269 extern void DEBUG_FreeExprMem(void);
270 struct expr * DEBUG_IntVarExpr(const char* name);
271 struct expr * DEBUG_SymbolExpr(const char * name);
272 struct expr * DEBUG_ConstExpr(int val);
273 struct expr * DEBUG_StringExpr(const char * str);
274 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
275 struct expr * DEBUG_USConstExpr(unsigned int val);
276 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
277 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
278 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
279 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
280 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
281 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
282 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
283 extern DBG_VALUE DEBUG_EvalExpr(struct expr *);
284 extern int DEBUG_DelDisplay(int displaynum);
285 extern struct expr * DEBUG_CloneExpr(const struct expr * exp);
286 extern int DEBUG_FreeExpr(struct expr * exp);
287 extern int DEBUG_DisplayExpr(const struct expr * exp);
289 /* debugger/hash.c */
290 extern struct name_hash * DEBUG_AddSymbol( const char *name,
291 const DBG_VALUE *addr,
292 const char *sourcefile,
294 extern BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
295 DBG_VALUE *addr, int );
296 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
297 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
298 struct name_hash ** rtn,
300 struct list_id * source);
301 extern void DEBUG_ReadSymbolTable( const char * filename );
302 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num,
303 unsigned long offset );
304 extern struct wine_locals *
305 DEBUG_AddLocal( struct name_hash * func, int regno,
310 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
311 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file,
313 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
314 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
315 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
316 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
317 extern BOOL DEBUG_GetLineNumberAddr( struct name_hash *, const int lineno,
318 DBG_ADDR *addr, int bp_flag );
320 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym,
321 struct datatype * type);
322 extern BOOL DEBUG_Normalize(struct name_hash * nh );
324 /* debugger/info.c */
325 extern void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format );
326 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr,
327 int addrlen, int flag );
328 extern void DEBUG_Help(void);
329 extern void DEBUG_HelpInfo(void);
330 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr,
334 extern void DEBUG_InfoClass(const char* clsName);
335 extern void DEBUG_WalkClasses(void);
336 extern void DEBUG_WalkModref(DWORD p);
337 extern void DEBUG_DumpModule(DWORD mod);
338 extern void DEBUG_WalkModules(void);
339 extern void DEBUG_WalkProcess(void);
340 extern void DEBUG_WalkThreads(void);
341 extern void DEBUG_DumpQueue(DWORD q);
342 extern void DEBUG_WalkQueues(void);
343 extern void DEBUG_InfoSegments(DWORD s, int v);
344 extern void DEBUG_InfoVirtual(void);
345 extern void DEBUG_InfoWindow(HWND hWnd);
346 extern void DEBUG_WalkWindows(HWND hWnd, int indent);
348 /* debugger/memory.c */
349 extern int DEBUG_ReadMemory( const DBG_VALUE* value );
350 extern void DEBUG_WriteMemory( const DBG_VALUE* val, int value );
351 extern void DEBUG_ExamineMemory( const DBG_VALUE *addr, int count, char format);
352 extern void DEBUG_InvalAddr( const DBG_ADDR* addr );
353 extern void DEBUG_InvalLinAddr( void* addr );
354 extern DWORD DEBUG_ToLinear( const DBG_ADDR *address );
355 extern void DEBUG_GetCurrentAddress( DBG_ADDR * );
357 extern void DEBUG_FixAddress( DBG_ADDR *address, DWORD def );
358 extern BOOL DEBUG_FixSegment( DBG_ADDR* addr );
359 extern int DEBUG_GetSelectorType( WORD sel );
360 extern int DEBUG_IsSelectorSystem( WORD sel );
363 /* debugger/module.c */
364 extern int DEBUG_LoadEntryPoints( const char * prefix );
365 extern void DEBUG_LoadModule32( const char* name, HANDLE hFile, DWORD base );
366 extern DBG_MODULE* DEBUG_AddModule(const char* name, int type,
367 void* mod_addr, HMODULE hmod);
368 extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, int type);
369 extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, int type);
370 extern DBG_MODULE* DEBUG_GetProcessMainModule(DBG_PROCESS* process);
371 extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, const char* name);
372 extern DBG_MODULE* DEBUG_RegisterELFModule(u_long load_addr, const char* name);
373 extern void DEBUG_InfoShare(void);
376 extern int DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile, void* nth, unsigned long nth_ofs);
377 extern int DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module, HANDLE hFile, void* nth, unsigned long nth_ofs);
378 extern void DEBUG_InitCVDataTypes(void);
380 /* debugger/registers.c */
381 extern void DEBUG_InfoRegisters(void);
382 extern BOOL DEBUG_ValidateRegisters(void);
384 /* debugger/stack.c */
385 extern void DEBUG_InfoStack(void);
386 extern void DEBUG_BackTrace(BOOL noisy);
387 extern int DEBUG_InfoLocals(void);
388 extern int DEBUG_SetFrame(int newframe);
389 extern int DEBUG_GetCurrentFrame(struct name_hash ** name,
393 /* debugger/stabs.c */
394 extern int DEBUG_ReadExecutableDbgInfo(const char* exe_name);
395 extern int DEBUG_ProcessElfObject(const char* filename, unsigned int load_offset);
396 extern int DEBUG_ParseStabs(char * addr, unsigned int load_offset, unsigned int staboff,
397 int stablen, unsigned int strtaboff, int strtablen);
399 /* debugger/types.c */
400 extern int DEBUG_nchar;
401 extern void DEBUG_InitTypes(void);
402 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype,
403 const char * typename);
404 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE *value, struct datatype ** newtype);
405 extern int DEBUG_AddStructElement(struct datatype * dt,
406 char * name, struct datatype * type,
407 int offset, int size);
408 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
409 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
410 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
411 struct datatype * dt2);
412 extern void DEBUG_Print( const DBG_VALUE *addr, int count, char format, int level );
413 extern unsigned int DEBUG_FindStructElement(DBG_VALUE * addr,
414 const char * ele_name, int * tmpbuf);
415 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
416 extern int DEBUG_GetObjectSize(struct datatype * dt);
417 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE * addr, DBG_VALUE * result, int index);
418 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
419 extern long long int DEBUG_GetExprValue(const DBG_VALUE * addr, char ** format);
420 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset,
421 int nbits, struct datatype * dt2);
422 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
423 extern enum debug_type DEBUG_GetType(struct datatype * dt);
424 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
425 extern int DEBUG_PrintTypeCast(const struct datatype *);
426 extern int DEBUG_PrintType( const DBG_VALUE* addr );
428 /* debugger/source.c */
429 extern void DEBUG_ShowDir(void);
430 extern void DEBUG_AddPath(const char * path);
431 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,
433 extern void DEBUG_NukePath(void);
434 extern void DEBUG_Disassemble( const DBG_VALUE *, const DBG_VALUE*, int offset );
436 /* debugger/winedbg.c */
437 #define DBG_CHN_MESG 1
438 #define DBG_CHN_ERR 2
439 #define DBG_CHN_WARN 4
440 #define DBG_CHN_FIXME 8
441 #define DBG_CHN_TRACE 16
442 extern void DEBUG_Output(int chn, const char* buffer, int len);
444 extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__((format (printf,2,3)));
446 extern int DEBUG_Printf(int chn, const char* format, ...);
448 extern DBG_INTVAR* DEBUG_GetIntVar(const char*);
449 extern BOOL DEBUG_Attach(DWORD pid, BOOL cofe);
450 extern void DEBUG_Run(const char* args);
451 extern int curr_frame;
453 /* Choose your allocator! */
455 /* this one is libc's fast one */
456 extern void* DEBUG_XMalloc(size_t size);
457 extern void* DEBUG_XReAlloc(void *ptr, size_t size);
458 extern char* DEBUG_XStrDup(const char *str);
460 #define DBG_alloc(x) DEBUG_XMalloc(x)
461 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
462 #define DBG_free(x) free(x)
463 #define DBG_strdup(x) DEBUG_XStrDup(x)
465 /* this one is slow (takes 5 minutes to load the debugger on my machine),
466 but is pretty crash-proof (can step through malloc() without problems,
467 malloc() arena (and other heaps) can be totally wasted and it'll still
468 work, etc... if someone could make optimized routines so it wouldn't
469 take so long to load, it could be made default) */
471 #define DBG_alloc(x) HeapAlloc(dbg_heap,0,x)
472 #define DBG_realloc(x,y) HeapRealloc(dbg_heap,0,x,y)
473 #define DBG_free(x) HeapFree(dbg_heap,0,x)
474 #define DBG_strdup(x) HEAP_strdupA(dbg_heap,0,x)
475 #define DBG_need_heap
476 extern HANDLE dbg_heap;
479 #define DEBUG_STATUS_OFFSET 0x80003000
480 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
481 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
482 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
483 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
485 extern DBG_INTVAR DEBUG_IntVars[];
487 #define DBG_IVARNAME(_var) DEBUG_IV_##_var
488 #define DBG_IVARSTRUCT(_var) DEBUG_IntVars[DBG_IVARNAME(_var)]
489 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
490 #define INTERNAL_VAR(_var,_val,_ref,_typ) DBG_IVARNAME(_var),
497 #endif /* __WINE_DEBUGGER_H */