JP2010287101A - Software debugging device and method - Google Patents

Software debugging device and method Download PDF

Info

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
Application number
JP2009141271A
Other languages
Japanese (ja)
Inventor
Yasutsugu Hiraki
康嗣 平木
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Lapis Semiconductor Co Ltd
Original Assignee
Oki Semiconductor Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Oki Semiconductor Co Ltd filed Critical Oki Semiconductor Co Ltd
Priority to JP2009141271A priority Critical patent/JP2010287101A/en
Publication of JP2010287101A publication Critical patent/JP2010287101A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

<P>PROBLEM TO BE SOLVED: To provide a software debugging device and method for correctly displaying a call stack when tail call optimization is performed by using a break point during debugging of software without interrupting execution every time function call is made. <P>SOLUTION: A source program is prepared with the function name of each function in an execution image program and address information as a symbol table in accordance with debug information obtained with the execution image program by compile processing, instructions of program codes are executed in order of the program codes of the execution image program, the program code of a branch instruction is stored in a trace memory while including an operant in it when the execution instruction is the branch instruction, and a call stack showing hierarchy of function calls is prepared and displayed in accordance with correspondence relation between the operant of the trace memory and the address information of the symbol table. <P>COPYRIGHT: (C)2011,JPO&INPIT

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.

特開平11−065885号公報Japanese Patent Application Laid-Open No. 11-065885

しかしながら、上記のような方法では、コンパイラにより出力アセンブリコードが最適化されるときに、正しくコールスタックを表示できない場合がある。   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 Patent Document 1. This conventional method is a method in which software breakpoints are set at the start and end addresses of all functions, and function information is acquired when a break occurs at each breakpoint.

しかしながら、この従来の方法では、プログラム実行中に関数呼び出しが発生する度にブレークして実行が中断されるため、デバッグ中の実行においてリアルタイム性が損なわれるという別の問題がある。   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 claim 1 of the present application is a software debugging device that compiles a source program and debugs an execution image program generated together with debugging information, according to the debugging information. Symbol table creation means for creating function name and address information for each function in the execution image program as a symbol table, program execution means for executing program code instructions in order of program codes of the execution image program, and program execution means When the execution instruction is a branch instruction, the trace means for storing the program code of the branch instruction in the trace memory including the operand, and the correspondence between the operand of the trace memory and the address information of the symbol table It is characterized by and a call stack display means for displaying it to create a call stack showing the hierarchy of function calls in accordance with the.

本願の請求項4に係る発明のソフトウエアデバッグ方法は、ソースプログラムをコンパイル処理してデバッグ情報と共に生成された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ方法であって、前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成ステップと、前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行ステップと、前記プログラム実行ステップによる実行命令が分岐命令である場合にその分岐命令のプログラムコードをオペラントを含めてトレースメモリに記憶させるトレース手段と、前記トレースメモリのオペラントと前記シンボルテーブルのアドレス情報との対応関係に応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示ステップと、を備えることを特徴としている。   The software debugging method of the invention according to claim 4 of the present application is a software debugging method for performing a debugging process of an execution image program generated by compiling a source program together with debugging information, according to the debugging information. A symbol table creating step for creating function name and address information for each function in the execution image program as a symbol table, a program execution step for executing program code instructions in the program code order of the execution image program, and the program execution step A trace means for storing the program code of the branch instruction in the trace memory including the operand when the execution instruction by the branch instruction is a branch instruction, and the address information of the operand of the trace memory and the symbol table It is characterized by and a call stack display step of displaying it by creating a call stack showing the hierarchy of function calls in accordance with the corresponding relationship between the.

