ntdll: Translate signal to trap when trap code is 0 on ARM.
[wine.git] / programs / winedbg / debugger.h
blob490bd06a0cf5af249a92b1a713a488d4dd572f74
1 /*
2 * Debugger definitions
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_DEBUGGER_H
22 #define __WINE_DEBUGGER_H
24 #include <assert.h>
25 #include <stdarg.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "ntstatus.h"
30 #define WIN32_NO_STATUS
31 #define WIN32_LEAN_AND_MEAN
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winver.h"
35 #include "winternl.h"
36 #include "dbghelp.h"
37 #include "cvconst.h"
38 #include "objbase.h"
39 #include "oaidl.h"
40 #include <wine/list.h>
42 #define ADDRSIZE (dbg_curr_process->be_cpu->pointer_size)
43 #define ADDRWIDTH (ADDRSIZE * 2)
45 /* the debugger uses these exceptions for its internal use */
46 #define DEBUG_STATUS_OFFSET 0x80003000
47 #define DEBUG_STATUS_INTERNAL_ERROR (DEBUG_STATUS_OFFSET+0) /* something went wrong */
48 #define DEBUG_STATUS_NO_SYMBOL (DEBUG_STATUS_OFFSET+1) /* no symbol found in lookup */
49 #define DEBUG_STATUS_DIV_BY_ZERO (DEBUG_STATUS_OFFSET+2)
50 #define DEBUG_STATUS_BAD_TYPE (DEBUG_STATUS_OFFSET+3) /* no type found, when type was expected */
51 #define DEBUG_STATUS_NO_FIELD (DEBUG_STATUS_OFFSET+4) /* when dereferencing a struct, the field was not found */
52 #define DEBUG_STATUS_ABORT (DEBUG_STATUS_OFFSET+5) /* user aborted on going action */
53 #define DEBUG_STATUS_CANT_DEREF (DEBUG_STATUS_OFFSET+6) /* either not deref:able, or index out of bounds */
54 #define DEBUG_STATUS_NOT_AN_INTEGER (DEBUG_STATUS_OFFSET+7) /* requiring an integral value */
57 * Return values for symbol_get_function_line_status. Used to determine
58 * what to do when the 'step' command is given.
60 enum dbg_line_status
62 dbg_no_line_info,
63 dbg_not_on_a_line_number,
64 dbg_on_a_line_number,
65 dbg_in_a_thunk,
68 enum dbg_internal_types
70 dbg_itype_first = 0xffffff00,
71 dbg_itype_unsigned_int,
72 dbg_itype_signed_int,
73 dbg_itype_signed_char_int,
74 dbg_itype_unsigned_char_int,
75 dbg_itype_unsigned_short_int,
76 dbg_itype_signed_short_int,
77 dbg_itype_unsigned_long_int,
78 dbg_itype_signed_long_int,
79 dbg_itype_unsigned_longlong_int,
80 dbg_itype_signed_longlong_int,
81 dbg_itype_char,
82 dbg_itype_wchar,
83 dbg_itype_short_real, /* aka float */
84 dbg_itype_real, /* aka double */
85 dbg_itype_long_real, /* aka long double */
86 dbg_itype_astring,
87 dbg_itype_ustring,
88 dbg_itype_segptr, /* hack for segmented pointers */
89 dbg_itype_m128a, /* 128-bit (XMM) registers */
90 dbg_itype_none = 0xffffffff
93 /* type description (in the following order):
94 * - if 'id' is dbg_itype_none (whatever 'module' value), the type isn't known
95 * - if 'module' is 0, it's an internal type (id is one of dbg_itype...)
96 * - if 'module' is non 0, then 'id' is a type ID referring to module (loaded in
97 * dbghelp) which (linear) contains address 'module'.
99 struct dbg_type
101 unsigned long id;
102 DWORD_PTR module;
105 struct dbg_lvalue /* structure to hold left-values... */
107 int cookie; /* DLV_??? */
108 /* DLV_TARGET references an address in debuggee's address space, whereas DLV_HOST
109 * references the winedbg's address space
111 # define DLV_TARGET 0xF00D
112 # define DLV_HOST 0x50DA
113 ADDRESS64 addr;
114 struct dbg_type type;
117 enum dbg_exec_mode
119 dbg_exec_cont, /* Continue execution */
120 dbg_exec_step_over_line, /* Stepping over a call to next source line */
121 dbg_exec_step_into_line, /* Step to next source line, stepping in if needed */
122 dbg_exec_step_over_insn, /* Stepping over a call */
123 dbg_exec_step_into_insn, /* Single-stepping an instruction */
124 dbg_exec_finish, /* Single-step until we exit current frame */
125 #if 0
126 EXEC_STEP_OVER_TRAMPOLINE, /* Step over trampoline. Requires that we dig the real
127 * return value off the stack and set breakpoint there -
128 * not at the instr just after the call.
130 #endif
133 struct dbg_breakpoint
135 ADDRESS64 addr;
136 unsigned long enabled : 1,
137 xpoint_type : 2,
138 refcount : 13,
139 skipcount : 16;
140 unsigned long info;
141 struct /* only used for watchpoints */
143 BYTE len : 2;
144 DWORD64 oldval;
145 } w;
146 struct expr* condition;
149 /* used for C++ exceptions in msvcrt
150 * parameters:
151 * [0] CXX_FRAME_MAGIC
152 * [1] pointer to exception object
153 * [2] pointer to type
155 #define CXX_EXCEPTION 0xe06d7363
156 #define CXX_FRAME_MAGIC 0x19930520
158 /* Wine extension; Windows doesn't have a name for this code. This is an
159 undocumented exception understood by MS VC debugger, allowing the program
160 to name a particular thread. Search google.com or deja.com for "0x406d1388"
161 for more info. */
162 #define EXCEPTION_NAME_THREAD 0x406D1388
164 /* Helper structure */
165 typedef struct tagTHREADNAME_INFO
167 DWORD dwType; /* Must be 0x1000 */
168 LPCSTR szName; /* Pointer to name - limited to 9 bytes (8 characters + terminator) */
169 DWORD dwThreadID; /* Thread ID (-1 = caller thread) */
170 DWORD dwFlags; /* Reserved for future use. Must be zero. */
171 } THREADNAME_INFO;
173 typedef union dbg_ctx
175 CONTEXT ctx;
176 WOW64_CONTEXT x86;
177 } dbg_ctx_t;
179 struct dbg_thread
181 struct list entry;
182 struct dbg_process* process;
183 HANDLE handle;
184 DWORD tid;
185 void* teb;
186 enum dbg_exec_mode exec_mode; /* mode the thread is run (step/run...) */
187 int exec_count; /* count of mode operations */
188 ADDRESS_MODE addr_mode; /* mode */
189 int stopped_xpoint; /* xpoint on which the thread has stopped (-1 if none) */
190 struct dbg_breakpoint step_over_bp;
191 char name[9];
192 BOOL in_exception; /* TRUE if thread stopped with an exception */
193 BOOL first_chance; /* TRUE if thread stopped with a first chance exception
194 * - only valid when in_exception is TRUE
196 EXCEPTION_RECORD excpt_record; /* only valid when in_exception is TRUE */
197 struct
199 ADDRESS64 addr_pc;
200 ADDRESS64 addr_frame;
201 ADDRESS64 addr_stack;
202 DWORD_PTR linear_pc;
203 DWORD_PTR linear_frame;
204 DWORD_PTR linear_stack;
205 dbg_ctx_t context; /* context we got out of stackwalk for this frame */
206 BOOL is_ctx_valid; /* is the context above valid */
207 }* frames;
208 int num_frames;
209 int curr_frame;
212 struct dbg_delayed_bp
214 BOOL is_symbol;
215 BOOL software_bp;
216 union
218 struct
220 int lineno;
221 char* name;
222 } symbol;
223 ADDRESS64 addr;
224 } u;
227 #define MAX_BREAKPOINTS 100
228 struct dbg_process
230 struct list entry;
231 HANDLE handle;
232 DWORD pid;
233 const struct be_process_io* process_io;
234 void* pio_data;
235 const WCHAR* imageName;
236 struct list threads;
237 struct backend_cpu* be_cpu;
238 BOOL continue_on_first_exception : 1,
239 active_debuggee : 1;
240 struct dbg_breakpoint bp[MAX_BREAKPOINTS];
241 unsigned next_bp;
242 struct dbg_delayed_bp* delayed_bp;
243 int num_delayed_bp;
244 struct open_file_list* source_ofiles;
245 char* search_path;
246 char source_current_file[MAX_PATH];
247 int source_start_line;
248 int source_end_line;
251 /* describes the way the debugger interacts with a given process */
252 struct be_process_io
254 BOOL (*close_process)(struct dbg_process*, BOOL);
255 BOOL (*read)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
256 BOOL (*write)(HANDLE, void*, const void*, SIZE_T, SIZE_T*);
257 BOOL (*get_selector)(HANDLE, DWORD, LDT_ENTRY*);
260 extern struct dbg_process* dbg_curr_process;
261 extern DWORD_PTR dbg_curr_pid;
262 extern struct dbg_thread* dbg_curr_thread;
263 extern DWORD_PTR dbg_curr_tid;
264 extern dbg_ctx_t dbg_context;
265 extern BOOL dbg_interactiveP;
266 extern HANDLE dbg_houtput;
268 struct dbg_internal_var
270 DWORD_PTR val;
271 const char* name;
272 DWORD_PTR *pval;
273 unsigned long typeid; /* always internal type */
276 enum sym_get_lval {sglv_found, sglv_unknown, sglv_aborted};
278 enum type_expr_e
280 type_expr_type_id,
281 type_expr_udt_class,
282 type_expr_udt_struct,
283 type_expr_udt_union,
284 type_expr_enumeration
287 struct type_expr_t
289 enum type_expr_e type;
290 unsigned deref_count;
291 union
293 struct dbg_type type;
294 const char* name;
295 } u;
298 enum dbg_start {start_ok, start_error_parse, start_error_init};
300 /* break.c */
301 extern void break_set_xpoints(BOOL set);
302 extern BOOL break_add_break(const ADDRESS64* addr, BOOL verbose, BOOL swbp);
303 extern BOOL break_add_break_from_lvalue(const struct dbg_lvalue* value, BOOL swbp);
304 extern void break_add_break_from_id(const char* name, int lineno, BOOL swbp);
305 extern void break_add_break_from_lineno(const char *filename, int lineno, BOOL swbp);
306 extern void break_add_watch_from_lvalue(const struct dbg_lvalue* lvalue, BOOL is_write);
307 extern void break_add_watch_from_id(const char* name, BOOL is_write);
308 extern void break_check_delayed_bp(void);
309 extern void break_delete_xpoint(int num);
310 extern void break_delete_xpoints_from_module(DWORD64 base);
311 extern void break_enable_xpoint(int num, BOOL enable);
312 extern void break_info(void);
313 extern void break_adjust_pc(ADDRESS64* addr, DWORD code, BOOL first_chance, BOOL* is_break);
314 extern BOOL break_should_continue(ADDRESS64* addr, DWORD code);
315 extern void break_suspend_execution(void);
316 extern void break_restart_execution(int count);
317 extern int break_add_condition(int bpnum, struct expr* exp);
319 /* crashdlg.c */
320 extern int display_crash_dialog(void);
321 extern HANDLE display_crash_details(HANDLE event);
322 extern int msgbox_res_id(HWND hwnd, UINT textId, UINT captionId, UINT uType);
324 /* dbg.y */
325 extern void parser_handle(HANDLE);
326 extern int input_read_line(const char* pfx, char* buffer, int size);
327 extern int input_fetch_entire_line(const char* pfx, char** line);
328 extern HANDLE parser_generate_command_file(const char*, ...);
330 /* debug.l */
331 extern void lexeme_flush(void);
332 extern char* lexeme_alloc_size(int);
334 /* display.c */
335 extern BOOL display_print(void);
336 extern BOOL display_add(struct expr* exp, int count, char format);
337 extern BOOL display_delete(int displaynum);
338 extern BOOL display_info(void);
339 extern BOOL display_enable(int displaynum, int enable);
341 /* expr.c */
342 extern void expr_free_all(void);
343 extern struct expr* expr_alloc_internal_var(const char* name);
344 extern struct expr* expr_alloc_symbol(const char* name);
345 extern struct expr* expr_alloc_sconstant(long int val);
346 extern struct expr* expr_alloc_uconstant(long unsigned val);
347 extern struct expr* expr_alloc_string(const char* str);
348 extern struct expr* expr_alloc_binary_op(int oper, struct expr*, struct expr*);
349 extern struct expr* expr_alloc_unary_op(int oper, struct expr*);
350 extern struct expr* expr_alloc_pstruct(struct expr*, const char* element);
351 extern struct expr* expr_alloc_struct(struct expr*, const char* element);
352 extern struct expr* expr_alloc_func_call(const char*, int nargs, ...);
353 extern struct expr* expr_alloc_typecast(struct type_expr_t*, struct expr*);
354 extern struct dbg_lvalue expr_eval(struct expr*);
355 extern struct expr* expr_clone(const struct expr* exp, BOOL *local_binding);
356 extern BOOL expr_free(struct expr* exp);
357 extern BOOL expr_print(const struct expr* exp);
359 /* info.c */
360 extern void print_help(void);
361 extern void info_help(void);
362 extern void info_win32_module(DWORD64 mod);
363 extern void info_win32_class(HWND hWnd, const char* clsName);
364 extern void info_win32_window(HWND hWnd, BOOL detailed);
365 extern void info_win32_processes(void);
366 extern void info_win32_threads(void);
367 extern void info_win32_frame_exceptions(DWORD tid);
368 extern void info_win32_virtual(DWORD pid);
369 extern void info_win32_segments(DWORD start, int length);
370 extern void info_win32_exception(void);
371 extern void info_wine_dbg_channel(BOOL add, const char* chnl, const char* name);
373 /* memory.c */
374 extern BOOL memory_read_value(const struct dbg_lvalue* lvalue, DWORD size, void* result);
375 extern BOOL memory_write_value(const struct dbg_lvalue* val, DWORD size, void* value);
376 extern void memory_examine(const struct dbg_lvalue *lvalue, int count, char format);
377 extern void* memory_to_linear_addr(const ADDRESS64* address);
378 extern BOOL memory_get_current_pc(ADDRESS64* address);
379 extern BOOL memory_get_current_stack(ADDRESS64* address);
380 extern BOOL memory_get_string(struct dbg_process* pcs, void* addr, BOOL in_debuggee, BOOL unicode, char* buffer, int size);
381 extern BOOL memory_get_string_indirect(struct dbg_process* pcs, void* addr, BOOL unicode, WCHAR* buffer, int size);
382 extern BOOL memory_get_register(DWORD regno, DWORD_PTR** value, char* buffer, int len);
383 extern void memory_disassemble(const struct dbg_lvalue*, const struct dbg_lvalue*, int instruction_count);
384 extern BOOL memory_disasm_one_insn(ADDRESS64* addr);
385 #define MAX_OFFSET_TO_STR_LEN 19
386 extern char* memory_offset_to_string(char *str, DWORD64 offset, unsigned mode);
387 extern void print_bare_address(const ADDRESS64* addr);
388 extern void print_address(const ADDRESS64* addr, BOOLEAN with_line);
389 extern void print_basic(const struct dbg_lvalue* value, char format);
391 /* source.c */
392 extern void source_list(IMAGEHLP_LINE64* src1, IMAGEHLP_LINE64* src2, int delta);
393 extern void source_list_from_addr(const ADDRESS64* addr, int nlines);
394 extern void source_show_path(void);
395 extern void source_add_path(const char* path);
396 extern void source_nuke_path(struct dbg_process* p);
397 extern void source_free_files(struct dbg_process* p);
399 /* stack.c */
400 extern void stack_info(int len);
401 extern void stack_backtrace(DWORD threadID);
402 extern BOOL stack_set_frame(int newframe);
403 extern BOOL stack_get_current_frame(IMAGEHLP_STACK_FRAME* ihsf);
404 extern BOOL stack_get_register_frame(const struct dbg_internal_var* div, DWORD_PTR** pval);
405 extern unsigned stack_fetch_frames(const dbg_ctx_t *ctx);
406 extern BOOL stack_get_current_symbol(SYMBOL_INFO* sym);
408 /* symbol.c */
409 extern enum sym_get_lval symbol_get_lvalue(const char* name, const int lineno, struct dbg_lvalue* addr, BOOL bp_disp);
410 extern void symbol_read_symtable(const char* filename, unsigned long offset);
411 extern enum dbg_line_status symbol_get_function_line_status(const ADDRESS64* addr);
412 extern BOOL symbol_get_line(const char* filename, const char* func, IMAGEHLP_LINE64* ret);
413 extern void symbol_info(const char* str);
414 extern void symbol_print_local(const SYMBOL_INFO* sym, DWORD_PTR base, BOOL detailed);
415 extern BOOL symbol_info_locals(void);
416 extern BOOL symbol_is_local(const char* name);
417 struct sgv_data;
418 typedef enum sym_get_lval (*symbol_picker_t)(const char* name, const struct sgv_data* sgv,
419 struct dbg_lvalue* rtn);
420 extern symbol_picker_t symbol_current_picker;
421 extern enum sym_get_lval symbol_picker_interactive(const char* name, const struct sgv_data* sgv,
422 struct dbg_lvalue* rtn);
423 extern enum sym_get_lval symbol_picker_scoped(const char* name, const struct sgv_data* sgv,
424 struct dbg_lvalue* rtn);
426 /* tgt_active.c */
427 extern void dbg_run_debuggee(const char* args);
428 extern void dbg_wait_next_exception(DWORD cont, int count, int mode);
429 extern enum dbg_start dbg_active_attach(int argc, char* argv[]);
430 extern enum dbg_start dbg_active_launch(int argc, char* argv[]);
431 extern enum dbg_start dbg_active_auto(int argc, char* argv[]);
432 extern enum dbg_start dbg_active_minidump(int argc, char* argv[]);
433 extern void dbg_active_wait_for_first_exception(void);
434 extern BOOL dbg_attach_debuggee(DWORD pid, BOOL cofe);
436 /* tgt_minidump.c */
437 extern void minidump_write(const char*, const EXCEPTION_RECORD*);
438 extern enum dbg_start minidump_reload(int argc, char* argv[]);
440 /* tgt_module.c */
441 extern enum dbg_start tgt_module_load(const char* name, BOOL keep);
443 /* types.c */
444 extern void print_value(const struct dbg_lvalue* addr, char format, int level);
445 extern BOOL types_print_type(const struct dbg_type*, BOOL details);
446 extern BOOL print_types(void);
447 extern long int types_extract_as_integer(const struct dbg_lvalue*);
448 extern LONGLONG types_extract_as_longlong(const struct dbg_lvalue*, unsigned* psize, BOOL *pissigned);
449 extern void types_extract_as_address(const struct dbg_lvalue*, ADDRESS64*);
450 extern BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lvalue_from);
451 extern BOOL types_udt_find_element(struct dbg_lvalue* value, const char* name, long int* tmpbuf);
452 extern BOOL types_array_index(const struct dbg_lvalue* value, int index, struct dbg_lvalue* result);
453 extern BOOL types_get_info(const struct dbg_type*, IMAGEHLP_SYMBOL_TYPE_INFO, void*);
454 extern BOOL types_get_real_type(struct dbg_type* type, DWORD* tag);
455 extern struct dbg_type types_find_pointer(const struct dbg_type* type);
456 extern struct dbg_type types_find_type(unsigned long linear, const char* name, enum SymTagEnum tag);
458 /* winedbg.c */
459 extern void dbg_outputW(const WCHAR* buffer, int len);
460 extern const char* dbg_W2A(const WCHAR* buffer, unsigned len);
461 #ifdef __GNUC__
462 extern int dbg_printf(const char* format, ...) __attribute__((format (printf,1,2)));
463 #else
464 extern int dbg_printf(const char* format, ...);
465 #endif
466 extern const struct dbg_internal_var* dbg_get_internal_var(const char*);
467 extern BOOL dbg_interrupt_debuggee(void);
468 extern unsigned dbg_num_processes(void);
469 extern struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid, HANDLE h);
470 extern void dbg_set_process_name(struct dbg_process* p, const WCHAR* name);
471 extern struct dbg_process* dbg_get_process(DWORD pid);
472 extern struct dbg_process* dbg_get_process_h(HANDLE handle);
473 extern void dbg_del_process(struct dbg_process* p);
474 struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid, HANDLE h, void* teb);
475 extern struct dbg_thread* dbg_get_thread(struct dbg_process* p, DWORD tid);
476 extern void dbg_del_thread(struct dbg_thread* t);
477 extern BOOL dbg_init(HANDLE hProc, const WCHAR* in, BOOL invade);
478 extern BOOL dbg_load_module(HANDLE hProc, HANDLE hFile, const WCHAR* name, DWORD_PTR base, DWORD size);
479 extern BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE64* imh_mod);
480 extern void dbg_set_option(const char*, const char*);
481 extern void dbg_start_interactive(HANDLE hFile);
482 extern void dbg_init_console(void);
484 /* gdbproxy.c */
485 extern int gdb_main(int argc, char* argv[]);
487 static inline BOOL dbg_read_memory(const void* addr, void* buffer, size_t len)
489 SIZE_T rlen;
490 return dbg_curr_process->process_io->read(dbg_curr_process->handle, addr, buffer, len, &rlen) && len == rlen;
493 static inline BOOL dbg_write_memory(void* addr, const void* buffer, size_t len)
495 SIZE_T wlen;
496 return dbg_curr_process->process_io->write(dbg_curr_process->handle, addr, buffer, len, &wlen) && len == wlen;
499 static inline void* dbg_heap_realloc(void* buffer, size_t size)
501 return (buffer) ? HeapReAlloc(GetProcessHeap(), 0, buffer, size) :
502 HeapAlloc(GetProcessHeap(), 0, size);
505 extern struct dbg_internal_var dbg_internal_vars[];
507 #define DBG_IVARNAME(_var) dbg_internal_var_##_var
508 #define DBG_IVARSTRUCT(_var) dbg_internal_vars[DBG_IVARNAME(_var)]
509 #define DBG_IVAR(_var) (*(DBG_IVARSTRUCT(_var).pval))
510 #define INTERNAL_VAR(_var,_val,_ref,itype) DBG_IVARNAME(_var),
511 enum debug_int_var
513 #include "intvar.h"
514 DBG_IV_LAST
516 #undef INTERNAL_VAR
518 /* include CPU dependent bits */
519 #include "be_cpu.h"
521 #endif /* __WINE_DEBUGGER_H */