From owner-freebsd-current Mon Mar 10 1:28:40 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3720A37B401 for ; Mon, 10 Mar 2003 01:28:37 -0800 (PST) Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7EA7243FCB for ; Mon, 10 Mar 2003 01:28:35 -0800 (PST) (envelope-from des@ofug.org) Received: by flood.ping.uio.no (Postfix, from userid 2602) id 3087E5308; Mon, 10 Mar 2003 10:28:32 +0100 (CET) X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: Jun Su Cc: freebsd-current@freebsd.org Subject: Re: GDB kernel debug new command From: Dag-Erling Smorgrav Date: Mon, 10 Mar 2003 10:28:31 +0100 In-Reply-To: <200303081224.53273.JunSu@gmx.net> (Jun Su's message of "Sat, 8 Mar 2003 12:24:53 +0800") Message-ID: User-Agent: Gnus/5.090014 (Oort Gnus v0.14) Emacs/21.2 (i386--freebsd) References: <200303081224.53273.JunSu@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Jun Su 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