FreeBSD kernel kern code
subr_kdb.c File Reference
#include <sys/cdefs.h>
#include "opt_kdb.h"
#include "opt_stack.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/cons.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/sbuf.h>
#include <sys/smp.h>
#include <sys/stack.h>
#include <sys/sysctl.h>
#include <machine/kdb.h>
#include <machine/pcb.h>
Include dependency graph for subr_kdb.c:

Go to the source code of this file.

Macros

#define KDB_BREAK_TO_DEBUGGER   0
 
#define KDB_ALT_BREAK_TO_DEBUGGER   0
 
#define KEY_CR   13 /* CR '\r' */
 
#define KEY_TILDE   126 /* ~ */
 
#define KEY_CRTLB   2 /* ^B */
 
#define KEY_CRTLP   16 /* ^P */
 
#define KEY_CRTLR   18 /* ^R */
 

Enumerations

enum  { KDB_ALT_BREAK_SEEN_NONE, KDB_ALT_BREAK_SEEN_CR, KDB_ALT_BREAK_SEEN_CR_TILDE }
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 KDB_BACKEND (null, NULL, NULL, NULL, NULL)
 
 SET_DECLARE (kdb_dbbe_set, struct kdb_dbbe)
 
static int kdb_sysctl_available (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_current (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_enter (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_panic (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_trap (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_trap_code (SYSCTL_HANDLER_ARGS)
 
static SYSCTL_NODE (_debug, OID_AUTO, kdb, CTLFLAG_RW, NULL,"KDB nodes")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, available, CTLTYPE_STRING|CTLFLAG_RD, NULL, 0, kdb_sysctl_available,"A","list of available KDB backends")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, current, CTLTYPE_STRING|CTLFLAG_RW, NULL, 0, kdb_sysctl_current,"A","currently selected KDB backend")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, enter, CTLTYPE_INT|CTLFLAG_RW, NULL, 0, kdb_sysctl_enter,"I","set to enter the debugger")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, panic, CTLTYPE_INT|CTLFLAG_RW, NULL, 0, kdb_sysctl_panic,"I","set to panic the kernel")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, trap, CTLTYPE_INT|CTLFLAG_RW, NULL, 0, kdb_sysctl_trap,"I","set to cause a page fault via data access")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, trap_code, CTLTYPE_INT|CTLFLAG_RW, NULL, 0, kdb_sysctl_trap_code,"I","set to cause a page fault via code access")
 
 SYSCTL_INT (_debug_kdb, OID_AUTO, break_to_debugger, CTLFLAG_RW|CTLFLAG_TUN,&kdb_break_to_debugger, 0,"Enable break to debugger")
 
 TUNABLE_INT ("debug.kdb.break_to_debugger",&kdb_break_to_debugger)
 
 SYSCTL_INT (_debug_kdb, OID_AUTO, alt_break_to_debugger, CTLFLAG_RW|CTLFLAG_TUN,&kdb_alt_break_to_debugger, 0,"Enable alternative break to debugger")
 
 TUNABLE_INT ("debug.kdb.alt_break_to_debugger",&kdb_alt_break_to_debugger)
 
void kdb_panic (const char *msg)
 
void kdb_reboot (void)
 
int kdb_break (void)
 
static int kdb_alt_break_state (int key, int *state)
 
static int kdb_alt_break_internal (int key, int *state, int force_gdb)
 
int kdb_alt_break (int key, int *state)
 
int kdb_alt_break_gdb (int key, int *state)
 
void kdb_backtrace (void)
 
void kdb_backtrace_thread (struct thread *td)
 
int kdb_dbbe_select (const char *name)
 
void kdb_enter (const char *why, const char *msg)
 
void kdb_init (void)
 
void * kdb_jmpbuf (jmp_buf new)
 
void kdb_reenter (void)
 
struct pcb * kdb_thr_ctx (struct thread *thr)
 
struct thread * kdb_thr_first (void)
 
struct thread * kdb_thr_from_pid (pid_t pid)
 
struct thread * kdb_thr_lookup (lwpid_t tid)
 
