Use the service thread for comm notifications.
[wine] / include / debugger.h
1 /*
2  * Debugger definitions
3  *
4  * Copyright 1995 Alexandre Julliard
5  */
6
7 #ifndef __WINE_DEBUGGER_H
8 #define __WINE_DEBUGGER_H
9
10 #include <sys/types.h> /* u_long ... */
11 #include "windef.h"
12 #include "sig_context.h"
13 #include "miscemu.h"
14
15 #define STEP_FLAG 0x100 /* single step flag */
16
17 #define SYM_FUNC         0x0
18 #define SYM_DATA         0x1
19 #define SYM_WIN32        0x2
20 #define SYM_WINE         0x4
21 #define SYM_INVALID      0x8
22 #define SYM_TRAMPOLINE   0x10
23 #define SYM_STEP_THROUGH 0x20
24
25 enum    debug_type {DT_BASIC, DT_CONST, DT_POINTER, DT_ARRAY, DT_STRUCT, DT_ENUM, DT_TYPEDEF, DT_FUNC, DT_BITFIELD};
26
27
28 /*
29  * Return values for DEBUG_CheckLinenoStatus.  Used to determine
30  * what to do when the 'step' command is given.
31  */
32 #define FUNC_HAS_NO_LINES       (0)
33 #define NOT_ON_LINENUMBER       (1)
34 #define AT_LINENUMBER           (2)
35 #define FUNC_IS_TRAMPOLINE      (3)
36
37 /*
38  * For constants generated by the parser, we use this datatype
39  */
40 extern struct datatype * DEBUG_TypeInt;
41 extern struct datatype * DEBUG_TypeIntConst;
42 extern struct datatype * DEBUG_TypeUSInt;
43 extern struct datatype * DEBUG_TypeString;
44
45 typedef struct
46 {
47     struct datatype * type;
48     DWORD seg;  /* 0xffffffff means current default segment (cs or ds) */
49     DWORD off;
50 } DBG_ADDR;
51
52 struct list_id
53 {
54     char * sourcefile;
55     int    line;
56 };
57
58 struct  wine_lines {
59   unsigned long         line_number;
60   DBG_ADDR              pc_offset;
61 };
62
63 struct symbol_info
64 {
65   struct name_hash * sym;
66   struct list_id     list;
67 };
68
69 typedef struct wine_lines WineLineNo;
70
71 /*
72  * This structure holds information about stack variables, function
73  * parameters, and register variables, which are all local to this
74  * function.
75  */
76 struct  wine_locals {
77   unsigned int          regno:8;        /* For register symbols */
78   signed int            offset:24;      /* offset from esp/ebp to symbol */
79   unsigned int          pc_start;       /* For RBRAC/LBRAC */
80   unsigned int          pc_end;         /* For RBRAC/LBRAC */
81   char                * name;           /* Name of symbol */
82   struct datatype     * type;           /* Datatype of symbol */
83 };
84
85 typedef struct wine_locals WineLocals;
86
87
88 #define DBG_V86_MODULE(seg) ((seg)>>16)
89 #define IS_SELECTOR_V86(seg) DBG_V86_MODULE(seg)
90
91 #define DBG_FIX_ADDR_SEG(addr,default) { \
92       if ((addr)->seg == 0xffffffff) (addr)->seg = (default); \
93       if (!IS_SELECTOR_V86((addr)->seg)) \
94       if (IS_SELECTOR_SYSTEM((addr)->seg)) (addr)->seg = 0; }
95
96 #define DBG_ADDR_TO_LIN(addr) \
97     (IS_SELECTOR_V86((addr)->seg) \
98       ? (char*)(DOSMEM_MemoryBase(DBG_V86_MODULE((addr)->seg)) + \
99          ((((addr)->seg)&0xFFFF)<<4)+(addr)->off) : \
100     (IS_SELECTOR_SYSTEM((addr)->seg) ? (char *)(addr)->off \
101       : (char *)PTR_SEG_OFF_TO_LIN((addr)->seg,(addr)->off)))
102
103 #define DBG_CHECK_READ_PTR(addr,len) \
104     (!DEBUG_IsBadReadPtr((addr),(len)) || \
105      (fprintf(stderr,"*** Invalid address "), \
106       DEBUG_PrintAddress((addr),dbg_mode, FALSE), \
107       fprintf(stderr,"\n"),0))
108
109 #define DBG_CHECK_WRITE_PTR(addr,len) \
110     (!DEBUG_IsBadWritePtr((addr),(len)) || \
111      (fprintf(stderr,"*** Invalid address "), \
112       DEBUG_PrintAddress(addr,dbg_mode, FALSE), \
113       fprintf(stderr,"\n"),0))
114
115 #ifdef REG_SP  /* Some Sun includes define this */
116 #undef REG_SP
117 #endif
118
119 enum debug_regs
120 {
121     REG_EAX, REG_EBX, REG_ECX, REG_EDX, REG_ESI,
122     REG_EDI, REG_EBP, REG_EFL, REG_EIP, REG_ESP,
123     REG_AX, REG_BX, REG_CX, REG_DX, REG_SI,
124     REG_DI, REG_BP, REG_FL, REG_IP, REG_SP,
125     REG_CS, REG_DS, REG_ES, REG_SS, REG_FS, REG_GS
126 };
127
128
129 enum exec_mode
130 {
131     EXEC_CONT,       /* Continuous execution */
132     EXEC_PASS,       /* Continue, passing exception to app */
133     EXEC_STEP_OVER,  /* Stepping over a call to next source line */
134     EXEC_STEP_INSTR,  /* Step to next source line, stepping in if needed */
135     EXEC_STEPI_OVER,  /* Stepping over a call */
136     EXEC_STEPI_INSTR,  /* Single-stepping an instruction */
137     EXEC_FINISH,                /* Step until we exit current frame */
138     EXEC_STEP_OVER_TRAMPOLINE  /* Step over trampoline.  Requires that
139                                 * we dig the real return value off the stack
140                                 * and set breakpoint there - not at the
141                                 * instr just after the call.
142                                 */
143 };
144
145 extern CONTEXT DEBUG_context;  /* debugger/registers.c */
146 extern unsigned int dbg_mode;
147 extern HANDLE dbg_heap;
148
149   /* debugger/break.c */
150 extern void DEBUG_SetBreakpoints( BOOL set );
151 extern int DEBUG_FindBreakpoint( const DBG_ADDR *addr );
152 extern void DEBUG_AddBreakpoint( const DBG_ADDR *addr );
153 extern void DEBUG_DelBreakpoint( int num );
154 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
155 extern void DEBUG_InfoBreakpoints(void);
156 extern void DEBUG_AddTaskEntryBreakpoint( HTASK16 hTask );
157 extern BOOL DEBUG_HandleTrap(void);
158 extern BOOL DEBUG_ShouldContinue( enum exec_mode mode, int * count );
159 extern enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count );
160 extern BOOL DEBUG_IsFctReturn(void);
161
162   /* debugger/db_disasm.c */
163 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
164
165   /* debugger/expr.c */
166 extern void DEBUG_FreeExprMem(void);
167 struct expr * DEBUG_RegisterExpr(enum debug_regs);
168 struct expr * DEBUG_SymbolExpr(const char * name);
169 struct expr * DEBUG_ConstExpr(int val);
170 struct expr * DEBUG_StringExpr(const char * str);
171 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
172 struct expr * DEBUG_USConstExpr(unsigned int val);
173 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
174 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
175 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
176 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
177 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
178 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
179 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
180 extern   int  DEBUG_ExprValue(DBG_ADDR *, unsigned int *);
181 DBG_ADDR DEBUG_EvalExpr(struct expr *);
182 extern int DEBUG_DelDisplay(int displaynum);
183 extern struct expr * DEBUG_CloneExpr(struct expr * exp);
184 extern int DEBUG_FreeExpr(struct expr * exp);
185 extern int DEBUG_DisplayExpr(struct expr * exp);
186
187   /* more debugger/break.c */
188 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
189
190   /* debugger/display.c */
191 extern int DEBUG_DoDisplay(void);
192 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
193 extern int DEBUG_DoDisplay(void);
194 extern int DEBUG_DelDisplay(int displaynum);
195 extern int DEBUG_InfoDisplay(void);
196
197   /* debugger/hash.c */
198 extern struct name_hash * DEBUG_AddSymbol( const char *name, 
199                                            const DBG_ADDR *addr,
200                                            const char * sourcefile,
201                                            int flags);
202 extern struct name_hash * DEBUG_AddInvSymbol( const char *name, 
203                                            const DBG_ADDR *addr,
204                                            const char * sourcefile);
205 extern BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
206                                     DBG_ADDR *addr, int );
207 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_ADDR *addr );
208 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
209                                              struct name_hash ** rtn,
210                                              unsigned int ebp,
211                                              struct list_id * source);
212 extern void DEBUG_ReadSymbolTable( const char * filename );
213 extern void DEBUG_LoadEntryPoints(void);
214 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num, 
215                      unsigned long offset );
216 extern struct wine_locals *
217             DEBUG_AddLocal( struct name_hash * func, int regno, 
218                             int offset,
219                             int pc_start,
220                             int pc_end,
221                             char * name);
222 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
223 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file, 
224                               const char * func);
225 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
226 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
227 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
228 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
229 extern BOOL DEBUG_GetLineNumberAddr( struct name_hash *, const int lineno, 
230                                 DBG_ADDR *addr, int bp_flag );
231
232 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym, 
233                                     struct datatype * type);
234 BOOL DEBUG_Normalize(struct name_hash * nh );
235
236   /* debugger/info.c */
237 extern void DEBUG_PrintBasic( const DBG_ADDR *addr, int count, char format );
238 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr, 
239                                               int addrlen, int flag );
240 extern void DEBUG_Help(void);
241 extern void DEBUG_HelpInfo(void);
242 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr, 
243                                                      int addrlen, 
244                                                      unsigned int ebp, 
245                                                      int flag );
246
247   /* debugger/memory.c */
248 extern BOOL DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size );
249 extern BOOL DEBUG_IsBadWritePtr( const DBG_ADDR *address, int size );
250 extern int DEBUG_ReadMemory( const DBG_ADDR *address );
251 extern void DEBUG_WriteMemory( const DBG_ADDR *address, int value );
252 extern void DEBUG_ExamineMemory( const DBG_ADDR *addr, int count, char format);
253
254   /* debugger/registers.c */
255 extern void DEBUG_SetRegister( enum debug_regs reg, int val );
256 extern int DEBUG_GetRegister( enum debug_regs reg );
257 extern void DEBUG_InfoRegisters(void);
258 extern BOOL DEBUG_ValidateRegisters(void);
259 extern int DEBUG_PrintRegister(enum debug_regs reg);
260
261   /* debugger/stack.c */
262 extern void DEBUG_InfoStack(void);
263 extern void DEBUG_BackTrace(void);
264 extern void DEBUG_SilentBackTrace(void);
265 extern int  DEBUG_InfoLocals(void);
266 extern int  DEBUG_SetFrame(int newframe);
267 extern int  DEBUG_GetCurrentFrame(struct name_hash ** name, 
268                                   unsigned int * eip,
269                                   unsigned int * ebp);
270
271   /* debugger/stabs.c */
272 extern int DEBUG_ReadExecutableDbgInfo(void);
273 extern int DEBUG_ParseStabs(char * addr, unsigned int load_offset, unsigned int staboff, int stablen, unsigned int strtaboff, int strtablen);
274
275   /* debugger/msc.c */
276 extern int DEBUG_RegisterDebugInfo( HMODULE, const char *);
277 extern int DEBUG_ProcessDeferredDebug(void);
278 extern int DEBUG_RegisterELFDebugInfo(int load_addr, u_long size, char * name);
279 extern void DEBUG_InfoShare(void);
280 extern void DEBUG_InitCVDataTypes(void);
281
282   /* debugger/types.c */
283 extern int DEBUG_nchar;
284 extern void DEBUG_InitTypes(void);
285 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype, 
286                                            const char * typename);
287 extern unsigned int 
288 DEBUG_TypeDerefPointer(DBG_ADDR * addr, struct datatype ** newtype);
289 extern int DEBUG_AddStructElement(struct datatype * dt, 
290                                   char * name, struct datatype * type, 
291                                   int offset, int size);
292 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
293 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
294 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
295                                 struct datatype * dt2);
296 extern void DEBUG_Print( const DBG_ADDR *addr, int count, char format, int level );
297 extern unsigned int DEBUG_FindStructElement(DBG_ADDR * addr, 
298                                             const char * ele_name, int * tmpbuf);
299 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
300 extern int DEBUG_GetObjectSize(struct datatype * dt);
301 extern unsigned int DEBUG_ArrayIndex(DBG_ADDR * addr, DBG_ADDR * result, int index);
302 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
303 extern long long int DEBUG_GetExprValue(DBG_ADDR * addr, char ** format);
304 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset, 
305                                    int nbits, struct datatype * dt2);
306 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
307 extern enum debug_type DEBUG_GetType(struct datatype * dt);
308 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
309 extern int DEBUG_PrintTypeCast(struct datatype *);
310
311   /* debugger/source.c */
312 extern void DEBUG_ShowDir(void);
313 extern void DEBUG_AddPath(const char * path);
314 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,  
315                        int delta);
316 extern void DEBUG_NukePath(void);
317 extern void DEBUG_Disassemble( const DBG_ADDR *, const DBG_ADDR*, int offset );
318
319   /* debugger/dbg.y */
320 extern DWORD wine_debugger( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance );
321
322   /* Choose your allocator! */
323 #if 1
324 /* this one is libc's fast one */
325 #include "xmalloc.h"
326 #define DBG_alloc(x) xmalloc(x)
327 #define DBG_realloc(x,y) xrealloc(x,y)
328 #define DBG_free(x) free(x)
329 #define DBG_strdup(x) xstrdup(x)
330 #else
331 /* this one is slow (takes 5 minutes to load the debugger on my machine),
332    but is pretty crash-proof (can step through malloc() without problems,
333    malloc() arena (and other heaps) can be totally wasted and it'll still
334    work, etc... if someone could make optimized routines so it wouldn't
335    take so long to load, it could be made default) */
336 #include "heap.h"
337 #define DBG_alloc(x) HEAP_xalloc(dbg_heap,0,x)
338 #define DBG_realloc(x,y) HEAP_xrealloc(dbg_heap,0,x,y)
339 #define DBG_free(x) HeapFree(dbg_heap,0,x)
340 #define DBG_strdup(x) HEAP_strdupA(dbg_heap,0,x)
341 #define DBG_need_heap
342 #endif
343
344 #endif  /* __WINE_DEBUGGER_H */