Refactor the special symbol handling out of db_trace.c into

db_interface.c, and abstract it away from having to read kernel
symbols directly.
This commit is contained in:
thorpej 2023-11-21 19:59:07 +00:00
parent f5ae7971ac
commit 8a3d61b79c
3 changed files with 110 additions and 78 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_interface.c,v 1.37 2022/10/26 23:38:05 riastradh Exp $ */
/* $NetBSD: db_interface.c,v 1.38 2023/11/21 19:59:07 thorpej Exp $ */
/*
* Mach Operating System
@ -47,12 +47,14 @@
* NASA Ames Research Center
*/
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
#endif
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.37 2022/10/26 23:38:05 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.38 2023/11/21 19:59:07 thorpej Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@ -566,3 +568,72 @@ db_branch_taken(int ins, db_addr_t pc, db_regs_t *regs)
return (newpc);
}
/*
* Alpha special symbol handling.
*/
db_alpha_nlist db_alpha_nl[] = {
DB_ALPHA_SYM(SYM_XentArith, XentArith),
DB_ALPHA_SYM(SYM_XentIF, XentIF),
DB_ALPHA_SYM(SYM_XentInt, XentInt),
DB_ALPHA_SYM(SYM_XentMM, XentMM),
DB_ALPHA_SYM(SYM_XentSys, XentSys),
DB_ALPHA_SYM(SYM_XentUna, XentUna),
DB_ALPHA_SYM(SYM_XentRestart, XentRestart),
DB_ALPHA_SYM(SYM_exception_return, exception_return),
DB_ALPHA_SYM(SYM_alpha_kthread_backstop, alpha_kthread_backstop),
DB_ALPHA_SYM_EOL
};
static int
db_alpha_nlist_lookup(db_addr_t addr)
{
int i;
for (i = 0; i < SYM___eol; i++) {
if (db_alpha_nl[i].n_value == addr) {
return i;
}
}
return -1;
}
bool
db_alpha_sym_is_trap(db_addr_t addr)
{
int i = db_alpha_nlist_lookup(addr);
return i >= SYM_XentArith && i <= SYM_exception_return;
}
bool
db_alpha_sym_is_backstop(db_addr_t addr)
{
return db_alpha_nlist_lookup(addr) == SYM_alpha_kthread_backstop;
}
bool
db_alpha_sym_is_syscall(db_addr_t addr)
{
return db_alpha_nlist_lookup(addr) == SYM_XentSys;
}
const char *
db_alpha_trapsym_description(db_addr_t addr)
{
static const char * const trap_descriptions[] = {
[SYM_XentArith] = "arithmetic trap",
[SYM_XentIF] = "instruction fault",
[SYM_XentInt] = "interrupt",
[SYM_XentMM] = "memory management fault",
[SYM_XentSys] = "syscall",
[SYM_XentUna] = "unaligned access fault",
[SYM_XentRestart] = "console restart",
[SYM_exception_return] = "(exception return)",
};
int i = db_alpha_nlist_lookup(addr);
if (i >= SYM_XentArith && i <= SYM_exception_return) {
return trap_descriptions[i];
}
return "??? trap ???";
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_trace.c,v 1.34 2023/11/21 18:57:29 thorpej Exp $ */
/* $NetBSD: db_trace.c,v 1.35 2023/11/21 19:59:07 thorpej Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.34 2023/11/21 18:57:29 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.35 2023/11/21 19:59:07 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -61,39 +61,6 @@ struct prologue_info {
int pi_frame_size; /* frame size */
};
/*
* We use several symbols to take special action:
*
* Trap vectors, which use a different (fixed-size) stack frame:
*
* XentArith
* XentIF
* XentInt
* XentMM
* XentSys
* XentUna
*/
static struct special_symbol {
vaddr_t ss_val;
const char *ss_note;
} special_symbols[] = {
{ (vaddr_t)&XentArith, "arithmetic trap" },
{ (vaddr_t)&XentIF, "instruction fault" },
{ (vaddr_t)&XentInt, "interrupt" },
{ (vaddr_t)&XentMM, "memory management fault" },
{ (vaddr_t)&XentSys, "syscall" },
{ (vaddr_t)&XentUna, "unaligned access fault" },
{ (vaddr_t)&XentRestart, "console restart" },
/*
* We'll not know what trap we took, but we'll find the
* trap frame, at least...
*/
{ (vaddr_t)&exception_return, "(exception return)" },
{ 0 }
};
/*
* Decode the function prologue for the function we're in, and note
* which registers are stored where, and how large the stack frame is.
@ -165,38 +132,11 @@ do { \
}
}
static bool
db_alpha_sym_is_trapsymbol(vaddr_t v)
static void
decode_syscall(int number, struct proc *p, void (*pr)(const char *, ...))
{
int i;
for (i = 0; special_symbols[i].ss_val != 0; ++i)
if (v == special_symbols[i].ss_val)
return true;
return false;
}
static bool
db_alpha_sym_is_backstop(vaddr_t v)
{
return v == (vaddr_t)&alpha_kthread_backstop;
}
static const char *
db_alpha_trap_description(vaddr_t v)
{
int i;
for (i = 0; special_symbols[i].ss_val != 0; ++i)
if (v == special_symbols[i].ss_val)
return special_symbols[i].ss_note;
return "(? trap ?)";
}
static bool
db_alpha_trap_is_syscall(vaddr_t v)
{
return v == (vaddr_t)&XentSys;
(*pr)(" (%d)", number);
}
static unsigned long
@ -209,13 +149,6 @@ db_alpha_tf_reg(struct trapframe *tf, unsigned int regno)
return reg;
}
static void
decode_syscall(int number, struct proc *p, void (*pr)(const char *, ...))
{
(*pr)(" (%d)", number);
}
void
db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
const char *modif, void (*pr)(const char *, ...))
@ -352,13 +285,13 @@ db_stack_trace_print_ra(db_expr_t ra, bool have_ra,
* If we are in a trap vector, frame points to a
* trapframe.
*/
if (db_alpha_sym_is_trapsymbol(symval)) {
if (db_alpha_sym_is_trap(symval)) {
tf = (struct trapframe *)frame;
(*pr)("--- %s", db_alpha_trap_description(symval));
(*pr)("--- %s", db_alpha_trapsym_description(symval));
tfps = db_alpha_tf_reg(tf, FRAME_PS);
if (db_alpha_trap_is_syscall(symval)) {
if (db_alpha_sym_is_syscall(symval)) {
decode_syscall(db_alpha_tf_reg(tf, FRAME_V0),
p, pr);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_machdep.h,v 1.20 2023/11/21 14:35:01 riastradh Exp $ */
/* $NetBSD: db_machdep.h,v 1.21 2023/11/21 19:59:07 thorpej Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
@ -183,6 +183,34 @@ typedef long kgdb_reg_t;
/* Too much? Must be large enough for register transfer. */
#define KGDB_BUFLEN 1024
/*
* Private alpha ddb internals.
*/
#define SYM_XentArith 0
#define SYM_XentIF 1
#define SYM_XentInt 2
#define SYM_XentMM 3
#define SYM_XentSys 4
#define SYM_XentUna 5
#define SYM_XentRestart 6
#define SYM_exception_return 7
#define SYM_alpha_kthread_backstop 8
#define SYM___eol (SYM_alpha_kthread_backstop + 1)
struct db_alpha_nlist {
vaddr_t n_value;
};
typedef struct db_alpha_nlist db_alpha_nlist;
#define DB_ALPHA_SYM(i, x) [(i)] = { .n_value = (vaddr_t)&(x) }
#define DB_ALPHA_SYM_EOL [SYM___eol] = { .n_value = 0 }
bool db_alpha_sym_is_trap(db_addr_t);
bool db_alpha_sym_is_backstop(db_addr_t);
bool db_alpha_sym_is_syscall(db_addr_t);
const char * db_alpha_trapsym_description(db_addr_t);
/*
* Extra ddb options.
*/