struct thread * kdb_thr_next (struct thread *thr)
 
int kdb_thr_select (struct thread *thr)
 
int kdb_trap (int type, int code, struct trapframe *tf)
 

Variables

int kdb_active = 0
 
static void * kdb_jmpbufp = NULL
 
struct kdb_dbbe * kdb_dbbe = NULL
 
static struct pcb kdb_pcb
 
struct pcb * kdb_thrctx = NULL
 
struct thread * kdb_thread = NULL
 
struct trapframe * kdb_frame = NULL
 
static int kdb_break_to_debugger = KDB_BREAK_TO_DEBUGGER
 
static int kdb_alt_break_to_debugger = KDB_ALT_BREAK_TO_DEBUGGER
 
const char *volatile kdb_why = KDB_WHY_UNSET
 

Macro Definition Documentation

#define KDB_ALT_BREAK_TO_DEBUGGER   0

Definition at line 70 of file subr_kdb.c.

#define KDB_BREAK_TO_DEBUGGER   0

Definition at line 64 of file subr_kdb.c.

#define KEY_CR   13 /* CR '\r' */

Definition at line 249 of file subr_kdb.c.

Referenced by kdb_alt_break_state().

#define KEY_CRTLB   2 /* ^B */

Definition at line 251 of file subr_kdb.c.

Referenced by kdb_alt_break_state().

#define KEY_CRTLP   16 /* ^P */

Definition at line 252 of file subr_kdb.c.

Referenced by kdb_alt_break_state().

#define KEY_CRTLR   18 /* ^R */

Definition at line 253 of file subr_kdb.c.

Referenced by kdb_alt_break_state().

#define KEY_TILDE   126 /* ~ */

Definition at line 250 of file subr_kdb.c.

Referenced by kdb_alt_break_state().

Enumeration Type Documentation

anonymous enum
Enumerator
KDB_ALT_BREAK_SEEN_NONE 
KDB_ALT_BREAK_SEEN_CR 
KDB_ALT_BREAK_SEEN_CR_TILDE 

Definition at line 256 of file subr_kdb.c.

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
int kdb_alt_break ( int  key,
int *  state 
)

Definition at line 336 of file subr_kdb.c.

References kdb_alt_break_internal().

Here is the call graph for this function:

int kdb_alt_break_gdb ( int  key,
int *  state 
)

Definition at line 348 of file subr_kdb.c.

References kdb_alt_break_internal().

Here is the call graph for this function:

static int kdb_alt_break_internal ( int  key,
int *  state,
int  force_gdb 
)
static

Definition at line 308 of file subr_kdb.c.

References kdb_alt_break_state(), kdb_alt_break_to_debugger, kdb_dbbe_select(), kdb_enter(), kdb_panic(), and kdb_reboot().

Referenced by kdb_alt_break(), and kdb_alt_break_gdb().

Here is the call graph for this function:

Here is the caller graph for this function:

static int kdb_alt_break_state ( int  key,
int *  state 
)
static

Definition at line 273 of file subr_kdb.c.

References KDB_ALT_BREAK_SEEN_CR, KDB_ALT_BREAK_SEEN_CR_TILDE, KDB_ALT_BREAK_SEEN_NONE, KEY_CR, KEY_CRTLB, KEY_CRTLP, KEY_CRTLR, and KEY_TILDE.

Referenced by kdb_alt_break_internal().

Here is the caller graph for this function:

KDB_BACKEND ( null  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)
void kdb_backtrace ( void  )

Definition at line 362 of file subr_kdb.c.

References kdb_dbbe, printf(), stack_print_ddb(), and stack_zero().

Referenced by _isitmyx(), adopt(), kdb_reenter(), kdb_switch(), malloc(), panic(), and sdt_probe_stub().

Here is the call graph for this function:

Here is the caller graph for this function:

void kdb_backtrace_thread ( struct thread *  td)

Definition at line 386 of file subr_kdb.c.

References kdb_dbbe, printf(), stack_print_ddb(), and stack_zero().

Referenced by propagate_priority().

Here is the call graph for this function:

