Difference between revisions of "Creating a Backtrace with GDB/ja"

From Lazarus wiki
Jump to navigationJump to search
Line 156: Line 156:
 
''Hint: At any time while your program is running you may press Ctrl+C (from the Terminal or MS-DOS prompt) to get a "(gdb) _" prompt''
 
''Hint: At any time while your program is running you may press Ctrl+C (from the Terminal or MS-DOS prompt) to get a "(gdb) _" prompt''
  
==Getting the Backtrace out of the terminal and into an email==
+
==端末の外部やメールからバックトレースを取得する==
 +
現在ターミナル(またはMS-DOSプロンプト)に出力されたバックトレースをメールに取り込むにはどうしたら良いでしょうか。それにはわたしの知る限り以下の二つの方法があります。
 +
# ターミナル(またはMS-DOSプロンプト)上でコピー&ペーストを行う。
 +
# 次のようにしてgdbの出力をリダイレクトする:
 +
gdb project1 > output.txt
 +
そしてこのファイルを開いてコピー&ペーストであなたのメールに取り込みます。 
 +
 
 
Currently we have made a backtrace and seen it in the Terminal(or MS-DOS prompt) but how do I get it into an email? There are two ways that I know of:
 
Currently we have made a backtrace and seen it in the Terminal(or MS-DOS prompt) but how do I get it into an email? There are two ways that I know of:
 
# Use the copy/paste functionality of your Terminal(or MS-DOS prompt)
 
# Use the copy/paste functionality of your Terminal(or MS-DOS prompt)
Line 162: Line 168:
 
  gdb project1 > output.txt
 
  gdb project1 > output.txt
 
Now you can open the file and copy/paste it into your email.
 
Now you can open the file and copy/paste it into your email.
 +
 +
警告: 2番目の方法はあなたが盲目的にタイプすることを必要とします。すなわち、あなたはスクリーンに何も表示されていない状態で、プログラムを走らせるために「run」をタイプし、バックトレースを作成するために「backtrace」をタイプしなければなりません。
  
 
Caveat: The second method requires that you type blindly. So you would type "run" to start the program and "backtrace" to make a backtrace like normal but nothing would show up on the screen.
 
Caveat: The second method requires that you type blindly. So you would type "run" to start the program and "backtrace" to make a backtrace like normal but nothing would show up on the screen.
 +
 +
例外: Linuxでは以下のコマンドを用いることによってコマンドを参照しながら行うことが可能です。
 +
touch output.txt & tail output.txt -f & gdb project1 > output.txt
  
 
Exception: On Linux you can get around not being able to see with the following command:
 
Exception: On Linux you can get around not being able to see with the following command:

Revision as of 17:00, 6 April 2006

Deutsch (de) English (en) 日本語 (ja) русский (ru)

なぜバックトレースを作るのか

バグレポートの作成

バグレポートを作るときに、バックトレースは非常に役立つことがあります。それらは間違いなく、バグがより速くフィックスされる可能性を高めるでしょう。

Backtraces can be very helpful when submitting bug reports. They will no doubt increase the chances of the bug getting fixed sooner.

自分で問題を発見するのを助ける

バックトレースはあなた自身のプログラムに関する問題を見つけやすくします。しばしば早い段階で、問題を暴露します。

A backtrace can really take the pain out of finding a problem with your own program. Often exposing the problem immediately.

まさしく明瞭な楽しみ!!

バックトレースを作ることは単純に楽しいです!

Okay this might be a stretch, but making backtraces is just plain fun!

もっとも真剣にあなたが、バックトレースを作成する他の理由を持っているのなら、ここにそれを加えてください。

Seriously though, if you can think of another reason to create a backtrace add it here.

バックトレースを作成する

