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_POINTER, DT_ARRAY, DT_STRUCT, DT_ENUM,
30 DT_FUNC, DT_BITFIELD};
32 enum debug_type_basic {DT_BASIC_INT = 1, DT_BASIC_CHAR, DT_BASIC_LONGINT, DT_BASIC_UINT,
33 DT_BASIC_ULONGINT, DT_BASIC_LONGLONGINT, DT_BASIC_ULONGLONGINT,
34 DT_BASIC_SHORTINT, DT_BASIC_USHORTINT, DT_BASIC_SCHAR, DT_BASIC_UCHAR,
35 DT_BASIC_FLOAT, DT_BASIC_LONGDOUBLE, DT_BASIC_DOUBLE,
36 DT_BASIC_CMPLX_INT, DT_BASIC_CMPLX_FLOAT, DT_BASIC_CMPLX_DOUBLE,
37 DT_BASIC_CMPLX_LONGDOUBLE, DT_BASIC_VOID,
38 /* modifier on size isn't possible on current types definitions
39 * so we need to add more types... */
40 DT_BASIC_BOOL1, DT_BASIC_BOOL2, DT_BASIC_BOOL4,
41 /* this is not really a basic type... */
43 /* this is for historical reasons... should take care of it RSN */
45 /* to be kept as last... sentinel entry... do not use */
49 * Return values for DEBUG_CheckLinenoStatus. Used to determine
50 * what to do when the 'step' command is given.
52 #define FUNC_HAS_NO_LINES (0)
53 #define NOT_ON_LINENUMBER (1)
54 #define AT_LINENUMBER (2)
55 #define FUNC_IS_TRAMPOLINE (3)
59 DWORD seg; /* 0xffffffff means current default segment (cs or ds) */
65 struct datatype* type;
66 int cookie; /* DV_??? */
67 /* DV_TARGET references an address in debugger's address space, whereas DV_HOST
68 * references the debuggee address space
70 # define DV_TARGET 0xF00D
71 # define DV_HOST 0x50DA
72 # define DV_INVALID 0x0000
84 unsigned long line_number;
90 struct name_hash * sym;
94 typedef struct wine_lines WineLineNo;
97 * This structure holds information about stack variables, function
98 * parameters, and register variables, which are all local to this
102 unsigned int regno:8; /* For register symbols */
103 signed int offset:24; /* offset from esp/ebp to symbol */
104 unsigned int pc_start; /* For RBRAC/LBRAC */
105 unsigned int pc_end; /* For RBRAC/LBRAC */
106 char * name; /* Name of symbol */
107 struct datatype * type; /* Datatype of symbol */
110 typedef struct wine_locals WineLocals;
114 EXEC_CONT, /* Continuous execution */
115 EXEC_PASS, /* Continue, passing exception to app */
116 EXEC_STEP_OVER, /* Stepping over a call to next source line */
117 EXEC_STEP_INSTR, /* Step to next source line, stepping in if needed */
118 EXEC_STEPI_OVER, /* Stepping over a call */
119 EXEC_STEPI_INSTR, /* Single-stepping an instruction */
120 EXEC_FINISH, /* Step until we exit current frame */
121 EXEC_STEP_OVER_TRAMPOLINE, /* Step over trampoline. Requires that
122 * we dig the real return value off the stack
123 * and set breakpoint there - not at the
124 * instr just after the call.
151 struct expr * condition;
156 MODE_INVALID, MODE_16, MODE_32, MODE_VM86
161 /* Wine extension; Windows doesn't have a name for this code. This is an
162 undocumented exception understood by MS VC debugger, allowing the program
163 to name a particular thread. Search google.com or deja.com for "0x406d1388"
165 #define EXCEPTION_NAME_THREAD 0x406D1388
167 /* Helper structure */
168 typedef struct tagTHREADNAME_INFO
170 DWORD dwType; /* Must be 0x1000 */
171 LPCTSTR szName; /* Pointer to name - limited to 9 bytes (8 characters + terminator) */
172 DWORD dwThreadID; /* Thread ID (-1 = caller thread) */
173 DWORD dwFlags; /* Reserved for future use. Must be zero. */
176 typedef struct tagDBG_THREAD {
177 struct tagDBG_PROCESS* process;
182 int wait_for_first_exception;
183 enum dbg_mode dbg_mode;
184 enum exec_mode dbg_exec_mode;
186 DBG_BREAKPOINT stepOverBP;
188 struct tagDBG_THREAD* next;
189 struct tagDBG_THREAD* prev;
192 typedef struct tagDBG_DELAYED_BP {
197 typedef struct tagDBG_PROCESS {
200 const char* imageName;
203 unsigned continue_on_first_exception;
204 struct tagDBG_MODULE** modules;
206 unsigned long dbg_hdr_addr;
207 DBG_DELAYED_BP* delayed_bp;
210 * This is an index we use to keep track of the debug information
211 * when we have multiple sources. We use the same database to also
212 * allow us to do an 'info shared' type of deal, and we use the index
213 * to eliminate duplicates.
216 struct tagDBG_PROCESS* next;
217 struct tagDBG_PROCESS* prev;
220 extern DBG_PROCESS* DEBUG_CurrProcess;
221 extern DBG_THREAD* DEBUG_CurrThread;
222 extern DWORD DEBUG_CurrTid;
223 extern DWORD DEBUG_CurrPid;
224 extern CONTEXT DEBUG_context;
225 extern BOOL DEBUG_interactiveP;
227 #define DEBUG_READ_MEM(addr, buf, len) \
228 (ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
230 #define DEBUG_WRITE_MEM(addr, buf, len) \
231 (WriteProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
233 #define DEBUG_READ_MEM_VERBOSE(addr, buf, len) \
234 (DEBUG_READ_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
236 #define DEBUG_WRITE_MEM_VERBOSE(addr, buf, len) \
237 (DEBUG_WRITE_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
239 enum DbgInfoLoad {DIL_DEFERRED, DIL_LOADED, DIL_NOINFO, DIL_ERROR};
240 enum DbgModuleType {DMT_UNKNOWN, DMT_ELF, DMT_NE, DMT_PE};
242 typedef struct tagDBG_MODULE {
246 enum DbgInfoLoad dil;
247 enum DbgModuleType type;
248 unsigned short main : 1;
251 struct tagMSC_DBG_INFO* msc_info;
252 struct tagELF_DBG_INFO* elf_info;
259 struct datatype* type;
262 #define OFFSET_OF(__c,__f) ((int)(((char*)&(((__c*)0)->__f))-((char*)0)))
264 /* from winelib.so */
265 extern void DEBUG_ExternalDebugger(void);
267 /* debugger/break.c */
268 extern void DEBUG_SetBreakpoints( BOOL set );
269 extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) );
270 extern void DEBUG_AddBreakpointFromId( const char *name, int lineno );
271 extern void DEBUG_AddBreakpointFromLineno( int lineno );
272 extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
273 extern void DEBUG_AddWatchpointFromId( const char *name );
274 extern void DEBUG_CheckDelayedBP( void );
275 extern void DEBUG_DelBreakpoint( int num );
276 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
277 extern void DEBUG_InfoBreakpoints(void);
278 extern BOOL DEBUG_HandleTrap(void);
279 extern BOOL DEBUG_ShouldContinue( DBG_ADDR *addr, DWORD code, enum exec_mode mode,
281 extern void DEBUG_SuspendExecution( void );
282 extern enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count );
283 extern BOOL DEBUG_IsFctReturn(void);
284 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
286 /* debugger/db_disasm.c */
287 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
290 extern BOOL DEBUG_Parser(void);
291 extern void DEBUG_Exit( DWORD );
293 /* debugger/debug.l */
294 extern void DEBUG_FlushSymbols(void);
295 extern char*DEBUG_MakeSymbol(const char*);
296 extern int DEBUG_ReadLine(const char* pfx, char* buffer, int size, int flush_sym, int keep_hist);
298 /* debugger/display.c */
299 extern int DEBUG_DoDisplay(void);
300 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
301 extern int DEBUG_DoDisplay(void);
302 extern int DEBUG_DelDisplay(int displaynum);
303 extern int DEBUG_InfoDisplay(void);
305 /* debugger/editline.c */
306 extern char * readline(const char *);
307 extern void add_history(char *);
309 /* debugger/expr.c */
310 extern void DEBUG_FreeExprMem(void);
311 struct expr * DEBUG_IntVarExpr(const char* name);
312 struct expr * DEBUG_SymbolExpr(const char * name);
313 struct expr * DEBUG_ConstExpr(int val);
314 struct expr * DEBUG_StringExpr(const char * str);
315 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
316 struct expr * DEBUG_USConstExpr(unsigned int val);
317 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
318 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
319 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
320 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
321 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
322 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
323 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
324 extern DBG_VALUE DEBUG_EvalExpr(struct expr *);
325 extern int DEBUG_DelDisplay(int displaynum);
326 extern struct expr * DEBUG_CloneExpr(const struct expr * exp);
327 extern int DEBUG_FreeExpr(struct expr * exp);
328 extern int DEBUG_DisplayExpr(const struct expr * exp);
330 /* debugger/hash.c */
331 extern struct name_hash * DEBUG_AddSymbol( const char *name,
332 const DBG_VALUE *addr,
333 const char *sourcefile,
335 extern int DEBUG_GetSymbolValue( const char * name, const int lineno,
336 DBG_VALUE *addr, int );
337 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
338 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
339 struct name_hash ** rtn,
341 struct list_id * source);
342 extern void DEBUG_ReadSymbolTable( const char * filename );
343 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num,
344 unsigned long offset );
345 extern struct wine_locals *
346 DEBUG_AddLocal( struct name_hash * func, int regno,
351 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
352 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file,
354 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
355 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
356 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
357 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
358 extern BOOL DEBUG_GetLineNumberAddr( const struct name_hash *, const int lineno,
359 DBG_ADDR *addr, int bp_flag );
361 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym,
362 struct datatype * type);
363 extern BOOL DEBUG_Normalize(struct name_hash * nh );
365 /* debugger/info.c */
366 extern void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format );
367 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr,
368 enum dbg_mode mode, int flag );
369 extern void DEBUG_Help(void);
370 extern void DEBUG_HelpInfo(void);
371 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr,
375 extern void DEBUG_InfoClass(const char* clsName);
376 extern void DEBUG_WalkClasses(void);
377 extern void DEBUG_WalkModref(DWORD p);
378 extern void DEBUG_DumpModule(DWORD mod);
379 extern void DEBUG_WalkModules(void);
380 extern void DEBUG_WalkProcess(void);
381 extern void DEBUG_WalkThreads(void);
382 extern void DEBUG_DumpQueue(DWORD q);
383 extern void DEBUG_WalkQueues(void);
384 extern void DEBUG_InfoSegments(DWORD s, int v);
385 extern void DEBUG_InfoVirtual(void);
386 extern void DEBUG_InfoWindow(HWND hWnd);
387 extern void DEBUG_WalkWindows(HWND hWnd, int indent);
389 /* debugger/memory.c */
390 extern int DEBUG_ReadMemory( const DBG_VALUE* value );
391 extern void DEBUG_WriteMemory( const DBG_VALUE* val, int value );
392 extern void DEBUG_ExamineMemory( const DBG_VALUE *addr, int count, char format);
393 extern void DEBUG_InvalAddr( const DBG_ADDR* addr );
394 extern void DEBUG_InvalLinAddr( void* addr );
395 extern DWORD DEBUG_ToLinear( const DBG_ADDR *address );
396 extern void DEBUG_GetCurrentAddress( DBG_ADDR * );
397 extern BOOL DEBUG_GrabAddress( DBG_VALUE* value, BOOL fromCode );
398 extern enum dbg_mode DEBUG_GetSelectorType( WORD sel );
400 extern void DEBUG_FixAddress( DBG_ADDR *address, DWORD def );
401 extern int DEBUG_IsSelectorSystem( WORD sel );
404 /* debugger/module.c */
405 extern int DEBUG_LoadEntryPoints( const char * prefix );
406 extern void DEBUG_LoadModule32( const char* name, HANDLE hFile, DWORD base );
407 extern DBG_MODULE* DEBUG_AddModule(const char* name, enum DbgModuleType type,
408 void* mod_addr, u_long size, HMODULE hmod);
409 extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, enum DbgModuleType type);
410 extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, enum DbgModuleType type);
411 extern DBG_MODULE* DEBUG_FindModuleByAddr(void* addr, enum DbgModuleType type);
412 extern DBG_MODULE* DEBUG_GetProcessMainModule(DBG_PROCESS* process);
413 extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, u_long size,
415 extern DBG_MODULE* DEBUG_RegisterELFModule(u_long load_addr, u_long size,
417 extern enum DbgInfoLoad DEBUG_RegisterPEDebugInfo(DBG_MODULE* wmod, HANDLE hFile,
418 void* _nth, unsigned long nth_ofs);
419 extern void DEBUG_ReportDIL(enum DbgInfoLoad dil, const char* pfx,
420 const char* filename, DWORD load_addr);
421 extern void DEBUG_InfoShare(void);
424 extern enum DbgInfoLoad DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile,
425 void* nth, unsigned long nth_ofs);
426 extern enum DbgInfoLoad DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module,
427 HANDLE hFile, void* nth,
428 unsigned long nth_ofs);
429 extern void DEBUG_InitCVDataTypes(void);
431 /* debugger/registers.c */
432 extern void DEBUG_InfoRegisters(void);
433 extern BOOL DEBUG_ValidateRegisters(void);
435 /* debugger/source.c */
436 extern void DEBUG_ShowDir(void);
437 extern void DEBUG_AddPath(const char * path);
438 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,
440 extern void DEBUG_NukePath(void);
441 extern void DEBUG_Disassemble(const DBG_VALUE *, const DBG_VALUE*, int offset);
442 extern BOOL DEBUG_DisassembleInstruction(DBG_ADDR *addr);
444 /* debugger/stack.c */
445 extern void DEBUG_InfoStack(void);
446 extern void DEBUG_BackTrace(DWORD threadID, BOOL noisy);
447 extern int DEBUG_InfoLocals(void);
448 extern int DEBUG_SetFrame(int newframe);
449 extern int DEBUG_GetCurrentFrame(struct name_hash ** name,
453 /* debugger/stabs.c */
454 extern enum DbgInfoLoad DEBUG_ReadExecutableDbgInfo(const char* exe_name);
455 extern enum DbgInfoLoad DEBUG_ParseStabs(char * addr, unsigned int load_offset,
456 unsigned int staboff, int stablen,
457 unsigned int strtaboff, int strtablen);
459 /* debugger/types.c */
460 extern int DEBUG_nchar;
461 extern void DEBUG_InitTypes(void);
462 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype,
463 const char * typename);
464 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE *value,
465 struct datatype ** newtype);
466 extern int DEBUG_AddStructElement(struct datatype * dt,
467 char * name, struct datatype * type,
468 int offset, int size);
469 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
470 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
471 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
472 struct datatype * dt2);
473 extern void DEBUG_Print( const DBG_VALUE *addr, int count, char format, int level );
474 extern unsigned int DEBUG_FindStructElement(DBG_VALUE * addr,
475 const char * ele_name, int * tmpbuf);
476 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
477 extern int DEBUG_GetObjectSize(struct datatype * dt);
478 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE * addr, DBG_VALUE * result,
480 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
481 extern long long int DEBUG_GetExprValue(const DBG_VALUE * addr, char ** format);
482 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset,
483 int nbits, struct datatype * dt2);
484 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
485 extern enum debug_type DEBUG_GetType(struct datatype * dt);
486 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
487 extern int DEBUG_PrintTypeCast(const struct datatype *);
488 extern int DEBUG_PrintType( const DBG_VALUE* addr );
489 extern struct datatype * DEBUG_GetBasicType(enum debug_type_basic);
491 /* debugger/winedbg.c */
492 #define DBG_CHN_MESG 1
493 #define DBG_CHN_ERR 2
494 #define DBG_CHN_WARN 4
495 #define DBG_CHN_FIXME 8
496 #define DBG_CHN_TRACE 16
497 extern void DEBUG_Output(int chn, const char* buffer, int len);
499 extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__((format (printf,2,3)));
501 extern int DEBUG_Printf(int chn, const char* format, ...);
503 extern DBG_INTVAR* DEBUG_GetIntVar(const char*);
504 extern BOOL DEBUG_Attach(DWORD pid, BOOL cofe);
505 extern void DEBUG_Run(const char* args);
506 extern DBG_PROCESS* DEBUG_GetProcess(DWORD pid);
507 extern DBG_THREAD* DEBUG_GetThread(DBG_PROCESS* p, DWORD tid);
508 extern int curr_frame;
510 /* Choose your allocator! */
512 /* this one is libc's fast one */
513 extern void* DEBUG_XMalloc(size_t size);
514 extern void* DEBUG_XReAlloc(void *ptr, size_t size);
515 extern char* DEBUG_XStrDup(const char *str);
517 #define DBG_alloc(x) DEBUG_XMalloc(x)
518 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
519 #define DBG_free(x) free(x)
520 #define DBG_strdup(x) DEBUG_XStrDup(x)
522 /* this one is slow (takes 5 minutes to load the debugger on my machine),
523 if someone could make optimized routines so it wouldn't
524 take so long to load, it could be made default) */
525 #define DBG_alloc(x) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,x)
526 #define DBG_realloc(x,y) HeapReAlloc(GetProcessHeap(),0,x,y)
527 #define DBG_free(x) HeapFree(GetProcessHeap(),0,x)
528 inline static LPSTR DBG_strdup( LPCSTR str )
530 INT len = strlen(str) + 1;
531 LPSTR p = DBG_alloc( len );
532 if (p) memcpy( p, str, len );
537 #define DEBUG_STATUS_OFFSET 0x80003000
538 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
539 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
540 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
541 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
542 #define DEBUG_STATUS_NO_FIELD (DEBUG_STATUS_OFFSET+4)
544 extern DBG_INTVAR DEBUG_IntVars[];
546 #define DBG_IVARNAME(_var) DEBUG_IV_##_var
547 #define DBG_IVARSTRUCT(_var) DEBUG_IntVars[DBG_IVARNAME(_var)]
548 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
549 #define INTERNAL_VAR(_var,_val,_ref,_typ) DBG_IVARNAME(_var),
556 #endif /* __WINE_DEBUGGER_H */