Re: lowlatency-2.2.14-B1 + 2.2.14aa7 fixes crash, but...

From: Artur Skawina (skawina@geocities.com)
Date: Fri Feb 11 2000 - 22:44:11 EST


Manfred Spraul wrote:
>
> What about writing a generic module that walks through the task array
> and dumps the complete (8kB) kernel stack? The big advantage is that we
> could load it at runtime, and it has zero impact on the normal kernel
> operations. Perhaps even a user space program could do that through
> kcore/kmem.

attached is the adhoc hack i did years ago when i needed a stacktrace
of a hung process.

you need to lookup the address of init_task_union in System.map,
update it, recompile, and insmod the module specifying the pid.

it could be made a lot nicer, but as it has always been enough for my needs...

artur


//gcc -D__KERNEL__ -DMODULE=1 -I/usr/src/linux/include -O2 -fno-strict-aliasing -pipe -c ksmod.c
//insmod -v ./ksmod.o pid=266
/*
 * Copyright 1998 Artur Skawina <skawina@geocities.com>
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/sched.h>

int pid = -1;

MODULE_PARM(pid,"i");

EXPORT_NO_SYMBOLS;

#define init_task_union ((void *)0xc022e000)

void printstack( int pid )
{
   struct task_struct *t;
   u32 *stack;
   u32 a;
   
   printk( KERN_DEBUG "ksmod PID=%d\n", pid );
   //for_each_task(t)
   for (t = init_task_union; (t = t->next_task) != init_task_union ; )
      if (t->pid == pid)
      {
         printk( KERN_DEBUG
               "EIP: [<%08lx>] "
               "ESP: %08lx "
               "SavedPC: %08lx\n",
                   t->thread.eip,
                   t->thread.esp,
                   thread_saved_pc( &t->thread ) );

         stack = (u32 *)t->thread.esp;
         
         while (((u32)stack & 4095) != 0)
         {
                 a = *stack++;

                 if ( (a > (u32)PAGE_OFFSET) && (a < 0xffffffff) )
                         printk( KERN_DEBUG "[<%08lx>]\n", a);
         }
         break;
      }
}

int init_module(void)
{
   if ( pid==-1 )
   {
      printk(KERN_ERR "ksmod: pid missing.\n");
      return -EINVAL;
   }

   printstack( pid );

   return 0;
}

void cleanup_module(void)
{
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Feb 15 2000 - 21:00:22 EST