29 #include <sys/cdefs.h>
32 #include <sys/param.h>
33 #include <sys/kernel.h>
37 #include <sys/linker.h>
38 #include <sys/malloc.h>
40 #include <sys/stack.h>
41 #include <sys/systm.h>
42 #include <sys/sysctl.h>
44 FEATURE(stack,
"Support for capturing kernel stack");
48 static int stack_symbol(vm_offset_t pc,
char *namebuf, u_int buflen,
57 st =
malloc(
sizeof *st, M_STACK, M_WAITOK | M_ZERO);
72 if (st->depth < STACK_MAX) {
73 st->pcs[st->depth++] = pc;
90 bzero(st,
sizeof *st);
100 KASSERT(st->depth <= STACK_MAX, (
"bogus stack"));
101 for (i = 0; i < st->depth; i++) {
102 (void)
stack_symbol(st->pcs[i], namebuf,
sizeof(namebuf),
104 printf(
"#%d %p at %s+%#lx\n", i, (
void *)st->pcs[i],
116 KASSERT(st->depth <= STACK_MAX, (
"bogus stack"));
117 for (i = 0; i < st->depth; i++) {
122 printf(
"%s+%#lx", namebuf, offset);
124 printf(
"%p", (
void *)st->pcs[i]);
136 KASSERT(st->depth <= STACK_MAX, (
"bogus stack"));
137 for (i = 0; i < st->depth; i++) {
139 printf(
"#%d %p at %s+%#lx\n", i, (
void *)st->pcs[i],
146 stack_print_short_ddb(
struct stack *st)
152 KASSERT(st->depth <= STACK_MAX, (
"bogus stack"));
153 for (i = 0; i < st->depth; i++) {
157 printf(
"%s+%#lx", name, offset);
159 printf(
"%p", (
void *)st->pcs[i]);
176 KASSERT(st->depth <= STACK_MAX, (
"bogus stack"));
177 for (i = 0; i < st->depth; i++) {
178 (void)
stack_symbol(st->pcs[i], namebuf,
sizeof(namebuf),
180 sbuf_printf(sb,
"#%d %p at %s+%#lx\n", i, (
void *)st->pcs[i],
187 stack_sbuf_print_ddb(
struct sbuf *sb,
struct stack *st)
193 KASSERT(st->depth <= STACK_MAX, (
"bogus stack"));
194 for (i = 0; i < st->depth; i++) {
196 sbuf_printf(sb,
"#%d %p at %s+%#lx\n", i, (
void *)st->pcs[i],
204 stack_ktr(u_int
mask,
const char *file,
int line,
struct stack *st, u_int depth,
213 KASSERT(st->depth <= STACK_MAX, (
"bogus stack"));
216 st->pcs[0], st->pcs[1], st->pcs[2], st->pcs[3],
217 st->pcs[4], st->pcs[5]);
221 st->pcs[6], st->pcs[7], st->pcs[8], st->pcs[9],
222 st->pcs[10], st->pcs[11]);
226 st->pcs[12], st->pcs[13], st->pcs[14], st->pcs[15],
227 st->pcs[16], st->pcs[17]);
230 if (depth == 0 || st->depth < depth)
232 for (i = 0; i < depth; i++) {
235 i, st->pcs[i], (u_long)name, offset, 0, 0);
247 stack_symbol(vm_offset_t pc,
char *namebuf, u_int buflen,
long *offset)
253 strlcpy(namebuf,
"??", buflen);
262 linker_symval_t symval;
269 if (symval.name != NULL) {
static int stack_symbol(vm_offset_t pc, char *namebuf, u_int buflen, long *offset)
FEATURE(stack,"Support for capturing kernel stack")
void stack_print(struct stack *st)
void stack_sbuf_print(struct sbuf *sb, struct stack *st)
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
static MALLOC_DEFINE(M_STACK,"stack","Stack Traces")
void stack_destroy(struct stack *st)
int linker_ddb_search_symbol(caddr_t value, c_linker_sym_t *sym, long *diffp)
void stack_zero(struct stack *st)
int sbuf_printf(struct sbuf *s, const char *fmt,...)
int stack_put(struct stack *st, vm_offset_t pc)
void stack_copy(struct stack *src, struct stack *dst)
void free(void *addr, struct malloc_type *mtp)
int printf(const char *fmt,...)
int linker_ddb_symbol_values(c_linker_sym_t sym, linker_symval_t *symval)
void stack_print_ddb(struct stack *st)
struct stack * stack_create(void)
int linker_search_symbol_name(caddr_t value, char *buf, u_int buflen, long *offset)
static int stack_symbol_ddb(vm_offset_t pc, const char **name, long *offset)
void stack_print_short(struct stack *st)
void ktr_tracepoint(u_int mask, const char *file, int line, const char *format, u_long arg1, u_long arg2, u_long arg3, u_long arg4, u_long arg5, u_long arg6)