lkml.org 
[lkml]   [1999]   [Jun]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC] [PATCH] <linux/kdebug.h> (was: Re:[PATCH] *(int)0=0...)
Riley Williams wrote:
> One problem is that I don't see a kdebug.h file in the 2.2.10 tree,
> other than the SPARC specific ones in asm-sparc{,64}/kdebug.h and, as
> a result, your comments are less than helpful.

I started this thread because I think this file is currently missing.

I've attached my current idea for this file.
[patch vs 2.3.8]

This patch also fixes that bug that the call trace only prints 1 page of
the 2 page kernel stack.

todo: other architectures, sysctl support.
--
Manfred// $Header: /pub/cvs/ms/patches/patch-kdebug.h-2.3.8,v 1.2 1999/06/26 13:45:46 manfreds Exp $
// Kernel Version:
// VERSION = 2
// PATCHLEVEL = 3
// SUBLEVEL = 8
// EXTRAVERSION =
diff -r -u -P -x CVS -x *,v 2.3/arch/i386/config.in build-2.3/arch/i386/config.in
--- 2.3/arch/i386/config.in Tue Jun 15 20:15:00 1999
+++ build-2.3/arch/i386/config.in Sat Jun 26 15:30:56 1999
@@ -205,5 +205,6 @@

#bool 'Debug kmalloc/kfree' CONFIG_DEBUG_MALLOC
bool 'Magic SysRq key' CONFIG_MAGIC_SYSRQ
+bool 'Enable debugging extensions' CONFIG_KDEBUG
endmenu

