kdb.h revision 145343
1139825Simp/*-
2131903Smarcel * Copyright (c) 2004 Marcel Moolenaar
3131903Smarcel * All rights reserved.
4131903Smarcel *
5131903Smarcel * Redistribution and use in source and binary forms, with or without
6131903Smarcel * modification, are permitted provided that the following conditions
7131903Smarcel * are met:
8131903Smarcel *
9131903Smarcel * 1. Redistributions of source code must retain the above copyright
10131903Smarcel *    notice, this list of conditions and the following disclaimer.
11131903Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12131903Smarcel *    notice, this list of conditions and the following disclaimer in the
13131903Smarcel *    documentation and/or other materials provided with the distribution.
14131903Smarcel *
15131903Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16131903Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17131903Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18131903Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19131903Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20131903Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21131903Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22131903Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23131903Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24131903Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25131903Smarcel *
26131903Smarcel * $FreeBSD: head/sys/sys/kdb.h 145343 2005-04-20 20:52:46Z ps $
27131903Smarcel */
28131903Smarcel
29131903Smarcel#ifndef _SYS_KDB_H_
30131903Smarcel#define	_SYS_KDB_H_
31131903Smarcel
32131903Smarcel#include <machine/setjmp.h>
33131903Smarcel
34131903Smarceltypedef int dbbe_init_f(void);
35131903Smarceltypedef void dbbe_trace_f(void);
36131903Smarceltypedef int dbbe_trap_f(int, int);
37131903Smarcel
38131903Smarcelstruct kdb_dbbe {
39131903Smarcel	const char	*dbbe_name;
40131903Smarcel	dbbe_init_f	*dbbe_init;
41131903Smarcel	dbbe_trace_f	*dbbe_trace;
42131903Smarcel	dbbe_trap_f	*dbbe_trap;
43131903Smarcel	int		dbbe_active;
44131903Smarcel};
45131903Smarcel
46131903Smarcel#define	KDB_BACKEND(name, init, trace, trap)		\
47131903Smarcel	static struct kdb_dbbe name##_dbbe = {		\
48131903Smarcel		.dbbe_name = #name,			\
49131903Smarcel		.dbbe_init = init,			\
50131903Smarcel		.dbbe_trace = trace,			\
51131903Smarcel		.dbbe_trap = trap			\
52131903Smarcel	};						\
53131903Smarcel	DATA_SET(kdb_dbbe_set, name##_dbbe)
54131903Smarcel
55131903Smarcelstruct pcb;
56131903Smarcelstruct thread;
57131903Smarcelstruct trapframe;
58131903Smarcel
59131903Smarcelextern int kdb_active;			/* Non-zero while in debugger. */
60145343Spsextern int debugger_on_panic;		/* enter the debugger on panic. */
61131903Smarcelextern struct kdb_dbbe *kdb_dbbe;	/* Default debugger backend or NULL. */
62131903Smarcelextern struct trapframe *kdb_frame;	/* Frame to kdb_trap(). */
63131903Smarcelextern struct pcb *kdb_thrctx;		/* Current context. */
64131903Smarcelextern struct thread *kdb_thread;	/* Current thread. */
65131903Smarcel
66131903Smarcelint	kdb_alt_break(int, int *);
67131903Smarcelvoid	kdb_backtrace(void);
68132001Smarcelint	kdb_dbbe_select(const char *);
69131903Smarcelvoid	kdb_enter(const char *);
70131903Smarcelvoid	kdb_init(void);
71131903Smarcelvoid *	kdb_jmpbuf(jmp_buf);
72131903Smarcelvoid	kdb_reenter(void);
73131903Smarcelstruct pcb *kdb_thr_ctx(struct thread *);
74131903Smarcelstruct thread *kdb_thr_first(void);
75132481Smarcelstruct thread *kdb_thr_from_pid(pid_t);
76132481Smarcelstruct thread *kdb_thr_lookup(lwpid_t);
77131903Smarcelstruct thread *kdb_thr_next(struct thread *);
78131903Smarcelint	kdb_thr_select(struct thread *);
79131903Smarcelint	kdb_trap(int, int, struct trapframe *);
80131903Smarcel
81131903Smarcel#endif /* !_SYS_KDB_H_ */
82