4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __WINE_DEBUGGER_H
22 #define __WINE_DEBUGGER_H
24 #include <sys/types.h> /* u_long ... */
28 #include "wine/exception.h"
31 #define STEP_FLAG 0x00000100 /* single step flag */
32 #define V86_FLAG 0x00020000
39 #define SYM_INVALID 0x8
40 #define SYM_TRAMPOLINE 0x10
41 #define SYM_STEP_THROUGH 0x20
43 enum debug_type {DT_BASIC, DT_POINTER, DT_ARRAY, DT_STRUCT, DT_ENUM,
44 DT_FUNC, DT_BITFIELD};
46 enum debug_type_basic {DT_BASIC_INT = 1, DT_BASIC_CHAR, DT_BASIC_LONGINT, DT_BASIC_UINT,
47 DT_BASIC_ULONGINT, DT_BASIC_LONGLONGINT, DT_BASIC_ULONGLONGINT,
48 DT_BASIC_SHORTINT, DT_BASIC_USHORTINT, DT_BASIC_SCHAR, DT_BASIC_UCHAR,
49 DT_BASIC_FLOAT, DT_BASIC_LONGDOUBLE, DT_BASIC_DOUBLE,
50 DT_BASIC_CMPLX_INT, DT_BASIC_CMPLX_FLOAT, DT_BASIC_CMPLX_DOUBLE,
51 DT_BASIC_CMPLX_LONGDOUBLE, DT_BASIC_VOID,
52 /* modifier on size isn't possible on current types definitions
53 * so we need to add more types... */
54 DT_BASIC_BOOL1, DT_BASIC_BOOL2, DT_BASIC_BOOL4,
55 /* this is not really a basic type... */
57 /* this is for historical reasons... should take care of it RSN */
59 /* to be kept as last... sentinel entry... do not use */
63 * Return values for DEBUG_CheckLinenoStatus. Used to determine
64 * what to do when the 'step' command is given.
66 #define FUNC_HAS_NO_LINES (0)
67 #define NOT_ON_LINENUMBER (1)
68 #define AT_LINENUMBER (2)
69 #define FUNC_IS_TRAMPOLINE (3)
73 DWORD seg; /* 0xffffffff means current default segment (cs or ds) */
79 struct datatype* type;
80 int cookie; /* DV_??? */
81 /* DV_TARGET references an address in debugger's address space, whereas DV_HOST
82 * references the debuggee address space
84 # define DV_TARGET 0xF00D
85 # define DV_HOST 0x50DA
86 # define DV_INVALID 0x0000
98 unsigned long line_number;
104 struct name_hash * sym;
108 typedef struct wine_lines WineLineNo;
111 * This structure holds information about stack variables, function
112 * parameters, and register variables, which are all local to this
116 unsigned int regno:8; /* For register symbols */
117 signed int offset:24; /* offset from esp/ebp to symbol */
118 unsigned int pc_start; /* For RBRAC/LBRAC */
119 unsigned int pc_end; /* For RBRAC/LBRAC */
120 char * name; /* Name of symbol */
121 struct datatype * type; /* Datatype of symbol */
124 typedef struct wine_locals WineLocals;
128 EXEC_CONT, /* Continuous execution */
129 EXEC_STEP_OVER, /* Stepping over a call to next source line */
130 EXEC_STEP_INSTR, /* Step to next source line, stepping in if needed */
131 EXEC_STEPI_OVER, /* Stepping over a call */
132 EXEC_STEPI_INSTR, /* Single-stepping an instruction */
133 EXEC_FINISH, /* Step until we exit current frame */
134 EXEC_STEP_OVER_TRAMPOLINE, /* Step over trampoline. Requires that
135 * we dig the real return value off the stack
136 * and set breakpoint there - not at the
137 * instr just after the call.
143 MODE_INVALID, MODE_16, MODE_32, MODE_VM86
146 enum exit_mode /* of exception handling */
148 EXIT_CONTINUE, /* continue execution */
149 EXIT_PASS, /* pass exception back to app (1st chance) */
150 EXIT_DETACH, /* detach debugger */
151 EXIT_QUIT, /* exit debugger and kill debuggee */
177 struct expr * condition;
180 /* Wine extension; Windows doesn't have a name for this code. This is an
181 undocumented exception understood by MS VC debugger, allowing the program
182 to name a particular thread. Search google.com or deja.com for "0x406d1388"
184 #define EXCEPTION_NAME_THREAD 0x406D1388
186 /* Helper structure */
187 typedef struct tagTHREADNAME_INFO
189 DWORD dwType; /* Must be 0x1000 */
190 LPCTSTR szName; /* Pointer to name - limited to 9 bytes (8 characters + terminator) */
191 DWORD dwThreadID; /* Thread ID (-1 = caller thread) */
192 DWORD dwFlags; /* Reserved for future use. Must be zero. */
195 typedef struct tagDBG_THREAD {
196 struct tagDBG_PROCESS* process;
201 int wait_for_first_exception;
202 enum exec_mode exec_mode; /* mode the thread is run (step/run...) */
203 int exec_count; /* count of mode operations */
204 enum dbg_mode dbg_mode; /* mode (VM86, 32bit, 16bit) */
205 DBG_BREAKPOINT stepOverBP;
207 struct tagDBG_THREAD* next;
208 struct tagDBG_THREAD* prev;
211 typedef struct tagDBG_DELAYED_BP {
216 typedef struct tagDBG_PROCESS {
219 const char* imageName;
222 unsigned continue_on_first_exception;
223 struct tagDBG_MODULE** modules;
225 unsigned long dbg_hdr_addr;
226 DBG_DELAYED_BP* delayed_bp;
229 * This is an index we use to keep track of the debug information
230 * when we have multiple sources. We use the same database to also
231 * allow us to do an 'info shared' type of deal, and we use the index
232 * to eliminate duplicates.
235 struct tagDBG_PROCESS* next;
236 struct tagDBG_PROCESS* prev;
239 extern DBG_PROCESS* DEBUG_CurrProcess;
240 extern DBG_THREAD* DEBUG_CurrThread;
241 extern DWORD DEBUG_CurrTid;
242 extern DWORD DEBUG_CurrPid;
243 extern CONTEXT DEBUG_context;
244 extern BOOL DEBUG_interactiveP;
245 extern enum exit_mode DEBUG_ExitMode;
247 #define DEBUG_READ_MEM(addr, buf, len) \
248 (ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
250 #define DEBUG_WRITE_MEM(addr, buf, len) \
251 (WriteProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
253 #define DEBUG_READ_MEM_VERBOSE(addr, buf, len) \
254 (DEBUG_READ_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
256 #define DEBUG_WRITE_MEM_VERBOSE(addr, buf, len) \
257 (DEBUG_WRITE_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
259 enum DbgInfoLoad {DIL_DEFERRED, DIL_LOADED, DIL_NOINFO, DIL_ERROR};
260 enum DbgModuleType {DMT_UNKNOWN, DMT_ELF, DMT_NE, DMT_PE};
262 typedef struct tagDBG_MODULE {
266 enum DbgInfoLoad dil;
267 enum DbgModuleType type;
268 unsigned short main : 1;
271 struct tagMSC_DBG_INFO* msc_info;
272 struct tagELF_DBG_INFO* elf_info;
279 struct datatype* type;
282 #define OFFSET_OF(__c,__f) ((int)(((char*)&(((__c*)0)->__f))-((char*)0)))
284 /* from winelib.so */
285 extern void DEBUG_ExternalDebugger(void);
287 /* debugger/break.c */
288 extern void DEBUG_SetBreakpoints( BOOL set );
289 extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) );
290 extern void DEBUG_AddBreakpointFromId( const char *name, int lineno );
291 extern void DEBUG_AddBreakpointFromLineno( int lineno );
292 extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
293 extern void DEBUG_AddWatchpointFromId( const char *name );
294 extern void DEBUG_CheckDelayedBP( void );
295 extern void DEBUG_DelBreakpoint( int num );
296 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
297 extern void DEBUG_InfoBreakpoints(void);
298 extern BOOL DEBUG_HandleTrap(void);
299 extern BOOL DEBUG_ShouldContinue( DBG_ADDR* addr, DWORD code, int* count );
300 extern void DEBUG_SuspendExecution( void );
301 extern void DEBUG_RestartExecution( int count );
302 extern BOOL DEBUG_IsFctReturn(void);
303 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
305 /* debugger/db_disasm.c */
306 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
309 extern void DEBUG_Parser(void);
310 extern void DEBUG_Exit( DWORD );
312 /* debugger/debug.l */
313 extern void DEBUG_FlushSymbols(void);
314 extern char*DEBUG_MakeSymbol(const char*);
315 extern int DEBUG_ReadLine(const char* pfx, char* buffer, int size, int flush_sym, int keep_hist);
317 /* debugger/display.c */
318 extern int DEBUG_DoDisplay(void);
319 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
320 extern int DEBUG_DoDisplay(void);
321 extern int DEBUG_DelDisplay(int displaynum);
322 extern int DEBUG_InfoDisplay(void);
324 /* debugger/editline.c */
325 extern char * readline(const char *);
326 extern void add_history(char *);
328 /* debugger/expr.c */
329 extern void DEBUG_FreeExprMem(void);
330 struct expr * DEBUG_IntVarExpr(const char* name);
331 struct expr * DEBUG_SymbolExpr(const char * name);
332 struct expr * DEBUG_ConstExpr(int val);
333 struct expr * DEBUG_StringExpr(const char * str);
334 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
335 struct expr * DEBUG_USConstExpr(unsigned int val);
336 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
337 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
338 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
339 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
340 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
341 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
342 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
343 extern DBG_VALUE DEBUG_EvalExpr(struct expr *);
344 extern int DEBUG_DelDisplay(int displaynum);
345 extern struct expr * DEBUG_CloneExpr(const struct expr * exp);
346 extern int DEBUG_FreeExpr(struct expr * exp);
347 extern int DEBUG_DisplayExpr(const struct expr * exp);
349 /* debugger/hash.c */
350 extern struct name_hash * DEBUG_AddSymbol( const char *name,
351 const DBG_VALUE *addr,
352 const char *sourcefile,
354 extern int DEBUG_GetSymbolValue( const char * name, const int lineno,
355 DBG_VALUE *addr, int );
356 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
357 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
358 struct name_hash ** rtn,
360 struct list_id * source);
361 extern void DEBUG_ReadSymbolTable( const char * filename );
362 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num,
363 unsigned long offset );
364 extern struct wine_locals *
365 DEBUG_AddLocal( struct name_hash * func, int regno,
370 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
371 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file,
373 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
374 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
375 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
376 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
377 extern BOOL DEBUG_GetLineNumberAddr( const struct name_hash *, const int lineno,
378 DBG_ADDR *addr, int bp_flag );
380 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym,
381 struct datatype * type);
382 extern BOOL DEBUG_Normalize(struct name_hash * nh );
384 /* debugger/info.c */
385 extern void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format );
386 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr,
387 enum dbg_mode mode, int flag );
388 extern void DEBUG_Help(void);
389 extern void DEBUG_HelpInfo(void);
390 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr,
394 extern void DEBUG_InfoClass(const char* clsName);
395 extern void DEBUG_WalkClasses(void);
396 extern void DEBUG_WalkModref(DWORD p);
397 extern void DEBUG_DumpModule(DWORD mod);
398 extern void DEBUG_WalkModules(void);
399 extern void DEBUG_WalkProcess(void);
400 extern void DEBUG_WalkThreads(void);
401 extern void DEBUG_DumpQueue(DWORD q);
402 extern void DEBUG_WalkQueues(void);
403 extern void DEBUG_InfoSegments(DWORD s, int v);
404 extern void DEBUG_InfoVirtual(void);
405 extern void DEBUG_InfoWindow(HWND hWnd);
406 extern void DEBUG_WalkWindows(HWND hWnd, int indent);
407 extern void DEBUG_DbgChannel(BOOL add, const char* chnl, const char* name);
409 /* debugger/memory.c */
410 extern int DEBUG_ReadMemory( const DBG_VALUE* value );
411 extern void DEBUG_WriteMemory( const DBG_VALUE* val, int value );
412 extern void DEBUG_ExamineMemory( const DBG_VALUE *addr, int count, char format);
413 extern void DEBUG_InvalAddr( const DBG_ADDR* addr );
414 extern void DEBUG_InvalLinAddr( void* addr );
415 extern DWORD DEBUG_ToLinear( const DBG_ADDR *address );
416 extern void DEBUG_GetCurrentAddress( DBG_ADDR * );
417 extern BOOL DEBUG_GrabAddress( DBG_VALUE* value, BOOL fromCode );
418 extern enum dbg_mode DEBUG_GetSelectorType( WORD sel );
420 extern void DEBUG_FixAddress( DBG_ADDR *address, DWORD def );
421 extern int DEBUG_IsSelectorSystem( WORD sel );
423 extern int DEBUG_PrintStringA( int chnl, const DBG_ADDR* address, int len );
424 extern int DEBUG_PrintStringW( int chnl, const DBG_ADDR* address, int len );
426 /* debugger/module.c */
427 extern int DEBUG_LoadEntryPoints( const char * prefix );
428 extern void DEBUG_LoadModule32( const char* name, HANDLE hFile, DWORD base );
429 extern DBG_MODULE* DEBUG_AddModule(const char* name, enum DbgModuleType type,
430 void* mod_addr, u_long size, HMODULE hmod);
431 extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, enum DbgModuleType type);
432 extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, enum DbgModuleType type);
433 extern DBG_MODULE* DEBUG_FindModuleByAddr(void* addr, enum DbgModuleType type);
434 extern DBG_MODULE* DEBUG_GetProcessMainModule(DBG_PROCESS* process);
435 extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, u_long size,
437 extern DBG_MODULE* DEBUG_RegisterELFModule(u_long load_addr, u_long size,
439 extern enum DbgInfoLoad DEBUG_RegisterPEDebugInfo(DBG_MODULE* wmod, HANDLE hFile,
440 void* _nth, unsigned long nth_ofs);
441 extern void DEBUG_ReportDIL(enum DbgInfoLoad dil, const char* pfx,
442 const char* filename, DWORD load_addr);
443 extern void DEBUG_InfoShare(void);
446 extern enum DbgInfoLoad DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile,
447 void* nth, unsigned long nth_ofs);
448 extern enum DbgInfoLoad DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module,
449 HANDLE hFile, void* nth,
450 unsigned long nth_ofs);
451 extern void DEBUG_InitCVDataTypes(void);
453 /* debugger/registers.c */
454 extern void DEBUG_InfoRegisters(void);
455 extern BOOL DEBUG_ValidateRegisters(void);
457 /* debugger/source.c */
458 extern void DEBUG_ShowDir(void);
459 extern void DEBUG_AddPath(const char * path);
460 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,
462 extern void DEBUG_NukePath(void);
463 extern void DEBUG_Disassemble(const DBG_VALUE *, const DBG_VALUE*, int offset);
464 extern BOOL DEBUG_DisassembleInstruction(DBG_ADDR *addr);
466 /* debugger/stack.c */
467 extern void DEBUG_InfoStack(void);
468 extern void DEBUG_BackTrace(DWORD threadID, BOOL noisy);
469 extern int DEBUG_InfoLocals(void);
470 extern int DEBUG_SetFrame(int newframe);
471 extern int DEBUG_GetCurrentFrame(struct name_hash ** name,
475 /* debugger/stabs.c */
476 extern enum DbgInfoLoad DEBUG_ReadExecutableDbgInfo(const char* exe_name);
477 extern enum DbgInfoLoad DEBUG_ParseStabs(char * addr, unsigned int load_offset,
478 unsigned int staboff, int stablen,
479 unsigned int strtaboff, int strtablen);
481 /* debugger/types.c */
482 extern int DEBUG_nchar;
483 extern void DEBUG_InitTypes(void);
484 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype,
485 const char * typename);
486 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE *value,
487 struct datatype ** newtype);
488 extern int DEBUG_AddStructElement(struct datatype * dt,
489 char * name, struct datatype * type,
490 int offset, int size);
491 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
492 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
493 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
494 struct datatype * dt2);
495 extern void DEBUG_Print( const DBG_VALUE *addr, int count, char format, int level );
496 extern unsigned int DEBUG_FindStructElement(DBG_VALUE * addr,
497 const char * ele_name, int * tmpbuf);
498 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
499 extern int DEBUG_GetObjectSize(struct datatype * dt);
500 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE * addr, DBG_VALUE * result,
502 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
503 extern long long int DEBUG_GetExprValue(const DBG_VALUE * addr, char ** format);
504 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset,
505 int nbits, struct datatype * dt2);
506 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
507 extern enum debug_type DEBUG_GetType(struct datatype * dt);
508 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
509 extern int DEBUG_PrintTypeCast(const struct datatype *);
510 extern int DEBUG_PrintType( const DBG_VALUE* addr );
511 extern struct datatype * DEBUG_GetBasicType(enum debug_type_basic);
513 /* debugger/winedbg.c */
514 #define DBG_CHN_MESG 1
515 #define DBG_CHN_ERR 2
516 #define DBG_CHN_WARN 4
517 #define DBG_CHN_FIXME 8
518 #define DBG_CHN_TRACE 16
519 extern void DEBUG_OutputA(int chn, const char* buffer, int len);
520 extern void DEBUG_OutputW(int chn, const WCHAR* buffer, int len);
522 extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__((format (printf,2,3)));
524 extern int DEBUG_Printf(int chn, const char* format, ...);
526 extern DBG_INTVAR* DEBUG_GetIntVar(const char*);
527 extern BOOL DEBUG_Attach(DWORD pid, BOOL cofe);
528 extern BOOL DEBUG_Detach(void);
529 extern void DEBUG_Run(const char* args);
530 extern DBG_PROCESS* DEBUG_GetProcess(DWORD pid);
531 extern DBG_THREAD* DEBUG_GetThread(DBG_PROCESS* p, DWORD tid);
532 extern int curr_frame;
533 extern int automatic_mode;
535 /* Choose your allocator! */
537 /* this one is libc's fast one */
538 extern void* DEBUG_XMalloc(size_t size);
539 extern void* DEBUG_XReAlloc(void *ptr, size_t size);
540 extern char* DEBUG_XStrDup(const char *str);
542 #define DBG_alloc(x) DEBUG_XMalloc(x)
543 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
544 #define DBG_free(x) free(x)
545 #define DBG_strdup(x) DEBUG_XStrDup(x)
547 /* this one is slow (takes 5 minutes to load the debugger on my machine),
548 if someone could make optimized routines so it wouldn't
549 take so long to load, it could be made default) */
550 #define DBG_alloc(x) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,x)
551 #define DBG_realloc(x,y) HeapReAlloc(GetProcessHeap(),0,x,y)
552 #define DBG_free(x) HeapFree(GetProcessHeap(),0,x)
553 inline static LPSTR DBG_strdup( LPCSTR str )
555 INT len = strlen(str) + 1;
556 LPSTR p = DBG_alloc( len );
557 if (p) memcpy( p, str, len );
562 #define DEBUG_STATUS_OFFSET 0x80003000
563 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
564 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
565 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
566 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
567 #define DEBUG_STATUS_NO_FIELD (DEBUG_STATUS_OFFSET+4)
569 extern DBG_INTVAR DEBUG_IntVars[];
571 #define DBG_IVARNAME(_var) DEBUG_IV_##_var
572 #define DBG_IVARSTRUCT(_var) DEBUG_IntVars[DBG_IVARNAME(_var)]
573 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
574 #define INTERNAL_VAR(_var,_val,_ref,_typ) DBG_IVARNAME(_var),
581 #endif /* __WINE_DEBUGGER_H */