GDB (Gnu DeBugger)を使ってバックトレースを作成する:

  1. あなたは GDBというプログラムを持っている必要があります。これは多くのUNIX系列のOSにインストールされていますし、もしあなたがLazarusやfpcのWindowsバージョンをダウンロードしてあるなら、GDBはすでに同時にインストールされているでしょう。Lazarus上で規定のデバッガを設定してください。メニューを Environment->Debugger Optionsと辿って、General Tabを見てください。Windows用のGDBなら、初期設定のパスはc:\lazarus\mingw\bin\gdb.exeとなっているはずです。
  2. You must have the program GDB. It is available on most *nix installation. If you downloaded the Windows version of fpc or Lazarus, GDB is already included in the installation. In Lazarus it is set up as the default debugger. Look in Environment->Debugger Options->General Tab. Default path for GDB on Windows is c:\lazarus\mingw\bin\gdb.exe.
  1. GDBは環境変数PATHに含まれている必要があります。もしそうでないなら、次の例を参考にコマンドプロンプトでタイプしてください。: set PATH=%PATH%;c:\lazarus\mingw\bin\
  2. GDB must be in the PATH environment variable. If it's not, from the command prompt type (example): set PATH=%PATH%;c:\lazarus\mingw\bin\
  1. プログラムのデバッグを行うためにはかならず、実行ファイルにデバッグ情報が含まれていなければなりません。もしあなたが"strip", "upx", "Xs" といった実行ファイル圧縮プログラムを使用していると、デバッグは行えません。
  2. The program you wish to debug MUST have debugging info included in the executable. If you have used "strip", "upx", compiled with "Xs" or used some other exe shrinker/compressor this won't work!


Windowsユーザー:

1. MS-DOSプロンプトを開いてください。

2. あなたの実行ファイルがあるドライブに移動します:

C: {press enter}

3. 実行ファイルがあるディレクトリに移動します:

cd \myprograms\Project1 {press enter}


1. Open a MS-DOS prompt

2. Change to the drive you have your exe on:

C: {press enter}

3. Change to the directory containing the exe:

cd \myprograms\Project1 {press enter}


Linux/BSDユーザー:

1. あなたのお気に入りの端末プログラムを起動してください

2. 実行ファイルのあるディレクトリに移動します:

cd $HOME/myprograms/project1 {press enter}

1. Open your favorite Terminal program

2. Change to the directory containing the exe:

cd $HOME/myprograms/project1 {press enter}

GDBを使ってあなたのプログラムをロードします:

gdb Project1.exe {press enter}

あなたは次のようなプロンプトを目にするはずです: You should see a prompt that looks something like this:

GNU gdb 6.3.50.20050217-cvs
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 "i686-pc-linux-gnu".
(gdb) _

例外が発生している場合GDBは停止しています Let GDB stop when an exception is raised

(gdb) break fpc_raiseexception {press enter}

それではあなたのプログラムを実行します: Now, run your program:

(gdb) run {press enter}

クラッシュするか、エラーが発生するまで、貴方のプログラムは通常どおり動作するでしょう。 Your program will run normally, until it crashes or causes an error.

あなたのプログラムが通常のエラー、「アクセス違反」や「ゼロ除算」によってクラッシュすると、プログラムは停止し、反応がなくなり、描画も行われなくなります。これはGDBがエラーを検出して、あなたがどうすればいいか指示してくれるのを待っているからです。

When your program crashes instead of the usual error "Access Violation" or "Division by Zero" your program will just seem to stop, not respond and not repaint itself. This is because gdb has caught the error and is waiting for you to tell it what to do.

MS-DOSウィンドウかターミナルに切替えてると、このようなスクリーンが表示されるはずです。

Switch over to your MS-DOS window or Terminal and you should have a screen something like this:

Program received signal SIGFPE, Arithmetic exception.
0x080733aa in TFORM1__BUTTON1CLICK (SENDER=0x403d8bd8, this=0x403d77d8) at unit1.pas:36
Current language:  auto; currently pascal
(gdb) _

バックトレースを作成するために: To create a backtrace now type:

backtrace {press enter}

もしくは or

bt {press enter}

というようにタイプしてください。

続いて、このようにスクリーンに表示されます。

You should now have a screen that looks something like this:

#0  0x080733aa in TFORM1__BUTTON1CLICK (SENDER=0x403d8bd8, this=0x403d77d8) at unit1.pas:36
#1  0x080ecd78 in TCONTROL__CLICK (this=0x403d8bd8) at control.inc:1768
#2  0x081274bd in TBUTTONCONTROL__CLICK (this=0x403d8bd8) at buttoncontrol.inc:57
#3  0x08129171 in TCUSTOMBUTTON__CLICK (this=0x403d8bd8) at buttons.inc:186
#4  0x08129198 in TCUSTOMBUTTON__WMDEFAULTCLICKED (MESSAGE={MSG = 1031, WPARAM = 
        136821192, LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, 
        WPARAMHI = 2087, LPARAMLO = 59548, LPARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at buttons.inc:198
