Setting things up to get core dumps

    dfaure's picture
    2009
    27
    Mar

    Drkonqi is nice and friendly, but some apps (e.g. kded or krunner) have a crash handler so that they restart instead of annoying the user with crash dialogs.

    As developers, we want to see backtraces of crashes in all cases; and to be in gdb in order to be able to print variables etc. Solution: asking for core dumps. That part is easy:

    export KDE_DEBUG=1
    ulimit -c unlimited
    

    You should put that somewhere that is read during KDE startup, for instance ~/.kde4/env/debug.sh

    But then after a while you find core dumps everywhere in your source and build dirs, and you need some "find all core dumps and delete them" scripts when your disk is full. Not convenient. Instead, I like to set it up like Mac OSX does: with a directory dedicated to core dumps. Fortunately, the linux kernel can be set up like that too. As root, do the following:

    mkdir /cores
    chmod 777 /cores
    

    and at the bottom of /etc/rc.local or any other script run by root during the boot sequence:

    # Let's have the core files in /cores
    echo /cores/core > /proc/sys/kernel/core_pattern
    echo 1 > /proc/sys/kernel/core_uses_pid
    

    Now when an application crashes you'll get a file like /cores/core.14030, which you can use with `gdb krunner /cores/core.14030` (random example... I swear).

    Which leaves one question open: if I go in /cores and I see 5 core files, how do I know which app generated them? You can use the file(1) command, if it's recent enough or old enough (at some point there was a bug, which I sent a patch for some time ago).

    $ file core.*
    core.14372: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from './resourcetest'
    core.16472: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from '/d/kde/build/t/kdelibs/khtml/tests/khtmlparttest'
    

    Comments

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.
    zagge's picture

    Added executable name to corefile

    You can add the executable name to the core file by e.g. :


    echo /cores/core.%e.%p > /proc/sys/kernel/core_pattern

    dfaure's picture

    Excellent

    Thanks for the tip, this is really a lot better!

    Blogging == teaching and learning at the same time, very nice ;)

    irina's picture

    > chown 777 /cores ... are

    > chown 777 /cores

    ... are you sure you don't mean chmod 777? :-)

    dfaure's picture

    Oops, fixed. Thanks for the

    Oops, fixed. Thanks for the comment :)

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.