xref: /haiku/headers/os/kernel/debugger.h (revision 1f0635d2277dcd0818dc7f539c1cb1b296f6444b)
1 /*
2  * Copyright 2005-2016 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _DEBUGGER_H
6 #define _DEBUGGER_H
7 
8 
9 #include <signal.h>
10 
11 #include <image.h>
12 #include <OS.h>
13 
14 // include architecture specific definitions
15 #include <arch/x86/arch_debugger.h>
16 #include <arch/x86_64/arch_debugger.h>
17 #include <arch/ppc/arch_debugger.h>
18 #include <arch/m68k/arch_debugger.h>
19 #include <arch/mipsel/arch_debugger.h>
20 #include <arch/arm/arch_debugger.h>
21 #include <arch/riscv64/arch_debugger.h>
22 #include <arch/sparc/arch_debugger.h>
23 
24 
25 #if defined(__x86_64__)
26 	typedef struct x86_64_debug_cpu_state debug_cpu_state;
27 #elif defined(__INTEL__)
28 	typedef struct x86_debug_cpu_state debug_cpu_state;
29 #elif defined(__POWERPC__)
30 	typedef struct ppc_debug_cpu_state debug_cpu_state;
31 #elif defined(__M68K__)
32 	typedef struct m68k_debug_cpu_state debug_cpu_state;
33 #elif defined(__MIPSEL__)
34 	typedef struct mipsel_debug_cpu_state debug_cpu_state;
35 #elif defined(__arm__)
36 	typedef struct arm_debug_cpu_state debug_cpu_state;
37 #elif defined(__RISCV__) || defined(__riscv64__)
38 	typedef struct riscv64_debug_cpu_state debug_cpu_state;
39 #elif defined(__sparc64__)
40 	typedef struct sparc_debug_cpu_state debug_cpu_state;
41 #else
42 	#error unsupported architecture
43 #endif
44 
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 extern status_t	install_default_debugger(port_id debuggerPort);
51 extern port_id	install_team_debugger(team_id team, port_id debuggerPort);
52 extern status_t	remove_team_debugger(team_id team);
53 extern status_t	debug_thread(thread_id thread);
54 extern void		wait_for_debugger(void);
55 
56 // EXPERIMENTAL: Self-debugging functions. Will fail when a team debugger is
57 // installed. A breakpoint/watchpoint hit will cause the default debugger to
58 // be installed for the team.
59 extern status_t	set_debugger_breakpoint(void *address);
60 extern status_t	clear_debugger_breakpoint(void *address);
61 extern status_t	set_debugger_watchpoint(void *address, uint32 type,
62 					int32 length);
63 extern status_t	clear_debugger_watchpoint(void *address);
64 
65 
66 // team debugging flags
67 enum {
68 	// event mask: If a flag is set, any of the team's threads will stop when
69 	// the respective event occurs. None of the flags are enabled by default.
70 	// Always enabled are debugger() calls and hardware exceptions, as well as
71 	// the deletion of the debugged team.
72 	B_TEAM_DEBUG_SIGNALS						= 0x00010000,
73 	B_TEAM_DEBUG_PRE_SYSCALL					= 0x00020000,
74 	B_TEAM_DEBUG_POST_SYSCALL					= 0x00040000,
75 	B_TEAM_DEBUG_TEAM_CREATION					= 0x00080000,
76 	B_TEAM_DEBUG_THREADS						= 0x00100000,
77 	B_TEAM_DEBUG_IMAGES							= 0x00200000,
78 	B_TEAM_DEBUG_PREVENT_EXIT					= 0x00400000,
79 
80 	// new thread handling
81 	B_TEAM_DEBUG_STOP_NEW_THREADS				= 0x01000000,
82 
83 	B_TEAM_DEBUG_USER_FLAG_MASK					= 0xffff0000,
84 };
85 
86 // per-thread debugging flags
87 enum {
88 	// event mask: If a flag is set, the thread will stop when the respective
89 	// event occurs. If there is a corresponding team flag, it is sufficient,
90 	// if either is set. Per default none of the flags is set.
91 	B_THREAD_DEBUG_PRE_SYSCALL					= 0x00010000,
92 	B_THREAD_DEBUG_POST_SYSCALL					= 0x00020000,
93 
94 	// child thread handling
95 	B_THREAD_DEBUG_STOP_CHILD_THREADS			= 0x00100000,
96 	B_THREAD_DEBUG_SYSCALL_TRACE_CHILD_THREADS	= 0x00200000,
97 
98 	B_THREAD_DEBUG_USER_FLAG_MASK				= 0xffff0000,
99 };
100 
101 // in case of a B_EXCEPTION_OCCURRED event: the type of the exception
102 typedef enum {
103 	B_NON_MASKABLE_INTERRUPT	= 0,
104 	B_MACHINE_CHECK_EXCEPTION,
105 	B_SEGMENT_VIOLATION,
106 	B_ALIGNMENT_EXCEPTION,
107 	B_DIVIDE_ERROR,
108 	B_OVERFLOW_EXCEPTION,
109 	B_BOUNDS_CHECK_EXCEPTION,
110 	B_INVALID_OPCODE_EXCEPTION,
111 	B_SEGMENT_NOT_PRESENT,
112 	B_STACK_FAULT,
113 	B_GENERAL_PROTECTION_FAULT,
114 	B_FLOATING_POINT_EXCEPTION,
115 } debug_exception_type;
116 
117 // Value indicating how a stopped thread shall continue.
118 enum {
119 	B_THREAD_DEBUG_HANDLE_EVENT = 0,	// handle the event normally
120 										// (e.g. a signal is delivered, a
121 										// CPU fault kills the team,...)
122 	B_THREAD_DEBUG_IGNORE_EVENT,		// ignore the event and continue as if
123 										// it didn't occur (e.g. a signal or
124 										// a CPU fault will be ignored)
125 };
126 
127 // watchpoint types (ToDo: Check PPC support.)
128 enum {
129 	B_DATA_READ_WATCHPOINT = 0,			// !x86
130 	B_DATA_WRITE_WATCHPOINT,
131 	B_DATA_READ_WRITE_WATCHPOINT,
132 };
133 
134 // how to apply signal ignore masks
135 typedef enum {
136 	B_DEBUG_SIGNAL_MASK_AND	= 0,
137 	B_DEBUG_SIGNAL_MASK_OR,
138 	B_DEBUG_SIGNAL_MASK_SET,
139 } debug_signal_mask_op;
140 
141 #define B_DEBUG_SIGNAL_TO_MASK(signal) (1ULL << ((signal) - 1))
142 
143 // maximal number of bytes to read/write via B_DEBUG_MESSAGE_{READ,WRITE]_MEMORY
144 enum {
145 	B_MAX_READ_WRITE_MEMORY_SIZE	= 1024,
146 };
147 
148 // messages to the debug nub thread
149 typedef enum {
150 	B_DEBUG_MESSAGE_READ_MEMORY	= 0,	// read from the team's memory
151 	B_DEBUG_MESSAGE_WRITE_MEMORY,		// write to the team's memory
152 	B_DEBUG_MESSAGE_SET_TEAM_FLAGS,		// set the team's debugging flags
153 	B_DEBUG_MESSAGE_SET_THREAD_FLAGS,	// set a thread's debugging flags
154 	B_DEBUG_MESSAGE_CONTINUE_THREAD,	// continue a stopped thread
155 	B_DEBUG_MESSAGE_SET_CPU_STATE,		// change a stopped thread's CPU state
156 	B_DEBUG_MESSAGE_GET_CPU_STATE,		// get the thread's current CPU state
157 	B_DEBUG_MESSAGE_SET_BREAKPOINT,		// set a breakpoint
158 	B_DEBUG_MESSAGE_CLEAR_BREAKPOINT,	// clear a breakpoint
159 	B_DEBUG_MESSAGE_SET_WATCHPOINT,		// set a watchpoint
160 	B_DEBUG_MESSAGE_CLEAR_WATCHPOINT,	// clear a watchpoint
161 	B_DEBUG_MESSAGE_SET_SIGNAL_MASKS,	// set/get a thread's masks of signals
162 	B_DEBUG_MESSAGE_GET_SIGNAL_MASKS,	//  the debugger is interested in
163 	B_DEBUG_MESSAGE_SET_SIGNAL_HANDLER,	// set/get the team's signal handler for
164 	B_DEBUG_MESSAGE_GET_SIGNAL_HANDLER,	//  a signal
165 
166 	B_DEBUG_MESSAGE_PREPARE_HANDOVER,	// prepares the debugged team for being
167 										// handed over to another debugger;
168 										// the new debugger can just invoke
169 										// install_team_debugger()
170 
171 	B_DEBUG_START_PROFILER,				// start/stop sampling
172 	B_DEBUG_STOP_PROFILER,				//
173 
174 	B_DEBUG_WRITE_CORE_FILE				// write a core file
175 } debug_nub_message;
176 
177 // messages sent to the debugger
178 typedef enum {
179 	B_DEBUGGER_MESSAGE_THREAD_DEBUGGED = 0,	// debugger message in reaction to
180 											// an invocation of debug_thread()
181 	B_DEBUGGER_MESSAGE_DEBUGGER_CALL,		// thread called debugger()
182 	B_DEBUGGER_MESSAGE_BREAKPOINT_HIT,		// thread hit a breakpoint
183 	B_DEBUGGER_MESSAGE_WATCHPOINT_HIT,		// thread hit a watchpoint
184 	B_DEBUGGER_MESSAGE_SINGLE_STEP,			// thread was single-stepped
185 	B_DEBUGGER_MESSAGE_PRE_SYSCALL,			// begin of a syscall
186 	B_DEBUGGER_MESSAGE_POST_SYSCALL,		// end of a syscall
187 	B_DEBUGGER_MESSAGE_SIGNAL_RECEIVED,		// thread received a signal
188 	B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED,	// an exception occurred
189 	B_DEBUGGER_MESSAGE_TEAM_CREATED,		// the debugged team created a new
190 											// one
191 	B_DEBUGGER_MESSAGE_TEAM_DELETED,		// the debugged team is gone
192 	B_DEBUGGER_MESSAGE_TEAM_EXEC,			// the debugged team executes exec()
193 	B_DEBUGGER_MESSAGE_THREAD_CREATED,		// a thread has been created
194 	B_DEBUGGER_MESSAGE_THREAD_DELETED,		// a thread has been deleted
195 	B_DEBUGGER_MESSAGE_IMAGE_CREATED,		// an image has been created
196 	B_DEBUGGER_MESSAGE_IMAGE_DELETED,		// an image has been deleted
197 
198 	B_DEBUGGER_MESSAGE_PROFILER_UPDATE,		// flush the profiling buffer for a
199 											// thread
200 
201 	B_DEBUGGER_MESSAGE_HANDED_OVER,			// the debugged team has been
202 											// handed over to another debugger,
203 											// sent to both debuggers
204 } debug_debugger_message;
205 
206 
207 // profile events -- when the buffer is in variable stack depth format, a sample
208 // count entry >= B_DEBUG_PROFILE_EVENT_BASE indicates a profile event
209 enum {
210 	B_DEBUG_PROFILE_EVENT_BASE				= 0x80000000,
211 	B_DEBUG_PROFILE_EVENT_PARAMETER_MASK	= 0x0000ffff,
212 		// & with to get the event's parameter count
213 
214 	B_DEBUG_PROFILE_IMAGE_EVENT				= 0x80010001
215 		// single parameter: the respective image event counter
216 };
217 
218 
219 // #pragma mark -
220 // #pragma mark ----- messages to the debug nub thread -----
221 
222 // B_DEBUG_MESSAGE_READ_MEMORY
223 
224 typedef struct {
225 	port_id		reply_port;		// port to send the reply to
226 	void		*address;		// address from which to read
227 	int32		size;			// number of bytes to read
228 } debug_nub_read_memory;
229 
230 typedef struct {
231 	status_t	error;			// B_OK, if reading went fine
232 	int32		size;			// the number of bytes actually read
233 								// > 0, iff error == B_OK
234 	char		data[B_MAX_READ_WRITE_MEMORY_SIZE];
235 								// the read data
236 } debug_nub_read_memory_reply;
237 
238 // B_DEBUG_MESSAGE_WRITE_MEMORY
239 
240 typedef struct {
241 	port_id		reply_port;		// port to send the reply to
242 	void		*address;		// address to which to write
243 	int32		size;			// number of bytes to write
244 	char		data[B_MAX_READ_WRITE_MEMORY_SIZE];
245 								// data to write
246 } debug_nub_write_memory;
247 
248 typedef struct {
249 	status_t	error;			// B_OK, if writing went fine
250 	int32		size;			// the number of bytes actually written
251 } debug_nub_write_memory_reply;
252 
253 // B_DEBUG_MESSAGE_SET_TEAM_FLAGS
254 
255 typedef struct {
256 	int32		flags;			// the new team debugging flags
257 } debug_nub_set_team_flags;
258 
259 // B_DEBUG_MESSAGE_SET_THREAD_FLAGS
260 
261 typedef struct {
262 	thread_id	thread;			// the thread
263 	int32		flags;			// the new thread debugging flags
264 } debug_nub_set_thread_flags;
265 
266 // B_DEBUG_MESSAGE_CONTINUE_THREAD
267 
268 typedef struct {
269 	thread_id	thread;			// the thread
270 	uint32		handle_event;	// how to handle the occurred event
271 	bool		single_step;	// true == single step, false == run full speed
272 } debug_nub_continue_thread;
273 
274 // B_DEBUG_MESSAGE_SET_CPU_STATE
275 
276 typedef struct {
277 	thread_id			thread;				// the thread
278 	debug_cpu_state		cpu_state;			// the new CPU state
279 } debug_nub_set_cpu_state;
280 
281 // B_DEBUG_MESSAGE_GET_CPU_STATE
282 
283 typedef struct {
284 	port_id					reply_port;		// port to send the reply to
285 	thread_id				thread;			// the thread
286 } debug_nub_get_cpu_state;
287 
288 typedef struct {
289 	status_t				error;		// != B_OK, if something went wrong
290 										// (bad thread ID, thread not stopped)
291 	debug_debugger_message	message;	// the reason why the thread stopped
292 	debug_cpu_state			cpu_state;	// the thread's CPU state
293 } debug_nub_get_cpu_state_reply;
294 
295 // B_DEBUG_MESSAGE_SET_BREAKPOINT
296 
297 typedef struct {
298 	port_id		reply_port;		// port to send the reply to
299 	void		*address;		// breakpoint address
300 } debug_nub_set_breakpoint;
301 
302 typedef struct {
303 	status_t	error;			// B_OK, if the breakpoint has been set
304 								// successfully
305 } debug_nub_set_breakpoint_reply;
306 
307 // B_DEBUG_MESSAGE_CLEAR_BREAKPOINT
308 
309 typedef struct {
310 	void		*address;		// breakpoint address
311 } debug_nub_clear_breakpoint;
312 
313 // B_DEBUG_MESSAGE_SET_WATCHPOINT
314 
315 typedef struct {
316 	port_id		reply_port;		// port to send the reply to
317 	void		*address;		// watchpoint address
318 	uint32		type;			// watchpoint type (see type constants above)
319 	int32		length;			// number of bytes to watch (typically 1, 2,
320 								// 4); architecture specific alignment
321 								// restrictions apply.
322 } debug_nub_set_watchpoint;
323 
324 typedef struct {
325 	status_t	error;			// B_OK, if the watchpoint has been set
326 								// successfully
327 } debug_nub_set_watchpoint_reply;
328 
329 // B_DEBUG_MESSAGE_CLEAR_WATCHPOINT
330 
331 typedef struct {
332 	void		*address;		// watchpoint address
333 } debug_nub_clear_watchpoint;
334 
335 // B_DEBUG_MESSAGE_SET_SIGNAL_MASKS
336 
337 typedef struct {
338 	thread_id				thread;				// the thread
339 	uint64					ignore_mask;		// the mask for signals the
340 												// debugger wishes not to be
341 												// notified of
342 	uint64					ignore_once_mask;	// the mask for signals the
343 												// debugger wishes not to be
344 												// notified of when they next
345 												// occur
346 	debug_signal_mask_op	ignore_op;			// what to do with ignore_mask
347 	debug_signal_mask_op	ignore_once_op;		// what to do with
348 												// ignore_once_mask
349 } debug_nub_set_signal_masks;
350 
351 // B_DEBUG_MESSAGE_GET_SIGNAL_MASKS
352 
353 typedef struct {
354 	port_id		reply_port;			// port to send the reply to
355 	thread_id	thread;				// the thread
356 } debug_nub_get_signal_masks;
357 
358 typedef struct {
359 	status_t	error;				// B_OK, if the thread exists
360 	uint64		ignore_mask;		// the mask for signals the debugger wishes
361 									// not to be notified of
362 	uint64		ignore_once_mask;	// the mask for signals the debugger wishes
363 									// not to be notified of when they next
364 									// occur
365 } debug_nub_get_signal_masks_reply;
366 
367 // B_DEBUG_MESSAGE_SET_SIGNAL_HANDLER
368 
369 typedef struct {
370 	int					signal;		// the signal
371 	struct sigaction	handler;	// the new signal handler
372 } debug_nub_set_signal_handler;
373 
374 // B_DEBUG_MESSAGE_GET_SIGNAL_HANDLER
375 
376 typedef struct {
377 	port_id				reply_port;	// port to send the reply to
378 	int					signal;		// the signal
379 } debug_nub_get_signal_handler;
380 
381 typedef struct {
382 	status_t			error;		// B_OK, if the thread exists
383 	struct sigaction	handler;	// the signal handler
384 } debug_nub_get_signal_handler_reply;
385 
386 // B_DEBUG_MESSAGE_PREPARE_HANDOVER
387 
388 // no parameters, no reply
389 
390 // B_DEBUG_START_PROFILER
391 
392 struct debug_profile_function {
393 	addr_t			base;	// function base address
394 	size_t			size;	// function size
395 };
396 
397 typedef struct {
398 	port_id				reply_port;		// port to send the reply to
399 	thread_id			thread;			// thread to profile
400 	bigtime_t			interval;		// sample interval
401 	area_id				sample_area;	// area into which the sample will be
402 										// written
403 	int32				stack_depth;	// number of return address per hit
404 	bool				variable_stack_depth;
405 										// variable number of samples per hit;
406 										// cf. debug_profiler_update
407 } debug_nub_start_profiler;
408 
409 typedef struct {
410 	status_t			error;
411 	int32				image_event;	// number of the last image event
412 	bigtime_t			interval;		// actual sample interval (might
413 										// differ from the requested one)
414 } debug_nub_start_profiler_reply;
415 
416 // B_DEBUG_STOP_PROFILER
417 
418 typedef struct {
419 	port_id				reply_port;		// port to send the reply to
420 	thread_id			thread;			// thread to profile
421 } debug_nub_stop_profiler;
422 
423 // B_DEBUG_WRITE_CORE_FILE
424 
425 typedef struct {
426 	port_id				reply_port;		// port to send the reply to
427 	char				path[B_PATH_NAME_LENGTH];
428 										// path of the core file; must not exist
429 										// yet; must be absolute
430 } debug_nub_write_core_file;
431 
432 typedef struct {
433 	status_t	error;					// B_OK on success
434 } debug_nub_write_core_file_reply;
435 
436 
437 // reply is debug_profiler_update
438 
439 // union of all messages structures sent to the debug nub thread
440 typedef union {
441 	debug_nub_read_memory			read_memory;
442 	debug_nub_write_memory			write_memory;
443 	debug_nub_set_team_flags		set_team_flags;
444 	debug_nub_set_thread_flags		set_thread_flags;
445 	debug_nub_continue_thread		continue_thread;
446 	debug_nub_set_cpu_state			set_cpu_state;
447 	debug_nub_get_cpu_state			get_cpu_state;
448 	debug_nub_set_breakpoint		set_breakpoint;
449 	debug_nub_clear_breakpoint		clear_breakpoint;
450 	debug_nub_set_watchpoint		set_watchpoint;
451 	debug_nub_clear_watchpoint		clear_watchpoint;
452 	debug_nub_set_signal_masks		set_signal_masks;
453 	debug_nub_get_signal_masks		get_signal_masks;
454 	debug_nub_set_signal_handler	set_signal_handler;
455 	debug_nub_get_signal_handler	get_signal_handler;
456 	debug_nub_start_profiler		start_profiler;
457 	debug_nub_stop_profiler			stop_profiler;
458 	debug_nub_write_core_file		write_core_file;
459 } debug_nub_message_data;
460 
461 
462 // #pragma mark -
463 // #pragma mark ----- messages to the debugger -----
464 
465 // first member of all debugger messages -- not a message by itself
466 typedef struct {
467 	thread_id	thread;			// the thread being the event origin
468 	team_id		team;			// the thread's team
469 	port_id		nub_port;		// port to debug nub for this team (only set
470 								// for synchronous messages)
471 } debug_origin;
472 
473 // B_DEBUGGER_MESSAGE_THREAD_DEBUGGED
474 
475 typedef struct {
476 	debug_origin		origin;
477 } debug_thread_debugged;
478 
479 // B_DEBUGGER_MESSAGE_DEBUGGER_CALL
480 
481 typedef struct {
482 	debug_origin		origin;
483 	void				*message;	// address of the message passed to
484 									// debugger()
485 } debug_debugger_call;
486 
487 // B_DEBUGGER_MESSAGE_BREAKPOINT_HIT
488 
489 typedef struct {
490 	debug_origin		origin;
491 	debug_cpu_state		cpu_state;	// cpu state
492 } debug_breakpoint_hit;
493 
494 // B_DEBUGGER_MESSAGE_WATCHPOINT_HIT
495 
496 typedef struct {
497 	debug_origin		origin;
498 	debug_cpu_state		cpu_state;	// cpu state
499 } debug_watchpoint_hit;
500 
501 // B_DEBUGGER_MESSAGE_SINGLE_STEP
502 
503 typedef struct {
504 	debug_origin		origin;
505 	debug_cpu_state		cpu_state;	// cpu state
506 } debug_single_step;
507 
508 // B_DEBUGGER_MESSAGE_PRE_SYSCALL
509 
510 typedef struct {
511 	debug_origin	origin;
512 	uint32			syscall;		// the syscall number
513 	uint8			args[128];		// syscall arguments
514 } debug_pre_syscall;
515 
516 // B_DEBUGGER_MESSAGE_POST_SYSCALL
517 
518 typedef struct {
519 	debug_origin	origin;
520 	bigtime_t		start_time;		// time of syscall start
521 	bigtime_t		end_time;		// time of syscall completion
522 	uint64			return_value;	// the syscall's return value
523 	uint32			syscall;		// the syscall number
524 	uint8			args[128];		// syscall arguments
525 } debug_post_syscall;
526 
527 // B_DEBUGGER_MESSAGE_SIGNAL_RECEIVED
528 
529 typedef struct {
530 	debug_origin		origin;
531 	int					signal;		// the signal
532 	struct sigaction	handler;	// the signal handler
533 	bool				deadly;		// true, if handling the signal will kill
534 									// the team
535 } debug_signal_received;
536 
537 // B_DEBUGGER_MESSAGE_EXCEPTION_OCCURRED
538 
539 typedef struct {
540 	debug_origin			origin;
541 	debug_exception_type	exception;		// the exception
542 	int						signal;			// the signal that will be sent,
543 											// when the thread continues
544 											// normally
545 } debug_exception_occurred;
546 
547 // B_DEBUGGER_MESSAGE_TEAM_CREATED
548 
549 typedef struct {
550 	debug_origin	origin;
551 	team_id			new_team;		// the newly created team
552 } debug_team_created;
553 
554 // B_DEBUGGER_MESSAGE_TEAM_DELETED
555 
556 typedef struct {
557 	debug_origin	origin;			// thread is < 0, team is the deleted team
558 									// (asynchronous message)
559 } debug_team_deleted;
560 
561 // B_DEBUGGER_MESSAGE_TEAM_EXEC
562 
563 typedef struct {
564 	debug_origin	origin;
565 	int32			image_event;	// number of the image event
566 } debug_team_exec;
567 
568 // B_DEBUGGER_MESSAGE_THREAD_CREATED
569 
570 typedef struct {
571 	debug_origin	origin;			// the thread that created the new thread
572 	team_id			new_thread;		// the newly created thread
573 } debug_thread_created;
574 
575 // B_DEBUGGER_MESSAGE_THREAD_DELETED
576 
577 typedef struct {
578 	debug_origin	origin;			// the deleted thread (asynchronous message)
579 } debug_thread_deleted;
580 
581 // B_DEBUGGER_MESSAGE_IMAGE_CREATED
582 
583 typedef struct {
584 	debug_origin	origin;
585 	image_info		info;			// info for the image
586 	int32			image_event;	// number of the image event
587 } debug_image_created;
588 
589 // B_DEBUGGER_MESSAGE_IMAGE_DELETED
590 
591 typedef struct {
592 	debug_origin	origin;
593 	image_info		info;			// info for the image
594 	int32			image_event;	// number of the image event
595 } debug_image_deleted;
596 
597 // B_DEBUGGER_MESSAGE_PROFILER_UPDATE
598 
599 typedef struct {
600 	debug_origin		origin;
601 	int32				image_event;	// number of the last image event; all
602 										// samples were recorded after this
603 										// event and before the next one
604 	int32				stack_depth;	// number of return addresses per tick
605 	int32				sample_count;	// number of samples in the buffer
606 	int32				dropped_ticks;	// number of ticks that had been
607 										// dropped, since the buffer was full
608 	bool				variable_stack_depth;
609 										// the number of samples per hit is
610 										// variable, i.e. the format for the
611 										// samples of a hit in the buffer is
612 										//   <n> <sample 1> ... <sample n>
613 										// instead of
614 										//   <sample 1> ... <sample stack_depth>
615 	bool				stopped;		// if true, the thread is no longer
616 										// being profiled
617 } debug_profiler_update;
618 
619 // B_DEBUGGER_MESSAGE_HANDED_OVER
620 
621 typedef struct {
622 	debug_origin	origin;			// thread is < 0, team is the deleted team
623 									// (asynchronous message)
624 	team_id			debugger;		// the new debugger
625 	port_id			debugger_port;	// the port the new debugger uses
626 	thread_id		causing_thread;	// the thread that caused entering the
627 									// debugger in the first place, -1 if the
628 									// debugger wasn't attached automatically
629 } debug_handed_over;
630 
631 // union of all messages structures sent to the debugger
632 typedef union {
633 	debug_thread_debugged			thread_debugged;
634 	debug_debugger_call				debugger_call;
635 	debug_breakpoint_hit			breakpoint_hit;
636 	debug_watchpoint_hit			watchpoint_hit;
637 	debug_single_step				single_step;
638 	debug_pre_syscall				pre_syscall;
639 	debug_post_syscall				post_syscall;
640 	debug_signal_received			signal_received;
641 	debug_exception_occurred		exception_occurred;
642 	debug_team_created				team_created;
643 	debug_team_deleted				team_deleted;
644 	debug_team_exec					team_exec;
645 	debug_thread_created			thread_created;
646 	debug_thread_deleted			thread_deleted;
647 	debug_image_created				image_created;
648 	debug_image_deleted				image_deleted;
649 	debug_profiler_update			profiler_update;
650 	debug_handed_over				handed_over;
651 
652 	debug_origin					origin;	// for convenience (no real message)
653 } debug_debugger_message_data;
654 
655 
656 extern void get_debug_message_string(debug_debugger_message message,
657 		char *buffer, int32 bufferSize);
658 extern void get_debug_exception_string(debug_exception_type exception,
659 		char *buffer, int32 bufferSize);
660 
661 
662 #ifdef __cplusplus
663 }	// extern "C"
664 #endif
665 
666 #endif	// _DEBUGGER_H
667