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/lock.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 ("$FreeBSD$")
 
 KDB_BACKEND (null, NULL, NULL, NULL, NULL)
 
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_panic_str (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_trap (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_trap_code (SYSCTL_HANDLER_ARGS)
 
static int kdb_sysctl_stack_overflow (SYSCTL_HANDLER_ARGS)
 
static SYSCTL_NODE (_debug, OID_AUTO, kdb, CTLFLAG_RW|CTLFLAG_MPSAFE, NULL, "KDB nodes")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, available, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, kdb_sysctl_available, "A", "list of available KDB backends")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, current, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_MPSAFE, NULL, 0, kdb_sysctl_current, "A", "currently selected KDB backend")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, enter, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|CTLFLAG_MPSAFE, NULL, 0, kdb_sysctl_enter, "I", "set to enter the debugger")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, panic, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|CTLFLAG_MPSAFE, NULL, 0, kdb_sysctl_panic, "I", "set to panic the kernel")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, panic_str, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_SECURE|CTLFLAG_MPSAFE, NULL, 0, kdb_sysctl_panic_str, "A", "trigger a kernel panic, using the provided string as the panic message")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, trap, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|CTLFLAG_MPSAFE, 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|CTLFLAG_SECURE|CTLFLAG_MPSAFE, NULL, 0, kdb_sysctl_trap_code, "I", "set to cause a page fault via code access")
 
 SYSCTL_PROC (_debug_kdb, OID_AUTO, stack_overflow, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|CTLFLAG_MPSAFE, NULL, 0, kdb_sysctl_stack_overflow, "I", "set to cause a stack overflow")
 
 SYSCTL_INT (_debug_kdb, OID_AUTO, break_to_debugger, CTLFLAG_RWTUN|CTLFLAG_SECURE, &kdb_break_to_debugger, 0, "Enable break to debugger")
 
 SYSCTL_INT (_debug_kdb, OID_AUTO, alt_break_to_debugger, CTLFLAG_RWTUN|CTLFLAG_SECURE, &kdb_alt_break_to_debugger, 0, "Enable alternative break to debugger")
 
static void kdb_stack_overflow (volatile int *x) __noinline
 
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)
 