Here is the caller graph for this function:

int kdb_break ( void  )

Definition at line 263 of file subr_kdb.c.

References kdb_break_to_debugger, and kdb_enter().

Here is the call graph for this function:

int kdb_dbbe_select ( const char *  name)

Definition at line 410 of file subr_kdb.c.

References kdb_dbbe.

Referenced by kdb_alt_break_internal(), and kdb_sysctl_current().

Here is the caller graph for this function:

void kdb_enter ( const char *  why,
const char *  msg 
)

Definition at line 433 of file subr_kdb.c.

References kdb_active, kdb_dbbe, kdb_why, and printf().

Referenced by kdb_alt_break_internal(), kdb_break(), kdb_sysctl_enter(), panic(), and vop_strategy_pre().

Here is the call graph for this function:

Here is the caller graph for this function:

void kdb_init ( void  )

Definition at line 450 of file subr_kdb.c.

References kdb_active, kdb_dbbe, and printf().

Here is the call graph for this function:

void* kdb_jmpbuf ( jmp_buf  new)

Definition at line 485 of file subr_kdb.c.

References kdb_jmpbufp.

void kdb_panic ( const char *  msg)

Definition at line 223 of file subr_kdb.c.

References panic(), and printf().

Referenced by kdb_alt_break_internal().

Here is the call graph for this function:

Here is the caller graph for this function:

void kdb_reboot ( void  )

Definition at line 231 of file subr_kdb.c.

References printf(), and shutdown_nice().

Referenced by kdb_alt_break_internal().

Here is the call graph for this function:

Here is the caller graph for this function:

void kdb_reenter ( void  )

Definition at line 495 of file subr_kdb.c.

References kdb_active, kdb_backtrace(), kdb_jmpbufp, and printf().

Referenced by kdb_switch().

Here is the call graph for this function:

Here is the caller graph for this function:

static int kdb_sysctl_available ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 121 of file subr_kdb.c.

References kdb_dbbe, sbuf_delete(), sbuf_finish(), sbuf_new_for_sysctl(), and sbuf_printf().

Here is the call graph for this function:

static int kdb_sysctl_current ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 138 of file subr_kdb.c.

References buf, kdb_active, kdb_dbbe, kdb_dbbe_select(), and sysctl_handle_string().

Here is the call graph for this function:

static int kdb_sysctl_enter ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 156 of file subr_kdb.c.

References kdb_active, kdb_enter(), sysctl_handle_int(), and sysctl_wire_old_buffer().

Here is the call graph for this function:

static int kdb_sysctl_panic ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 174 of file subr_kdb.c.

References panic(), sysctl_handle_int(), and sysctl_wire_old_buffer().

Here is the call graph for this function:

static int kdb_sysctl_trap ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 190 of file subr_kdb.c.

References sysctl_handle_int(), and sysctl_wire_old_buffer().

Here is the call graph for this function:

static int kdb_sysctl_trap_code ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 206 of file subr_kdb.c.

References sysctl_handle_int(), and sysctl_wire_old_buffer().

Here is the call graph for this function:

struct pcb* kdb_thr_ctx ( struct thread *  thr)

Definition at line 512 of file subr_kdb.c.

References kdb_pcb.

Referenced by kdb_thr_select().

Here is the caller graph for this function:

struct thread* kdb_thr_first ( void  )

Definition at line 532 of file subr_kdb.c.

References allproc.

Referenced by kdb_thr_lookup().

Here is the caller graph for this function:

struct thread* kdb_thr_from_pid ( pid_t  pid)

Definition at line 550 of file subr_kdb.c.

References allproc.

struct thread* kdb_thr_lookup ( lwpid_t  tid)

Definition at line 564 of file subr_kdb.c.

References kdb_thr_first(), and kdb_thr_next().

Here is the call graph for this function:

struct thread* kdb_thr_next ( struct thread *  thr)

Definition at line 575 of file subr_kdb.c.

Referenced by kdb_thr_lookup().

Here is the caller graph for this function:

int kdb_thr_select ( struct thread *  thr)

Definition at line 592 of file subr_kdb.c.

