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