void kdb_reenter_silent (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

u_char __read_frequently 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

◆ KDB_ALT_BREAK_TO_DEBUGGER

#define KDB_ALT_BREAK_TO_DEBUGGER   0

Definition at line 73 of file subr_kdb.c.

◆ KDB_BREAK_TO_DEBUGGER

#define KDB_BREAK_TO_DEBUGGER   0

Definition at line 67 of file subr_kdb.c.

◆ KEY_CR

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

Definition at line 317 of file subr_kdb.c.

◆ KEY_CRTLB

#define KEY_CRTLB   2 /* ^B */

Definition at line 319 of file subr_kdb.c.

◆ KEY_CRTLP

#define KEY_CRTLP   16 /* ^P */

Definition at line 320 of file subr_kdb.c.

◆ KEY_CRTLR

#define KEY_CRTLR   18 /* ^R */

Definition at line 321 of file subr_kdb.c.

◆ KEY_TILDE

#define KEY_TILDE   126 /* ~ */

Definition at line 318 of file subr_kdb.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
KDB_ALT_BREAK_SEEN_NONE 
KDB_ALT_BREAK_SEEN_CR 
KDB_ALT_BREAK_SEEN_CR_TILDE 

Definition at line 324 of file subr_kdb.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ kdb_alt_break()

int kdb_alt_break ( int  key,
int *  state 
)

Definition at line 404 of file subr_kdb.c.

References kdb_alt_break_internal().

Here is the call graph for this function:

◆ kdb_alt_break_gdb()

int kdb_alt_break_gdb ( int  key,
int *  state 
)

Definition at line 416 of file subr_kdb.c.

References kdb_alt_break_internal().

Here is the call graph for this function:

◆ kdb_alt_break_internal()

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

Definition at line 376 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:

◆ kdb_alt_break_state()

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

Definition at line 341 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()

KDB_BACKEND ( null  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)

◆ kdb_backtrace()

void kdb_backtrace ( void  )

Definition at line 429 of file subr_kdb.c.

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

Referenced by _isitmyx(), adopt(), kdb_reenter(), kdb_switch(), sdt_probe_stub(), vpanic(), and watchdog_fire().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kdb_backtrace_thread()

void kdb_backtrace_thread ( struct thread *  td)

Definition at line 453 of file subr_kdb.c.

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

Referenced by propagate_priority().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kdb_break()

int kdb_break ( void  )

Definition at line 331 of file subr_kdb.c.

References kdb_break_to_debugger, and kdb_enter().

Here is the call graph for this function:

◆ kdb_dbbe_select()

int kdb_dbbe_select ( const char *  name)

Definition at line 475 of file subr_kdb.c.

References kdb_dbbe, and name.

Referenced by kdb_alt_break_internal(), and kdb_sysctl_current().

Here is the caller graph for this function:

◆ kdb_enter()

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

Definition at line 498 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(), vpanic(), watchdog_fire(), and witness_enter_debugger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kdb_init()

void kdb_init ( void  )

Definition at line 514 of file subr_kdb.c.

References kdb_active, kdb_dbbe, and printf().

Here is the call graph for this function:

◆ kdb_jmpbuf()

void * kdb_jmpbuf ( jmp_buf  new)

Definition at line 548 of file subr_kdb.c.

References kdb_jmpbufp.

◆ kdb_panic()

void kdb_panic ( const char *  msg)

Definition at line 292 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:

◆ kdb_reboot()

void kdb_reboot ( void  )

Definition at line 300 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:

◆ kdb_reenter()

void kdb_reenter ( void  )

Definition at line 558 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:

◆ kdb_reenter_silent()

void kdb_reenter_silent ( void  )

Definition at line 571 of file subr_kdb.c.

References kdb_active, and kdb_jmpbufp.

◆ kdb_stack_overflow()

static void kdb_stack_overflow ( volatile int *  x)
static

Definition at line 264 of file subr_kdb.c.

References kdb_stack_overflow().

Referenced by kdb_stack_overflow(), and kdb_sysctl_stack_overflow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kdb_sysctl_available()

static int kdb_sysctl_available ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 147 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:

◆ kdb_sysctl_current()

static int kdb_sysctl_current ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 164 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:

◆ kdb_sysctl_enter()

static int kdb_sysctl_enter ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 182 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:

◆ kdb_sysctl_panic()

static int kdb_sysctl_panic ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 200 of file subr_kdb.c.

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

Here is the call graph for this function:

◆ kdb_sysctl_panic_str()

static int kdb_sysctl_panic_str ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 216 of file subr_kdb.c.

References buf, panic(), and sysctl_handle_string().

Here is the call graph for this function:

◆ kdb_sysctl_stack_overflow()

static int kdb_sysctl_stack_overflow ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 274 of file subr_kdb.c.

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

Here is the call graph for this function:

◆ kdb_sysctl_trap()

static int kdb_sysctl_trap ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 230 of file subr_kdb.c.

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

Here is the call graph for this function:

◆ kdb_sysctl_trap_code()

static int kdb_sysctl_trap_code ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 246 of file subr_kdb.c.

References sysctl_handle_int(), and sysctl_wire_old_buffer().

Here is the call graph for this function:

◆ kdb_thr_ctx()

struct pcb * kdb_thr_ctx ( struct thread *  thr)

Definition at line 585 of file subr_kdb.c.

References kdb_pcb.

Referenced by kdb_thr_select().

Here is the caller graph for this function:

◆ kdb_thr_first()

struct thread * kdb_thr_first ( void  )

Definition at line 605 of file subr_kdb.c.

References pidhash, and pidhashtbl.

Referenced by kdb_thr_lookup().

Here is the caller graph for this function:

◆ kdb_thr_from_pid()

struct thread * kdb_thr_from_pid ( pid_t  pid)

Definition at line 626 of file subr_kdb.c.

◆ kdb_thr_lookup()

struct thread * kdb_thr_lookup ( lwpid_t  tid)

Definition at line 638 of file subr_kdb.c.

References kdb_thr_first(), and kdb_thr_next().

Here is the call graph for this function:

◆ kdb_thr_next()

struct thread * kdb_thr_next ( struct thread *  thr)

Definition at line 649 of file subr_kdb.c.

References pidhash, and pidhashtbl.

Referenced by kdb_thr_lookup().

Here is the caller graph for this function:

◆ kdb_thr_select()

int kdb_thr_select ( struct thread *  thr)

Definition at line 675 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:

◆ kdb_trap()

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

Definition at line 688 of file subr_kdb.c.

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

Here is the call graph for this function:

◆ SYSCTL_INT() [1/2]

SYSCTL_INT ( _debug_kdb  ,
OID_AUTO  ,
alt_break_to_debugger  ,
CTLFLAG_RWTUN|  CTLFLAG_SECURE,
kdb_alt_break_to_debugger,
,
"Enable alternative break to debugger"   
)

◆ SYSCTL_INT() [2/2]

SYSCTL_INT ( _debug_kdb  ,
OID_AUTO  ,
break_to_debugger  ,
CTLFLAG_RWTUN|  CTLFLAG_SECURE,
kdb_break_to_debugger,
,
"Enable break to debugger"   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _debug  ,
OID_AUTO  ,
kdb  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
NULL  ,
"KDB nodes"   
)
static

◆ SYSCTL_PROC() [1/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
available  ,
CTLTYPE_STRING|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_available  ,
"A"  ,
"list of available KDB backends"   
)

◆ SYSCTL_PROC() [2/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
current  ,
CTLTYPE_STRING|CTLFLAG_RW|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_current  ,
"A"  ,
"currently selected KDB backend"   
)

◆ SYSCTL_PROC() [3/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
enter  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_enter  ,
"I"  ,
"set to enter the debugger"   
)

◆ SYSCTL_PROC() [4/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
panic  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_panic  ,
"I"  ,
"set to panic the kernel"   
)

◆ SYSCTL_PROC() [5/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
panic_str  ,
CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_SECURE|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_panic_str  ,
"A"  ,
"trigger a kernel  panic,
using the provided string as the panic message"   
)

◆ SYSCTL_PROC() [6/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
stack_overflow  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_stack_overflow  ,
"I"  ,
"set to cause a stack overflow"   
)

◆ SYSCTL_PROC() [7/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
trap  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_trap  ,
"I"  ,
"set to cause a page fault via data access"   
)

◆ SYSCTL_PROC() [8/8]

SYSCTL_PROC ( _debug_kdb  ,
OID_AUTO  ,
trap_code  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_SECURE|  CTLFLAG_MPSAFE,
NULL  ,
,
kdb_sysctl_trap_code  ,
"I"  ,
"set to cause a page fault via code access"   
)

Variable Documentation

◆ kdb_active

◆ kdb_alt_break_to_debugger

int kdb_alt_break_to_debugger = KDB_ALT_BREAK_TO_DEBUGGER
static

Definition at line 77 of file subr_kdb.c.

Referenced by kdb_alt_break_internal().

◆ kdb_break_to_debugger

int kdb_break_to_debugger = KDB_BREAK_TO_DEBUGGER
static

Definition at line 76 of file subr_kdb.c.

Referenced by kdb_break().

◆ kdb_dbbe

struct kdb_dbbe* kdb_dbbe = NULL

◆ kdb_frame

struct trapframe* kdb_frame = NULL

Definition at line 62 of file subr_kdb.c.

Referenced by kdb_trap().

◆ kdb_jmpbufp

void* kdb_jmpbufp = NULL
static

Definition at line 57 of file subr_kdb.c.

Referenced by kdb_jmpbuf(), kdb_reenter(), and kdb_reenter_silent().

◆ kdb_pcb

struct pcb kdb_pcb
static

Definition at line 59 of file subr_kdb.c.

Referenced by kdb_thr_ctx(), and kdb_trap().

◆ kdb_thrctx

struct pcb* kdb_thrctx = NULL

Definition at line 60 of file subr_kdb.c.

Referenced by kdb_thr_select().

◆ kdb_thread

struct thread* kdb_thread = NULL

Definition at line 61 of file subr_kdb.c.

Referenced by kdb_thr_select().

◆ kdb_why

const char* volatile kdb_why = KDB_WHY_UNSET

Definition at line 144 of file subr_kdb.c.

Referenced by kdb_enter().