ddb: de-duplicate decode_syscall()

Only i386 and amd64 print the decoded syscall name in the backtrace.
This de-duplication facilitates further changes and adoption by other
platforms.

Reviewed by:	jrtc27, markj, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36565
This commit is contained in:
Mitchell Horne 2022-10-02 19:46:00 -03:00
parent e571b0f8f8
commit 754cb545b6
4 changed files with 27 additions and 50 deletions

View file

@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
#include <sys/reg.h>
#include <sys/smp.h>
#include <sys/stack.h>
#include <sys/sysent.h>
#include <machine/cpu.h>
#include <machine/md_var.h>
@ -139,28 +138,6 @@ db_print_stack_entry(const char *name, db_addr_t callpc, void *frame)
db_printf("\n");
}
static void
decode_syscall(int number, struct thread *td)
{
struct proc *p;
c_db_sym_t sym;
db_expr_t diff;
sy_call_t *f;
const char *symname;
db_printf(" (%d", number);
p = (td != NULL) ? td->td_proc : NULL;
if (p != NULL && 0 <= number && number < p->p_sysent->sv_size) {
f = p->p_sysent->sv_table[number].sy_call;
sym = db_search_symbol((db_addr_t)f, DB_STGY_ANY, &diff);
if (sym != DB_SYM_NULL && diff == 0) {
db_symbol_values(sym, &symname, NULL);
db_printf(", %s, %s", p->p_sysent->sv_name, symname);
}
}
db_printf(")");
}
/*
* Figure out the next frame up in the call stack.
*/
@ -242,7 +219,7 @@ db_nextframe(struct amd64_frame **fp, db_addr_t *ip, struct thread *td)
break;
case SYSCALL:
db_printf("--- syscall");
decode_syscall(tf->tf_rax, td);
db_decode_syscall(tf->tf_rax, td);
break;
case INTERRUPT:
db_printf("--- interrupt");

View file

@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/pcpu.h>
#include <sys/smp.h>
#include <sys/systm.h>
#include <sys/sysent.h>
#include <net/vnet.h>
@ -481,3 +481,25 @@ db_sym_numargs(c_db_sym_t sym, int *nargp, char **argnames)
{
return (X_db_sym_numargs(db_last_symtab, sym, nargp, argnames));
}
void
db_decode_syscall(int number, struct thread *td)
{
struct proc *p;
c_db_sym_t sym;
db_expr_t diff;
sy_call_t *f;
const char *symname;
db_printf(" (%d", number);
p = (td != NULL) ? td->td_proc : NULL;
if (p != NULL && 0 <= number && number < p->p_sysent->sv_size) {
f = p->p_sysent->sv_table[number].sy_call;
sym = db_search_symbol((db_addr_t)f, DB_STGY_ANY, &diff);
if (sym != DB_SYM_NULL && diff == 0) {
db_symbol_values(sym, &symname, NULL);
db_printf(", %s, %s", p->p_sysent->sv_name, symname);
}
}
db_printf(")");
}

View file

@ -105,4 +105,6 @@ bool X_db_sym_numargs(db_symtab_t *, c_db_sym_t, int *, char **);
void X_db_symbol_values(db_symtab_t *symtab, c_db_sym_t sym,
const char **namep, db_expr_t *valuep);
void db_decode_syscall(int number, struct thread *td);
#endif /* !_DDB_DB_SYM_H_ */

View file

@ -32,7 +32,6 @@ __FBSDID("$FreeBSD$");
#include <sys/kdb.h>
#include <sys/proc.h>
#include <sys/reg.h>
#include <sys/sysent.h>
#include <machine/cpu.h>
#include <machine/frame.h>
@ -196,7 +195,6 @@ static void db_nextframe(struct i386_frame **, db_addr_t *, struct thread *);
static int db_numargs(struct i386_frame *);
static void db_print_stack_entry(const char *, int, char **, int *, db_addr_t,
void *);
static void decode_syscall(int, struct thread *);
/*
* Figure out how many arguments were passed into the frame at "fp".
@ -262,28 +260,6 @@ db_print_stack_entry(name, narg, argnp, argp, callpc, frame)
db_printf("\n");
}
static void
decode_syscall(int number, struct thread *td)
{
struct proc *p;
c_db_sym_t sym;
db_expr_t diff;
sy_call_t *f;
const char *symname;
db_printf(" (%d", number);
p = (td != NULL) ? td->td_proc : NULL;
if (p != NULL && 0 <= number && number < p->p_sysent->sv_size) {
f = p->p_sysent->sv_table[number].sy_call;
sym = db_search_symbol((db_addr_t)f, DB_STGY_ANY, &diff);
if (sym != DB_SYM_NULL && diff == 0) {
db_symbol_values(sym, &symname, NULL);
db_printf(", %s, %s", p->p_sysent->sv_name, symname);
}
}
db_printf(")");
}
/*
* Figure out the next frame up in the call stack.
*/
@ -396,7 +372,7 @@ db_nextframe(struct i386_frame **fp, db_addr_t *ip, struct thread *td)
break;
case SYSCALL:
db_printf("--- syscall");
decode_syscall(tf->tf_eax, td);
db_decode_syscall(tf->tf_eax, td);
break;
case INTERRUPT:
db_printf("--- interrupt");