本願の請求項5に係る発明のソフトウエアデバッグ装置は、ソースプログラムをコンパイル処理してデバッグ情報と共に生成され、関数呼び出しの分岐命令の直前に、関数呼び出しがあることを表す第1擬似命令が配置され、その関数呼び出しのうち末尾呼び出しの最適化が適用された場合には前記第1擬似命令に代えて第2擬似命令が配置された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ装置であって、前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成手段と、前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行手段と、前記ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーを作成する関数コールツリー作成手段と、前記実行イメージプログラム中の前記第1擬似命令及び前記第2擬似命令、前記関数コールツリー並び前記シンボルテーブルに基づいて前記末尾呼び出しの最適化が適用された関数、その復帰元関数及び戻りアドレスからなる戻りアドレステーブルを作成する戻りアドレステーブル作成手段と、前記プログラム実行手段による命令実行によりリンクレジスタに格納された戻りアドレスと前記戻りアドレステーブルとに応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示手段と、を備えることを特徴としている。   In the software debugging device according to claim 5 of the present application, a first pseudo instruction indicating that there is a function call is arranged immediately before a branch instruction of a function call, which is generated together with debug information by compiling a source program. When the optimization of tail call is applied among the function calls, the software debug device performs debugging processing of an execution image program in which a second pseudo instruction is arranged instead of the first pseudo instruction. A symbol table creating means for creating function name and address information for each function in the execution image program according to the debug information as a symbol table; and program execution for executing program code instructions in the order of the program code of the execution image program Means and static for the source program A function call tree creating means for creating a function call tree indicating a function calling relationship by performing analysis, the first pseudo instruction and the second pseudo instruction in the execution image program, the function call tree and the symbol table A return address table creating means for creating a return address table composed of a function to which the tail call optimization is applied, a return source function and a return address, and stored in the link register by instruction execution by the program executing means Call stack display means for creating and displaying a call stack indicating a hierarchy of function calls according to a return address and the return address table is provided.

本願の請求項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 claim 1 of the present application and the software debugging method of the invention according to claim 5, when the execution instruction of the program code is a branch instruction, the program code of the branch instruction is operated on Since it is stored in the trace memory and stored in the trace memory and the branch trace function is used, execution is interrupted for each function call during debugging even when the compiler performs tail call optimization. The call stack can be displayed correctly.

本願の請求項5に係る発明のソフトウエアデバッグ装置及び請求項9に係る発明のソフトウエアデバッグ方法によれば、ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーが作成され、また、実行イメージプログラム中の第1擬似命令及び前記第2擬似命令、関数コールツリー並びシンボルテーブルに基づいて末尾呼び出しの最適化が適用された関数、その復帰元関数及び戻りアドレスからなる戻りアドレステーブルが作成されるので、リンクレジスタに格納された戻りアドレスとシンボルテーブル又は戻りアドレステーブルとを用いることにより、コンパイラによって末尾呼び出し最適化が行われた場合にもデバッグ中に関数呼び出し毎に実行を中断することなく、コールスタックを正しく表示することができる。   According to the software debugging device of the invention according to claim 5 of the present application and the software debugging method of the invention according to claim 9, a function call tree that performs a static analysis on a source program and indicates a function calling relationship is provided. A first pseudo instruction in the execution image program, the second pseudo instruction, a function to which tail call optimization is applied based on a function call tree and a symbol table, a return source function, and a return address. A return address table is created. By using the return address stored in the link register and the symbol table or the return address table, even if tail call optimization is performed by the compiler, each function call during debugging Display the call stack correctly without interrupting execution Can.

