git: 754cb545b68b - main - ddb: de-duplicate decode_syscall()

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 03 Oct 2022 16:56:44 UTC
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=754cb545b68ba0a1643792763d000018ffe2afec

commit 754cb545b68ba0a1643792763d000018ffe2afec
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-10-02 22:46:00 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-10-03 16:49:54 +0000

    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
---
 sys/amd64/amd64/db_trace.c | 25 +------------------------
 sys/ddb/db_sym.c           | 24 +++++++++++++++++++++++-
 sys/ddb/db_sym.h           |  2 ++
 sys/i386/i386/db_trace.c   | 26 +-------------------------
 4 files changed, 27 insertions(+), 50 deletions(-)

diff --git a/sys/amd64/amd64/db_trace.c b/sys/amd64/amd64/db_trace.c
index 90fcce5732d1..414202ef1008 100644
--- a/sys/amd64/amd64/db_trace.c
+++ b/sys/amd64/amd64/db_trace.c
@@ -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");
diff --git a/sys/ddb/db_sym.c b/sys/ddb/db_sym.c
index 0c3a8963baae..3fdf80a76ae6 100644
--- a/sys/ddb/db_sym.c
+++ b/sys/ddb/db_sym.c
@@ -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(")");
+}
diff --git a/sys/ddb/db_sym.h b/sys/ddb/db_sym.h
index 1ad35e2b0c85..7ad7fb71f970 100644
--- a/sys/ddb/db_sym.h
+++ b/sys/ddb/db_sym.h
@@ -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_ */
diff --git a/sys/i386/i386/db_trace.c b/sys/i386/i386/db_trace.c
index 529b94b76cc4..aee90ee058de 100644
--- a/sys/i386/i386/db_trace.c
+++ b/sys/i386/i386/db_trace.c
@@ -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");