Working with core files
HelenOS can 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 the configuration option: Write core files
Now we need a disk image with a FAT file system. 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.
$ qemu-system-i386 -hda img -cdrom image.iso -boot d $ qemu-system-x86_64 -hda img -cdrom image.iso -boot d
The ATA driver should detect the disk device. Use the following commands to find the ATA device name and mount it.
# loc bd: devices/\hw\pci0\00:01.0\ata-c1\d0 : devman devices/\hw\pci0\00:01.0\ata-c2\d0 : devman ... # fat # mount fat /data devices/\hw\pci0\00:01.0\ata-c1\d0
The first ATA device is usually the hard disk, the second ATA device is usually the CD-ROM drive. You have to manually start the FAT file system driver (if it is not yet stated) and mount the file system under /data.
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!