プログラムに定義された3つの関数の呼び出し関係を示す図である。It is a figure which shows the calling relationship of three functions defined in the program. デバッグにおけるコールスタックの表示例を示す図である。It is a figure which shows the example of a display of the call stack in debugging. コンパイラの出力アセンブリコード例を示す図である。It is a figure which shows the output assembly code example of a compiler. スタックフレームの例を示す図である。It is a figure which shows the example of a stack frame. 末尾呼び出しの最適化が実施された場合のコンパイラの出力アセンブリコード例を示す図である。It is a figure which shows the output assembly code example of a compiler when the optimization of a tail call is implemented. 末尾呼び出しの最適化が実施された場合のスタックフレームの例を示す図である。It is a figure which shows the example of a stack frame when the optimization of a tail call is implemented. 末尾呼び出しの最適化が実施された場合のコールスタックの表示例を示す図である。It is a figure which shows the example of a display of a call stack when the optimization of a tail call is implemented. 本発明の第1の実施例としてソフトウエアデバッグ装置の構成を示すブロック図である。It is a block diagram which shows the structure of a software debugging apparatus as 1st Example of this invention. シンボルテーブルの内容を示す図である。It is a figure which shows the content of the symbol table. トレースメモリの内容を示す図である。It is a figure which shows the content of the trace memory. 関数から復帰後のトレースメモリの内容を示す図である。It is a figure which shows the contents of the trace memory after returning from a function. main関数へ復帰後のコールスタックの表示例を示す図である。It is a figure which shows the example of a display of the call stack after returning to a main function. 本発明の第2の実施例としてソフトウエアデバッグ装置の構成を示すブロック図である。It is a block diagram which shows the structure of a software debugging apparatus as 2nd Example of this invention. プログラムに定義された3つの関数の呼び出し関係を示す図である。It is a figure which shows the calling relationship of three functions defined in the program. 関数コールツリーを示す図である。It is a figure which shows a function call tree. 末尾呼び出しの最適化が実施された場合のコンパイラの出力アセンブリコード例を示す図である。It is a figure which shows the output assembly code example of a compiler when the optimization of a tail call is implemented. 戻りアドレステーブルを示す図である。It is a figure which shows a return address table.

以下、本発明の実施例を図面を参照しつつ詳細に説明する。   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 debugger 11 and a debug target 12. The debugger 11 includes a debugger control unit 21, a symbol table 22, and a call stack display unit 23.

デバッガ制御部21はシンボルテーブル22及びコールスタック表示部23の各々接続されている。シンボルテーブル22はメモリからなる。シンボルテーブル作成手段はデバッガ制御部21及びシンボルテーブル22からなる。   The debugger control unit 21 is connected to each of a symbol table 22 and a call stack display unit 23. The symbol table 22 includes a memory. The symbol table creation means includes a debugger control unit 21 and a symbol table 22.

また、デバッガ制御部21は後述の実行イメージプログラム(実行形式プログラム)46をデバッグ情報47と共に読み出して実行イメージプログラム46からプログラムコードを抽出し、そのプログラムコードをデバッグターゲット12に出力する。また、デバッガ制御部21は読み出したデバッグ情報47から関数を抽出し、関数の名前、関数の開始アドレス及び関数に含まれる命令コードの合計サイズをシンボルテーブル22に格納(記憶)させる。コールスタック表示部23はデバッガ制御部21の指令に応じて図示しない表示器にコールスタックを表示する。コールスタック表示手段はデバッガ制御部21及びコールスタック表示部23からなる。   In addition, the debugger control unit 21 reads an execution image program (execution format program) 46 described later together with debug information 47, extracts a program code from the execution image program 46, and outputs the program code to the debug target 12. The debugger control unit 21 extracts a function from the read debug information 47 and stores (stores) the function name, the function start address, and the total size of the instruction code included in the function in the symbol table 22. The call stack display unit 23 displays the call stack on a display (not shown) in response to a command from the debugger control unit 21. The call stack display means includes a debugger control unit 21 and a call stack display unit 23.

デバッグターゲット12はデバッグインターフェース31、プログラムメモリ32、プログラム実行部33及びトレースメモリ34を備えている。デバッグインターフェース31はプログラムメモリ32、プログラム実行部33及びトレースメモリ34の各々に接続され、プログラム実行部33はプログラムメモリ32及びトレースメモリ34各々に接続されている。   The debug target 12 includes a debug interface 31, a program memory 32, a program execution unit 33, and a trace memory 34. The debug interface 31 is connected to each of the program memory 32, the program execution unit 33, and the trace memory 34, and the program execution unit 33 is connected to each of the program memory 32 and the trace memory 34.

デバッグインターフェース31はデバッガ11のデバッガ制御部21とのプログラムコード等の情報の入出力のために設けられている。   The debug interface 31 is provided for input / output of information such as program code with the debugger control unit 21 of the debugger 11.

