Review: add lineno+source file info to panic output

From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Date: Sat, 17 Jan 2004 14:26:40 +0100
This patch adds sourcefile and linenumber to panics output:

	db> panic
	panic: from debugger
>>>	at line 450 in file ../../../ddb/db_command.c
	cpuid = 0; 

I'm not 100% sure about the assembler bits.

Poul-Henning

Index: alpha/alpha/support.s
===================================================================
RCS file: /home/ncvs/src/sys/alpha/alpha/support.s,v
retrieving revision 1.15
diff -u -r1.15 support.s
--- alpha/alpha/support.s	24 Jul 2003 07:49:45 -0000	1.15
+++ alpha/alpha/support.s	17 Jan 2004 13:21:33 -0000
_at__at_ -680,8 +680,10 _at__at_
 
 longjmp_botch:
 	lda	a0, longjmp_botchmsg
-	mov	ra, a1
-	CALL(panic)
+	mov	0, a1
+	mov	0, a2
+	mov	ra, a3
+	CALL(__panic)
 	call_pal PAL_bugchk
 
 	.data
Index: i386/i386/swtch.s
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/swtch.s,v
retrieving revision 1.143
diff -u -r1.143 swtch.s
--- i386/i386/swtch.s	30 Sep 2003 08:11:35 -0000	1.143
+++ i386/i386/swtch.s	17 Jan 2004 13:21:33 -0000
_at__at_ -303,20 +303,26 _at__at_
 #ifdef INVARIANTS
 badsw1:
 	pushal
+	pushl	$0
+	pushl	$0
 	pushl	$sw0_1
-	call	panic
+	call	__panic
 sw0_1:	.asciz	"cpu_throw: no newthread supplied"
 
 badsw2:
 	pushal
+	pushl	$0
+	pushl	$0
 	pushl	$sw0_2
-	call	panic
+	call	__panic
 sw0_2:	.asciz	"cpu_switch: no curthread supplied"
 
 badsw3:
 	pushal
+	pushl	$0
+	pushl	$0
 	pushl	$sw0_3
-	call	panic
+	call	__panic
 sw0_3:	.asciz	"cpu_switch: no newthread supplied"
 #endif
 
Index: kern/kern_shutdown.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_shutdown.c,v
retrieving revision 1.146
diff -u -r1.146 kern_shutdown.c
--- kern/kern_shutdown.c	16 Aug 2003 16:57:57 -0000	1.146
+++ kern/kern_shutdown.c	17 Jan 2004 13:23:10 -0000
_at__at_ -476,7 +476,7 _at__at_
  * MPSAFE
  */
 void
-panic(const char *fmt, ...)
+__panic(const char *file, int line, const char *fmt, ...)
 {
 	struct thread *td = curthread;
 	int bootopt, newpanic;
_at__at_ -510,11 +510,11 _at__at_
 	if (newpanic) {
 		(void)vsnprintf(buf, sizeof(buf), fmt, ap);
 		panicstr = buf;
-		printf("panic: %s\n", buf);
+		printf("panic: %s\nat line %d in file %s\n", buf, line, file);
 	} else {
 		printf("panic: ");
 		vprintf(fmt, ap);
-		printf("\n");
+		printf("\nat line %d in file %s", line, file);
 	}
 	va_end(ap);
 #ifdef SMP
Index: sys/systm.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/systm.h,v
retrieving revision 1.201
diff -u -r1.201 systm.h
--- sys/systm.h	26 Dec 2003 05:54:35 -0000	1.201
+++ sys/systm.h	17 Jan 2004 13:21:33 -0000
_at__at_ -136,10 +136,12 _at__at_
 void	*phashinit(int count, struct malloc_type *type, u_long *nentries);
 
 #ifdef RESTARTABLE_PANICS
-void	panic(const char *, ...) __printflike(1, 2);
+void	__panic(const char *file, int line, const char *, ...) __printflike(3, 4);
 #else
-void	panic(const char *, ...) __dead2 __printflike(1, 2);
+void	__panic(const char *file, int line, const char *, ...) __dead2 __printflike(3, 4);
 #endif
+
+#define panic(...) __panic(__FILE__, __LINE__, __VA_ARGS__)
 
 void	backtrace(void);
 void	cpu_boot(int);
-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk_at_FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
Received on Sat Jan 17 2004 - 04:26:43 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:38 UTC