References kdb_thr_ctx(), kdb_thrctx, and kdb_thread.

Referenced by kdb_trap().

Here is the call graph for this function:

Here is the caller graph for this function:

int kdb_trap ( int  type,
int  code,
struct trapframe *  tf 
)

Definition at line 606 of file subr_kdb.c.

References all_cpus, cngrab(), cnungrab(), kdb_active, kdb_dbbe, kdb_frame, kdb_pcb, kdb_thr_select(), and printf().

Here is the call graph for this function:

SET_DECLARE ( kdb_dbbe_set  ,
struct kdb_dbbe   
)
SYSCTL_INT ( _debug_kdb  ,
OID_AUTO  ,
break_to_debugger  ,
CTLFLAG_RW|  CTLFLAG_TUN,
kdb_break_to_debugger,
,
"Enable break to debugger"   
)
SYSCTL_INT ( _debug_kdb  ,
OID_AUTO  ,
alt_break_to_debugger  ,
CTLFLAG_RW|  CTLFLAG_TUN,
kdb_alt_break_to_debugger,
,
"Enable alternative break to debugger"   
)
static SYSCTL_NODE ( _debug  ,
OID_AUTO  ,
kdb  ,
CTLFLAG_RW  ,
NULL  ,
"KDB nodes"   
)
static
SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
available  ,
CTLTYPE_STRING|  CTLFLAG_RD,
NULL  ,
,
kdb_sysctl_available  ,
"A"  ,
"list of available KDB backends"   
)
SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
current  ,
CTLTYPE_STRING|  CTLFLAG_RW,
NULL  ,
,
kdb_sysctl_current  ,
"A"  ,
"currently selected KDB backend"   
)
SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
enter  ,
CTLTYPE_INT|  CTLFLAG_RW,
NULL  ,
,
kdb_sysctl_enter  ,
"I"  ,
"set to enter the debugger"   
)
SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
panic  ,
CTLTYPE_INT|  CTLFLAG_RW,
NULL  ,
,
kdb_sysctl_panic  ,
"I"  ,
"set to panic the kernel"   
)
SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
trap  ,
CTLTYPE_INT|  CTLFLAG_RW,
NULL  ,
,
kdb_sysctl_trap  ,
"I"  ,
"set to cause a page fault via data access"   
)
SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
trap_code  ,
CTLTYPE_INT|  CTLFLAG_RW,
NULL  ,
,
kdb_sysctl_trap_code  ,
"I"  ,
"set to cause a page fault via code access"   
)
TUNABLE_INT ( "debug.kdb.break_to_debugger"  ,
kdb_break_to_debugger 
)
TUNABLE_INT ( "debug.kdb.alt_break_to_debugger"  ,
kdb_alt_break_to_debugger 
)

Variable Documentation

int kdb_alt_break_to_debugger = KDB_ALT_BREAK_TO_DEBUGGER
static

Definition at line 74 of file subr_kdb.c.

Referenced by kdb_alt_break_internal().

int kdb_break_to_debugger = KDB_BREAK_TO_DEBUGGER
static

Definition at line 73 of file subr_kdb.c.

Referenced by kdb_break().

struct kdb_dbbe* kdb_dbbe = NULL
struct trapframe* kdb_frame = NULL

Definition at line 59 of file subr_kdb.c.

Referenced by kdb_trap().

void* kdb_jmpbufp = NULL
static

Definition at line 54 of file subr_kdb.c.

Referenced by kdb_jmpbuf(), and kdb_reenter().

struct pcb kdb_pcb
static

Definition at line 56 of file subr_kdb.c.

Referenced by kdb_thr_ctx(), and kdb_trap().

struct pcb* kdb_thrctx = NULL

Definition at line 57 of file subr_kdb.c.

Referenced by kdb_thr_select().

struct thread* kdb_thread = NULL

Definition at line 58 of file subr_kdb.c.

Referenced by kdb_thr_select().

const char* volatile kdb_why = KDB_WHY_UNSET

Definition at line 118 of file subr_kdb.c.

Referenced by kdb_enter().