Don't call a NE DLL's DllEntryPoint twice during one single
[wine/multimedia.git] / debugger / debugger.h
blob7bda3c5ccadfa76cfee40596431876baac6f388e
1 /*
2 * Debugger definitions
4 * Copyright 1995 Alexandre Julliard
5 */
7 #ifndef __WINE_DEBUGGER_H
8 #define __WINE_DEBUGGER_H
10 #include <sys/types.h> /* u_long ... */
11 #include <assert.h>
12 #include "windef.h"
13 #include "winbase.h"
14 #include "wine/exception.h"
16 #ifdef __i386__
17 #define STEP_FLAG 0x00000100 /* single step flag */
18 #define V86_FLAG 0x00020000
19 #endif
21 #define SYM_FUNC 0x0
22 #define SYM_DATA 0x1
23 #define SYM_WIN32 0x2
24 #define SYM_WINE 0x4
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;
51 typedef struct
53 DWORD seg; /* 0xffffffff means current default segment (cs or ds) */
54 DWORD off;
55 } DBG_ADDR;
57 typedef struct
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
68 DBG_ADDR addr;
69 } DBG_VALUE;
71 struct list_id
73 char * sourcefile;
74 int line;
77 struct wine_lines {
78 unsigned long line_number;
79 DBG_ADDR pc_offset;
82 struct symbol_info
84 struct name_hash * sym;
85 struct list_id list;
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
93 * function.
95 struct wine_locals {
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;
106 enum exec_mode
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.
122 #define DBG_BREAK 0
123 #define DBG_WATCH 1
125 typedef struct
127 DBG_ADDR addr;
128 WORD enabled : 1,
129 type : 1,
130 is32 : 1,
131 refcount : 13;
132 WORD skipcount;
133 union {
134 struct {
135 BYTE opcode;
136 BOOL (*func)(void);
137 } b;
138 struct {
139 BYTE rw : 1,
140 len : 2;
141 BYTE reg;
142 DWORD oldval;
143 } w;
144 } u;
145 struct expr * condition;
146 } DBG_BREAKPOINT;
148 enum dbg_mode
150 MODE_INVALID, MODE_16, MODE_32, MODE_VM86
153 typedef struct tagDBG_THREAD {
154 struct tagDBG_PROCESS* process;
155 HANDLE handle;
156 DWORD tid;
157 LPVOID start;
158 LPVOID teb;
159 int wait_for_first_exception;
160 enum dbg_mode dbg_mode;
161 enum exec_mode dbg_exec_mode;
162 int dbg_exec_count;
163 DBG_BREAKPOINT stepOverBP;
164 struct tagDBG_THREAD* next;
165 struct tagDBG_THREAD* prev;
166 } DBG_THREAD;
168 typedef struct tagDBG_PROCESS {
169 HANDLE handle;
170 DWORD pid;
171 DBG_THREAD* threads;
172 int num_threads;
173 unsigned continue_on_first_exception;
174 struct tagDBG_MODULE** modules;
175 int num_modules;
176 unsigned long dbg_hdr_addr;
178 * This is an index we use to keep track of the debug information
179 * when we have multiple sources. We use the same database to also
180 * allow us to do an 'info shared' type of deal, and we use the index
181 * to eliminate duplicates.
183 int next_index;
184 struct tagDBG_PROCESS* next;
185 struct tagDBG_PROCESS* prev;
186 } DBG_PROCESS;
188 extern DBG_PROCESS* DEBUG_CurrProcess;
189 extern DBG_THREAD* DEBUG_CurrThread;
190 extern DWORD DEBUG_CurrTid;
191 extern DWORD DEBUG_CurrPid;
192 extern CONTEXT DEBUG_context;
194 #define DEBUG_READ_MEM(addr, buf, len) \
195 (ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
197 #define DEBUG_WRITE_MEM(addr, buf, len) \
198 (WriteProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
200 #define DEBUG_READ_MEM_VERBOSE(addr, buf, len) \
201 (DEBUG_READ_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
203 #define DEBUG_WRITE_MEM_VERBOSE(addr, buf, len) \
204 (DEBUG_WRITE_MEM((addr), (buf), (len)) || (DEBUG_InvalLinAddr( addr ),0))
206 enum DbgInfoLoad {DIL_DEFERRED, DIL_LOADED, DIL_NOINFO, DIL_ERROR};
207 enum DbgModuleType {DMT_UNKNOWN, DMT_ELF, DMT_NE, DMT_PE};
209 typedef struct tagDBG_MODULE {
210 void* load_addr;
211 unsigned long size;
212 char* module_name;
213 enum DbgInfoLoad dil;
214 enum DbgModuleType type;
215 unsigned char main;
216 short int dbg_index;
217 HMODULE handle;
218 struct tagMSC_DBG_INFO* msc_info;
219 struct tagELF_DBG_INFO* elf_info;
220 } DBG_MODULE;
222 typedef struct {
223 DWORD val;
224 const char* name;
225 LPDWORD pval;
226 struct datatype* type;
227 } DBG_INTVAR;
229 #define OFFSET_OF(__c,__f) ((int)(((char*)&(((__c*)0)->__f))-((char*)0)))
231 /* from winelib.so */
232 extern void DEBUG_ExternalDebugger(void);
234 /* debugger/break.c */
235 extern void DEBUG_SetBreakpoints( BOOL set );
236 extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) );
237 extern void DEBUG_AddBreakpointFromId( const char *name, int lineno );
238 extern void DEBUG_AddBreakpointFromLineno( int lineno );
239 extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
240 extern void DEBUG_AddWatchpointFromId( const char *name, int lineno );
241 extern void DEBUG_DelBreakpoint( int num );
242 extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
243 extern void DEBUG_InfoBreakpoints(void);
244 extern BOOL DEBUG_HandleTrap(void);
245 extern BOOL DEBUG_ShouldContinue( DBG_ADDR *addr, DWORD code, enum exec_mode mode,
246 int * count );
247 extern void DEBUG_SuspendExecution( void );
248 extern enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count );
249 extern BOOL DEBUG_IsFctReturn(void);
250 extern int DEBUG_AddBPCondition(int bpnum, struct expr * exp);
252 /* debugger/db_disasm.c */
253 extern void DEBUG_Disasm( DBG_ADDR *addr, int display );
255 /* debugger/dbg.y */
256 extern BOOL DEBUG_Parser(void);
257 extern void DEBUG_Exit( DWORD );
259 /* debugger/debug.l */
260 extern void DEBUG_FlushSymbols(void);
262 /* debugger/display.c */
263 extern int DEBUG_DoDisplay(void);
264 extern int DEBUG_AddDisplay(struct expr * exp, int count, char format);
265 extern int DEBUG_DoDisplay(void);
266 extern int DEBUG_DelDisplay(int displaynum);
267 extern int DEBUG_InfoDisplay(void);
269 /* debugger/editline.c */
270 extern char * readline(const char *);
271 extern void add_history(char *);
273 /* debugger/expr.c */
274 extern void DEBUG_FreeExprMem(void);
275 struct expr * DEBUG_IntVarExpr(const char* name);
276 struct expr * DEBUG_SymbolExpr(const char * name);
277 struct expr * DEBUG_ConstExpr(int val);
278 struct expr * DEBUG_StringExpr(const char * str);
279 struct expr * DEBUG_SegAddr(struct expr *, struct expr *);
280 struct expr * DEBUG_USConstExpr(unsigned int val);
281 struct expr * DEBUG_BinopExpr(int oper, struct expr *, struct expr *);
282 struct expr * DEBUG_UnopExpr(int oper, struct expr *);
283 struct expr * DEBUG_StructPExpr(struct expr *, const char * element);
284 struct expr * DEBUG_StructExpr(struct expr *, const char * element);
285 struct expr * DEBUG_ArrayExpr(struct expr *, struct expr * index);
286 struct expr * DEBUG_CallExpr(const char *, int nargs, ...);
287 struct expr * DEBUG_TypeCastExpr(struct datatype *, struct expr *);
288 extern DBG_VALUE DEBUG_EvalExpr(struct expr *);
289 extern int DEBUG_DelDisplay(int displaynum);
290 extern struct expr * DEBUG_CloneExpr(const struct expr * exp);
291 extern int DEBUG_FreeExpr(struct expr * exp);
292 extern int DEBUG_DisplayExpr(const struct expr * exp);
294 /* debugger/hash.c */
295 extern struct name_hash * DEBUG_AddSymbol( const char *name,
296 const DBG_VALUE *addr,
297 const char *sourcefile,
298 int flags);
299 extern BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
300 DBG_VALUE *addr, int );
301 extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
302 extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
303 struct name_hash ** rtn,
304 unsigned int ebp,
305 struct list_id * source);
306 extern void DEBUG_ReadSymbolTable( const char * filename );
307 extern void DEBUG_AddLineNumber( struct name_hash * func, int line_num,
308 unsigned long offset );
309 extern struct wine_locals *
310 DEBUG_AddLocal( struct name_hash * func, int regno,
311 int offset,
312 int pc_start,
313 int pc_end,
314 char * name);
315 extern int DEBUG_CheckLinenoStatus(const DBG_ADDR *addr);
316 extern void DEBUG_GetFuncInfo(struct list_id * ret, const char * file,
317 const char * func);
318 extern int DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len);
319 extern int DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int len);
320 extern int DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr);
321 extern int DEBUG_cmp_sym(const void * p1, const void * p2);
322 extern BOOL DEBUG_GetLineNumberAddr( const struct name_hash *, const int lineno,
323 DBG_ADDR *addr, int bp_flag );
325 extern int DEBUG_SetLocalSymbolType(struct wine_locals * sym,
326 struct datatype * type);
327 extern BOOL DEBUG_Normalize(struct name_hash * nh );
329 /* debugger/info.c */
330 extern void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format );
331 extern struct symbol_info DEBUG_PrintAddress( const DBG_ADDR *addr,
332 enum dbg_mode mode, int flag );
333 extern void DEBUG_Help(void);
334 extern void DEBUG_HelpInfo(void);
335 extern struct symbol_info DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr,
336 enum dbg_mode mode,
337 unsigned int ebp,
338 int flag );
339 extern void DEBUG_InfoClass(const char* clsName);
340 extern void DEBUG_WalkClasses(void);
341 extern void DEBUG_WalkModref(DWORD p);
342 extern void DEBUG_DumpModule(DWORD mod);
343 extern void DEBUG_WalkModules(void);
344 extern void DEBUG_WalkProcess(void);
345 extern void DEBUG_WalkThreads(void);
346 extern void DEBUG_DumpQueue(DWORD q);
347 extern void DEBUG_WalkQueues(void);
348 extern void DEBUG_InfoSegments(DWORD s, int v);
349 extern void DEBUG_InfoVirtual(void);
350 extern void DEBUG_InfoWindow(HWND hWnd);
351 extern void DEBUG_WalkWindows(HWND hWnd, int indent);
353 /* debugger/memory.c */
354 extern int DEBUG_ReadMemory( const DBG_VALUE* value );
355 extern void DEBUG_WriteMemory( const DBG_VALUE* val, int value );
356 extern void DEBUG_ExamineMemory( const DBG_VALUE *addr, int count, char format);
357 extern void DEBUG_InvalAddr( const DBG_ADDR* addr );
358 extern void DEBUG_InvalLinAddr( void* addr );
359 extern DWORD DEBUG_ToLinear( const DBG_ADDR *address );
360 extern void DEBUG_GetCurrentAddress( DBG_ADDR * );
361 extern BOOL DEBUG_GrabAddress( DBG_VALUE* value, BOOL fromCode );
362 extern enum dbg_mode DEBUG_GetSelectorType( WORD sel );
363 #ifdef __i386__
364 extern void DEBUG_FixAddress( DBG_ADDR *address, DWORD def );
365 extern int DEBUG_IsSelectorSystem( WORD sel );
366 #endif
368 /* debugger/module.c */
369 extern int DEBUG_LoadEntryPoints( const char * prefix );
370 extern void DEBUG_LoadModule32( const char* name, HANDLE hFile, DWORD base );
371 extern DBG_MODULE* DEBUG_AddModule(const char* name, enum DbgModuleType type,
372 void* mod_addr, u_long size, HMODULE hmod);
373 extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, enum DbgModuleType type);
374 extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, enum DbgModuleType type);
375 extern DBG_MODULE* DEBUG_GetProcessMainModule(DBG_PROCESS* process);
376 extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, u_long size,
377 const char* name);
378 extern DBG_MODULE* DEBUG_RegisterELFModule(u_long load_addr, u_long size,
379 const char* name);
380 extern enum DbgInfoLoad DEBUG_RegisterPEDebugInfo(DBG_MODULE* wmod, HANDLE hFile,
381 void* _nth, unsigned long nth_ofs);
382 extern void DEBUG_ReportDIL(enum DbgInfoLoad dil, const char* pfx,
383 const char* filename, DWORD load_addr);
384 extern void DEBUG_InfoShare(void);
386 /* debugger/msc.c */
387 extern enum DbgInfoLoad DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile,
388 void* nth, unsigned long nth_ofs);
389 extern enum DbgInfoLoad DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module,
390 HANDLE hFile, void* nth,
391 unsigned long nth_ofs);
392 extern void DEBUG_InitCVDataTypes(void);
394 /* debugger/registers.c */
395 extern void DEBUG_InfoRegisters(void);
396 extern BOOL DEBUG_ValidateRegisters(void);
398 /* debugger/source.c */
399 extern void DEBUG_ShowDir(void);
400 extern void DEBUG_AddPath(const char * path);
401 extern void DEBUG_List(struct list_id * line1, struct list_id * line2,
402 int delta);
403 extern void DEBUG_NukePath(void);
404 extern void DEBUG_Disassemble(const DBG_VALUE *, const DBG_VALUE*, int offset);
405 extern BOOL DEBUG_DisassembleInstruction(DBG_ADDR *addr);
407 /* debugger/stack.c */
408 extern void DEBUG_InfoStack(void);
409 extern void DEBUG_BackTrace(BOOL noisy);
410 extern int DEBUG_InfoLocals(void);
411 extern int DEBUG_SetFrame(int newframe);
412 extern int DEBUG_GetCurrentFrame(struct name_hash ** name,
413 unsigned int * eip,
414 unsigned int * ebp);
416 /* debugger/stabs.c */
417 extern enum DbgInfoLoad DEBUG_ReadExecutableDbgInfo(const char* exe_name);
418 extern enum DbgInfoLoad DEBUG_ParseStabs(char * addr, unsigned int load_offset,
419 unsigned int staboff, int stablen,
420 unsigned int strtaboff, int strtablen);
422 /* debugger/types.c */
423 extern int DEBUG_nchar;
424 extern void DEBUG_InitTypes(void);
425 extern struct datatype * DEBUG_NewDataType(enum debug_type xtype,
426 const char * typename);
427 extern unsigned int DEBUG_TypeDerefPointer(const DBG_VALUE *value,
428 struct datatype ** newtype);
429 extern int DEBUG_AddStructElement(struct datatype * dt,
430 char * name, struct datatype * type,
431 int offset, int size);
432 extern int DEBUG_SetStructSize(struct datatype * dt, int size);
433 extern int DEBUG_SetPointerType(struct datatype * dt, struct datatype * dt2);
434 extern int DEBUG_SetArrayParams(struct datatype * dt, int min, int max,
435 struct datatype * dt2);
436 extern void DEBUG_Print( const DBG_VALUE *addr, int count, char format, int level );
437 extern unsigned int DEBUG_FindStructElement(DBG_VALUE * addr,
438 const char * ele_name, int * tmpbuf);
439 extern struct datatype * DEBUG_GetPointerType(struct datatype * dt);
440 extern int DEBUG_GetObjectSize(struct datatype * dt);
441 extern unsigned int DEBUG_ArrayIndex(const DBG_VALUE * addr, DBG_VALUE * result,
442 int index);
443 extern struct datatype * DEBUG_FindOrMakePointerType(struct datatype * reftype);
444 extern long long int DEBUG_GetExprValue(const DBG_VALUE * addr, char ** format);
445 extern int DEBUG_SetBitfieldParams(struct datatype * dt, int offset,
446 int nbits, struct datatype * dt2);
447 extern int DEBUG_CopyFieldlist(struct datatype * dt, struct datatype * dt2);
448 extern enum debug_type DEBUG_GetType(struct datatype * dt);
449 extern struct datatype * DEBUG_TypeCast(enum debug_type, const char *);
450 extern int DEBUG_PrintTypeCast(const struct datatype *);
451 extern int DEBUG_PrintType( const DBG_VALUE* addr );
453 /* debugger/winedbg.c */
454 #define DBG_CHN_MESG 1
455 #define DBG_CHN_ERR 2
456 #define DBG_CHN_WARN 4
457 #define DBG_CHN_FIXME 8
458 #define DBG_CHN_TRACE 16
459 extern void DEBUG_Output(int chn, const char* buffer, int len);
460 #ifdef __GNUC__
461 extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__((format (printf,2,3)));
462 #else
463 extern int DEBUG_Printf(int chn, const char* format, ...);
464 #endif
465 extern DBG_INTVAR* DEBUG_GetIntVar(const char*);
466 extern BOOL DEBUG_Attach(DWORD pid, BOOL cofe);
467 extern void DEBUG_Run(const char* args);
468 extern int curr_frame;
470 /* Choose your allocator! */
471 #if 1
472 /* this one is libc's fast one */
473 extern void* DEBUG_XMalloc(size_t size);
474 extern void* DEBUG_XReAlloc(void *ptr, size_t size);
475 extern char* DEBUG_XStrDup(const char *str);
477 #define DBG_alloc(x) DEBUG_XMalloc(x)
478 #define DBG_realloc(x,y) DEBUG_XReAlloc(x,y)
479 #define DBG_free(x) free(x)
480 #define DBG_strdup(x) DEBUG_XStrDup(x)
481 #else
482 /* this one is slow (takes 5 minutes to load the debugger on my machine),
483 but is pretty crash-proof (can step through malloc() without problems,
484 malloc() arena (and other heaps) can be totally wasted and it'll still
485 work, etc... if someone could make optimized routines so it wouldn't
486 take so long to load, it could be made default) */
487 #include "heap.h"
488 #define DBG_alloc(x) HeapAlloc(dbg_heap,0,x)
489 #define DBG_realloc(x,y) HeapRealloc(dbg_heap,0,x,y)
490 #define DBG_free(x) HeapFree(dbg_heap,0,x)
491 #define DBG_strdup(x) HEAP_strdupA(dbg_heap,0,x)
492 #define DBG_need_heap
493 extern HANDLE dbg_heap;
494 #endif
496 #define DEBUG_STATUS_OFFSET 0x80003000
497 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0)
498 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1)
499 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
500 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3)
502 extern DBG_INTVAR DEBUG_IntVars[];
504 #define DBG_IVARNAME(_var) DEBUG_IV_##_var
505 #define DBG_IVARSTRUCT(_var) DEBUG_IntVars[DBG_IVARNAME(_var)]
506 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
507 #define INTERNAL_VAR(_var,_val,_ref,_typ) DBG_IVARNAME(_var),
508 enum debug_int_var {
509 #include "intvar.h"
510 DBG_IV_LAST
512 #undef INTERNAL_VAR
514 #endif /* __WINE_DEBUGGER_H */