#5  0x0805bbf7 in SYSTEM_TOBJECT_$__DISPATCH$formal ()
#6  0x080ec6e0 in TCONTROL__WNDPROC (THEMESSAGE={MSG = 1031, WPARAM = 136821192, 
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, 
        LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at control.inc:1447 
#7  0x080e4ed9 in TWINCONTROL__WNDPROC (MESSAGE={MSG = 1031, WPARAM = 136821192, 
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, 
        LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at wincontrol.inc:2154
#8  0x08161955 in DELIVERMESSAGE (TARGET=0x403d8bd8, AMESSAGE=void) at gtkproc.inc:3242
#9  0x0818897c in GTKWSBUTTON_CLICKED (AWIDGET=0x8285380, AINFO=0x40453794) at gtkwsbuttons.pp:112
... { Truncated for simplicity} Complete listing here
(gdb) _

注意: もしバックトレースが長い場合、あなたがプロンプト上でEnterキーを押せば次のページが表示されます。全てが表示されるまでそのように続きます。

Note: If the backtrace it too long you will be prompted to press enter for the next page of the backtrace until it is complete

表示された情報にはエラーが発生するまでのイベントのシークエンスが表示されています。 Understanding a Backtrace

The information displayed here has the sequence of events up to where the error occured. Understanding a Backtrace

GDB(とあなたのプログラム)から抜けるためには次のようにタイプしてください: To exit GDB (and your program) you may now type:

quit {press enter}

処理を続けるならば次のようにタイプしてください: Or to continue running until the next exception type:

cont {press enter}

ヒント:自分のプログラムを走らせているとき、すばやくGDBに処理を移すには、Ctrl+CをターミナルやMS-DOSプロンプト上で押してください

Hint: At any time while your program is running you may press Ctrl+C (from the Terminal or MS-DOS prompt) to get a "(gdb) _" prompt

端末の外部やメールからバックトレースを取得する

現在ターミナル(またはMS-DOSプロンプト)に出力されたバックトレースをメールに取り込むにはどうしたら良いでしょうか。それにはわたしの知る限り以下の二つの方法があります。

  1. ターミナル(またはMS-DOSプロンプト)上でコピー&ペーストを行う。
  2. 次のようにしてgdbの出力をリダイレクトする:
gdb project1 > output.txt

そしてこのファイルを開いてコピー&ペーストであなたのメールに取り込みます。 

Currently we have made a backtrace and seen it in the Terminal(or MS-DOS prompt) but how do I get it into an email? There are two ways that I know of:

  1. Use the copy/paste functionality of your Terminal(or MS-DOS prompt)
  2. Redirect the output of gdb to a file like so:
gdb project1 > output.txt

Now you can open the file and copy/paste it into your email.

警告: 2番目の方法はあなたが盲目的にタイプすることを必要とします。すなわち、あなたはスクリーンに何も表示されていない状態で、プログラムを走らせるために「run」をタイプし、バックトレースを作成するために「backtrace」をタイプしなければなりません。

Caveat: The second method requires that you type blindly. So you would type "run" to start the program and "backtrace" to make a backtrace like normal but nothing would show up on the screen.

例外: Linuxでは以下のコマンドを用いることによってコマンドを参照しながら行うことが可能です。

touch output.txt & tail output.txt -f & gdb project1 > output.txt

Exception: On Linux you can get around not being able to see with the following command:

touch output.txt & tail output.txt -f & gdb project1 > output.txt

Understanding a Backtrace

TODO: Write Me :)

(gdb) bt
#0  0x080733aa in TFORM1__BUTTON1CLICK (SENDER=0x403d8bd8, this=0x403d77d8) at unit1.pas:36
#1  0x080ecd78 in TCONTROL__CLICK (this=0x403d8bd8) at control.inc:1768
#2  0x081274bd in TBUTTONCONTROL__CLICK (this=0x403d8bd8) at buttoncontrol.inc:57
#3  0x08129171 in TCUSTOMBUTTON__CLICK (this=0x403d8bd8) at buttons.inc:186
#4  0x08129198 in TCUSTOMBUTTON__WMDEFAULTCLICKED (MESSAGE={MSG = 1031, WPARAM = 136821192, 
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, 
        LPARAMLO = 59548, LPARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at buttons.inc:198