プログラムメモリ32には上記のプログラムコードが供給順に格納される。プログラム実行部33はプログラム実行手段であり、プログラムメモリ32に格納されたプログラムコードの命令を順に実行する。また、プログラム実行部33はプログラム実行中に命令が分岐命令であるときに、実行した分岐命令の命令コードをオペランドの情報を含めてトレースメモリ34に格納するトレース手段を含んでいる。   The program memory 32 stores the program codes in the order of supply. The program execution unit 33 is a program execution unit, and executes the instructions of the program code stored in the program memory 32 in order. Further, the program execution unit 33 includes a tracing means for storing the instruction code of the executed branch instruction in the trace memory 34 including the operand information when the instruction is a branch instruction during program execution.

かかるソフトウエアデバッグ装置においては、コールスタックの情報を表示する際に、ターゲットの分岐トレースの情報を利用する。分岐トレースとは、プログラム実行部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 trace memory 34 in the order of execution when the program execution unit 33 executes the branch instructions during the program execution. With this function, the trace memory 34 stores the history data of the executed branch instruction.

デバッガ制御部21は、実行イメージプログラム46をデバッグ情報47と共に取り込んだときに、デバッグ情報47に含まれるシンボルテーブル22を取得し、シンボルテーブル22から実行イメージプログラム46に含まれる関数の名前とアドレスとの対応関係を検出する。従って、トレースメモリ34から取得した各分岐命令のオペランドから分岐先アドレスを取得し、そのアドレスで特定される関数がシンボルテーブル22に含まれていれば、その分岐命令は関数呼び出しであると判断できる。そして、トレースメモリ34から関数呼び出しに相当する分岐命令を検出すれば、それは関数の呼び出しの履歴として解釈することができ、その履歴情報から表示すべきコールスタックの情報を生成する。コールスタックの情報はコールスタック表示部23に供給されて表示される。   The debugger control unit 21 acquires the symbol table 22 included in the debug information 47 when the execution image program 46 is fetched together with the debug information 47, and the name and address of the function included in the execution image program 46 from the symbol table 22. The correspondence of is detected. Therefore, if the branch destination address is acquired from the operand of each branch instruction acquired from the trace memory 34 and the function specified by the address is included in the symbol table 22, it can be determined that the branch instruction is a function call. . If a branch instruction corresponding to a function call is detected from the trace memory 34, it can be interpreted as a function call history, and call stack information to be displayed is generated from the history information. The call stack information is supplied to the call stack display unit 23 and displayed.

次に、かかるソフトウエアデバッグ装置において、末尾呼び出しの最適化が実施されたプログラムをデバッグする場合について説明する。   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 execution image program 46 is generated from a C source file (C source program) 41 by a compiler 43, an assembler 44 and a linker 45 of a code generation tool 42, and the execution image program 46 is stored together with debug information 47. The compiler 43 generates an assembly program from the C source file 41, the assembler 44 converts the assembly program into an object file, and the linker 45 executes an execution image program 46 based on the object file obtained by the assembler 44. Generate. These code generation tools 42 are provided with so-called options so that debug information 47 is generated.

デバッガ11のデバッガ制御部21は実行イメージプログラム46からプログラムコードを抽出する。抽出されたプログラムコードは順にデバッグターゲット12のデバッグインターフェース部31を介して、プログラムメモリ32に格納される。プログラムメモリ32に格納されたプログラムコード群をプログラムと称す。また、同時にデバッガ制御部21は実行イメージプログラム46のデバッグ情報47から関数を抽出して、図9に示すような関数のシンボルテーブル22を形成する。このシンボルテーブル22には、関数の名前と、関数の開始アドレス及び関数に含まれる命令コードの合計サイズの情報が含まれている。   The debugger control unit 21 of the debugger 11 extracts a program code from the execution image program 46. The extracted program codes are sequentially stored in the program memory 32 via the debug interface unit 31 of the debug target 12. A group of program codes stored in the program memory 32 is referred to as a program. At the same time, the debugger control unit 21 extracts a function from the debug information 47 of the execution image program 46 to form a function symbol table 22 as shown in FIG. The symbol table 22 includes information on the name of the function, the start address of the function, and the total size of instruction codes included in the function.