diff -r -u -P -x CVS -x *,v 2.3/arch/i386/kernel/traps.c build-2.3/arch/i386/kernel/traps.c
--- 2.3/arch/i386/kernel/traps.c Sat Jun 26 15:23:38 1999
+++ build-2.3/arch/i386/kernel/traps.c Sat Jun 26 15:39:48 1999
@@ -119,14 +119,53 @@
*/
#define VMALLOC_OFFSET (8*1024*1024)
#define MODULE_RANGE (8*1024*1024)
+void show_stack(unsigned long* stack)
+{
+ int i;
+ unsigned long addr, module_start, module_end;
+ unsigned long limit = ((unsigned long)current)+8192;
+
+ printk("\nStack: ");
+ for(i=0; i < kstack_depth_to_print; i++) {
+ if (((unsigned long) stack) < limit)
+ break;
+ if (i && ((i % 8) == 0))
+ printk("\n ");
+ printk("%08lx ", *stack++);
+ }
+ printk("\nCall Trace: ");
+ i = 1;
+ module_start = PAGE_OFFSET + (max_mapnr << PAGE_SHIFT);
+ module_start = ((module_start + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1));
+ module_end = module_start + MODULE_RANGE;

+ while ( ((unsigned long) stack) <limit) {
+ addr = *stack++;
+ /*
+ * If the address is either in the text segment of the
+ * kernel, or in the region which contains vmalloc'ed
+ * memory, it *may* be the address of a calling
+ * routine; if so, print it so that someone tracing
+ * down the cause of the crash will be able to figure
+ * out the call path that was taken.
+ */
+ if (((addr >= (unsigned long) &_stext) &&
+ (addr <= (unsigned long) &_etext)) ||
+ ((addr >= module_start) && (addr <= module_end))) {
+ if (i && ((i % 8) == 0))
+ printk("\n ");
+ printk("[<%08lx>] ", addr);
+ i++;
+ }
+ }
+ printk("\n");
+}
static void show_registers(struct pt_regs *regs)
{
int i;
int in_kernel = 1;
unsigned long esp;
unsigned short ss;
- unsigned long *stack, addr, module_start, module_end;

esp = (unsigned long) (1+regs);
ss = __KERNEL_DS;
@@ -152,40 +191,8 @@
* time of the fault..
*/
if (in_kernel) {
- printk("\nStack: ");
- stack = (unsigned long *) esp;
- for(i=0; i < kstack_depth_to_print; i++) {
- if (((long) stack & 4095) == 0)
- break;
- if (i && ((i % 8) == 0))
- printk("\n ");
- printk("%08lx ", *stack++);
- }
- printk("\nCall Trace: ");
- stack = (unsigned long *) esp;
- i = 1;
- module_start = PAGE_OFFSET + (max_mapnr << PAGE_SHIFT);
- module_start = ((module_start + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1));
- module_end = module_start + MODULE_RANGE;
- while (((long) stack & 4095) != 0) {
- addr = *stack++;
- /*
- * If the address is either in the text segment of the
- * kernel, or in the region which contains vmalloc'ed
- * memory, it *may* be the address of a calling
- * routine; if so, print it so that someone tracing
- * down the cause of the crash will be able to figure
- * out the call path that was taken.
- */
- if (((addr >= (unsigned long) &_stext) &&
- (addr <= (unsigned long) &_etext)) ||
- ((addr >= module_start) && (addr <= module_end))) {
- if (i && ((i % 8) == 0))
- printk("\n ");
- printk("[<%08lx>] ", addr);
- i++;
- }
- }
+ show_stack((unsigned long*)esp);
+
printk("\nCode: ");
for(i=0;i<20;i++)
printk("%02x ", ((unsigned char *)regs->eip)[i]);
diff -r -u -P -x CVS -x *,v 2.3/include/linux/kdebug.h build-2.3/include/linux/kdebug.h
--- 2.3/include/linux/kdebug.h Thu Jan 1 01:00:00 1970
+++ build-2.3/include/linux/kdebug.h Sat Jun 26 15:30:56 1999
@@ -0,0 +1,78 @@
+#ifndef _LINUX_KDEBUG_H
+#define _LINUX_KDEBUG_H
+
+
+extern int kassert_dontreturn;
+void kassert_failed(char* file, char* function, int line, char* condition, int dontreturn);
+
+#define __kassert(cond, dontreturn) \
+ do { \
+ if(!(cond)) { \
+ kassert_failed(__FILE__, __FUNCTION__, \
+ __LINE__, #cond, dontreturn); \
+ } \
+ } while(0)
+
+#ifdef CONFIG_KDEBUG
+ #define kassert(cond) __kassert(cond, kassert_dontreturn)
+
+#ifndef DBG_PKGRP
+ #define DBG_PKGRP main
+#endif
+
+
+#define dbg_cat(x,y) x ## y
+#define dbg_xcat(x,y) dbg_cat(x,y)
+#define __DBG_PKGRP dbg_xcat(dbg_printk_,DBG_PKGRP)
+extern int __DBG_PKGRP;
+extern int dbg_printk_global;
+
+#ifdef DBG_PKGRP_DEFAULT
+ int __DBG_PKGRP = DBG_PKGRP_DEFAULT;
+#endif
+
+ #define dbgprintk(args...) \
+ do { \
+ if(__DBG_PKGRP || dbg_printk_global) \
+ printk(##args); \
+ } while(0)
+
+ #define kassert_down(sem) \
+ do { \
+ if(down_trylock(sem)) { \
+ kassert(!"kassert_down(): down missing"); \
+ up(sem); \
+ } \
+ } while(0)
+
+ #define kassert_locked(spinlock) \
+ do { \
+ if(spinlock_trylock(spinlock)) { \
+ kassert(!"kassert_locked(): lock missing"); \
+ spinlock_unlock(spinlock); \
+ } \
+ } while(0)
+
+#ifdef __SMP__
+ #define kassert_kernel_locked() \
+ do { \
+ kassert(current->lock_depth>=0); \
+ } while(0)
+#else
+ #define kassert_kernel_locked() do { } while(0)
+#endif
+
+#else /* CONFIG_KDEBUG */
+
+ #define kassert(cond) do { } while(0)
+
+ #define dbgprintk(args...) \
+ do { } while(0)
+
+ #define kassert_down(sem) do { } while(0)
+ #define kassert_locked(spinlock) do { } while(0)
+ #define kassert_kernel_locked() do { } while(0)
+
+#endif
+
+#endif /* _LINUX_KDEBUG_H */
diff -r -u -P -x CVS -x *,v 2.3/init/main.c build-2.3/init/main.c
--- 2.3/init/main.c Sat Jun 26 11:52:55 1999
+++ build-2.3/init/main.c Sat Jun 26 15:30:56 1999
@@ -74,6 +74,7 @@
extern void init_IRQ(void);
extern void init_modules(void);
extern long console_init(long, long);
+extern void init_kdebug(void);
extern void sock_init(void);
extern void uidcache_init(void);
extern void mca_init(void);
@@ -1180,6 +1181,9 @@
kmem_cache_sizes_init();
#ifdef CONFIG_PROC_FS
proc_root_init();
+#endif
+#ifdef CONFIG_KDEBUG
+ init_kdebug();
#endif
uidcache_init();
filescache_init();
diff -r -u -P -x CVS -x *,v 2.3/kernel/Makefile build-2.3/kernel/Makefile
--- 2.3/kernel/Makefile Wed May 6 20:01:46 1998
+++ build-2.3/kernel/Makefile Sat Jun 26 15:30:56 1999
@@ -13,7 +13,7 @@
O_TARGET := kernel.o
O_OBJS = sched.o dma.o fork.o exec_domain.o panic.o printk.o sys.o \
module.o exit.o itimer.o info.o time.o softirq.o resource.o \
- sysctl.o acct.o capability.o
+ sysctl.o acct.o capability.o kdebug.o

OX_OBJS += signal.o

diff -r -u -P -x CVS -x *,v 2.3/kernel/kdebug.c build-2.3/kernel/kdebug.c
--- 2.3/kernel/kdebug.c Thu Jan 1 01:00:00 1970
+++ build-2.3/kernel/kdebug.c Sat Jun 26 15:30:56 1999
@@ -0,0 +1,43 @@
+/*
+ * linux/kernel/kdebug.c
+ *
+ * Copyright (C) 1999 Manfred Spraul
+ */
+
+#include <linux/kernel.h>
+#include <linux/config.h>
+#define DBG_PKGRP main
+#define DBG_PKGRP_DEFAULT 1
+#include <linux/kdebug.h>
+
+static int kassert_level = 2;
+int kassert_dontreturn = 0;
+int dbg_printk_global = 1;
+
+void show_stack(unsigned long* stack);
+
+void kassert_failed(char* file, char* function, int line, char* condition, int dontreturn)
+{
+ printk("<%d> Assertion failed in file %s, line %d, function %s:\n",
+ kassert_level, file, line, function);
+ printk("<%d> Condition: %s\n",
+ kassert_level, condition);
+
+ show_stack(((unsigned long*)&dontreturn)+1);
+
+ if(dontreturn) {
+ printk("<%d> forcing an NULL pointer exception.\n",
+ kassert_level);
+ *(int*)0 = 0;
+ }
+}
+
+void init_kdebug(void)
+{
+ /* TODO: sysctl support for
+ kassert_level
+ dbg_printk_global
+ kassert_dontreturn
+ */
+ dbgprintk("Kernel debugging extensions enabled.\n");
+}
diff -r -u -P -x CVS -x *,v 2.3/kernel/ksyms.c build-2.3/kernel/ksyms.c
--- 2.3/kernel/ksyms.c Sat Jun 26 11:52:55 1999
+++ build-2.3/kernel/ksyms.c Sat Jun 26 15:30:56 1999
@@ -39,6 +39,7 @@
#include <linux/console.h>
#include <linux/poll.h>
#include <linux/mm.h>
+#include <linux/kdebug.h>

#if defined(CONFIG_PROC_FS)
#include <linux/proc_fs.h>
@@ -342,6 +343,11 @@
EXPORT_SYMBOL(secure_tcp_sequence_number);
EXPORT_SYMBOL(get_random_bytes);
EXPORT_SYMBOL(securebits);
+EXPORT_SYMBOL(kassert_failed);
+EXPORT_SYMBOL(kassert_dontreturn);
+#ifdef CONFIG_KDEBUG
+EXPORT_SYMBOL(dbg_printk_global);
+#endif

/* Program loader interfaces */
EXPORT_SYMBOL(setup_arg_pages);
\
 
 \ /
  Last update: 2005-03-22 13:52    [W:0.060 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site