ddb: print the actual syscall name

Some architectures will pretty-print a system call trap in the
backtrace. Rather than printing the symbol, use the syscallname()
function to pull the string from the sv_syscallnames array corresponding
to the process. This simplifies the function somewhat.

Mostly, this will result in dropping the "sys" prefix, e.g. "sys_exit"
will now be printed simply as "exit".

Make two minor tweaks to the function signature: use a u_int for the
syscall number since this is a more correct type (see the 'code' member
of struct syscall_args), and make the thread pointer the first argument.
The latter is more natural and conventional.

Suggested by:   jrtc27
Reviewed by:	jrtc27, markj, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37200
This commit is contained in:
Mitchell Horne 2022-10-28 18:20:05 -03:00
parent 1da65dcb1c
commit aba921bd9e
5 changed files with 9 additions and 17 deletions

View File

@ -218,7 +218,7 @@ db_nextframe(struct amd64_frame **fp, db_addr_t *ip, struct thread *td)
break;
case SYSCALL:
db_printf("--- syscall");
db_decode_syscall(tf->tf_rax, td);
db_decode_syscall(td, tf->tf_rax);
break;
case INTERRUPT:
db_printf("--- interrupt");

View File

@ -485,23 +485,15 @@ db_sym_numargs(c_db_sym_t sym, int *nargp, char **argnames)
}
void
db_decode_syscall(int number, struct thread *td)
db_decode_syscall(struct thread *td, u_int number)
{
struct proc *p;
c_db_sym_t sym;
db_expr_t diff;
sy_call_t *f;
const char *symname;
db_printf(" (%d", number);
db_printf(" (%u", 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);
}
if (p != NULL) {
db_printf(", %s, %s", p->p_sysent->sv_name,
syscallname(p, number));
}
db_printf(")");
}

View File

@ -105,6 +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);
void db_decode_syscall(struct thread *td, u_int number);
#endif /* !_DDB_DB_SYM_H_ */

View File

@ -372,7 +372,7 @@ db_nextframe(struct i386_frame **fp, db_addr_t *ip, struct thread *td)
break;
case SYSCALL:
db_printf("--- syscall");
db_decode_syscall(tf->tf_eax, td);
db_decode_syscall(td, tf->tf_eax);
break;
case INTERRUPT:
db_printf("--- interrupt");

View File

@ -97,7 +97,7 @@ db_stack_trace_cmd(struct thread *td, struct unwind_state *frame)
tf->tf_scause & SCAUSE_CODE);
} else if (tf->tf_scause == SCAUSE_ECALL_USER) {
db_printf("--- syscall");
db_decode_syscall(td->td_sa.code, td);
db_decode_syscall(td, td->td_sa.code);
db_printf("\n");
} else {
db_printf("--- exception %ld, tval = %#lx\n",