qemu が Bad system call で落ちるので、おもむろに gdb を起動する2008年01月11日 15時05分07秒

何年かぶりに、qemu を使ってみることにした。

% qemu qemu.md
Bad system call

動いて少し経つと止まる。Bad system call と言われただけでは分からない。

そこで gdb を使い、原因を探ってみることにした。


% gdb qemu
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...(no debugging symbols found).
..
(gdb) run qemu.md
Starting program: /usr/local/bin/qemu qemu.md
(no debugging symbols found)...(no debugging symbols found)...(no debugging symb
ols found)...(no debugging symbols found)...(no debugging symbols found)...[New 
LWP 100145]
(no debugging symbols found)...(no debugging symbols found)...(no debugging symb
ols found)...(no debugging symbols found)...(no debugging symbols found)...(no d
ebugging symbols found)...(no debugging symbols found)...(no debugging symbols f
ound)...(no debugging symbols found)...(no debugging symbols found)...(no debugg
ing symbols found)...(no debugging symbols found)...(no debugging symbols found)
...(no debugging symbols found)...(no debugging symbols found)...(no debugging s
ymbols found)...[New Thread 0x88601100 (LWP 100145)]
(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSYS, Bad system call.
[Switching to Thread 0x88601100 (LWP 100145)]
0x8824651b in aio_read () from /lib/libc.so.7
(gdb)

デバッグシンボルが入っていないが、十分な情報は得られる。しかも、いきなり答えが明示されている。aio_read が Bad system call らしい。

そこで、


% man aio_read
AIO_READ(2)               FreeBSD System Calls Manual              AIO_READ(2)

NAME
     aio_read -- asynchronous read from a file (REALTIME)

LIBRARY
     Standard C Library (libc, -lc)

...

SEE ALSO
     aio_cancel(2), aio_error(2), aio_return(2), aio_suspend(2),
     aio_waitcomplete(2), aio_write(2), siginfo(3), aio(4)
...

で、aio.4 があることが分かる。

% man aio
AIO(4)                 FreeBSD Kernel Interfaces Manual                 AIO(4)

NAME
     aio -- asynchronous I/O

SYNOPSIS
     To link into the kernel:
     options VFS_AIO

     To load as a kernel loadable module:
           kldload aio

ということで、kldload aio をすれば解決することが分かった。

実は「qemu bad system call」 などで、検索をすると簡単に同じ答えは見つかる。問題があったときに、gdb で起動するだけで、解決できる問題もある。Bad system call が今回の例だ。