プログラムメモリ32にプログラムが格納された後、デバッグインターフェース部31を介して供給されるデバッガ制御部21の指令に応じて、プログラム実行部33によりそのプログラム中の命令が順に実行される。プログラム実行部33は、実行した命令が分岐命令だった場合に、同時にその命令コードをオペランドの情報を含めてトレースメモリ34に格納する。例えば、func2の実行中にデバッガ11への操作に応じてプログラムの実行が中断(ブレーク)したときのトレースメモリ34の内容は図10に示すようになる。   After the program is stored in the program memory 32, the program execution unit 33 sequentially executes instructions in the program in response to a command from the debugger control unit 21 supplied via the debug interface unit 31. When the executed instruction is a branch instruction, the program execution unit 33 simultaneously stores the instruction code including the operand information in the trace memory 34. For example, the contents of the trace memory 34 when the execution of the program is interrupted (break) according to the operation to the debugger 11 during the execution of func2 are as shown in FIG.

デバッガ制御部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 debugger control unit 21 acquires the contents of the trace memory 34 and investigates whether the address value in the symbol table 22 in FIG. 9 is used as the operand of the branch instruction in the trace memory 34. That is, the correspondence between the operant in the trace memory 34 and the address information in the symbol table 22 is detected. In the case of the example of FIGS. 9 and 10, as a result of this investigation, the debugger control unit 21 indicates that the branch instruction at Index2 in FIG. 10 is a call to the function main, and the branch instruction at Index3 is a call to the function func1. Further, it can be detected that the branch instruction of Index4 is a call to the function func2. Since there is no index1 branch instruction whose operand address matches the value of the address in the symbol table 22, it can be determined that it is not a function call. The debugger control unit 21 displays the branch destination function names in descending order of the index of the branch instruction that has been determined to be a function call, so that the call stack display unit 23 displays the call stack as shown in FIG. Is displayed.

次に、デバッガ動作を続けて実行させて、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 trace memory 34 are as shown in FIG.

トレースメモリ34のIndex5には、関数func2からの復帰となる分岐命令であるrt命令と、その分岐先アドレスの情報が格納される。デバッガ制御部21は、トレースメモリ34の中に関数からの復帰命令を見つけると、その復帰先のアドレスがどの関数の範囲内にあるかを調べるため、シンボルテーブル22を調査する。図11の例では復帰先アドレスが0x1020であり、図9の情報からmain関数の先頭アドレス0x1000からそのサイズ0x40進んだアドレスまでの範囲に含まれるため、main関数内のアドレスであることが分かる。   In the index memory 5 of the trace memory 34, an rt instruction that is a branch instruction for returning from the function func2 and information of the branch destination address are stored. When the debugger control unit 21 finds a return instruction from the function in the trace memory 34, the debugger control unit 21 checks the symbol table 22 in order to check which function range the return destination address is in. In the example of FIG. 11, the return destination address is 0x1020, which is included in the range from the information of FIG. 9 to the main function start address 0x1000 to the address advanced by the size 0x40.

このとき、コールスタックを表示する場合には、デバッガ制御部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 debugger control unit 21 examines the contents of the trace memory 34 in the same manner as described above, and determines the branch destination function name in descending order of the index of the branch instruction that can be determined to be a function call. Try to display them side by side. However, since it can be seen that the main function has been returned by the return instruction of Index5, the function call between Index2 and Index5 representing the main call (that is, func1 of Index3 and func2 of Index4) is already in the function. It can be considered that the execution has finished. Therefore, the call stack displayed on the call stack display unit 23 is displayed only for the main function as shown in FIG. 12 excluding the functions corresponding to Index 3 and Index 4 of the trace memory.

