sakana

very short memo

symbol table reference

Now the time has come that we can debug core file. In this case, dropbox seems to have yielded core file.

$ file /var/cores/core.dropbox.2172.1378900464
/var/cores/core.dropbox.2172.1378900464: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-style, from '<HOME>/.dropbox-dist/dropbox'

But some dependent libraries (e.g. libc.so) are stripped and they do not have symbol table.

$ file /lib/i386-linux-gnu/libc-2.17.so
/lib/i386-linux-gnu/libc-2.17.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), BuildID[sha1]=0x81a55e819c61f581e6a9179eaf59726dd80aea31, for GNU/Linux 2.6.24, stripped
$ objdump -t /lib/i386-linux-gnu/libc-2.17.so

/lib/i386-linux-gnu/libc-2.17.so:     file format elf32-i386

SYMBOL TABLE:
no symbols

On linux we do not replace stripped library with non-stripped one. Instead we install separate debug information file and configure debugger to reference it.

$ apt-cache search libc-
libc6-dbg - Embedded GNU C Library: detached debugging symbols
$ sudo apt-get install libc6-dbg

Packages for debug information has suffix of -dbg (it seems to be so). Installation will deploy files under /usr/lib/debug directory.

$ file /usr/lib/debug/lib/i386-linux-gnu/libc-2.17.so
/usr/lib/debug/lib/i386-linux-gnu/libc-2.17.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), BuildID[sha1]=0x81a55e819c61f581e6a9179eaf59726dd80aea31, for GNU/Linux 2.6.24, not stripped
$ objdump -t /usr/lib/debug/lib/i386-linux-gnu/libc-2.17.so

/usr/lib/debug/lib/i386-linux-gnu/libc-2.17.so:     file format elf32-i386

SYMBOL TABLE:
00000174 l    d  .note.gnu.build-id 00000000 .note.gnu.build-id
00000198 l    d  .note.ABI-tag      00000000 .note.ABI-tag

gdb is wise enough to automatically detect debug information (as long as libc6 and libc6-dbg match) and applies it!

(gdb) set verbose on
(gdb) run
...
Reading symbols from /lib/i386-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug/lib/i386-linux-gnu/libc-2.17.so...done.
done.

This entry is quite of help for debug information.

Now we can see precise stack!

spell check in vim

If my memory does not deceive me, I started using vi as my editor on HP-UX 10. (Yes, it is quite long time ago) I have not noticed it until quite recently though, vim (vi improved) has evolved so much more than I had expected.

I write almost all of text on vim, which includes this blog post. As seen, my vocabulary is quite limited and incorrect. And phrase does not go beyond routine. That is, I need spell checking mechanism to correct many typo I make and suggestions to meet what I want to express.

spell check

vim provides spell checking mechanism and you can enable it by:

:set spell

You will see color indicators, which tells you that there is typo. You can list correct word candidates by setting cursor on the relevant word and

z=

You will see list of words. Select appropriate one out of them.

dictionary extension

You can add words, which are not listed in default dictionary into your own custom one. Type zg(ood) on the relevant word.

zg

This operation simply adds that word into spellfile, e.g.) en.utf-8.add file under ~/.vim/spell directory.

$ cat en.utf-8.add
vim

If you would like to revert back, then type zw(rong).

zw

It seems that vim appends “/!” for that word in spell file.

$ cat en.utf-8.add
vim/!

For details of spell checking, please refer to ”:help spell”.

how to notify core file creation

Now you are able to configure system to yield core files for designated directory.

But there is no way to notice creation of core file (as apport has been disabled). Core files shall pile up silently behind the door. Repetition of core dump can easily consume disk space. You have to be careful and pay attention for such situation.

Let’s find out effective method to notify creation of core file.

inotify

inotify?

inotify (inode notify) is a Linux kernel subsystem to notice changes on file system. (quoted from wiki) You can enjoy this functionality via inotify-tools package.

Installation is quite easy (as always).

$ apt-cache search inotify-tools
inotify-tools - command-line programs providing a simple interface to inotify
$ sudo apt-get install inotify-tools
$ inotifywa<TAB>
inotifywait   inotifywatch

You can make use of these tools to watch tagger directory and do some action(s). For example,

#!/usr/bin/env bash

while inotifywait -e create,modify /tmp; do
    echo "Lupin, something happened under /tmp directory"
done

Touching file “hi” under /tmp directory will yield.

$ ./watch.sh
Setting up watches.
Watches established.
/tmp/ CREATE hi
Lupin, something happened under /tmp directory

In the above sample, inotifywait monitors following events:

  • CREATE
  • MODIFY

You can monitor other events like OPEN/CLOSE/DELETE/ATTRIB. And if you would like to configure inotify* to monitor directory recursively, then you can use -r option for that sake.

Fine.

libnotify-bin

Now we have a method of detection. Next item is means to notify you.

There is a tool called libnotify-bin, which sends message to notification daemon.

$ apt-cache search libnotify-bin
libnotify-bin - sends desktop notifications to a notification daemon (Utilities)
$ apt-get install libnotify-bin

As far as I checked, libnotify-bin has already been installed by default.

Sending a message will give you pop-up message on desktop.

$ for i in `seq 10 -1 0`
> do
> echo $i|festival --tts
> done && notify-send 'Ten Count! Knockout!'

You win!

automatic start upon login

It may not be appropriate to put here though, let’s make use of /etc/profile.d directory for automatic start up upon login.

Prepare a script, which launches inotifywait under the name of, say, watchCore.sh.

#!/usr/bin/env bash

while inotifywait -e create /var/cores; do
    notify-send -u critical "a new core file is created. Please check /var/cores directory"
done

Deploy another script under /etc/profile.d directory which launches former one.

#!/usr/bin/env bash

nohup <PATH>/watchCore.sh 1> /dev/null 2>&1 &

Please do not forget to run script in background. :-)

Voila!