cvs commit: src/gnu/usr.bin/gdb/kgdb kgdb.h kld.c trgt.c
John Baldwin
jhb at freebsd.org
Mon Jan 28 15:09:36 PST 2008
On Monday 28 January 2008 04:40:10 pm John Baldwin wrote:
> jhb 2008-01-28 21:40:10 UTC
>
> FreeBSD src repository
>
> Modified files:
> gnu/usr.bin/gdb/kgdb kgdb.h kld.c trgt.c
> Log:
> Add support for automatically loading symbols for kld's on startup:
> - Add a new 'kgdb_auto_load_klds()' routine which is invoked during
> startup that walks the list of linker files and tries to find a matching
> kld on disk for each non-kernel kld. If a kld file is found, then it
> is added as if the 'add-kld' command is invoked. One change from
> 'add-kld' is that this method attempts to use the 'pathname' from the
> linker_file structure first to try to load the file. If that fails
> it then looks in the kernel directory followed by the directories in
> the module path.
> - Move the kld file suffix handling into a separate routine so that it
> can be called standalone and to reduce duplicate code in
find_kld_path().
> - Cache the offsets of members of 'struct linker_file' during startup
> instead of computing them for each 'add-kld'.
> - Use GDB's target_read_string() instead of direct KVM access.
> - Add all resident sections from a kld by using bfd_map_over_sections() to
> build the section list rather than just adding symbols for ".text",
> ".data", ".bss", and ".rodata".
> - Change the 'add-kld' command to do a y/n prompt before adding the
> symbols when run interactively to match 'add-symbol-file'.
Now 'add-kld' can be optional, you can always use it if the automatic magic
picks a poor foo.ko (e.g. a stripped one w/o symbols). Example:
> sudo ./kgdb -q -c /usr/crash/vmcore.10 /boot/kernel/kernel
[GDB will not be able to debug user-mode threads: /usr/lib/libthread_db.so:
Undefined symbol "ps_pglobal_lookup"]
Loaded symbols for kld "crash.ko" from "/boot/modules/crash.ko"
#0 doadump () at pcpu.h:195
195 pcpu.h: No such file or directory.
in pcpu.h
(kgdb) where
#0 doadump () at pcpu.h:195
#1 0xc05d399c in boot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:417
#2 0xc05d3c0a in panic (fmt=Variable "fmt" is not available.
) at /usr/src/sys/kern/kern_shutdown.c:571
#3 0xc08115d9 in dblfault_handler () at /usr/src/sys/i386/i386/trap.c:927
#4 0xc05c6220 in mtx_pool_setup_dynamic ()
#5 0xc065e125 in arc4rand (ptr=0xe61b0168, len=4, reseed=0)
at /usr/src/sys/libkern/arc4random.c:142
#6 0xc065e171 in arc4random () at /usr/src/sys/libkern/arc4random.c:150
#7 0xc3d43402 in blow_stack () at crash.c:773
#8 0xc3d43410 in blow_stack () at crash.c:764
#9 0xc3d43410 in blow_stack () at crash.c:764
(Note that blow_stack() is in crash.ko and the stack trace worked right away.)
It even works for the live kernel (scary):
> sudo ./kgdb -q /boot/kernel/kernel /dev/mem
[GDB will not be able to debug user-mode threads: /usr/lib/libthread_db.so:
Undefined symbol "ps_pglobal_lookup"]
Loaded symbols for kld "iwi_bss.ko" from "/boot/kernel/iwi_bss.ko"
Loaded symbols for kld "logo_saver.ko" from "/boot/kernel/logo_saver.ko"
#0 sched_switch (td=0xc08fdb90, newtd=Variable "newtd" is not available.
) at /usr/src/sys/kern/sched_ule.c:1905
1905 cpuid = PCPU_GET(cpuid);
(kgdb)
Now just need to axe that '[GDB will not be able blah blah blah]' message.
Note that you can't see which kld's are loaded currently. At some point I
will rewrite the kld support to actually hook into GDB's shared library
support so that 'info sharedlibrary' will work. I'm slowly learning GDB
internals, but that bit will probably take a while.
--
John Baldwin
More information about the cvs-src
mailing list