wiki:CoreFiles

Version 1 (modified by Jiri Svoboda, 15 years ago) ( diff )

Core files. Finally.

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 only memory state is saved as of yet. Register state is not stored in the core file. 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 /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
losetup /dev/loop0 img
mount -t vfat -o fat=16 /dev/loop0 /tmp/hcore
cp /tmp/hcore/core* .
umount /tmp/hcore
losetup -d /dev/loop0
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

It will complain that register state is not present in the core file, but it will work. 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.