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};
34 * Return values for DEBUG_CheckLinenoStatus. Used to determine
35 * what to do when the 'step' command is given.
37 #define FUNC_HAS_NO_LINES (0)
38 #define NOT_ON_LINENUMBER (1)
39 #define AT_LINENUMBER (2)
40 #define FUNC_IS_TRAMPOLINE (3)
43 * For constants generated by the parser, we use this datatype
45 extern struct datatype * DEBUG_TypeShortUInt;
46 extern struct datatype * DEBUG_TypeInt;
47 extern struct datatype * DEBUG_TypeIntConst;
48 extern struct datatype * DEBUG_TypeUSInt;
49 extern struct datatype * DEBUG_TypeString;
53 DWORD seg; /* 0xffffffff means current default segment (cs or ds) */
59 struct datatype* type;
60 int cookie; /* DV_??? */
61 /* DV_TARGET references an address in debugger's address space, whereas DV_HOST
62 * references the debuggee address space
64 # define DV_TARGET 0xF00D
65 # define DV_HOST 0x50DA
66 # define DV_INVALID 0x0000
78 unsigned long line_number;
84 struct name_hash * sym;
88 typedef struct wine_lines WineLineNo;
91 * This structure holds information about stack variables, function
92 * parameters, and register variables, which are all local to this
96 unsigned int regno:8; /* For register symbols */
97 signed int offset:24; /* offset from esp/ebp to symbol */
98 unsigned int pc_start; /* For RBRAC/LBRAC */
99 unsigned int pc_end; /* For RBRAC/LBRAC */
100 char * name; /* Name of symbol */
101 struct datatype * type; /* Datatype of symbol */
104 typedef struct wine_locals WineLocals;
108 EXEC_CONT, /* Continuous execution */
109 EXEC_PASS, /* Continue, passing exception to app */
110 EXEC_STEP_OVER, /* Stepping over a call to next source line */
111 EXEC_STEP_INSTR, /* Step to next source line, stepping in if needed */
112 EXEC_STEPI_OVER, /* Stepping over a call */
113 EXEC_STEPI_INSTR, /* Single-stepping an instruction */
114 EXEC_FINISH, /* Step until we exit current frame */
115 EXEC_STEP_OVER_TRAMPOLINE, /* Step over trampoline. Requires that
116 * we dig the real return value off the stack
117 * and set breakpoint there - not at the
118 * instr just after the call.
145 struct expr * condition;
150 MODE_INVALID, MODE_16, MODE_32, MODE_VM86
155 /* Wine extension; Windows doesn't have a name for this code. This is an
156 undocumented exception understood by MS VC debugger, allowing the program
157 to name a particular thread. Search google.com or deja.com for "0x406d1388"
159 #define EXCEPTION_NAME_THREAD 0x406D1388
161 /* Helper structure */
162 typedef struct tagTHREADNAME_INFO
164 DWORD dwType; /* Must be 0x1000 */
165 LPCTSTR szName; /* Pointer to name - limited to 9 bytes (8 characters + terminator) */
166 DWORD dwThreadID; /* Thread ID (-1 = caller thread) */
167 DWORD dwFlags; /* Reserved for future use. Must be zero. */
170 typedef struct tagDBG_THREAD {
171 struct tagDBG_PROCESS* process;
176 int wait_for_first_exception;
177 enum dbg_mode dbg_mode;
178 enum exec_mode dbg_exec_mode;
180 DBG_BREAKPOINT stepOverBP;
182 struct tagDBG_THREAD* next;
183 struct tagDBG_THREAD* prev;
186 typedef struct tagDBG_DELAYED_BP {
191 typedef struct tagDBG_PROCESS {
194 const char* imageName;
197 unsigned continue_on_first_exception;
198 struct tagDBG_MODULE** modules;
200 unsigned long dbg_hdr_addr;
201 DBG_DELAYED_BP* delayed_bp;
204 * This is an index we use to keep track of the debug information
205 * when we have multiple sources. We use the same database to also
206 * allow us to do an 'info shared' type of deal, and we use the index
207 * to eliminate duplicates.
210 struct tagDBG_PROCESS* next;
211 struct tagDBG_PROCESS* prev;
214 extern DBG_PROCESS* DEBUG_CurrProcess;
215 extern DBG_THREAD* DEBUG_CurrThread;
216 extern DWORD DEBUG_CurrTid;
217 extern DWORD DEBUG_CurrPid;
218 extern CONTEXT DEBUG_context;
219 extern BOOL DEBUG_interactiveP;
221 #define DEBUG_READ_MEM(addr, buf, len) \
222 (ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
224 #define DEBUG_WRITE_MEM(addr, buf, len) \
225 (WriteProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
227 #define DEBUG_READ_MEM_VERBOSE(addr, buf, len) \
228 (DEBUG_READ_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
230 #define DEBUG_WRITE_MEM_VERBOSE(addr, buf, len) \
231 (DEBUG_WRITE_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
233 enum DbgInfoLoad {DIL_DEFERRED, DIL_LOADED, DIL_NOINFO, DIL_ERROR};
234 enum DbgModuleType {DMT_UNKNOWN, DMT_ELF, DMT_NE, DMT_PE};
236 typedef struct tagDBG_MODULE {
240 enum DbgInfoLoad dil;
241 enum DbgModuleType type;
242 unsigned short main : 1;
245 struct tagMSC_DBG_INFO* msc_info;
246 struct tagELF_DBG_INFO* elf_info;
253 struct datatype* type;
256 #define OFFSET_OF(__c,__f) ((int)(((char*)&(((__c*)0)->__f))-((char*)0)))
258 /* from winelib.so */
259 extern void DEBUG_ExternalDebugger(void);
261 /* debugger/break.c */
262 extern void DEBUG_SetBreakpoints( BOOL set );
263 extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) );
264 extern void DEBUG_AddBreakpointFromId( const char *name, int lineno );
265 extern void DEBUG_AddBreakpointFromLineno( int lineno );
266 extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
267 extern void DEBUG_AddWatchpointFromId( const char *name );
268 extern void DEBUG_CheckDelayedBP( void );
269 extern void DEBUG_DelBreakpoint( int num );
270 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
271 extern void DEBUG_InfoBreakpoints(void);
272 extern BOOL DEBUG_HandleTrap(void);
273 extern BOOL DEBUG_ShouldContinue( DBG_ADDR *addr, DWORD code, enum exec_mode mode,
275 extern void DEBUG_SuspendExecution( void );
276 extern enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count );
277 extern BOOL DEBUG_IsFctReturn(void);
278 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
280 /* debugger/db_disasm.c */
281 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
284 extern BOOL DEBUG_Parser(void);
285 extern void DEBUG_Exit( DWORD );
287 /* debugger/debug.l */
288 extern void DEBUG_FlushSymbols(void);
289 extern char*DEBUG_MakeSymbol(const char*);
290 extern int DEBUG_ReadLine(const char* pfx, char* buffer, int size, int remind);
292 /* debugger/display.c */
293 extern int DEBUG_DoDisplay(void);
294 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
295 extern int DEBUG_DoDisplay(void);
296 extern int DEBUG_DelDisplay(int displaynum);
297 extern int DEBUG_InfoDisplay(void);
299 /* debugger/editline.c */
300 extern char * readline(const char *);
301 extern void add_history(char *);
303 /* debugger/expr.c */
304 extern void DEBUG_FreeExprMem(void);
305 struct expr * DEBUG_IntVarExpr(const char* name);
306 struct expr * DEBUG_SymbolExpr(const char * name);
307 struct expr * DEBUG_ConstExpr(int val);
308 struct expr * DEBUG_StringExpr(const char * str);
309 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
310 struct expr * DEBUG_USConstExpr(unsigned int val);
311 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
312 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
313 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
314 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
315 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
316 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
317 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
318 extern DBG_VALUE DEBUG_EvalExpr(struct expr *);
319 extern int DEBUG_DelDisplay(int displaynum);
320 extern struct expr * DEBUG_CloneExpr(const struct expr * exp);
321 extern int DEBUG_FreeExpr(struct expr * exp);
322 extern int DEBUG_DisplayExpr(const struct expr * exp);
324 /* debugger/hash.c */
325 extern struct name_hash * DEBUG_AddSymbol( const char *name,
326 const DBG_VALUE *addr,
327 const char *sourcefile,
329 extern int DEBUG_GetSymbolValue( const char * name, const int lineno,
330 DBG_VALUE *addr, int );
331 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
332 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
333 struct name_hash ** rtn,
335 struct list_id * source);
336 extern void DEBUG_ReadSymbolTable( const char * filename );
337 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num,
338 unsigned long offset );
339 extern struct wine_locals *
340 DEBUG_AddLocal( struct name_hash * func, int regno,
345 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
346 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file,
348 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
349 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
350 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
351 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
352 extern BOOL DEBUG_GetLineNumberAddr( const struct name_hash *, const int lineno,
353 DBG_ADDR *addr, int bp_flag );
355 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym,
356 struct datatype * type);
357 extern BOOL DEBUG_Normalize(struct name_hash * nh );
359 /* debugger/info.c */
360 extern void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format );
361 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr,
362 enum dbg_mode mode, int flag );
363 extern void DEBUG_Help(void);
364 extern void DEBUG_HelpInfo(void);
365 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr,
369 extern void DEBUG_InfoClass(const char* clsName);
370 extern void DEBUG_WalkClasses(void);
371 extern void DEBUG_WalkModref(DWORD p);
372 extern void DEBUG_DumpModule(DWORD mod);
373 extern void DEBUG_WalkModules(void);
374 extern void DEBUG_WalkProcess(void);
375 extern void DEBUG_WalkThreads(void);
376 extern void DEBUG_DumpQueue(DWORD q);
377 extern void DEBUG_WalkQueues(void);
378 extern void DEBUG_InfoSegments(DWORD s, int v);
379 extern void DEBUG_InfoVirtual(void);
380 extern void DEBUG_InfoWindow(HWND hWnd);
381 extern void DEBUG_WalkWindows(HWND hWnd, int indent);
383 /* debugger/memory.c */
384 extern int DEBUG_ReadMemory( const DBG_VALUE* value );
385 extern void DEBUG_WriteMemory( const DBG_VALUE* val, int value );
386 extern void DEBUG_ExamineMemory( const DBG_VALUE *addr, int count, char format);
387 extern void DEBUG_InvalAddr( const DBG_ADDR* addr );
388 extern void DEBUG_InvalLinAddr( void* addr );
389 extern DWORD DEBUG_ToLinear( const DBG_ADDR *address );
390 extern void DEBUG_GetCurrentAddress( DBG_ADDR * );
391 extern BOOL DEBUG_GrabAddress( DBG_VALUE* value, BOOL fromCode );
392 extern enum dbg_mode DEBUG_GetSelectorType( WORD sel );
394 extern void DEBUG_FixAddress( DBG_ADDR *address, DWORD def );
395 extern int DEBUG_IsSelectorSystem( WORD sel );
398 /* debugger/module.c */
399 extern int DEBUG_LoadEntryPoints( const char * prefix );
400 extern void DEBUG_LoadModule32( const char* name, HANDLE hFile, DWORD base );
401 extern DBG_MODULE* DEBUG_AddModule(const char* name, enum DbgModuleType type,
402 void* mod_addr, u_long size, HMODULE hmod);
403 extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, enum DbgModuleType type);
404 extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, enum DbgModuleType type);
405 extern DBG_MODULE* DEBUG_FindModuleByAddr(void* addr, enum DbgModuleType type);
406 extern DBG_MODULE* DEBUG_GetProcessMainModule(DBG_PROCESS* process);
407 extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, u_long size,
409 extern DBG_MODULE* DEBUG_RegisterELFModule(u_long load_addr, u_long size,
411 extern enum DbgInfoLoad DEBUG_RegisterPEDebugInfo(DBG_MODULE* wmod, HANDLE hFile,
412 void* _nth, unsigned long nth_ofs);
413 extern void DEBUG_ReportDIL(enum DbgInfoLoad dil, const char* pfx,
414 const char* filename, DWORD load_addr);
415 extern void DEBUG_InfoShare(void);
418 extern enum DbgInfoLoad DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile,
419 void* nth, unsigned long nth_ofs);
420 extern enum DbgInfoLoad DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module,
421 HANDLE hFile, void* nth,
422 unsigned long nth_ofs);
423 extern void DEBUG_InitCVDataTypes(void);
425 /* debugger/registers.c */
426 extern void DEBUG_InfoRegisters(void);
427 extern BOOL DEBUG_ValidateRegisters(void);
429 /* debugger/source.c */
430 extern void DEBUG_ShowDir(void);
431 extern void DEBUG_AddPath(const char * path);
432 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,
434 extern void DEBUG_NukePath(void);
435 extern void DEBUG_Disassemble(const DBG_VALUE *, const DBG_VALUE*, int offset);
436 extern BOOL DEBUG_DisassembleInstruction(DBG_ADDR *addr);
438 /* debugger/stack.c */
439 extern void DEBUG_InfoStack(void);
440 extern void DEBUG_BackTrace(DWORD threadID, BOOL noisy);
441 extern int DEBUG_InfoLocals(void);
442 extern int DEBUG_SetFrame(int newframe);
443 extern int DEBUG_GetCurrentFrame(struct name_hash ** name,
447 /* debugger/stabs.c */
448 extern enum DbgInfoLoad DEBUG_ReadExecutableDbgInfo(const char* exe_name);
449 extern enum DbgInfoLoad DEBUG_ParseStabs(char * addr, unsigned int load_offset,
450 unsigned int staboff, int stablen,
451 unsigned int strtaboff, int strtablen);
453 /* debugger/types.c */
454 extern int DEBUG_nchar;
455 extern void DEBUG_InitTypes(void);
456 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype,
457 const char * typename);
458 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE *value,
459 struct datatype ** newtype);
460 extern int DEBUG_AddStructElement(struct datatype * dt,
461 char * name, struct datatype * type,
462 int offset, int size);
463 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
464 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
465 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
466 struct datatype * dt2);
467 extern void DEBUG_Print( const DBG_VALUE *addr, int count, char format, int level );
468 extern unsigned int DEBUG_FindStructElement(DBG_VALUE * addr,
469 const char * ele_name, int * tmpbuf);
470 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
471 extern int DEBUG_GetObjectSize(struct datatype * dt);
472 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE * addr, DBG_VALUE * result,
474 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
475 extern long long int DEBUG_GetExprValue(const DBG_VALUE * addr, char ** format);
476 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset,
477 int nbits, struct datatype * dt2);
478 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
479 extern enum debug_type DEBUG_GetType(struct datatype * dt);
480 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
481 extern int DEBUG_PrintTypeCast(const struct datatype *);
482 extern int DEBUG_PrintType( const DBG_VALUE* addr );
484 /* debugger/winedbg.c */
485 #define DBG_CHN_MESG 1
486 #define DBG_CHN_ERR 2
487 #define DBG_CHN_WARN 4
488 #define DBG_CHN_FIXME 8
489 #define DBG_CHN_TRACE 16
490 extern void DEBUG_Output(int chn, const char* buffer, int len);
492 extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__((format (printf,2,3)));
494 extern int DEBUG_Printf(int chn, const char* format, ...);
496 extern DBG_INTVAR* DEBUG_GetIntVar(const char*);
497 extern BOOL DEBUG_Attach(DWORD pid, BOOL cofe);
498 extern void DEBUG_Run(const char* args);
499 extern DBG_PROCESS* DEBUG_GetProcess(DWORD pid);
500 extern DBG_THREAD* DEBUG_GetThread(DBG_PROCESS* p, DWORD tid);
501 extern int curr_frame;
503 /* Choose your allocator! */
505 /* this one is libc's fast one */
506 extern void* DEBUG_XMalloc(size_t size);
507 extern void* DEBUG_XReAlloc(void *ptr, size_t size);
508 extern char* DEBUG_XStrDup(const char *str);
510 #define DBG_alloc(x) DEBUG_XMalloc(x)
511 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
512 #define DBG_free(x) free(x)
513 #define DBG_strdup(x) DEBUG_XStrDup(x)
515 /* this one is slow (takes 5 minutes to load the debugger on my machine),
516 if someone could make optimized routines so it wouldn't
517 take so long to load, it could be made default) */
518 #define DBG_alloc(x) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,x)
519 #define DBG_realloc(x,y) HeapReAlloc(GetProcessHeap(),0,x,y)
520 #define DBG_free(x) HeapFree(GetProcessHeap(),0,x)
521 inline static LPSTR DBG_strdup( LPCSTR str )
523 INT len = strlen(str) + 1;
524 LPSTR p = DBG_alloc( len );
525 if (p) memcpy( p, str, len );
530 #define DEBUG_STATUS_OFFSET 0x80003000
531 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
532 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
533 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
534 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
535 #define DEBUG_STATUS_NO_FIELD (DEBUG_STATUS_OFFSET+4)
537 extern DBG_INTVAR DEBUG_IntVars[];
539 #define DBG_IVARNAME(_var) DEBUG_IV_##_var
540 #define DBG_IVARSTRUCT(_var) DEBUG_IntVars[DBG_IVARNAME(_var)]
541 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
542 #define INTERNAL_VAR(_var,_val,_ref,_typ) DBG_IVARNAME(_var),
549 #endif /* __WINE_DEBUGGER_H */