wiki:CoreFiles

Version 4 (modified by Jiri Svoboda, 13 years ago) ( diff )

Again, presence of register state depends on arch

Working with core files

HelenOS can now produce an ELF core file when a task crashes. While you cannot really use it yet in HelenOS directly, you can extract this core file and use it with GDB to debug the application.

Note that all architectures do not support saving register state in the core file, see ArchFeature, check the line labeled Write GP-register state to core file. If the architecture does not support it, you will not be able to view register state nor a stack trace in GDB!

Here we assume you are using Linux as your host system and that you run HelenOS in Qemu.

First configure and build HelenOS as follows:

  • Load preconfigured defaults: ia32 (or amd64)
  • Enable options: Load disk drivers on startup, Mount /data on startup, Write core files

Now we need a disk image with a FAT filesystem. Make sure it has at least 20 MB (we are using 4 kB clusters and we must have at least 4 k clusters for FAT16).

$ dd if=/dev/zero of=img bs=4096 count=5000
$ losetup /dev/loop0 img
$ mkdosfs -s 8 -F 16 /dev/loop0
$ losetup -d /dev/loop0

Run HelenOS in Qemu now and it will mount the new filesystem on /data automatically.

$ qemu -hda img -cdrom image.iso -boot d

Good. Now we can take the crashdump. If you run tester fault1 it will save a core dump under /data. Another way is to dump a running task. Let's start Tetris, determine it's task ID using the kernel console and finally run taskdump on it.

# tetris
[press F2 to switch to another VC]
# kcon
kconsole> tasks
...
32 tetris....
kconsole> continue
# taskdump -t 32 -c /data/coretet
# unmount /data

The last command unmount /data forces all data to be written out to the block device. Exit Qemu. Now you can extract the core file, for example with the following commands (tip: save this as a shell script).

#!/bin/sh

mkdir /tmp/hcore
mount -t vfat -o loop img /tmp/hcore
cp /tmp/hcore/core* .
umount /tmp/hcore
rmdir /tmp/hcore
chmod 644 core*

Now you have the file coretet in your HelenOS source root directory. Time to fire up GDB:

$ gdb uspace/dist/app/tetris coretet

On some arches it may complain that register state is not present in the core file, but it will work anyway (but you don't get a stack trace). Also note that you may want to compile your binary with debugging symbols so that type and line number information is available to GDB… Happy debugging!

Note: See TracWiki for help on using the wiki.