#5  0x0805bbf7 in SYSTEM_TOBJECT_$__DISPATCH$formal ()
#6  0x080ec6e0 in TCONTROL__WNDPROC (THEMESSAGE={MSG = 1031, WPARAM = 136821192, 
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, 
        LPARAMLO = 59548, LPARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at control.inc:1447
#7  0x080e4ed9 in TWINCONTROL__WNDPROC (MESSAGE={MSG = 1031, WPARAM = 136821192, 
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, 
        LPARAMLO = 59548, LPARAMHI = 49151, RESULTLO = 27682, RESULTHI =   16416},
        this=0x403d8bd8) at wincontrol.inc:2154
#8  0x08161955 in DELIVERMESSAGE (TARGET=0x403d8bd8, AMESSAGE=void) at gtkproc.inc:3242
#9  0x0818897c in GTKWSBUTTON_CLICKED (AWIDGET=0x8285380, AINFO=0x40453794) at gtkwsbuttons.pp:112
#10 0x401d7877 in gtk_marshal_NONE__NONE () from /usr/lib/libgtk-1.2.so.0
#11 0x40206e5a in gtk_signal_remove_emission_hook () from /usr/lib/libgtk-1.2.so.0
#12 0x4020616a in gtk_signal_set_funcs () from /usr/lib/libgtk-1.2.so.0
#13 0x40204234 in gtk_signal_emit () from /usr/lib/libgtk-1.2.so.0
#14 0x40176e1c in gtk_button_clicked () from /usr/lib/libgtk-1.2.so.0
#15 0x4017838a in gtk_button_get_relief () from /usr/lib/libgtk-1.2.so.0
#16 0x401d7877 in gtk_marshal_NONE__NONE () from /usr/lib/libgtk-1.2.so.0
#17 0x4020607b in gtk_signal_set_funcs () from /usr/lib/libgtk-1.2.so.0
#18 0x40204234 in gtk_signal_emit () from /usr/lib/libgtk-1.2.so.0
#19 0x40176d60 in gtk_button_released () from /usr/lib/libgtk-1.2.so.0
#20 0x40177d26 in gtk_button_get_relief () from /usr/lib/libgtk-1.2.so.0
#21 0x401d764d in gtk_marshal_BOOL__POINTER () from /usr/lib/libgtk-1.2.so.0
#22 0x4020619f in gtk_signal_set_funcs () from /usr/lib/libgtk-1.2.so.0
#23 0x40204234 in gtk_signal_emit () from /usr/lib/libgtk-1.2.so.0
#24 0x40239fd9 in gtk_widget_event () from /usr/lib/libgtk-1.2.so.0
#25 0x401d74d0 in gtk_propagate_event () from /usr/lib/libgtk-1.2.so.0
#26 0x401d65c1 in gtk_main_do_event () from /usr/lib/libgtk-1.2.so.0
#27 0x40065b44 in gdk_wm_protocols_filter () from /usr/lib/libgdk-1.2.so.0
#28 0x4003de75 in g_get_current_time () from /usr/lib/libglib-1.2.so.0
#29 0x4003e32c in g_get_current_time () from /usr/lib/libglib-1.2.so.0
#30 0x4003e4f5 in g_main_iteration () from /usr/lib/libglib-1.2.so.0
#31 0x401d6388 in gtk_main_iteration_do () from /usr/lib/libgtk-1.2.so.0
#32 0x080b4d26 in TGTKWIDGETSET__WAITMESSAGE (this=0x40473014) at gtkobject.inc:1427
#33 0x08070073 in TAPPLICATION__IDLE (this=0x4045b014) at application.inc:319
#34 0x08070ffb in TAPPLICATION__HANDLEMESSAGE (this=0x4045b014) at application.inc:827
#35 0x08071380 in RUNMESSAGE (parentfp=0xbffff5a4) at application.inc:933
#36 0x080712d7 in TAPPLICATION__RUN (this=0x4045b014) at application.inc:944
#37 0x080531c3 in main () at project1.lpr:13
(gdb)

This Backtrace was produced using this code:

30. procedure TForm1.Button1Click(Sender: TObject);
31. var
32.  X, Y, Z: Integer;
33. begin
34.   X := 0;
35.   Y := 0;
36.   Z := X div Y;
37. end;