git: 8bfdf839270b - stable/13 - kdump: Add a facility to print numbers in decimal format always

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Thu, 29 Jun 2023 08:20:42 UTC
The branch stable/13 has been updated by dchagin:

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

commit 8bfdf839270b3c9be013ec4b51ef8fdc1fe80636
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-05-26 16:35:08 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-06-29 08:16:00 +0000

    kdump: Add a facility to print numbers in decimal format always
    
    To help grepping kdump output by pid or tid it makes sence to print
    some numbers in decimal format always. Eg, process or thread identifier
    at least, as they already printed in decimal format.
    Switch to print pid/tid arguments of some Linux signal related syscalls
    in decimal format.
    
    Reviewed by:            jhb
    Differential Revision:  https://reviews.freebsd.org/D40099
    MFC after:              1 week
    
    (cherry picked from commit c2c9ac88c2bb62423ae91beeee4083b596922adc)
---
 usr.bin/kdump/kdump.h | 13 +++++++++----
 usr.bin/kdump/linux.c | 12 ++++++------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/usr.bin/kdump/kdump.h b/usr.bin/kdump/kdump.h
index f5b9b85f9779..1d3e9be2b6e0 100644
--- a/usr.bin/kdump/kdump.h
+++ b/usr.bin/kdump/kdump.h
@@ -34,7 +34,7 @@
 
 extern bool decimal, fancy, resolv;
 
-#define	print_number64(first,i,n,c) do {				\
+#define	_print_number64(first,i,n,c,d) do {				\
 	uint64_t __v;							\
 									\
 	if (quad_align && (((ptrdiff_t)((i) - (first))) & 1) == 1) {	\
@@ -46,7 +46,7 @@ extern bool decimal, fancy, resolv;
 		    ((uint64_t)(uint32_t)(i)[1]) << 32;			\
 	else								\
 		__v = (uint64_t)*(i);					\
-	if (decimal)							\
+	if (d)								\
 		printf("%c%jd", (c), (intmax_t)__v);			\
 	else								\
 		printf("%c%#jx", (c), (uintmax_t)__v);			\
@@ -55,8 +55,8 @@ extern bool decimal, fancy, resolv;
 	(c) = ',';							\
 } while (0)
 
-#define print_number(i,n,c) do {					\
-	if (decimal)							\
+#define _print_number(i,n,c,d) do {					\
+	if (d)								\
 		printf("%c%jd", c, (intmax_t)*i);			\
 	else								\
 		printf("%c%#jx", c, (uintmax_t)(u_register_t)*i);	\
@@ -65,6 +65,11 @@ extern bool decimal, fancy, resolv;
 	c = ',';							\
 } while (0)
 
+#define	print_number(i,n,c)		_print_number(i,n,c,decimal)
+#define	print_decimal_number(i,n,c)	_print_number(i,n,c,true)
+#define	print_number64(first,i,n,c)	_print_number64(first,i,n,c,decimal)
+#define	print_decimal_number64(first,i,n,c) _print_number64(first,i,n,c,true)
+
 void	decode_filemode(int value);
 void	print_integer_arg(const char *(*decoder)(int), int value);
 void	print_integer_arg_valid(const char *(*decoder)(int), int value);
diff --git a/usr.bin/kdump/linux.c b/usr.bin/kdump/linux.c
index 57f89f9e2faf..df400f554c23 100644
--- a/usr.bin/kdump/linux.c
+++ b/usr.bin/kdump/linux.c
@@ -202,7 +202,7 @@ ktrsyscall_linux(struct ktr_syscall *ktr, register_t **resip,
 	case LINUX_SYS_linux_kill:
 	case LINUX_SYS_linux_tkill:
 	case LINUX_SYS_linux_rt_sigqueueinfo:
-		print_number(ip, narg, c);
+		print_decimal_number(ip, narg, c);
 		putchar(',');
 		print_linux_signal(*ip);
 		ip++;
@@ -210,8 +210,8 @@ ktrsyscall_linux(struct ktr_syscall *ktr, register_t **resip,
 		break;
 	case LINUX_SYS_linux_tgkill:
 	case LINUX_SYS_linux_rt_tgsigqueueinfo:
-		print_number(ip, narg, c);
-		print_number(ip, narg, c);
+		print_decimal_number(ip, narg, c);
+		print_decimal_number(ip, narg, c);
 		putchar(',');
 		print_linux_signal(*ip);
 		ip++;
@@ -411,7 +411,7 @@ ktrsyscall_linux32(struct ktr_syscall *ktr, register_t **resip,
 	case LINUX32_SYS_linux_kill:
 	case LINUX32_SYS_linux_tkill:
 	case LINUX32_SYS_linux_rt_sigqueueinfo:
-		print_number(ip, narg, c);
+		print_decimal_number(ip, narg, c);
 		putchar(',');
 		print_linux_signal(*ip);
 		ip++;
@@ -419,8 +419,8 @@ ktrsyscall_linux32(struct ktr_syscall *ktr, register_t **resip,
 		break;
 	case LINUX32_SYS_linux_tgkill:
 	case LINUX32_SYS_linux_rt_tgsigqueueinfo:
-		print_number(ip, narg, c);
-		print_number(ip, narg, c);
+		print_decimal_number(ip, narg, c);
+		print_decimal_number(ip, narg, c);
 		putchar(',');
 		print_linux_signal(*ip);
 		ip++;