Open Source WEB

デバッグオプションを付けてmakeしたので、 デバッガで直接ソースが調べられるのである。 変数の値とか、ソースを1行ごとに追いかけて行くこともできる。

ここでは、GDBというデバッガを用いる。 Linux上で、 C, C++ の標準デバッガである。 他の言語でも大丈夫なのだが、今は関係ないので省略。

さて、実行は、以下のように行なう。

gdbの起動:

$ gdb [実行ファイル]

実行ファイルを指定しないで起動すると、

shell$ gdb
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 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-redhat-linux-gnu".
(gdb)

となり、プロンプトが (gdb) と表示され、 GDBのコマンド入力待ち状態であることが分かる。

分らないときには、h(help) と入力してみよう。

(gdb) h
List of classes of commands:
 
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands
 
Type "help" followed by a class name for a list of commands in that class.
Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.
(gdb)

ヘルプなんだが、これでは慣れないと分からないだろう。

大切なのは、終了する方法である。

CTRL-C を押せば抜けられるかと思ったら、

(gdb) Quit
(gdb)

と表示されてしまった。 exit で抜けられるかと思ったが、

(gdb) exit
Undefined command: "exit".  Try "help".
(gdb)

となり、そんなコマンドはないらしい。 では、q (quit) くらいしか考えられないということで試したら、

(gdb) q
shell$ 

目出度く抜けられた。

quit   gdbを終了する


mysqlクライアント実行プログラムをgdbから起動する。

mysql実行プログラムを gdb の引数に指定してみよう。 普通は、このように、デバッグオプション付でコンパイルされた 実行ファイルを指定する。

$ gdb mysql
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 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-redhat-linux-gnu"...
(gdb)

これだけだと、実行ファイルを指定しなかったときと何も変っていないみたいだ。

まず、l(list) コマンドを入力してみよう。 とりあえず、ここでは、l だけを入力してみよう。

(gdb) l
339
340     int main(int argc,char *argv[])
341     {
342       char buff[80];
343       char *defaults, *extra_defaults, *group_suffix;
344       char *emb_argv[4];
345       int emb_argc;
346
347       /* Get --defaults-xxx args for mysql_server_init() */
348       emb_argc= get_defaults_options(argc, argv, &defaults, 
(gdb)

ソースプログラムのmain()関数の最初の方が見えているようだ。 今日のところは、ソースプログラムが見えたところまでとしよう。


GDBのマニュアル

ここでは、GDBの詳しい説明はしない。 GDBのマニュアルの翻訳、やさしい使い方などは、 インターネット上に多数用意されているので、適当に探されたし。

私的 GNU マニュアル翻訳プロジェクトGDB 4.18 が参考になるかも。


戻る:kinput2からの入力を可能にするconfigureオプション

次へ:print_table_data()にブレークポイントを設定


フィードバック:

Name:
Comment:

There is no comment.

このサイトは、 IPA の「平成15年度オープンソフトウエア活用基盤整備事業」 の委託事業として開発されたKahuaで試験的に運用しております。

Copyright (c) 2004-2007 株式会社タイムインターメディア About Us