git: a4dd26ead25d - stable/13 - ddb: de-duplicate decode_syscall()

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Sun, 06 Nov 2022 14:55:37 UTC
The branch stable/13 has been updated by mhorne:

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

commit a4dd26ead25db6d5aa07938ccb83413172c9cf2b
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-10-02 22:46:00 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-11-06 14:54:46 +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
    
    (cherry picked from commit 754cb545b68ba0a1643792763d000018ffe2afec)
    (cherry picked from commit 6f8a182b15c4c14cfb9462b806a928ddaf47c87e)
    (cherry picked from commit 89e5ef8917af900558c2d275f5d5c4c703520ead)
    (cherry picked from commit 85b715baae22ca12f2d24e1b2980f3d5b32937b8)
---
 sys/amd64/amd64/db_trace.c | 26 +-------------------------
 sys/ddb/db_sym.c           | 26 +++++++++++++++++++++++++-
 sys/ddb/db_sym.h           |  2 ++
 sys/i386/i386/db_trace.c   | 26 +-------------------------
 4 files changed, 29 insertions(+), 51 deletions(-)

diff --git a/sys/amd64/amd64/db_trace.c b/sys/amd64/amd64/db_trace.c
index 037cae200e2e..1eae53f3d06d 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>
@@ -126,7 +125,6 @@ db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
 
 static void db_nextframe(struct amd64_frame **, db_addr_t *, struct thread *);
 static void db_print_stack_entry(const char *, db_addr_t, void *);
-static void decode_syscall(int, struct thread *);
 
 static void
 db_print_stack_entry(const char *name, db_addr_t callpc, void *frame)
@@ -139,28 +137,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 +218,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..43a0b5447479 100644
--- a/sys/ddb/db_sym.c
+++ b/sys/ddb/db_sym.c
@@ -36,9 +36,11 @@ __FBSDID("$FreeBSD$");
 #include "opt_kstack_pages.h"
 
 #include <sys/param.h>
+#include <sys/systm.h>
 #include <sys/pcpu.h>
+#include <sys/proc.h>
 #include <sys/smp.h>
-#include <sys/systm.h>
+#include <sys/sysent.h>
 
 #include <net/vnet.h>
 
@@ -481,3 +483,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");