以上のように、第1の実施例によれば、デバッグターゲット12に付加された、分岐命令のみをトレースメモリ34に格納する分岐トレースの機能を利用することにより、コンパイラ43の末尾呼び出し最適化が行われた場合にも正しくコールスタックを表示させることができる。また、コールスタックの表示に必要な関数呼び出しの履歴情報を取得するために関数呼び出し毎にプログラムをブレークさせることがないため、プログラム実行中のリアルタイム性を損なうことがない。更に、分岐トレース機能は、通常のトレース機能に比べてトレースメモリ34に格納する情報は分岐命令のみであるため、トレースメモリ34の容量も小さくて済むため、大きなコスト増加にはならないという利点がある。   As described above, according to the first embodiment, the tail call optimization of the compiler 43 can be optimized by using the branch trace function added to the debug target 12 and storing only the branch instruction in the trace memory 34. If done, the call stack can be displayed correctly. Also, since the function call history information necessary for displaying the call stack is acquired, the program is not broken at each function call, so that real-time performance during program execution is not impaired. Further, the branch trace function has an advantage that the information stored in the trace memory 34 is only a branch instruction and the capacity of the trace memory 34 can be reduced as compared with the normal trace function, and the cost does not increase greatly. .

図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 debugger 11 and a debug target 12 as in the apparatus of the first embodiment shown in FIG. The debugger 11 includes a return address table 24 in addition to the debugger control unit 21, the symbol table 22, and the call stack display unit 23. The return address table 24 stores return addresses. The debugger control unit 21 and the return address table 24 constitute return address table creation means.

デバッグターゲット12はデバッグインターフェース31、プログラムメモリ32及びプログラム実行部33を備えている。トレースメモリ34は備えられていない。   The debug target 12 includes a debug interface 31, a program memory 32, and a program execution unit 33. The trace memory 34 is not provided.

また、かかるソフトウエアデバッグ装置は、関数コールツリー生成部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 tree generation unit 13 and a function call tree memory 14. The function call tree generation unit 13 is a function call tree creation unit that statically analyzes the C source file 41 and outputs a call tree 14 representing a function calling relationship to the function call tree memory 15. The function call tree 14 is a representation of function calling relationships in a tree structure. For example, an output as shown in FIG. 15 is obtained as a function call tree 14 from a source program as shown in FIG. In the source program 41 shown in FIG. 14, func1 and func2 are called from the main2 function, and func2 is called from func1. This call relationship represents the call relationship on the C source program 41 before being optimized by the compiler 43.

更に、かかるソフトウエアデバッグ装置において、コンパイラ43は、末尾呼び出しの最適化を行った関数の出力アセンブリコードに、末尾呼び出しの最適化が行われたことを表す擬似命令を出力する。デバッガ11は、この擬似命令の有無と、関数コールツリーの情報により、どの関数に末尾呼び出し最適化されているか知ることができるため、正しくコールスタックを表示できるようになる。   Further, in such a software debugging apparatus, the compiler 43 outputs a pseudo instruction indicating that the tail call optimization has been performed to the output assembly code of the function that has performed the tail call optimization. The debugger 11 can know which function is optimized for the tail call from the presence / absence of the pseudo instruction and the information of the function call tree, so that the call stack can be displayed correctly.

次に、かかるソフトウエアデバッグ装置において、末尾呼び出しの最適化が実施されたプログラムをデバッグする場合について説明する。   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 execution image program 46 is created from the C source file 41 by the compiler 43, assembler 44 and linker 45 of the code generation tool 42, and the execution image program 46 is stored together with debug information 47.

ここで、コンパイラ43がCソースプログラム41からアセンブリプログラムを生成する際においては、図16に示すように、関数呼び出しの分岐命令の直前に、関数呼び出しがあることを表す擬似命令FUNCCALL(第1疑似命令)が配置され、また、末尾呼び出しの最適化が適用された関数呼び出しにはTAILCALL擬似命令(第2疑似命令)が配置される。これらの擬似命令は、アセンブラ44及びリンカ45により実行イメージプログラム46の中にその情報が埋め込まれる。一方、関数コールツリー生成部13により、Cソースプログラム41の静的解析が行われ、関数コールツリーが出力される。   Here, when the compiler 43 generates an assembly program from the C source program 41, as shown in FIG. 16, the pseudo instruction FUNCCALL (first pseudo instruction) indicating that there is a function call immediately before the branch instruction of the function call. An instruction) is arranged, and a TAILCALL pseudo instruction (second pseudo instruction) is arranged in a function call to which optimization of tail call is applied. These pseudo instructions are embedded in the execution image program 46 by the assembler 44 and the linker 45. On the other hand, the function call tree generator 13 performs a static analysis of the C source program 41 and outputs a function call tree.

