Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Mar 2003 10:28:31 +0100
From:      Dag-Erling Smorgrav <des@ofug.org>
To:        Jun Su <JunSu@gmx.net>
Cc:        freebsd-current@freebsd.org
Subject:   Re: GDB kernel debug new command
Message-ID:  <xzpllznbmf4.fsf@flood.ping.uio.no>
In-Reply-To: <200303081224.53273.JunSu@gmx.net> (Jun Su's message of "Sat, 8 Mar 2003 12:24:53 %2B0800")
References:  <200303081224.53273.JunSu@gmx.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Jun Su <JunSu@gmx.net> writes:
> To help myself more easily check the kernel dump, I added two new command. One 
> is ps, the other is kldstat. I know we can print the kernel data manually to 
> get the same information. I still think this is useful. This can help the 
> newbies to get the information without many knowledge about the kernel. This 
> also can help the experienced user to get the data more quickly. 
>
> Here is the new file. Just put it in /usr/src/gnu/usr.bin/binutils/gdb. And 
> add the file to Makefile. Please give me some comments if this is garbage. :)

This is pointless as it won't work unless gdb is in synch with the
kernel (since it depends on knowing the layout of struct proc and
struct linker_file).  Both of these commands can be implemented as
macros, which will not depend on gdb being in synch with the kernel.

Greg Lehey wrote this ps macro:

define ps
    set $nproc = nprocs
    set $aproc = allproc.lh_first
    set $proc = allproc.lh_first
    printf "  pid    proc    addr   uid  ppid  pgrp   flag stat comm         wchan\n"
    while (--$nproc >= 0)
        set $pptr = $proc.p_pptr
        if ($pptr == 0)
           set $pptr = $proc
        end
        if ($proc.p_stat)
            printf "%5d %08x %08x %4d %5d %5d  %06x  %d  %-10s   ", \
                   $proc.p_pid, $aproc, \
                   $proc.p_addr, $proc.p_cred->p_ruid, $pptr->p_pid, \
                   $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_stat, \
                   &$proc.p_comm[0]
            if ($proc.p_wchan)
                if ($proc.p_wmesg)
                    printf "%s ", $proc.p_wmesg
                end
                printf "%x", $proc.p_wchan
            end
            printf "\n"
        end
        set $aproc = $proc.p_list.le_next
        if ($aproc == 0 && $nproc > 0)
            set $aproc = zombproc
        end
        set $proc = $aproc
    end
end

document ps
"ps" -- when kernel debugging, type out a ps-like listing of active processes.
end

and I've written two variants of kldstat myself, plus a kldload:

end

document kldstat
  Lists the modules that were loaded when the kernel crashed.
end

define kldstat-v
  set $kld = linker_files.tqh_first
  printf "Id Refs Address    Size     Name\n"
  while ($kld != 0)
    printf "%2d %4d 0x%08x %-8x %s\n", \
      $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename
    printf "        Contains modules:\n"
    printf "                Id Name\n"
    set $module = $kld->modules.tqh_first
    while ($module != 0)
      printf "                %2d %s\n", $module->id, $module->name
      set $module = $module->link.tqe_next
    end
    set $kld = $kld->link.tqe_next
  end
end

document kldstat-v
  Lists modules with full information.
end

define kldload
  set $kld = linker_files.tqh_first
  set $done = 0
  while ($kld != 0 && $done == 0)
    if ($kld->filename == $arg0)
      set $done = 1
    else
      set $kld = $kld->link.tqe_next
    end
  end
  if ($done == 1)
    shell /usr/bin/objdump -h $arg0 | \
      awk '/ .text/ { print "set \$offset = 0x" $6 }' > .kgdb.temp
    source .kgdb.temp
    add-symbol-file $arg0 $kld->address + $offset
  end
end

document kldload
  Loads a module. Arguments are module name and offset of text section.
end

Note that for kldload to work, you need to know the offset of the text
section for the module you wish to load (objdump -h will tell you)

Note also that I haven't used any of these macros in a long time, so
there may be some issues related to KSE or whatnot.

DES
-- 
Dag-Erling Smorgrav - des@ofug.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpllznbmf4.fsf>