JP2010287101A - Software debugging device and method - Google Patents
Software debugging device and method Download PDFInfo
- Publication number
- JP2010287101A JP2010287101A JP2009141271A JP2009141271A JP2010287101A JP 2010287101 A JP2010287101 A JP 2010287101A JP 2009141271 A JP2009141271 A JP 2009141271A JP 2009141271 A JP2009141271 A JP 2009141271A JP 2010287101 A JP2010287101 A JP 2010287101A
- Authority
- JP
- Japan
- Prior art keywords
- function
- program
- call
- execution
- instruction
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Debugging And Monitoring (AREA)
Abstract
Description
本発明は、ソフトウェアのデバッグにおいて高級言語レベルで実行された関数の履歴を取得するソフトウエアデバッグ装置及び方法に関するものである。 The present invention relates to a software debugging apparatus and method for acquiring a history of functions executed at a high-level language level in software debugging.
ソフトウェアのデバッグ中に、プログラム実行中の任意の時点で処理を実行している関数がどの関数から呼ばれたものなのかを知るために、コールスタックの機能が用いられる。コールスタックは、プログラムの実行開始から現在実行している関数が呼び出されるまでの関数呼び出しの階層を表示する機能である。 During software debugging, the function of the call stack is used to know from which function a function executing processing is called at an arbitrary point during program execution. The call stack is a function that displays a hierarchy of function calls from the start of program execution until the currently executing function is called.
例えば、C言語のプログラムにおいて、図1に示すように3つの関数main、func1、func2が定義されている場合に、プログラム実行時には、main→func1→func2の順に関数が呼び出される。 For example, in a C language program, when three functions main, func1, and func2 are defined as shown in FIG. 1, the functions are called in order of main → func1 → func2 when the program is executed.
このプログラムをソースコードレベルでデバッグする際、func2の実行中にデバッガのコールスタックウィンドウを開くと、デバッガは、図2に示すようにfunc2が呼び出されるまでの関数呼び出しの階層を表示し、現在実行中の関数を例えば、矢印でマークして表示する。 When debugging this program at the source code level, if the debugger call stack window is opened while func2 is running, the debugger displays the hierarchy of function calls until func2 is called, as shown in Figure 2, and is currently running. The function inside is marked with an arrow and displayed, for example.
一般に、このようなコールスタックの情報を表示するためには、デバッガはスタックの内容を解析する必要がある。例として、次に、図1に示したようなプログラムの実行におけるスタックの動作とその解析方法を説明する。 In general, in order to display such call stack information, the debugger needs to analyze the contents of the stack. As an example, the stack operation and its analysis method in the execution of the program as shown in FIG.
先ず、図1に示したようなソースコードに対して、コンパイラは図3に示すようなアセンブリコードを出力する。このアセンブリコードにおいて、bl命令が関数呼び出しを実行する命令である。この命令により、関数の先頭アドレスへの分岐と、復帰アドレスのリンクレジスタlrへの設定とが行われる。mainとfunc1の先頭では"push lr"の命令があるが、これは、その後に実行されるbl命令によりリンクレジスタlrが上書きされるため、その内容をスタックに退避させる命令である。また、この命令の後、各関数の処理に入る前に、各関数が使用するローカル変数用の領域とワークレジスタ退避用の領域がスタックに確保される。このように、各関数が使用するためにスタック内に確保した領域をスタックフレームと呼ぶ。各関数のスタックフレームのサイズは、コンパイラがアセンブリコードを生成するときに一緒に出力されるデバッグ情報から知ることができる。mainからfunc1→func2の順に関数が呼び出され、func2内の処理を実行途中の状態ではスタックの内容は図4に示すようになる。 First, the compiler outputs an assembly code as shown in FIG. 3 for the source code as shown in FIG. In this assembly code, the bl instruction is an instruction for executing a function call. By this instruction, branching to the head address of the function and setting of the return address in the link register lr are performed. There is a “push lr” instruction at the beginning of main and func1, but this is an instruction to save the contents of the link register lr on the stack because the link register lr is overwritten by the bl instruction executed thereafter. Also, after this instruction, before entering the processing of each function, an area for local variables and an area for saving work registers used by each function are secured in the stack. Thus, an area secured in the stack for use by each function is called a stack frame. The stack frame size of each function can be known from debug information output together when the compiler generates assembly code. The functions are called in the order from main to func1 → func2, and the contents of the stack are as shown in FIG.
コールスタックを表示する場合には、デバッガはプログラムカウンタ(PC)の値を読み出し、その内容がfunc2の関数内のアドレスであることから、func2の実行中であることを知ることができる。次に、コンパイラが出力したfunc2のデバッグ情報から、func2の復帰アドレスがリンクレジスタlrに格納されていることが分かるので、lrからその復帰アドレスを読み出す。この復帰アドレスがどの関数内のアドレスであるかを調べることにより、func2がfunc1から呼び出されていることを知ることができる。 When displaying the call stack, the debugger reads the value of the program counter (PC), and since the content is an address in the function of func2, it can know that func2 is being executed. Next, it can be seen from the debug information of func2 output by the compiler that the return address of func2 is stored in the link register lr, so the return address is read from lr. By examining which function the return address is in, it can be known that func2 is called from func1.
更に、func1のデバッグ情報を調べることにより、func1の復帰アドレスはスタックに退避されていることが分かる。退避されているスタック内のアドレスは、現在のスタックポインタが指すアドレスからfunc1及びfunc2のスタックフレームのサイズを差し引くことにより算出することができる。この算出したアドレスからfunc1の復帰アドレスを読み出すと、そのアドレスがmain関数内のアドレスであることが分かり、func1がmainから呼び出されていることを知ることができる。このようにして、デバッガは図2に示したようなコールスタックを表示する。 Further, by examining the debug information of func1, it can be seen that the return address of func1 is saved in the stack. The saved address in the stack can be calculated by subtracting the stack frame sizes of func1 and func2 from the address pointed to by the current stack pointer. When the return address of func1 is read from the calculated address, it can be seen that the address is an address in the main function, and that func1 is called from main. In this way, the debugger displays the call stack as shown in FIG.
しかしながら、上記のような方法では、コンパイラにより出力アセンブリコードが最適化されるときに、正しくコールスタックを表示できない場合がある。 However, in the above method, when the output assembly code is optimized by the compiler, the call stack may not be displayed correctly.
正しくコールスタックを表示できない場合の例として、コンパイラによる関数の「末尾呼び出しの最適化」が挙げられる。 An example of a case where the call stack cannot be displayed correctly is "optimization of tail call" of a function by a compiler.
末尾呼び出しの最適化とは、図1の中の関数func1のように、関数の末尾で関数func2を呼び出している場合に実施される最適化である。このfunc2の呼び出しは、func1の末尾で実施されているため、func2の処理を終えてfunc1に戻ってきても、その後、mainに戻るだけである。そこで、コンパイラは、func2からfunc1に戻らず直接mainに戻るように、func2の呼び出し前にfunc1のスタックフレームを破棄し、func2の呼び出しを行う。このfunc2の呼び出しを実行するための分岐命令は、戻り番地をリンクレジスタlrに設定しない分岐命令(b命令)が使用される。すなわち、リンクレジスタlrには、mainからfunc1が呼び出されたときに設定されたリンクレジスタlrの値が格納されたままになる。func2から戻るときは、このリンクレジスタlrの値が戻りアドレスとして使用されるため、func1には戻らず直接mainに戻ることができ、func1に戻る分の処理時間のオーバヘッドを減らすことができる。この末尾呼び出しの最適化が実施された場合のアセンブリコードは図5に示されている。 The tail call optimization is an optimization performed when the function func2 is called at the end of the function, like the function func1 in FIG. Since the call to func2 is performed at the end of func1, even if the process of func2 is finished and the process returns to func1, it only returns to main after that. Therefore, the compiler discards the stack frame of func1 and calls func2 before calling func2, so that it returns directly to main without returning from func2 to func1. A branch instruction (b instruction) that does not set the return address in the link register lr is used as the branch instruction for executing the call to func2. That is, the value of the link register lr set when the func1 is called from the main remains stored in the link register lr. When returning from func2, the value of this link register lr is used as a return address, so that it is possible to return directly to main without returning to func1, thereby reducing the processing time overhead for returning to func1. The assembly code when this tail call optimization is performed is shown in FIG.
図5に示すようなアセンブリコードにおいては、func2を実行中のスタックの内容は図6に示すようになる。 In the assembly code as shown in FIG. 5, the contents of the stack that is executing func2 are as shown in FIG.
この状態においてコールスタックを表示する場合には、先ず、デバッガはプログラムカウンタ(PC)の値を読み出し、その内容がfunc2の関数内のアドレスであることから、func2の実行中であることを知ることができる。次に、コンパイラが出力したfunc2のデバッグ情報から、func2の復帰アドレスがリンクレジスタlrに格納されていることが分かるので、リンクレジスタlrからその復帰アドレスを読み出す。この復帰アドレスがどの関数内のアドレスであるかを調べることにより、呼び出し元の関数を知ることができるが、図5に示したように最適化が実施されている場合には、func2を実行している状態でリンクレジスタlrに格納されているのはmain関数内のアドレスである。従って、このような場合は、デバッガはfunc2がmainから呼び出されたものを判定してしまうため、コールスタックにはmainからfunc2の呼び出しまでの間にfunc1が呼び出されていることの情報が出力されなくなるという問題が発生する。このときのコールスタックの表示は図7に示すようになる。 When displaying the call stack in this state, the debugger first reads the value of the program counter (PC) and knows that func2 is being executed because its contents are the address in the function of func2. Can do. Next, it can be seen from the debug information of func2 output by the compiler that the return address of func2 is stored in the link register lr, and the return address is read from the link register lr. By examining which function the return address is in, it is possible to know the function of the caller. However, when optimization is performed as shown in FIG. 5, the function func2 is executed. In this state, the address stored in the link register lr is the address in the main function. Therefore, in such a case, since the debugger determines that func2 is called from main, information that func1 is called is output to the call stack between main and func2 calls. The problem of disappearing occurs. The call stack display at this time is as shown in FIG.
このように、コンパイラの末尾呼び出しの最適化が行われた場合、実際にはfunc2はfunc1から呼び出されたものであるにもかかわらず、その情報が欠落した誤った表示となるため、コールスタックを使ってデバッグを行う場合はデバッグの作業の効率を低下させる要因となる。 In this way, when optimization of the tail call of the compiler is performed, even though func2 is actually called from func1, the information is missing, so the call stack is changed. If debugging is performed, it becomes a factor of reducing the efficiency of debugging work.
コンパイラによる最適化が実施された場合に正しくコールスタックを表示させる方法としては、特許文献1に挙げられている従来の方法がある。この従来の方法は、全ての関数の先頭アドレスと最終アドレスとにソフトウェアブレークポイントを設定し、それぞれのブレークポイントでブレークしたときに関数の情報を取得するという方法である。
As a method of displaying a call stack correctly when optimization by a compiler is performed, there is a conventional method described in
しかしながら、この従来の方法では、プログラム実行中に関数呼び出しが発生する度にブレークして実行が中断されるため、デバッグ中の実行においてリアルタイム性が損なわれるという別の問題がある。 However, this conventional method has another problem that the real-time property is impaired during execution during debugging because the execution is interrupted by breaking each time a function call occurs during program execution.
そこで、本発明の目的は、ソフトウェアのデバッグ中にブレークポイントを使用して関数呼び出し毎に実行を中断することなく、末尾呼び出しの最適化が行われた場合のコールスタックを正しく表示することができるソフトウエアデバッグ装置及び方法を提供することである。 Accordingly, an object of the present invention is to correctly display a call stack when tail call optimization is performed without interrupting execution for each function call using a breakpoint during software debugging. A software debugging apparatus and method is provided.
本願の請求項1に係る発明のソフトウエアデバッグ装置は、ソースプログラムをコンパイル処理してデバッグ情報と共に生成された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ装置であって、前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成手段と、前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行手段と、前記プログラム実行手段による実行命令が分岐命令である場合にその分岐命令のプログラムコードをオペラントを含めてトレースメモリに記憶させるトレース手段と、前記トレースメモリのオペラントと前記シンボルテーブルのアドレス情報との対応関係に応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示手段と、を備えることを特徴としている。
A software debugging device according to
本願の請求項4に係る発明のソフトウエアデバッグ方法は、ソースプログラムをコンパイル処理してデバッグ情報と共に生成された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ方法であって、前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成ステップと、前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行ステップと、前記プログラム実行ステップによる実行命令が分岐命令である場合にその分岐命令のプログラムコードをオペラントを含めてトレースメモリに記憶させるトレース手段と、前記トレースメモリのオペラントと前記シンボルテーブルのアドレス情報との対応関係に応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示ステップと、を備えることを特徴としている。
The software debugging method of the invention according to
本願の請求項5に係る発明のソフトウエアデバッグ装置は、ソースプログラムをコンパイル処理してデバッグ情報と共に生成され、関数呼び出しの分岐命令の直前に、関数呼び出しがあることを表す第1擬似命令が配置され、その関数呼び出しのうち末尾呼び出しの最適化が適用された場合には前記第1擬似命令に代えて第2擬似命令が配置された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ装置であって、前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成手段と、前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行手段と、前記ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーを作成する関数コールツリー作成手段と、前記実行イメージプログラム中の前記第1擬似命令及び前記第2擬似命令、前記関数コールツリー並び前記シンボルテーブルに基づいて前記末尾呼び出しの最適化が適用された関数、その復帰元関数及び戻りアドレスからなる戻りアドレステーブルを作成する戻りアドレステーブル作成手段と、前記プログラム実行手段による命令実行によりリンクレジスタに格納された戻りアドレスと前記戻りアドレステーブルとに応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示手段と、を備えることを特徴としている。
In the software debugging device according to
本願の請求項9に係る発明のソフトウエアデバッグ方法は、ソースプログラムをコンパイル処理してデバッグ情報と共に生成され、関数呼び出しの分岐命令の直前に、関数呼び出しがあることを表す第1擬似命令が配置され、その関数呼び出しのうち末尾呼び出しの最適化が適用された場合には前記第1擬似命令に代えて第2擬似命令が配置された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ方法であって、前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成ステップと、前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行ステップと、前記ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーを作成する関数コールツリー作成ステップと、前記実行イメージプログラム中の前記第1擬似命令及び前記第2擬似命令、前記関数コールツリー並び前記シンボルテーブルに基づいて前記末尾呼び出しの最適化が適用された関数、その復帰元関数及び戻りアドレスからなる戻りアドレステーブルを作成する戻りアドレステーブル作成ステップと、前記プログラム実行ステップによる命令実行によりリンクレジスタに格納された戻りアドレスと前記戻りアドレステーブルとに応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示ステップと、を備えることを特徴としている。 In the software debugging method of the invention according to claim 9 of the present application, a first pseudo-instruction indicating that there is a function call is placed immediately before a branch instruction of a function call, which is generated together with debug information by compiling a source program. And a software debugging method for debugging an execution image program in which a second pseudo instruction is arranged instead of the first pseudo instruction when tail call optimization is applied among the function calls. A symbol table creation step for creating function name and address information for each function in the execution image program as a symbol table in accordance with the debug information, and program execution for executing program code instructions in the order of the program code of the execution image program Step and the source program A function call tree creating step for creating a function call tree indicating a function calling relationship by performing static analysis, the first pseudo instruction and the second pseudo instruction in the execution image program, and the function call tree array A return address table creation step for creating a return address table composed of a function to which the tail call optimization is applied based on a symbol table, a return source function and a return address thereof, and an instruction execution by the program execution step. A call stack display step of creating and displaying a call stack indicating a hierarchy of function calls according to the stored return address and the return address table.
本願の請求項1に係る発明のソフトウエアデバッグ装置及び請求項5に係る発明のソフトウエアデバッグ方法によれば、プログラムコードの実行命令が分岐命令である場合にその分岐命令のプログラムコードをオペラントを含めてトレースメモリに記憶させるので、トレースメモリに格納して分岐トレースの機能を利用することにより、コンパイラによって末尾呼び出し最適化が行われた場合にもデバッグ中に関数呼び出し毎に実行を中断することなく、コールスタックを正しく表示することができる。
According to the software debugging apparatus of the invention according to
本願の請求項5に係る発明のソフトウエアデバッグ装置及び請求項9に係る発明のソフトウエアデバッグ方法によれば、ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーが作成され、また、実行イメージプログラム中の第1擬似命令及び前記第2擬似命令、関数コールツリー並びシンボルテーブルに基づいて末尾呼び出しの最適化が適用された関数、その復帰元関数及び戻りアドレスからなる戻りアドレステーブルが作成されるので、リンクレジスタに格納された戻りアドレスとシンボルテーブル又は戻りアドレステーブルとを用いることにより、コンパイラによって末尾呼び出し最適化が行われた場合にもデバッグ中に関数呼び出し毎に実行を中断することなく、コールスタックを正しく表示することができる。
According to the software debugging device of the invention according to
以下、本発明の実施例を図面を参照しつつ詳細に説明する。 Hereinafter, embodiments of the present invention will be described in detail with reference to the drawings.
図8は、本発明の第1の実施例としてソフトウエアデバッグ装置の構成を示している。ソフトウエアデバッグ装置は、デバッガ11とデバッグターゲット12とを備えている。デバッガ11はデバッガ制御部21、シンボルテーブル22及びコールスタック表示部23を備えている。
FIG. 8 shows the configuration of a software debugging apparatus as a first embodiment of the present invention. The software debug device includes a
デバッガ制御部21はシンボルテーブル22及びコールスタック表示部23の各々接続されている。シンボルテーブル22はメモリからなる。シンボルテーブル作成手段はデバッガ制御部21及びシンボルテーブル22からなる。
The
また、デバッガ制御部21は後述の実行イメージプログラム(実行形式プログラム)46をデバッグ情報47と共に読み出して実行イメージプログラム46からプログラムコードを抽出し、そのプログラムコードをデバッグターゲット12に出力する。また、デバッガ制御部21は読み出したデバッグ情報47から関数を抽出し、関数の名前、関数の開始アドレス及び関数に含まれる命令コードの合計サイズをシンボルテーブル22に格納(記憶)させる。コールスタック表示部23はデバッガ制御部21の指令に応じて図示しない表示器にコールスタックを表示する。コールスタック表示手段はデバッガ制御部21及びコールスタック表示部23からなる。
In addition, the
デバッグターゲット12はデバッグインターフェース31、プログラムメモリ32、プログラム実行部33及びトレースメモリ34を備えている。デバッグインターフェース31はプログラムメモリ32、プログラム実行部33及びトレースメモリ34の各々に接続され、プログラム実行部33はプログラムメモリ32及びトレースメモリ34各々に接続されている。
The
デバッグインターフェース31はデバッガ11のデバッガ制御部21とのプログラムコード等の情報の入出力のために設けられている。
The
プログラムメモリ32には上記のプログラムコードが供給順に格納される。プログラム実行部33はプログラム実行手段であり、プログラムメモリ32に格納されたプログラムコードの命令を順に実行する。また、プログラム実行部33はプログラム実行中に命令が分岐命令であるときに、実行した分岐命令の命令コードをオペランドの情報を含めてトレースメモリ34に格納するトレース手段を含んでいる。
The
かかるソフトウエアデバッグ装置においては、コールスタックの情報を表示する際に、ターゲットの分岐トレースの情報を利用する。分岐トレースとは、プログラム実行部33がプログラム実行中に分岐命令を実行した時に、実行した分岐命令の命令コードを実行した順番にトレースメモリ34に格納する機能である。この機能により、トレースメモリ34には、実行した分岐命令の履歴データが格納されることになる。
In such a software debugging apparatus, information on a target branch trace is used when displaying call stack information. The branch trace is a function of storing the instruction codes of the executed branch instructions in the
デバッガ制御部21は、実行イメージプログラム46をデバッグ情報47と共に取り込んだときに、デバッグ情報47に含まれるシンボルテーブル22を取得し、シンボルテーブル22から実行イメージプログラム46に含まれる関数の名前とアドレスとの対応関係を検出する。従って、トレースメモリ34から取得した各分岐命令のオペランドから分岐先アドレスを取得し、そのアドレスで特定される関数がシンボルテーブル22に含まれていれば、その分岐命令は関数呼び出しであると判断できる。そして、トレースメモリ34から関数呼び出しに相当する分岐命令を検出すれば、それは関数の呼び出しの履歴として解釈することができ、その履歴情報から表示すべきコールスタックの情報を生成する。コールスタックの情報はコールスタック表示部23に供給されて表示される。
The
次に、かかるソフトウエアデバッグ装置において、末尾呼び出しの最適化が実施されたプログラムをデバッグする場合について説明する。 Next, a description will be given of a case in which a program in which tail call optimization is performed is debugged in such a software debugging apparatus.
先ず、Cソースファイル(Cソースプログラム)41からコード生成ツール42のコンパイラ43、アセンブラ44及びリンカ45により実行イメージプログラム46が生成され、その実行イメージプログラム46はデバッグ情報47と共に格納されている。なお、コンパイラ43はCソースファイル41からアセンブリブログラムを生成し、アセンブラ44はそのアセンブリプログラムをオブジェクトファイルに変換し、リンカ45はそのアセンブラ44によって得られたオブジェクトファイルに基づいて実行イメージプログラム46を生成する。これらのコード生成ツール42においてはデバッグ情報47が生成されるようにいわゆるオプションが付けられる。
First, an
デバッガ11のデバッガ制御部21は実行イメージプログラム46からプログラムコードを抽出する。抽出されたプログラムコードは順にデバッグターゲット12のデバッグインターフェース部31を介して、プログラムメモリ32に格納される。プログラムメモリ32に格納されたプログラムコード群をプログラムと称す。また、同時にデバッガ制御部21は実行イメージプログラム46のデバッグ情報47から関数を抽出して、図9に示すような関数のシンボルテーブル22を形成する。このシンボルテーブル22には、関数の名前と、関数の開始アドレス及び関数に含まれる命令コードの合計サイズの情報が含まれている。
The
プログラムメモリ32にプログラムが格納された後、デバッグインターフェース部31を介して供給されるデバッガ制御部21の指令に応じて、プログラム実行部33によりそのプログラム中の命令が順に実行される。プログラム実行部33は、実行した命令が分岐命令だった場合に、同時にその命令コードをオペランドの情報を含めてトレースメモリ34に格納する。例えば、func2の実行中にデバッガ11への操作に応じてプログラムの実行が中断(ブレーク)したときのトレースメモリ34の内容は図10に示すようになる。
After the program is stored in the
デバッガ制御部21は、先ず、トレースメモリ34の内容を取得し、図9のシンボルテーブル22のアドレスの値が、トレースメモリ34内の分岐命令のオペランドに使用されていないか調査する。すなわち、トレースメモリ34のオペラントとシンボルテーブル22のアドレス情報との対応関係を検出することが行われる。図9及び図10の例の場合においては、この調査の結果、デバッガ制御部21は、図10のIndex2の分岐命令が関数mainの呼び出しであり、Index3の分岐命令が関数func1の呼び出しであり、更に、Index4の分岐命令が関数func2の呼び出しであることを検出することができる。Index1の分岐命令は、そのオペランドのアドレスがシンボルテーブル22のアドレスの値と一致するものがないため、関数呼び出しではないと判断することができる。デバッガ制御部21は、関数呼び出しであると判断できた分岐命令のIndexの大きい順に分岐先の関数名を並べて表示することにより、コールスタック表示部23には図2に示したようにコールスタックが表示される。
First, the
次に、デバッガ動作を続けて実行させて、func2からmainまで戻った時点でプログラム実行をブレークさせた場合には、トレースメモリ34の内容は図11に示すようになったとする。
Next, when the debugger operation is continuously executed and the program execution is broken when returning from func2 to main, it is assumed that the contents of the
トレースメモリ34のIndex5には、関数func2からの復帰となる分岐命令であるrt命令と、その分岐先アドレスの情報が格納される。デバッガ制御部21は、トレースメモリ34の中に関数からの復帰命令を見つけると、その復帰先のアドレスがどの関数の範囲内にあるかを調べるため、シンボルテーブル22を調査する。図11の例では復帰先アドレスが0x1020であり、図9の情報からmain関数の先頭アドレス0x1000からそのサイズ0x40進んだアドレスまでの範囲に含まれるため、main関数内のアドレスであることが分かる。
In the
このとき、コールスタックを表示する場合には、デバッガ制御部21は前述と同様に、トレースメモリ34の内容を調べ、関数呼び出しであると判断できた分岐命令のIndexの大きい順に分岐先の関数名を並べて表示しようとする。しかしながら、Index5の復帰命令により現在main関数に戻ってきていることが分かるので、mainの呼び出しを表すIndex2からIndex5の間の関数呼び出し、(すなわちIndex3のfunc1とIndex4のfunc2)は、既にその関数の実行が終了しているとみなすことができる。よって、コールスタック表示部23に表示するコールスタックは、トレースメモリのIndex3及びIndex4に相当する関数を省いた図12に示すようにmain関数のみの表示となる。
At this time, when displaying the call stack, the
以上のように、第1の実施例によれば、デバッグターゲット12に付加された、分岐命令のみをトレースメモリ34に格納する分岐トレースの機能を利用することにより、コンパイラ43の末尾呼び出し最適化が行われた場合にも正しくコールスタックを表示させることができる。また、コールスタックの表示に必要な関数呼び出しの履歴情報を取得するために関数呼び出し毎にプログラムをブレークさせることがないため、プログラム実行中のリアルタイム性を損なうことがない。更に、分岐トレース機能は、通常のトレース機能に比べてトレースメモリ34に格納する情報は分岐命令のみであるため、トレースメモリ34の容量も小さくて済むため、大きなコスト増加にはならないという利点がある。
As described above, according to the first embodiment, the tail call optimization of the
図13は本発明の第2の実施例としてソフトウエアデバッグ装置の構成を示している。ソフトウエアデバッグ装置は、図8の第1の実施例の装置と同様に、デバッガ11とデバッグターゲット12とを備えている。デバッガ11はデバッガ制御部21、シンボルテーブル22及びコールスタック表示部23の他に、戻りアドレステーブル24を備えている。戻りアドレステーブル24には戻りアドレスが格納される。デバッガ制御部21及び戻りアドレステーブル24が戻りアドレステーブル作成手段を構成している。
FIG. 13 shows the configuration of a software debugging apparatus as a second embodiment of the present invention. The software debug apparatus includes a
デバッグターゲット12はデバッグインターフェース31、プログラムメモリ32及びプログラム実行部33を備えている。トレースメモリ34は備えられていない。
The
また、かかるソフトウエアデバッグ装置は、関数コールツリー生成部13と関数コールツリーメモリ14とを備えている。関数コールツリー生成部13はCソースファイル41を静的に解析し、関数の呼び出し関係を表すコールツリー14を関数コールツリーメモリ15に出力する関数コールツリー作成手段である。関数コールツリー14は、関数の呼び出し関係をツリー構造で表現したものであり、例えば、図14に示すようソースプログラムからは、関数コールツリー14として図15に示すような出力が得られる。図14に示したソースプログラム41では、main2関数からfunc1とfunc2が呼び出されており、更にfunc1からはfunc2が呼び出されている。この呼び出し関係は、コンパイラ43により最適化される前のCソースプログラム41上での呼び出し関係を表している。
The software debugging apparatus includes a function call
更に、かかるソフトウエアデバッグ装置において、コンパイラ43は、末尾呼び出しの最適化を行った関数の出力アセンブリコードに、末尾呼び出しの最適化が行われたことを表す擬似命令を出力する。デバッガ11は、この擬似命令の有無と、関数コールツリーの情報により、どの関数に末尾呼び出し最適化されているか知ることができるため、正しくコールスタックを表示できるようになる。
Further, in such a software debugging apparatus, the
次に、かかるソフトウエアデバッグ装置において、末尾呼び出しの最適化が実施されたプログラムをデバッグする場合について説明する。 Next, a description will be given of a case in which a program in which tail call optimization is performed is debugged in such a software debugging apparatus.
先ず、Cソースファイル41からコード生成ツール42のコンパイラ43、アセンブラ44及びリンカ45により実行イメージプログラム46が作成され、その実行イメージプログラム46はデバッグ情報47と共に格納されている。
First, an
ここで、コンパイラ43がCソースプログラム41からアセンブリプログラムを生成する際においては、図16に示すように、関数呼び出しの分岐命令の直前に、関数呼び出しがあることを表す擬似命令FUNCCALL(第1疑似命令)が配置され、また、末尾呼び出しの最適化が適用された関数呼び出しにはTAILCALL擬似命令(第2疑似命令)が配置される。これらの擬似命令は、アセンブラ44及びリンカ45により実行イメージプログラム46の中にその情報が埋め込まれる。一方、関数コールツリー生成部13により、Cソースプログラム41の静的解析が行われ、関数コールツリーが出力される。
Here, when the
次に、デバッガ11では、第1の実施例と同様に、実行イメージプログラム46からプログラムコードをプログラムメモリ32にダウンロードするとともに、関数のシンボルテーブル22を抽出することが行われる。
Next, as in the first embodiment, the
このとき、デバッガ制御部21は実行イメージプログラム46内の各関数内のプログラムコードにTAILCALL擬似命令があるか否かを調査する。この調査において、デバッガ制御部21はTAILCALL擬似命令が見つかった場合には、関数コールツリー14を調べて、それが存在する関数を呼び出している関数を検出する。
At this time, the
図16に示すようなアセンブリコードについては、func1関数のプログラムコードの中にTAILCALL擬似命令が見つかる。そして関数コールツリー14の中からfunc1を呼び出している関数を探し出す。図15の例では、main2がfunc1を呼び出している関数に相当する。
For the assembly code as shown in FIG. 16, the TAILCALL pseudo instruction is found in the program code of the func1 function. The
次に、デバッガ制御部21は、TAILCALL擬似命令を持つfunc1関数を呼び出しているmain2関数のプログラムコードの中でfunc1を呼び出している位置(アドレス)を探す。これは、main2の中から関数呼び出しを表すFUNCCALL擬似命令を探し、その直後の分岐命令のオペランド(分岐先アドレス)を調べ、その分岐先アドレスが、シンボルテーブル22に登録されているfunc1のアドレスと一致すれば、func1を呼び出す分岐命令であると分かる。func1への分岐命令が見つかったら、その直後のアドレスがfunc1から戻るはずの戻り番地になる。
Next, the
ただし、実際には末尾呼び出しの最適化が行われているので、この戻り番地は、TAILCALL擬似命令の直後の分岐命令で呼び出される関数からの戻り番地と解釈することができる。図16の例では、戻りアドレスは0x1020であったとする。TAILCALL擬似命令の直後の分岐命令で呼び出される関数は、その分岐命令のオペランド(分岐先アドレス)をシンボルテーブル22から検索することにより、func2関数であることが分かる。従って、戻りアドレス0x1020は、実際はfunc2からの戻りアドレスとなる。そこで、デバッガ制御部21はこのアドレス0x1020と、実際の復帰元関数であるfunc2と、末尾呼び出しの最適化が実施された関数func1とを戻りアドレステーブル24に登録しておく。よって、戻りアドレステーブルの内容は図17に示すように戻りアドレスと復帰元関数func2と、最適化が実施されたfunc1が登録される。
However, since the tail call is optimized in practice, this return address can be interpreted as a return address from a function called by a branch instruction immediately after the TAILCALL pseudo instruction. In the example of FIG. 16, it is assumed that the return address is 0x1020. The function called by the branch instruction immediately after the TAILCALL pseudo-instruction is found to be a func2 function by searching the operand (branch destination address) of the branch instruction from the symbol table 22. Therefore, the return address 0x1020 is actually the return address from func2. Therefore, the
このようにして、TAILCALL擬似命令を持つすべての関数について、その呼び出し元の関数と戻りアドレスが、戻りアドレステーブルに登録される。 In this way, for all functions having the TAILCALL pseudo instruction, the function of the caller and the return address are registered in the return address table.
戻りアドレステーブル作成の実行後、デバッガ制御部21はデバッグインターフェース31を介してプログラム実行部33にプログラムを実行させる。
After execution of the return address table creation, the
そして、例えば、func2の実行中にデバッガ11に対する操作によりプログラムの実行が中断(ブレーク)したとする。ここで、そのブレークに応答してコールスタックを表示する場合には、最初にデバッガ制御部21は、上記の背景技術の欄で説明したように、func2からの戻りアドレスをリンクレジスタlrから読み出す。そして、リンクレジスタlrに格納されていたアドレスが図17の戻りアドレステーブル24に登録されていれば、その戻りアドレステーブル24の内容からfunc2が呼び出されるまでの間にfunc1の呼び出しがあったことが分かるので、デバッガ制御部21はコールスタックにfunc1の呼び出し履歴を追加して、図2に示したような表示を得ることが行われる。なお、リンクレジスタlrに格納されていたアドレスが戻りアドレステーブル24に登録されていない場合には上記の背景技術の欄に示したように、スタックフレームを用いて戻りアドレスがどの関数内のアドレスかを調べることにより呼び出された関数を判別することが行われる。
For example, it is assumed that the program execution is interrupted (broken) by an operation on the
かかる第2の実施例によれば、第1の実施例のようにデバッグターゲット12が分岐トレース機能を持たない場合において、関数コールツリー生成部13が追加されているので、末尾呼び出しの最適化が実施されたプログラムについてもコールスタックが正しく表示することができる。また、関数コールツリー生成部13はソフトウェア処理として追加されるだけであり、デバッグターゲット12の内部にトレースメモリのような専用ハードウェアを設けないで済むので、ハードウェアのコストを下げることができる。
According to the second embodiment, since the function call
使用するデバッグターゲットが分岐トレースの機能を有する場合には第1の実施例の構成を利用することができ、分岐トレースの機能を有しない場合には第2の実施例の構成を選択して利用することができる。 When the debug target to be used has a branch trace function, the configuration of the first embodiment can be used. When the debug target has no branch trace function, the configuration of the second embodiment is selected and used. can do.
Claims (9)
前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成手段と、
前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行手段と、
前記プログラム実行手段による実行命令が分岐命令である場合にその分岐命令のプログラムコードをオペラントを含めてトレースメモリに記憶させるトレース手段と、
前記トレースメモリのオペラントと前記シンボルテーブルのアドレス情報との対応関係に応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示手段と、を備えることを特徴とするソフトウエアデバッグ装置。 A software debugging device for performing a debugging process of an execution image program generated by compiling a source program and debugging information,
Symbol table creating means for creating a function name and address information for each function in the execution image program according to the debug information as a symbol table;
Program execution means for executing program code instructions in the order of the program code of the execution image program;
Trace means for storing the program code of the branch instruction in the trace memory including the operand when the execution instruction by the program execution means is a branch instruction;
Call stack display means for creating a call stack indicating a function call hierarchy in accordance with the correspondence between the trace memory operant and the address information of the symbol table, and displaying the call stack. Debug device.
前記コールスタック表示手段は、前記シンボルテーブルの開始アドレスが前記トレースメモリのオペラントに使用されている前記分岐命令である場合にはその開始アドレスの関数名を前記シンボルテーブルから取得し、
前記トレースメモリに関数からの復帰命令が記憶されている場合にはその復帰命令の復帰先アドレスが前記シンボルテーブルに含まれている関数の開始アドレスから前記アドレスサイズのアドレス範囲に含まれているならば、その開始アドレスの関数名を前記シンボルテーブルから取得することを特徴とする請求項1記載のソフトウエアデバッグ装置。 The symbol table includes a function start address and an address size as the address information,
The call stack display means acquires the function name of the start address from the symbol table when the start address of the symbol table is the branch instruction used for the operand of the trace memory,
If a return instruction from a function is stored in the trace memory, the return destination address of the return instruction is included in the address range of the address size from the start address of the function included in the symbol table. 2. The software debug device according to claim 1, wherein the function name of the start address is obtained from the symbol table.
前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成ステップと、
前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行ステップと、
前記プログラム実行ステップによる実行命令が分岐命令である場合にその分岐命令のプログラムコードをオペラントを含めてトレースメモリに記憶させるトレース手段と、
前記トレースメモリのオペラントと前記シンボルテーブルのアドレス情報との対応関係に応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示ステップと、を備えることを特徴とするソフトウエアデバッグ方法。 A software debugging method for debugging an execution image program generated by compiling a source program and debugging information,
A symbol table creation step of creating a function name and address information for each function in the execution image program according to the debug information as a symbol table;
A program execution step of executing instructions of the program code in the order of the program code of the execution image program;
Trace means for storing the program code of the branch instruction in the trace memory including the operand when the execution instruction by the program execution step is a branch instruction;
A call stack display step for creating and displaying a call stack indicating a function call hierarchy in accordance with a correspondence relationship between the trace memory operant and the address information of the symbol table. How to debug.
前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成手段と、
前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行手段と、
前記ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーを作成する関数コールツリー作成手段と、
前記実行イメージプログラム中の前記第1擬似命令及び前記第2擬似命令、前記関数コールツリー並び前記シンボルテーブルに基づいて前記末尾呼び出しの最適化が適用された関数、その復帰元関数及び戻りアドレスからなる戻りアドレステーブルを作成する戻りアドレステーブル作成手段と、
前記プログラム実行手段による命令実行によりリンクレジスタに格納された戻りアドレスと前記戻りアドレステーブルとに応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示手段と、を備えることを特徴とするソフトウエアデバッグ装置。 A source program is compiled and generated together with debug information. The first pseudo instruction indicating that there is a function call is placed immediately before the branch instruction of the function call, and the optimization of the tail call is applied among the function calls. A software debugging device for debugging an execution image program in which a second pseudo instruction is arranged instead of the first pseudo instruction,
Symbol table creating means for creating a function name and address information for each function in the execution image program according to the debug information as a symbol table;
Program execution means for executing program code instructions in the order of the program code of the execution image program;
A function call tree creating means for performing a static analysis on the source program and creating a function call tree indicating a function calling relationship;
The execution image program includes the first pseudo instruction and the second pseudo instruction, the function to which the tail call optimization is applied based on the function call tree and the symbol table, a return source function and a return address thereof. A return address table creating means for creating a return address table;
Call stack display means for creating a call stack indicating a function call hierarchy in accordance with a return address stored in a link register by instruction execution by the program execution means and the return address table and displaying the call stack. Software debugging device characterized by
前記呼び出している関数のプログラムコード中に前記第1擬似命令が存在する場合には、その直後の分岐命令のオペラントが示すアドレスを前記戻りアドレスとし、その戻りアドレスに応じて前記シンボルテーブルを検索して前記復帰元関数及び前記末尾呼び出しの最適化が適用された関数を検出することを特徴とする請求項5記載のソフトウエアデバッグ装置。 When there is a function in which the second pseudo instruction in the execution image program exists as a program code, the return address table creation unit calls the function in which the second pseudo instruction exists according to the call tree. Detect the function
If the first pseudo instruction is present in the program code of the function being called, the address indicated by the operand of the branch instruction immediately after that is used as the return address, and the symbol table is searched according to the return address. 6. The software debugging apparatus according to claim 5, wherein a function to which the return source function and the tail call optimization are applied is detected.
前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成ステップと、
前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行ステップと、
前記ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーを作成する関数コールツリー作成ステップと、
前記実行イメージプログラム中の前記第1擬似命令及び前記第2擬似命令、前記関数コールツリー並び前記シンボルテーブルに基づいて前記末尾呼び出しの最適化が適用された関数、その復帰元関数及び戻りアドレスからなる戻りアドレステーブルを作成する戻りアドレステーブル作成ステップと、
前記プログラム実行ステップによる命令実行によりリンクレジスタに格納された戻りアドレスと前記戻りアドレステーブルとに応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示ステップと、を備えることを特徴とするソフトウエアデバッグ方法。 A source program is compiled and generated together with debug information. The first pseudo instruction indicating that there is a function call is placed immediately before the branch instruction of the function call, and the optimization of the tail call is applied among the function calls. A software debugging method for debugging an execution image program in which a second pseudo instruction is arranged instead of the first pseudo instruction,
A symbol table creation step of creating a function name and address information for each function in the execution image program according to the debug information as a symbol table;
A program execution step of executing instructions of the program code in the order of the program code of the execution image program;
A function call tree creating step for creating a function call tree that performs a static analysis on the source program and indicates a function calling relationship;
The execution image program includes the first pseudo instruction and the second pseudo instruction, the function to which the tail call optimization is applied based on the function call tree and the symbol table, a return source function and a return address thereof. A return address table creation step for creating a return address table;
A call stack display step of creating and displaying a call stack indicating a hierarchy of function calls according to a return address stored in a link register by instruction execution by the program execution step and the return address table; A software debugging method characterized by the above.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2009141271A JP2010287101A (en) | 2009-06-12 | 2009-06-12 | Software debugging device and method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2009141271A JP2010287101A (en) | 2009-06-12 | 2009-06-12 | Software debugging device and method |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2010287101A true JP2010287101A (en) | 2010-12-24 |
Family
ID=43542745
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2009141271A Pending JP2010287101A (en) | 2009-06-12 | 2009-06-12 | Software debugging device and method |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2010287101A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110603527A (en) * | 2017-05-04 | 2019-12-20 | 微软技术许可有限责任公司 | Conditional debugging of server-side production code |
US10747644B2 (en) | 2017-10-13 | 2020-08-18 | Samsung Electronics Co., Ltd. | Method of executing instructions of core, method of debugging core system, and core system |
CN111611161A (en) * | 2020-05-20 | 2020-09-01 | 中电科航空电子有限公司 | Implementation method of lightweight debugging tool applied to avionic software |
CN112232027A (en) * | 2020-10-19 | 2021-01-15 | 腾讯科技(深圳)有限公司 | Symbol translation method, device, equipment and computer readable storage medium |
-
2009
- 2009-06-12 JP JP2009141271A patent/JP2010287101A/en active Pending
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110603527A (en) * | 2017-05-04 | 2019-12-20 | 微软技术许可有限责任公司 | Conditional debugging of server-side production code |
CN110603527B (en) * | 2017-05-04 | 2023-03-31 | 微软技术许可有限责任公司 | Method, system and apparatus for conditional debugging of server-side production code |
US10747644B2 (en) | 2017-10-13 | 2020-08-18 | Samsung Electronics Co., Ltd. | Method of executing instructions of core, method of debugging core system, and core system |
CN111611161A (en) * | 2020-05-20 | 2020-09-01 | 中电科航空电子有限公司 | Implementation method of lightweight debugging tool applied to avionic software |
CN111611161B (en) * | 2020-05-20 | 2023-08-08 | 中电科航空电子有限公司 | Implementation method of lightweight debugging tool applied to avionic software |
CN112232027A (en) * | 2020-10-19 | 2021-01-15 | 腾讯科技(深圳)有限公司 | Symbol translation method, device, equipment and computer readable storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7478366B2 (en) | Debugger and method for debugging computer programs across multiple programming languages | |
US9582396B2 (en) | Techniques for generating an executable debugger script | |
US20080127113A1 (en) | Method and system for implementing watchpoints | |
JP3612294B2 (en) | Debugging method and debugging device | |
US9489286B2 (en) | Method and system for computer assisted hot-tracing mechanism | |
CN103514072A (en) | Method and device for debugging graphical service for visual programming | |
JP2010079894A (en) | Reducing trace overhead by modifying trace operation | |
JP2004164554A (en) | Device and method for executing and monitoring program | |
JP2010287101A (en) | Software debugging device and method | |
US8473903B2 (en) | Code edit apparatus and recording medium | |
JP2009237610A (en) | Code converter and code conversion method | |
CN114510429B (en) | Debugging method, system and medium based on dynamic symbol execution | |
JP2008052688A (en) | Patch data generation device for program | |
JPS62113244A (en) | Program test device | |
JP2009258796A (en) | Program development device and program development method | |
Vipindeep et al. | Efficient static analysis with path pruning using coverage data | |
JP2011186806A (en) | Debugging device and debugging method | |
JP2007004516A (en) | Program debugging method of built-in system | |
JPH11110256A (en) | Device and method for debugging program, and computer readable recording medium recorded with the method for the same | |
JP2004287869A (en) | Program execution monitoring device and method | |
RU2390821C1 (en) | Dynamic instrumentation technique | |
JP3165105B2 (en) | Program tracer, compiler and linker | |
JPH07191873A (en) | Transition output system for value of variable at debugger | |
JP2006350676A (en) | Program debugging method of built-in system | |
JP2000353112A (en) | Method and system for debugging intermediate language level |