次に、デバッガ11では、第1の実施例と同様に、実行イメージプログラム46からプログラムコードをプログラムメモリ32にダウンロードするとともに、関数のシンボルテーブル22を抽出することが行われる。   Next, as in the first embodiment, the debugger 11 downloads the program code from the execution image program 46 to the program memory 32 and extracts the function symbol table 22.

このとき、デバッガ制御部21は実行イメージプログラム46内の各関数内のプログラムコードにTAILCALL擬似命令があるか否かを調査する。この調査において、デバッガ制御部21はTAILCALL擬似命令が見つかった場合には、関数コールツリー14を調べて、それが存在する関数を呼び出している関数を検出する。   At this time, the debugger control unit 21 investigates whether the program code in each function in the execution image program 46 has a TAILCALL pseudo instruction. In this investigation, when the TAILCALL pseudo-instruction is found, the debugger control unit 21 examines the function call tree 14 and detects a function that calls a function in which it exists.

図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 function call tree 14 is searched for the function calling func1. In the example of FIG. 15, main2 corresponds to a function calling func1.

次に、デバッガ制御部21は、TAILCALL擬似命令を持つfunc1関数を呼び出しているmain2関数のプログラムコードの中でfunc1を呼び出している位置(アドレス)を探す。これは、main2の中から関数呼び出しを表すFUNCCALL擬似命令を探し、その直後の分岐命令のオペランド(分岐先アドレス)を調べ、その分岐先アドレスが、シンボルテーブル22に登録されているfunc1のアドレスと一致すれば、func1を呼び出す分岐命令であると分かる。func1への分岐命令が見つかったら、その直後のアドレスがfunc1から戻るはずの戻り番地になる。   Next, the debugger control unit 21 searches for the position (address) at which func1 is called in the program code of the main2 function that calls the func1 function having the TAILCALL pseudo instruction. This searches for a FUNCCALL pseudo-instruction representing a function call from main2, examines the operand (branch destination address) of the branch instruction immediately after that, and determines that the branch destination address is the address of func1 registered in the symbol table 22. If they match, it is understood that the branch instruction calls func1. If a branch instruction to func1 is found, the address immediately after that becomes the return address that should return from func1.

ただし、実際には末尾呼び出しの最適化が行われているので、この戻り番地は、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 debugger control unit 21 registers the address 0x1020, the actual return source function func2, and the function func1 for which tail call optimization has been performed, in the return address table 24. Accordingly, as shown in FIG. 17, the return address table registers the return address, the return source function func2, and the optimized func1.

このようにして、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 debugger control unit 21 causes the program execution unit 33 to execute the program via the debug interface 31.

そして、例えば、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 debugger 11 during the execution of func2. Here, when displaying the call stack in response to the break, first, the debugger control unit 21 reads the return address from func2 from the link register lr as described in the section of the background art. Then, if the address stored in the link register lr is registered in the return address table 24 of FIG. 17, there has been a call to func1 before the func2 is called from the contents of the return address table 24. As can be seen, the debugger control unit 21 adds the call history of func1 to the call stack and obtains a display as shown in FIG. If the address stored in the link register lr is not registered in the return address table 24, the function in which function the return address is in the stack frame as shown in the background art section above. The function that was called is determined by examining.

かかる第2の実施例によれば、第1の実施例のようにデバッグターゲット12が分岐トレース機能を持たない場合において、関数コールツリー生成部13が追加されているので、末尾呼び出しの最適化が実施されたプログラムについてもコールスタックが正しく表示することができる。また、関数コールツリー生成部13はソフトウェア処理として追加されるだけであり、デバッグターゲット12の内部にトレースメモリのような専用ハードウェアを設けないで済むので、ハードウェアのコストを下げることができる。   According to the second embodiment, since the function call tree generation unit 13 is added when the debug target 12 does not have the branch trace function as in the first embodiment, the tail call can be optimized. The call stack can be correctly displayed for the executed program. Further, the function call tree generation unit 13 is only added as software processing, and it is not necessary to provide dedicated hardware such as a trace memory inside the debug target 12, so that the cost of hardware can be reduced.

使用するデバッグターゲットが分岐トレースの機能を有する場合には第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.
操作に応じて前記プログラム実行手段の実行動作が中断されたとき前記コールスタック表示手段は前記コールスタックを作成することを特徴とする請求項1記載のソフトウエアデバッグ装置。   2. The software debugging apparatus according to claim 1, wherein the call stack display means creates the call stack when the execution operation of the program execution means is interrupted in accordance with an operation. ソースプログラムをコンパイル処理してデバッグ情報と共に生成された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ方法であって、
前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成ステップと、
前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行ステップと、
前記プログラム実行ステップによる実行命令が分岐命令である場合にその分岐命令のプログラムコードをオペラントを含めてトレースメモリに記憶させるトレース手段と、
前記トレースメモリのオペラントと前記シンボルテーブルのアドレス情報との対応関係に応じて関数呼び出しの階層を示すコールスタックを作成してそれを表示するコールスタック表示ステップと、を備えることを特徴とするソフトウエアデバッグ方法。
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擬似命令が配置され、その関数呼び出しのうち末尾呼び出しの最適化が適用された場合には前記第1擬似命令に代えて第2擬似命令が配置された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ装置であって、
前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成手段と、
前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行手段と、
前記ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーを作成する関数コールツリー作成手段と、
前記実行イメージプログラム中の前記第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
前記戻りアドレステーブル作成手段は、前記実行イメージプログラム中の前記第2擬似命令がプログラムコードとして存在する関数がある場合には、前記コールツリーに応じて前記第2擬似命令が存在する関数を呼び出している関数を検出し、
前記呼び出している関数のプログラムコード中に前記第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.
前記コールスタック表示手段は、前記リンクレジスタに格納された戻りアドレスが前記戻りアドレステーブルに存在する場合には前記戻りアドレステーブルからその戻りアドレスについての前記末尾呼び出しの最適化が適用された関数の関数名を読み出して前記コールスタックを作成することを特徴とする請求項5記載のソフトウエアデバッグ装置。   When the return address stored in the link register exists in the return address table, the call stack display means is a function of the function to which the optimization of the tail call for the return address is applied from the return address table. 6. The software debugging apparatus according to claim 5, wherein the call stack is created by reading a name. 操作に応じて前記プログラム実行手段の実行動作が中断されたとき前記コールスタック表示手段は前記コールスタックを作成することを特徴とする請求項5又は7記載のソフトウエアデバッグ装置。   8. The software debugging apparatus according to claim 5, wherein the call stack display means creates the call stack when the execution operation of the program execution means is interrupted according to an operation. ソースプログラムをコンパイル処理してデバッグ情報と共に生成され、関数呼び出しの分岐命令の直前に、関数呼び出しがあることを表す第1擬似命令が配置され、その関数呼び出しのうち末尾呼び出しの最適化が適用された場合には前記第1擬似命令に代えて第2擬似命令が配置された実行イメージプログラムのデバッグ処理を行うソフトウエアデバッグ方法であって、
前記デバッグ情報に応じて前記実行イメージプログラム中の関数毎の関数名及びアドレス情報をシンボルテーブルとして作成するシンボルテーブル作成ステップと、
前記実行イメージプログラムのプログラムコード順にプログラムコードの命令を実行するプログラム実行ステップと、
前記ソースプログラムに対して静的解析を施して関数の呼び出し関係を示す関数コールツリーを作成する関数コールツリー作成ステップと、
前記実行イメージプログラム中の前記第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.
JP2009141271A 2009-06-12 2009-06-12 Software debugging device and method Pending JP2010287101A (en)

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)

* Cited by examiner, † Cited by third party
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

Cited By (6)

* Cited by examiner, † Cited by third party
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