WO2024069730A1 - Debugging device and debugging method - Google Patents

Debugging device and debugging method Download PDF

Info

Publication number
WO2024069730A1
WO2024069730A1 PCT/JP2022/035836 JP2022035836W WO2024069730A1 WO 2024069730 A1 WO2024069730 A1 WO 2024069730A1 JP 2022035836 W JP2022035836 W JP 2022035836W WO 2024069730 A1 WO2024069730 A1 WO 2024069730A1
Authority
WO
WIPO (PCT)
Prior art keywords
breakpoint
code
optimized code
program
optimized
Prior art date
Application number
PCT/JP2022/035836
Other languages
French (fr)
Japanese (ja)
Inventor
勝己 奥田
Original Assignee
三菱電機株式会社
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 三菱電機株式会社 filed Critical 三菱電機株式会社
Priority to PCT/JP2022/035836 priority Critical patent/WO2024069730A1/en
Publication of WO2024069730A1 publication Critical patent/WO2024069730A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software

Definitions

  • This invention relates to debugging programs executed on a computer.
  • Debugging is essential in computer program development. Even experienced programmers find it difficult to create a program that works as expected from the start. Usually, a program is written once, then run and tested, and the program is rewritten while checking the test results. If a program does not work as expected, the programmer debugs the program to find errors.
  • a debugger provides the ability to stop a running program and step through it. Using a debugger, a programmer can freely read and write data while the program is stopped. In this case, the user does not need to rewrite the program to debug, allowing the work to proceed more efficiently.
  • Step execution can be performed on a per-instruction basis in machine language programs, or on a per-statement basis in high-level languages.
  • step execution on a per-statement basis is essential.
  • One method for performing step execution on a per-statement basis is disclosed in Patent Document 1.
  • step execution method disclosed in Patent Document 1 which causes a computer that operates based on a source program written in a high-level language to step execute, one statement in the high-level language is executed by successively executing the machine code corresponding to one line of the source program as a step execution unit.
  • step execution means were realized by successively executing a series of machine language instructions equivalent to one line of a source program.
  • the lines of the source program are converted into multiple instruction sequences whose order is jumbled up, making it impossible to step through each line in the correct order.
  • the object of this invention is to provide users with the same debugging functionality as programs without optimization, while primarily executing programs with optimization.
  • the debugging device is a debugging device that includes a program execution means for executing a program that includes optimized code and non-optimized code corresponding to the same source code, as well as a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting means for setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when a breakpoint is specified at a position in the source code, and a breakpoint switching means for switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
  • the debugging method is a debugging method including a program execution step of executing a program having optimized code and non-optimized code corresponding to the same source code, and a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting step of setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when the breakpoints are specified at the position of the source code, and a breakpoint switching step of switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
  • a program can be executed at high speed using optimized code until a source code level breakpoint is set, and after the breakpoint is set, interactive debugging operations such as step execution can be provided using non-optimized code.
  • FIG. 1 is a block diagram showing an example of a debugging device according to a first embodiment.
  • FIG. 2 is a diagram showing an example of a program that is assumed to be the target of debugging.
  • FIG. 3 shows an example of the result of disassembling the optimized code.
  • FIG. 4 is an example of a line number table for optimized code.
  • FIG. 5 is a diagram showing an example of the disassembled result of code without optimization.
  • FIG. 6 is a diagram showing an example of a line number table for non-optimized code.
  • FIG. 7 is an example of a flowchart of the breakpoint management means.
  • FIG. 8 is an example of a flowchart of a breakpoint setting process.
  • FIG. 9 is an example of a flowchart of a breakpoint clear process.
  • FIG. 10 is an example of a flowchart of the breakpoint management means.
  • a program execution means 101 executes a program 102 to be debugged.
  • the program execution means 101 is a CPU (Central Processing Unit), but may be a CPU emulator, a virtual machine, an interpreter, an instruction set simulator, etc., instead of a real CPU.
  • the program 102 to be debugged is a program obtained by compiling a program in a high-level language.
  • the program 102 to be debugged is composed of various data 103, code 104, etc., and is stored in a storage device such as a memory.
  • the code 104 is composed of optimized code 105 and non-optimized code 106.
  • the optimized code 105 and non-optimized code 106 are machine code 104 generated from the same source program, and there are two types of code for each function of the original source program: optimized code 105 and non-optimized code 106.
  • the code 104 that is normally executed by the program execution means 101 is optimized code 105.
  • the program execution means 101 executes the non-optimized code 106.
  • the program execution means 101 executes the debug target program 102 that includes optimized code 105 and non-optimized code 106 that correspond to the same source code, as well as a line number table 109 for the optimized code 105 and a line number table 109 for the non-optimized code 106.
  • the breakpoint management means 107 is composed of a breakpoint setting means 120 and a breakpoint switching means 121.
  • the breakpoint setting means 120 accepts breakpoints by the high-level language source file name and line number, and sets breakpoints in both the optimized code 105 and the non-optimized code 106 using the line number table 109 and the symbol table 110.
  • the breakpoint setting means 120 sets breakpoints at the instruction level in two locations, the optimized code 105 and the non-optimized code 106. The locations at which breakpoints are set will be explained in detail later.
  • the execution control means 108 switches the code to be executed by the program execution means 101 from optimized code 105 to non-optimized code 106 based on the set breakpoint.
  • the line number table 109 holds the correspondence information between the line numbers of the source program and the instruction addresses of the non-optimized code 106.
  • the symbol table 110 holds the address and area size corresponding to each symbol, such as a variable name or a function name in the source code.
  • the symbol table 110 holds both the address of the optimized code 105 and the address of the non-optimized code 106.
  • the symbol table 110 also includes the start address and size of the function. For this reason, the function can be identified by searching the symbol table 110 for the address of an instruction that constitutes part of the function. For example, if an entry in the symbol table 110 has a start address f and a size s of a function, it is possible to confirm whether the instruction at address a is part of a function by determining whether a given address a is greater than or equal to f and less than f+s. By repeating this process for all symbol table 110 entries, the start address of the function, the symbol name, etc. can be obtained from the address of part of the function.
  • Figure 2 is an example of a program that is intended to be debugged.
  • the programmer wants to step through lines 8 and 9 of the program in Figure 2 and check whether the overtime salary has been calculated correctly.
  • the programmer can step through lines 8 and 9 and obtain the values of the variables overtime and salary to check whether the salary, including the overtime salary, has been calculated as the programmer intended.
  • the programmer sets a breakpoint on line 8 and then starts running the program. After a while, when the program stops at the breakpoint on line 8, the debugger will offer the programmer interactive operations such as stepping through the program. If the programmer instructs the debugger to step through line 8, the program will stop at line 9. If the programmer then instructs the debugger to step through the program again, the program will stop at line 10.
  • FIG. 3 shows the result of disassembling optimized code 105 generated from the source program in FIG. 2.
  • the format of FIG. 3 conforms to the format of the disassembly result by the objdump command of GNU binutils.
  • the first line indicates that the function wage starts at address 0x740.
  • lines 2 to 10 show the result of disassembling the instruction sequence contained in wage.
  • line 2 indicates that the instruction code at address 740 is 0xd2e80880, and its mnemonic is mov.
  • this mov instruction means that the immediate value 0x4044000000000000 is stored in register x0. Note that the details of each instruction are not directly related to this invention, so an explanation will be omitted.
  • FIG. 4 shows line number table 109 for optimized code 105 corresponding to function wage in FIG. 2.
  • the format of line number table 109 in FIG. 4 conforms to the output format of the line number information dump result by the readelf command of GNU binutils.
  • Lines 3 to 16 show the correspondence between each line of the actual source code and an address, with the first column showing the file name, the second column showing the line number, and the third column showing the corresponding address.
  • line 3 shows that line 5 of file name wage.c exists at address 0x740 in optimized code 105. It can be seen from FIG. 4 that the debugger cannot perform step execution at the source code level using optimized code 105. For example, lines 3 to 5 in FIG.
  • the basic idea of this invention is to switch to and execute unoptimized code 106 only while debugging is providing interactive operations to the user. This switching is performed automatically by breakpoint switching means 121, so the user can perform general debugging operations such as step execution and variable display as if they had been executing unoptimized code 106 from the beginning.
  • Interactive interaction with the user begins when the program stops at a breakpoint.
  • line number table 109 is made up of an address correspondence table for non-optimized code 106 and an address correspondence table for optimized code 105.
  • the disassembly result of the non-optimized code 106 corresponding to the wage function in FIG. 3 is as shown in FIG. 5.
  • the line number table 109 for the non-optimized code 106 is shown in FIG. 6. Note that in FIG. 6, _O2 is added to the end of the base name wage of the original file name wage.c, such as wage_O0.c, so that it can be seen that this is for the non-optimized code 106 generated from wage.c.
  • Lines 2 to 27 in FIG. 5 are the code corresponding to the processing of the function wage, and start from address 0x780.
  • Lines 3 to 10 in FIG. 6 indicate which addresses in the non-optimized code 106 in FIG.
  • each address always corresponds to only one line, and it can be seen that the order of the line numbers in the source code and the order of the addresses in the non-optimized code 106 are arranged in the same order.
  • the line numbers of the non-optimized code 106 in FIG. 6 are all different numbers, and the instruction sequence is arranged in ascending order.
  • the line numbers of the optimized code 105 in FIG. 4 include some identical numbers and some numbers that are swapped, and the lines of the source program are converted into multiple instruction sequences with their order jumbled up, making it impossible to execute each line in the correct order. For this reason, while it is easy to trace the line numbers of the source code from the non-optimized code 106, it is not easy to trace the line numbers of the source code from the optimized code 105. Naturally, the execution speed of the optimized code 105 is faster than that of the non-optimized code 106.
  • the following describes the procedure for setting a breakpoint when the user sets a source code level breakpoint on line n of the source code of file name s.
  • a breakpoint specified by a pair of a file name and a line number will be called a source level breakpoint
  • a breakpoint specified by the memory address of the instruction at which program control means 108 actually stops will be called an instruction level breakpoint to distinguish between the two.
  • the breakpoint setting means 120 sets an instruction-level breakpoint at an instruction address in the unoptimized code 106 that corresponds to the source file name s and line number n specified by the user.
  • the breakpoint management means 107 also sets an auxiliary instruction level breakpoint in the optimized code 105 so that the execution control means 108 can switch the code 104 to be executed from the optimized code 105 to the non-optimized code 106.
  • the execution control means 108 switches from the optimized code 105 to the non-optimized code 106.
  • the breakpoint switching means 121 switches the code to be executed from the optimized code 105 to the non-optimized code 106.
  • Figure 7 is a flowchart of the breakpoint management means 107.
  • the input is the file name s, line number n, and type of breakpoint operation specified by the user.
  • step S701 the address x corresponding to the file name s and line number n is searched and obtained from the line number table 109 for the non-optimized code 106.
  • s is wage.c and n is 8.
  • x is 0x7b0. Note that in FIG. 6, wage.c has been renamed to wage_O0.c to indicate that this is non-optimized code 106.
  • step S702 function f containing instruction address x is searched for in symbol table 110, and the starting address y of function f in non-optimized code 106 is obtained. For example, if function f is wage, the starting address y starts from address 0x780 as shown in the second line of FIG. 5. This wage and 0x780 are obtained by searching symbol table 110 using instruction address x, i.e., 0x7b0.
  • step S703 the starting address y' of the optimized code 105 of function f is obtained from the symbol table 110.
  • the symbol name of function f obtained when searching the symbol table 110 in step S702 can be used.
  • the symbol table 110 holds the addresses of both the optimized code 105 and the non-optimized code 106 for each function. For example, when the function f is wage, the starting address y' of the optimized function wage is 0x740 from the second line in FIG. 3. This 0x740 is obtained by searching the symbol table 110 for the starting address of the optimized wage function.
  • the breakpoint setting means 120 sets an auxiliary breakpoint at the beginning of a subroutine that includes the location of the specified breakpoint as a part of it. This allows the program to be executed at high speed by executing the optimized code 105 up to a position as close as possible to the source code level breakpoint.
  • the beginning of the subroutine is a position where it is possible to switch from the optimized code 105 to the non-optimized code 106, and which includes a source code level breakpoint at a position relatively close to the source code level breakpoint specified by the user.
  • the breakpoint setting means 120 sets an auxiliary breakpoint at the beginning of a subroutine that is higher in the call graph than the subroutine that includes the location of the specified breakpoint as part of it.
  • step S704 depending on whether the user operation is to set or clear (delete) a breakpoint, the process proceeds to step S705 or step S706, respectively.
  • Both steps S705 and S706 are processes that take as input the address x in the non-optimized code 106, the start address y of function f in the non-optimized code 106, and the address y' of function f in the optimized code 105.
  • step S705 is set, and in S706, the breakpoint is cleared (deleted).
  • FIG. 8 is a flowchart of the breakpoint setting process.
  • the input is a triplet of addresses (x, y, y').
  • x is an address in the non-optimized code 106
  • y is the start address of function f in the non-optimized code 106
  • y' is the start address of function f in the optimized code 105
  • function f is a function that includes the instruction at address x as part of it.
  • the triplet corresponding to line 8 of the program wage.c in FIG. 2, which has been used as an example so far is (0x7b0, 0x780, 0x740).
  • step S801 an instruction-level breakpoint is set at address x.
  • the method for setting an instruction-level breakpoint is the same as in the past, and a hardware breakpoint or a software breakpoint can be used. For example, if x is 0x7b0, a breakpoint is set at the instruction corresponding to line 14 in Figure 5.
  • step S802 an instruction-level breakpoint is set at the starting address y'. For example, if y' is 0x740, a breakpoint is set at the instruction corresponding to the second line in Figure 3.
  • step S803 the information (x, y, y') is added to the auxiliary breakpoint table.
  • the triplet (x, y, y') is stored in the auxiliary breakpoint table 111.
  • FIG. 9 is a flowchart of the breakpoint clearing process.
  • the input is the same as in the breakpoint setting process.
  • step S901 the triplet (x, y, y') is deleted from the auxiliary breakpoint table 111.
  • step S902 the instruction-level breakpoint at address x in the non-optimized code 106 is cleared.
  • step S903 it is confirmed whether or not there is an entry corresponding to address y in auxiliary breakpoint table 111. If there are entries corresponding to addresses y, y' of function f in auxiliary breakpoint table 111, step S904 is skipped and the process ends. On the other hand, if there is no entry, the process proceeds to step S904. In step S904, the instruction level breakpoint at the start address y of function f in optimized code 105 is cleared and the process ends. The method of clearing the instruction level breakpoint is the same as conventional, whether it is implemented as a hardware breakpoint or a software breakpoint.
  • the breakpoint setting means 120 checks whether the auxiliary breakpoint is shared. In step S903, it is checked whether there is an entry corresponding to address y in the auxiliary breakpoint table 111, because auxiliary breakpoint y allows multiple source level breakpoints to share a single auxiliary breakpoint.
  • both auxiliary breakpoints will be the start address of the function wage in the optimized code 105.
  • clearing the breakpoint on line 8 of wage.c will also clear the auxiliary breakpoint for the source-level breakpoint on line 9.
  • the source-level breakpoint on line 9 will also be disabled. If there is confirmation process in step S903, the clearing of the auxiliary breakpoints is skipped, so the source-level breakpoint on line 9 will remain valid even after the source-level breakpoint on line 8 is cleared.
  • the execution control means 108 can switch from the start address y of the optimized code 105 of function f to the non-optimized code 106y'.
  • arguments and a return address are stored at the top of the CPU stack, and the stack for saving local variables and registers has not yet been used. Therefore, the optimized code 105 can continue execution by taking over the stack frame initialized by the optimized code 105.
  • breakpoint management means 107 and in particular the breakpoint switching means 121, is shown using the flowchart in FIG. 10.
  • the breakpoint switching means 121 is a procedure means that is executed when the program stops at an instruction breakpoint. If the input of the process in the flowchart in FIG. 10 is the instruction address B at which the program stopped, for example, if the program stopped at the instruction level breakpoint on the second line in FIG. 3, B is 0x740.
  • step S1001 a check is made to see if the instruction address B at which the program stopped is an auxiliary breakpoint. This can be confirmed by checking whether there is an entry in the auxiliary breakpoint table 111 where the third element y' of the triplet is the instruction address B. Note that the triplet of entries in the auxiliary breakpoint table 111 updated in step S803 of FIG. 8 is the address x of the instruction breakpoint in the non-optimized code 106, the start address y' of the function in the optimized code 105, and the start address y of the function in the non-optimized code 106.
  • step S1002 executes steps S1002 and S1003; if not, execute step S1004.
  • the stopped instruction address B is 0x740, if (0x7b0, 0x780, 0x740) is in the auxiliary breakpoint table 111, then the stopped instruction address B is an auxiliary breakpoint.
  • step S1002 the switch destination address B' is obtained from the auxiliary breakpoint table 111.
  • an entry where y' B is searched for, and the start address y of the function in the non-optimized code 106 of that entry is used as the switch destination address B'. If the stopped instruction address B is 0x740 and the entry obtained from the auxiliary breakpoint table 111 is (0x7b0, 0x780, 0x740), the switch destination address B' is 0x780.
  • step S1003 the program execution means 101 switches the current program counter of the program to be debugged from the stopped instruction address B to the switch destination address B', and the process proceeds to step S1005.
  • step S1004 interactive operations are offered to the user to start interactive processing in order to stop at a normal breakpoint. For example, if a breakpoint is set on line 8 of the program in Figure 3 used as an example so far, the program will stop at address 0x7b0, which corresponds to line 14 in Figure 5, as a normal breakpoint. At this point, the program has already switched to non-optimized code 106, so operations such as step execution and display of local variables can be offered to the user.
  • step S1004 the process proceeds to step S1005.
  • step S1005 execution of the debug target program 102 is resumed. If the stopped instruction address B is an auxiliary breakpoint, then at this point the code 104 has switched from optimized code 105 to non-optimized code 106. After the program continues to run for a while, it stops at the breakpoint in non-optimized code 106, and processing stops again. This series of processes is performed automatically, so the user does not notice that the program has stopped.
  • the breakpoint is not an auxiliary address
  • the execution control means 108 enters a state where it waits for an operation from the user. In this state, the debug target has already switched to non-optimized code 106, so variable values can be displayed and step execution can be performed in the same manner as before.
  • C language is used as an example of a high-level language, but the present invention does not limit the high-level language to C language.
  • the high-level language is assumed to be the descriptive language of the program that is to be converted into a machine language program.
  • the source language includes not only programming languages with textual expressions, but also visual programming languages. Examples of visual languages include the FBD language of IEC 61131-3 and block diagrams such as those used in MATLAB (registered trademark)/Simulink.
  • the line number is a kind of address for specifying a specific statement in the source code.
  • the line number corresponds to the address of a visual program element.
  • the high-level language is a block diagram in MATLAB (registered trademark)/Simulink
  • the block identifier is the line number.
  • the line number table holds the correspondence between the address of the program element and the instruction address.
  • the source language may be machine language. Even if the source language is different, each reusable conversion unit is converted into a machine language level subroutine. In this embodiment, the conversion unit is a C language function.
  • the conversion unit in the case of a block diagram such as MATLAB (registered trademark)/Simulink, the conversion unit can be a subsystem.
  • the source language is another machine language
  • basic blocks and superblocks in addition to subroutines of a machine language program, can be considered as conversion units.
  • the language described as a machine language in this embodiment does not need to be a machine language with a real processor, but can also be a virtual machine.
  • the address of the machine language corresponds to the line number in this embodiment.
  • this embodiment has been described assuming that the non-optimized code 106 is pre-loaded in the main memory, but it may be dynamically loaded when the user sets a breakpoint. By dynamically loading the non-optimized code 106 as needed, it is possible to reduce the capacity of the main memory until the start of debugging operations.
  • the debugging device is equipped with a program execution means for executing a program having optimized code and non-optimized code corresponding to the same source code, as well as a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting means for setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when a breakpoint is specified at a position in the source code, and a breakpoint switching means for switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
  • the debugging method also includes a program execution step for executing a program having optimized code and non-optimized code corresponding to the same source code, and a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting step for setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when the breakpoints are specified at the position of the source code, and a breakpoint switching step for switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
  • Embodiment 2 In the first embodiment, no mention is made of the function call configuration of the optimized code 105 and the non-optimized code 106.
  • the call of function B in the non-optimized code 106A usually becomes a call of function B in the non-optimized code 106.
  • non-optimized code 106 is used in which any call of f in the non-optimized code 106 becomes a call to function f in the optimized code 105.
  • step-in operation into function f is achieved by a series of processes: setting breakpoint B at the first line of function f, executing the program, and clearing breakpoint B after stopping at breakpoint B.
  • 101 program execution means 101 program execution means, 102 program to be debugged, 103 data, 104 code, 105 optimized code, 106 non-optimized code, 107 breakpoint management means, 108 execution control means, 109 line number table, 110 symbol table, 111 auxiliary breakpoint table, 120 breakpoint setting means, 121 breakpoint switching means.

Abstract

The debugging device comprises: a program execution means (101) which executes a program including an optimized code (105) and an unoptimized code (106) corresponding to the same source code and a line number table for the optimized code and a line number table for the unoptimized code; a breakpoint setting means (120) which, when a breakpoint is designated at a position in the source code, sets the breakpoint in two portions of the optimized code (105) and the unoptimized code (106) at a command level; and a breakpoint switching means (121) which, when the program stops at the breakpoint, which is set by the breakpoint setting means (120), in the optimized code (105), switches the code to be executed from the optimized code (105) to the unoptimized code (106).

Description

デバッグ装置及びデバッグ方法Debugging device and debugging method
 この発明は、計算機で実行されるプログラムのデバッグに関するものである。 This invention relates to debugging programs executed on a computer.
 計算機プログラムの開発においてデバッグは不可欠である。熟練したプログラマであってもはじめから期待通りに動作するプログラムを作成することは困難である。通常は一度書いたプログラムを実行して試験し、試験結果を確認しながらプログラムを書き直す。プログラムが期待通りに動作しない場合、プログラマは誤りを発見するためにプログラムをデバッグする。デバッガは、実行中のプログラムを停止したり、ステップ実行したりする機能を提供する。プログラマは、デバッガを用いることで、プログラムが停止している間に、自由にデータを読み書きできる。このときユーザはデバッグのためにプログラムを書き換える必要がないため、効率的に作業を進めることができる。 Debugging is essential in computer program development. Even experienced programmers find it difficult to create a program that works as expected from the start. Usually, a program is written once, then run and tested, and the program is rewritten while checking the test results. If a program does not work as expected, the programmer debugs the program to find errors. A debugger provides the ability to stop a running program and step through it. Using a debugger, a programmer can freely read and write data while the program is stopped. In this case, the user does not need to rewrite the program to debug, allowing the work to proceed more efficiently.
 ステップ実行には、機械語プログラムの1命令単位のステップ実行と高級言語の1文単位のステップ実行とがある。高級言語のプログラムをデバッグする場合、1文単位のステップ実行はデバッグに不可欠である。1文単位のステップ実行を行う方式としては、特許文献1の方法が存在する。特許文献1の発明による高級言語のステップ実行方式では、高級言語で記述されたソースプログラムに基づいて動作する計算機をステップ実行させる高級言語のステップ実行方式において、ソースプログラムの1行をステップ実行単位として前記1行に対応した機械語を連続的に実行させることで、高級言語での1文をステップ実行している。 Step execution can be performed on a per-instruction basis in machine language programs, or on a per-statement basis in high-level languages. When debugging a high-level language program, step execution on a per-statement basis is essential. One method for performing step execution on a per-statement basis is disclosed in Patent Document 1. In the high-level language step execution method disclosed in Patent Document 1, which causes a computer that operates based on a source program written in a high-level language to step execute, one statement in the high-level language is executed by successively executing the machine code corresponding to one line of the source program as a step execution unit.
特開昭61-180342JP 61-180342 A
 このように従来のステップ実行手段では、ソースプログラムの1行に相当する一連の機械語命令列を連続して実行することで実現していた。しかしながら、ソースプログラムを最適化した場合、ソースプログラムの行は順序が入り乱れた複数の命令列に変換されるため、正しい順序で行ごとのステップ実行ができない。このため、ステップ実行をサポートするには、最適化なしのプログラムを使用する必要があり、実行速度が遅いという問題があった。この発明では、この問題を解決するため、最適化ありのプログラムを主に実行しながらも、最適化がないプログラムと同様のデバッグ機能をユーザに提供することを目的とする。 In this way, conventional step execution means were realized by successively executing a series of machine language instructions equivalent to one line of a source program. However, when a source program is optimized, the lines of the source program are converted into multiple instruction sequences whose order is jumbled up, making it impossible to step through each line in the correct order. As a result, in order to support step execution, it is necessary to use a program without optimization, which results in a problem of slow execution speed. In order to solve this problem, the object of this invention is to provide users with the same debugging functionality as programs without optimization, while primarily executing programs with optimization.
 この発明に係るデバッグ装置は、同一のソースコードに対応する最適化済みコード及び最適化なしコード並びに最適化済みコード用の行番号表及び最適化なしコード用の行番号表を備えたプログラムを実行するプログラム実行手段と、ブレークポイントがソースコードの位置で指定された場合には、最適化済みコード及び最適化なしコードの2箇所に命令レベルでブレークポイントを設定するブレークポイント設定手段と、ブレークポイント設定手段が設定した最適化済みコード中のブレークポイントでプログラムが停止した場合には、実行対象のコードを最適化済みコードから最適化なしコードに切り替えるブレークポイント切替手段とを備えたデバッグ装置である。 The debugging device according to the present invention is a debugging device that includes a program execution means for executing a program that includes optimized code and non-optimized code corresponding to the same source code, as well as a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting means for setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when a breakpoint is specified at a position in the source code, and a breakpoint switching means for switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
 また、この発明に係るデバッグ方法は、同一のソースコードに対応する最適化済みコード及び最適化なしコード並びに最適化済みコード用の行番号表及び最適化なしコード用の行番号表を備えたプログラムを実行するプログラム実行ステップと、ブレークポイントがソースコードの位置で指定された場合には、最適化済みコード及び最適化なしコードの2箇所に命令レベルでブレークポイントを設定するブレークポイント設定ステップと、ブレークポイント設定手段が設定した最適化済みコード中のブレークポイントでプログラムが停止した場合には、実行対象のコードを最適化済みコードから最適化なしコードに切り替えるブレークポイント切替ステップとを備えたデバッグ方法である。 The debugging method according to the present invention is a debugging method including a program execution step of executing a program having optimized code and non-optimized code corresponding to the same source code, and a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting step of setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when the breakpoints are specified at the position of the source code, and a breakpoint switching step of switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
 この発明では、ソースコードレベルのブレークポイントが設定されるまでは、最適化済みコードでプログラムを高速に実行することができ、ブレークポイントが設定された後は、最適化なしコードを用いてステップ実行などの対話的なデバッグ操作を提供することができる。 In this invention, a program can be executed at high speed using optimized code until a source code level breakpoint is set, and after the breakpoint is set, interactive debugging operations such as step execution can be provided using non-optimized code.
図1は実施の形態1のデバッグ装置の例を示すブロック図である。FIG. 1 is a block diagram showing an example of a debugging device according to a first embodiment. 図2はデバッグ対象として想定するプログラムの例を示す図である。FIG. 2 is a diagram showing an example of a program that is assumed to be the target of debugging. 図3は最適化済みコードをディスアセンブルした結果の例を示す図である。FIG. 3 shows an example of the result of disassembling the optimized code. 図4は最適化済みコード用の行番号表の例を示す図である。FIG. 4 is an example of a line number table for optimized code. 図5は最適化なしコードのディスアセンブル結果の例を示す図である。FIG. 5 is a diagram showing an example of the disassembled result of code without optimization. 図6は最適化なしコード用の行番号表の例を示す図である。FIG. 6 is a diagram showing an example of a line number table for non-optimized code. 図7はブレークポイント管理手段のフローチャートの例である。FIG. 7 is an example of a flowchart of the breakpoint management means. 図8はブレークポイント設定処理のフローチャートの例である。FIG. 8 is an example of a flowchart of a breakpoint setting process. 図9はブレークポイントクリア処理のフローチャートの例である。FIG. 9 is an example of a flowchart of a breakpoint clear process. 図10はブレークポイント管理手段のフローチャートの例である。FIG. 10 is an example of a flowchart of the breakpoint management means.
実施の形態1.
 この発明では、プログラム実行手段101がデバッグ対象プログラム102を実行する。プログラム実行手段101はCPU(Central Processing Unit)であるが、実CPUの代わりにCPUエミュレータ、仮想マシン、インタプリタ、命令セットシミュレータなどであってもよい。デバッグ対象プログラム102は、高級言語のプログラムからコンパイルによって得られたプログラムである。また、デバッグ対象プログラム102は、各種のデータ103とコード104などから構成され、メモリなどの記憶装置に格納される。
Embodiment 1
In this invention, a program execution means 101 executes a program 102 to be debugged. The program execution means 101 is a CPU (Central Processing Unit), but may be a CPU emulator, a virtual machine, an interpreter, an instruction set simulator, etc., instead of a real CPU. The program 102 to be debugged is a program obtained by compiling a program in a high-level language. The program 102 to be debugged is composed of various data 103, code 104, etc., and is stored in a storage device such as a memory.
 コード104は、最適化済みコード105と最適化なしコード106とから構成される。最適化済みコード105と最適化なしコード106とは、同じソースプログラムから生成された機械語コード104であり、元のソースプログラムの関数ごとにそれぞれ適化済みのコード105と最適化なしのコード106の2通りが存在する。プログラム実行手段101が通常実行するコード104は最適化済みコード105である。一方、ユーザに対話的な操作を提供する間は、プログラム実行手段101は最適化なしコード106を実行する。即ち、プログラム実行手段101は、同一のソースコードに対応する最適化済みコード105及び最適化なしコード106並びに最適化済みコード105用の行番号表109及び前記最適化なしコード106用の行番号表109を備えたデバッグ対象プログラム102を実行することになる。 The code 104 is composed of optimized code 105 and non-optimized code 106. The optimized code 105 and non-optimized code 106 are machine code 104 generated from the same source program, and there are two types of code for each function of the original source program: optimized code 105 and non-optimized code 106. The code 104 that is normally executed by the program execution means 101 is optimized code 105. On the other hand, while providing interactive operations to the user, the program execution means 101 executes the non-optimized code 106. In other words, the program execution means 101 executes the debug target program 102 that includes optimized code 105 and non-optimized code 106 that correspond to the same source code, as well as a line number table 109 for the optimized code 105 and a line number table 109 for the non-optimized code 106.
 ブレークポイント管理手段107は、ブレークポイント設定手段120とブレークポイント切替手段121とから構成されている。ブレークポイント設定手段120は、高級言語のソースファイル名と行番号でブレークポイントを受付け、行番号表109とシンボルテーブル110を用いて最適化済みコード105と最適化なしコード106との両方にそれぞれブレークポイントを設定する。即ち、ブレークポイント設定手段120は、ブレークポイントがソースコードの位置で指定された場合には、最適化済みコード105及び最適化なしコード106の2箇所に命令レベルでブレークポイントを設定する。ブレークポイントを設定する位置については後で詳細を説明する。 The breakpoint management means 107 is composed of a breakpoint setting means 120 and a breakpoint switching means 121. The breakpoint setting means 120 accepts breakpoints by the high-level language source file name and line number, and sets breakpoints in both the optimized code 105 and the non-optimized code 106 using the line number table 109 and the symbol table 110. In other words, when a breakpoint is specified by a position in the source code, the breakpoint setting means 120 sets breakpoints at the instruction level in two locations, the optimized code 105 and the non-optimized code 106. The locations at which breakpoints are set will be explained in detail later.
 実行制御手段108は、設定されたブレークポイントに基づいてプログラム実行手段101の実行対象のコードを最適化済みコード105から最適化なしコード106へと切り替える。また、行番号表109は、ソースプログラムの行番号と最適化なしコード106の命令アドレスとの対応情報を保持する。 The execution control means 108 switches the code to be executed by the program execution means 101 from optimized code 105 to non-optimized code 106 based on the set breakpoint. In addition, the line number table 109 holds the correspondence information between the line numbers of the source program and the instruction addresses of the non-optimized code 106.
 シンボルテーブル110は、ソースコードにおける変数名や関数名などのシンボルごとに対応するアドレスと領域のサイズを保持する。ここで、シンボルテーブル110は、ソースコードにおける1つの関数名に対して、最適化済みコード105のアドレスと最適化なしコード106のアドレスとの両方を保持している。また、シンボルテーブル110は、関数の先頭アドレスとサイズを含むものとする。このため、関数の一部を構成する命令のアドレスをシンボルテーブル110で検索すると関数が特定できる。例えば、シンボルテーブル110のエントリが関数の先頭アドレスがfでサイズがsとするとき、与えられたアドレスaがf以上でかつf+sより小さいか否かを判定することでアドレスaの命令が関数の一部か否かを確認できる。これをすべてのシンボルテーブル110エントリに繰り返すことで、関数の一部のアドレスから関数の先頭アドレスやシンボル名などを取得することができる。 The symbol table 110 holds the address and area size corresponding to each symbol, such as a variable name or a function name in the source code. Here, for one function name in the source code, the symbol table 110 holds both the address of the optimized code 105 and the address of the non-optimized code 106. The symbol table 110 also includes the start address and size of the function. For this reason, the function can be identified by searching the symbol table 110 for the address of an instruction that constitutes part of the function. For example, if an entry in the symbol table 110 has a start address f and a size s of a function, it is possible to confirm whether the instruction at address a is part of a function by determining whether a given address a is greater than or equal to f and less than f+s. By repeating this process for all symbol table 110 entries, the start address of the function, the symbol name, etc. can be obtained from the address of part of the function.
 以下では、はじめに簡単なプログラムをデバッグする場合を例としてこの実施の形態で実現可能なステップ実行のシナリオを示した後、従来のデバッグ方法における問題とこれを解決するための本発明固有のブレークポイント管理手段107と実行制御手段108について詳細を示す。 Below, we will first show a step execution scenario that can be realized in this embodiment using an example of debugging a simple program, and then provide details on problems with conventional debugging methods and the breakpoint management means 107 and execution control means 108 unique to this invention that solve these problems.
 図2はデバッグ対象として想定するプログラムの例である。ここでは、例として、給与計算プログラムの一部をデバッグする場合を考える。ここで、プログラマは図2のプログラムの8行と9行目とをステップ実行し、時間超過分の給与が正しく計算されているか否かを確認したいものと想定する。この場合、プログラマは8行目と9行目とをステップ実行し、変数overtimeやsalaryの値を取得することで、時間超過分を含む給与がプログラマの意図通りに計算されているか否かを確認できる。 Figure 2 is an example of a program that is intended to be debugged. As an example, let us consider the case of debugging part of a payroll calculation program. Here, we assume that the programmer wants to step through lines 8 and 9 of the program in Figure 2 and check whether the overtime salary has been calculated correctly. In this case, the programmer can step through lines 8 and 9 and obtain the values of the variables overtime and salary to check whether the salary, including the overtime salary, has been calculated as the programmer intended.
 このようなステップ実行を行いたい場合に、プログラマは8行目にブレークポインを設定してからプログラムの実行を開始する。しばらくしてプログラムが8行目のブレークポイントで停止すると、デバッガはプログラマに対して、プログラムのステップ実行などの対話的な操作を提供することになる。プログラマは8行目のステップ実行をデバッガに指示すると、プログラムは9行目で停止する。次に、再度ステップ実行を指示すると10行目で停止する。 To perform this type of step execution, the programmer sets a breakpoint on line 8 and then starts running the program. After a while, when the program stops at the breakpoint on line 8, the debugger will offer the programmer interactive operations such as stepping through the program. If the programmer instructs the debugger to step through line 8, the program will stop at line 9. If the programmer then instructs the debugger to step through the program again, the program will stop at line 10.
 上記のようなデバッグを従来のデバッグ方法で実現しようとした場合、最適化なしコード106を用いる必要がある。すなわち、図2の関数wageの最適化済みコード105をデバッグ対象とする場合、上述したようなデバッグを行うことはできない。この問題を以下では、wageの最適化済みコード105とそれに対応する行番号表109を用いて説明する。 If you try to achieve the above debugging using conventional debugging methods, you need to use non-optimized code 106. In other words, if the optimized code 105 of the function wage in FIG. 2 is the debugging target, you cannot perform the above debugging. This problem will be explained below using the optimized code 105 of wage and the corresponding line number table 109.
 まず、図3は図2のソースプログラムから生成された最適化済みコード105をディスアセンブルした結果を示す図である。図3のフォーマットは、GNU binutilsのobjdumpコマンドによるディスアセンブル結果のフォーマットに準ずる。1行目は、関数wageが0x740番地から始まることを示している。また、2行目から10行目まではwageに含まれる命令列をディスアセンブルした結果である。例えば、2行目は740番地の命令コードが0xd2e80880であり、このニーモニックはmovであることを意味する。また、このmov命令は即値の0x4044000000000000をレジスタx0に格納することを意味する。なお、各命令の詳細はこの発明とは直接関係しないため説明は割愛する。 First, FIG. 3 shows the result of disassembling optimized code 105 generated from the source program in FIG. 2. The format of FIG. 3 conforms to the format of the disassembly result by the objdump command of GNU binutils. The first line indicates that the function wage starts at address 0x740. Furthermore, lines 2 to 10 show the result of disassembling the instruction sequence contained in wage. For example, line 2 indicates that the instruction code at address 740 is 0xd2e80880, and its mnemonic is mov. Furthermore, this mov instruction means that the immediate value 0x4044000000000000 is stored in register x0. Note that the details of each instruction are not directly related to this invention, so an explanation will be omitted.
 次に、図4は図2の関数wageに対応する最適化済みコード105用の行番号表109を示す図である。図4の行番号表109のフォーマットはGNU binutilsのreadelfコマンドによる行番号情報のダンプ結果の出力フォーマットに準ずる。3行目から16行目が実際のソースコードの各行とアドレスとの対応を示しており、1列目がファイル名、2列目が行番号、3列目が対応するアドレスを示す。例えば、3行目はファイル名wage.cの5行目が最適化済みコード105では0x740番地に存在することを表している。図4からデバッガは最適化済みコード105を用いてソースコードのレベルでステップ実行を行うことができないことがわかる。例えば、図4の3行目から5行目は、0x740番地がソースコードの5、6、7行目が対応していることを示す。このため、5行目や6行目だけを実行するつもりで0x740番地の命令を実行しても5、6、7行目に対応する処理も一部実行されてしまうことがわかる。したがって、従来のデバッグ方法では、最適化済みコード105を用いた場合には、ソースコードの行ごとのステップ実行ができないことが問題となる。 Next, FIG. 4 shows line number table 109 for optimized code 105 corresponding to function wage in FIG. 2. The format of line number table 109 in FIG. 4 conforms to the output format of the line number information dump result by the readelf command of GNU binutils. Lines 3 to 16 show the correspondence between each line of the actual source code and an address, with the first column showing the file name, the second column showing the line number, and the third column showing the corresponding address. For example, line 3 shows that line 5 of file name wage.c exists at address 0x740 in optimized code 105. It can be seen from FIG. 4 that the debugger cannot perform step execution at the source code level using optimized code 105. For example, lines 3 to 5 in FIG. 4 show that address 0x740 corresponds to lines 5, 6, and 7 of the source code. For this reason, even if the instruction at address 0x740 is executed with the intention of executing only lines 5 and 6, it turns out that part of the processing corresponding to lines 5, 6, and 7 is also executed. Therefore, with the conventional debugging method, when optimized code 105 is used, the problem is that it is not possible to step through the source code line by line.
 この発明の基本的なアイデアは、デバッグがユーザに対話的な操作を提供する間だけ最適化なしのコード106に切り替えて実行することである。この切替えはブレークポイント切替手段121が自動的に行うため、ユーザはあたかもはじめから最適化なしコード106を実行しているかのうように、ステップ実行や変数の表示などの一般的なデバッグ操作ができるようになる。 The basic idea of this invention is to switch to and execute unoptimized code 106 only while debugging is providing interactive operations to the user. This switching is performed automatically by breakpoint switching means 121, so the user can perform general debugging operations such as step execution and variable display as if they had been executing unoptimized code 106 from the beginning.
 ユーザとの対話的な操作を開始するのは、プログラムがブレークポイントで止まった場合である。 Interactive interaction with the user begins when the program stops at a breakpoint.
 以下では、はじめに最適化なしコード106とその行番号表109の具体例を示した後、どのように最適化なしコード106に切り替えるかを示す。なお、行番号表109は、最適化なしコード106用のアドレス対応表と、最適化済みコード105用のアドレス対応表とで構成されている。 Below, we first show a concrete example of non-optimized code 106 and its line number table 109, and then show how to switch to non-optimized code 106. Note that line number table 109 is made up of an address correspondence table for non-optimized code 106 and an address correspondence table for optimized code 105.
 まず、図3のwage関数に対応する最適化なしコード106のディスアセンブル結果は図5のとおりである。また、最適化なしコード106用の行番号表109を図6に示す。なお、図6では、wage.cから生成した最適化なしコード106用のものであることがわかるように、wage_O0.cのように元のファイル名wage.cのベース名wageの末尾に_O2を付与している。図5の2行目から27行目までが関数wageの処理と対応するコードであり0x780番地から始まっている。また、図6の3行目から10行目までは、図2のプログラムの5行目から13行目までが図5の最適化なしコード106の何番地と対応しているかを示すものである。最適化済みコード105の場合と異なり、各番地は必ず1つの行とのみ対応しており、ソースコードの行番号の順と最適化なしコード106の番地の順が同じ順で並んでいることがわかる。 First, the disassembly result of the non-optimized code 106 corresponding to the wage function in FIG. 3 is as shown in FIG. 5. Also, the line number table 109 for the non-optimized code 106 is shown in FIG. 6. Note that in FIG. 6, _O2 is added to the end of the base name wage of the original file name wage.c, such as wage_O0.c, so that it can be seen that this is for the non-optimized code 106 generated from wage.c. Lines 2 to 27 in FIG. 5 are the code corresponding to the processing of the function wage, and start from address 0x780. Lines 3 to 10 in FIG. 6 indicate which addresses in the non-optimized code 106 in FIG. 5 correspond to lines 5 to 13 in the program in FIG. 2. Unlike the case of the optimized code 105, each address always corresponds to only one line, and it can be seen that the order of the line numbers in the source code and the order of the addresses in the non-optimized code 106 are arranged in the same order.
 換言すると、図6の最適化なしコード106の行番号(Line number)は総ての行が異なる番号で昇順に命令列が整列している。これに対して、図4の最適化済みコード105の行番号は同じ番号が出現したり、番号の大小が入れ替わったりしており、ソースプログラムの行は順序が入り乱れた複数の命令列に変換されるため、正しい順序で行ごとのステップ実行ができない。このため、最適化なしコード106からはソースコードの行番号を容易に辿ることができるのに対して、最適化済みコード105からはソースコードの行番号を辿ることは容易なことではない。当然のことながら、最適化なしコード106に対して最適化済みコード105の方が実行速度は早くなる。 In other words, the line numbers of the non-optimized code 106 in FIG. 6 are all different numbers, and the instruction sequence is arranged in ascending order. In contrast, the line numbers of the optimized code 105 in FIG. 4 include some identical numbers and some numbers that are swapped, and the lines of the source program are converted into multiple instruction sequences with their order jumbled up, making it impossible to execute each line in the correct order. For this reason, while it is easy to trace the line numbers of the source code from the non-optimized code 106, it is not easy to trace the line numbers of the source code from the optimized code 105. Naturally, the execution speed of the optimized code 105 is faster than that of the non-optimized code 106.
 以下では、ユーザがファイル名sのソースコードのn行目にソースコードレベルのブレークポイントを設定した場合のブレークポイント設定手順を示す。ここでは、この実施の形態の例による解決手法を示す。以降、この明細書ではファイル名と行番号のペアで指定されるブレークポイントをソースレベルブレークポイントと呼び、プログラム制御手段108が実際に停止する命令のメモリ番地で指定されるブレークポイントを命令レベルブレークポイントと読んで両者を区別するものとする。 The following describes the procedure for setting a breakpoint when the user sets a source code level breakpoint on line n of the source code of file name s. Here, we show a solution method using an example of this embodiment. Hereafter, in this specification, a breakpoint specified by a pair of a file name and a line number will be called a source level breakpoint, and a breakpoint specified by the memory address of the instruction at which program control means 108 actually stops will be called an instruction level breakpoint to distinguish between the two.
 ブレークポイント設定手段120は、ユーザが指定したソースファイル名sと行番号nに対応する最適化なしコード106中の命令アドレスに命令レベルブレークポイントを設定する。 The breakpoint setting means 120 sets an instruction-level breakpoint at an instruction address in the unoptimized code 106 that corresponds to the source file name s and line number n specified by the user.
 ところが、プログラム実行手段101は、通常、最適化済みコード105を実行するため、最適化なしコード106が実行されることがない。そこで、ブレークポイント管理手段107では、実行制御手段108が実行対象のコード104を最適化済みコード105から最適化なしコード106に切り替えられるように、最適化済みコード105にも補助的な命令レベルブレークポイントを設定しておく。実行制御手段108は、補助的なブレークポイントで停止したときに、最適化済みコード105から最適化なしコード106に切り替える。 However, since the program execution means 101 normally executes optimized code 105, the non-optimized code 106 is never executed. Therefore, the breakpoint management means 107 also sets an auxiliary instruction level breakpoint in the optimized code 105 so that the execution control means 108 can switch the code 104 to be executed from the optimized code 105 to the non-optimized code 106. When stopped at the auxiliary breakpoint, the execution control means 108 switches from the optimized code 105 to the non-optimized code 106.
 換言すると、ブレークポイント切替手段121は、ブレークポイント設定手段120が設定した最適化済みコード105中のブレークポイントでプログラムが停止した場合には、実行対象のコードを最適化済みコード105から最適化なしコード106に切り替えることになる。 In other words, when the program stops at a breakpoint in the optimized code 105 set by the breakpoint setting means 120, the breakpoint switching means 121 switches the code to be executed from the optimized code 105 to the non-optimized code 106.
 図7はブレークポイント管理手段107のフローチャートである。入力はユーザが指定したファイル名s、行番号nとブレークポイント操作の種類である。指定可能なブレークポイント操作は、設定またはクリアの2種類である。 Figure 7 is a flowchart of the breakpoint management means 107. The input is the file name s, line number n, and type of breakpoint operation specified by the user. There are two types of breakpoint operations that can be specified: set or clear.
 まず、ステップS701では、最適化なしコード106用の行番号表109からファイル名sと行番号nに対応するアドレスxを検索して取得する。例えば、図2のプログラムwage.cの8行目が指定された場合、sはwage.cであり、nは8である。このとき、図6の6行目よりwage.cの8行目は0x7b0番地から開始していることがわかる。したがって、この場合xは0x7b0である。なお、図6では最適化なしコード106であることを示すため、wage.cをwage_O0.cに改名してある点に注意が必要である。 First, in step S701, the address x corresponding to the file name s and line number n is searched and obtained from the line number table 109 for the non-optimized code 106. For example, when the 8th line of the program wage.c in FIG. 2 is specified, s is wage.c and n is 8. In this case, it can be seen from the 6th line in FIG. 6 that the 8th line of wage.c starts at address 0x7b0. Therefore, in this case, x is 0x7b0. Note that in FIG. 6, wage.c has been renamed to wage_O0.c to indicate that this is non-optimized code 106.
 次に、ステップS702では、命令アドレスxを含む関数fをシンボルテーブル110から検索し、最適化なしコード106における関数fの先頭アドレスyを取得する。例えば、関数fがwageの場合には、先頭アドレスyは図5の2行目のように0x780番地から始まる。このwageと0x780は、命令アドレスxすなわち0x7b0を用いてシンボルテーブル110を検索することで得られる。 Next, in step S702, function f containing instruction address x is searched for in symbol table 110, and the starting address y of function f in non-optimized code 106 is obtained. For example, if function f is wage, the starting address y starts from address 0x780 as shown in the second line of FIG. 5. This wage and 0x780 are obtained by searching symbol table 110 using instruction address x, i.e., 0x7b0.
 次に、ステップS703では、関数fの最適化済みコード105における先頭アドレスy’をシンボルテーブル110から取得する。ステップS703におけるシンボルテーブル110の検索では、ステップS702でシンボルテーブル110を検索した時に得た関数fのシンボル名を用いることができる。なお、先述のとおりシンボルテーブル110は、各関数について最適化済みコード105と最適化なしコード106の両方のアドレスを保持している。例えば、関数fがwageのとき、最適化済み関数wageの先頭アドレスy’は、図3の2行目より0x740である。この0x740は、シンボルテーブル110で最適化済みのwage関数の先頭アドレスを検索することで得られる。 Next, in step S703, the starting address y' of the optimized code 105 of function f is obtained from the symbol table 110. When searching the symbol table 110 in step S703, the symbol name of function f obtained when searching the symbol table 110 in step S702 can be used. As described above, the symbol table 110 holds the addresses of both the optimized code 105 and the non-optimized code 106 for each function. For example, when the function f is wage, the starting address y' of the optimized function wage is 0x740 from the second line in FIG. 3. This 0x740 is obtained by searching the symbol table 110 for the starting address of the optimized wage function.
 ブレークポイント設定手段120は、ブレークポイントが指定された場合には、当該ブレークポイントの位置を一部として含むサブルーチンの先頭に補助ブレークポイントを設定することになる。これによって、ソースコードレベルのブレークポイントにできるだけ近い位置まで最適化済みコード105で実行してプログラムを高速に実行することができる。ここで、サブルーチンの先頭とは、最適化済みコード105から最適化なしコード106への切り替えが可能な位置であって、ユーザが指定したソースコードレベルのブレークポイントに比較的近い位置がソースコードレベルのブレークポイントを含むものである。 When a breakpoint is specified, the breakpoint setting means 120 sets an auxiliary breakpoint at the beginning of a subroutine that includes the location of the specified breakpoint as a part of it. This allows the program to be executed at high speed by executing the optimized code 105 up to a position as close as possible to the source code level breakpoint. Here, the beginning of the subroutine is a position where it is possible to switch from the optimized code 105 to the non-optimized code 106, and which includes a source code level breakpoint at a position relatively close to the source code level breakpoint specified by the user.
 換言すれば、ブレークポイント設定手段120は、ブレークポイントが指定された場合には、当該ブレークポイントの位置を一部として含むサブルーチンよりもコールグラフで上位に位置するサブルーチンの先頭に補助ブレークポイントを設定することになる。 In other words, when a breakpoint is specified, the breakpoint setting means 120 sets an auxiliary breakpoint at the beginning of a subroutine that is higher in the call graph than the subroutine that includes the location of the specified breakpoint as part of it.
 ステップS704では、ユーザ操作がブレークポイントの設定かクリア(削除)かで、それぞれステップS705またはステップS706に進む。ステップS705とステップS706は両方とも、最適化なしコード106中でのアドレスx、最適化なしコード106中での関数fの先頭アドレスy、最適化済みコード105中での関数fのアドレスy’を入力とする処理である。ステップS705では、ブレークポイントを設定し、S706ではブレークポイントをクリア(削除)する。 In step S704, depending on whether the user operation is to set or clear (delete) a breakpoint, the process proceeds to step S705 or step S706, respectively. Both steps S705 and S706 are processes that take as input the address x in the non-optimized code 106, the start address y of function f in the non-optimized code 106, and the address y' of function f in the optimized code 105. In step S705, a breakpoint is set, and in S706, the breakpoint is cleared (deleted).
 以下では、ブレークポイントの設定手順とブレークポイントのクリア手順をそれぞれ図8と図9のフローチャートを用いて説明する。 Below, the procedure for setting a breakpoint and the procedure for clearing a breakpoint are explained using the flowcharts in Figures 8 and 9, respectively.
 図8はブレークポイント設定処理のフローチャートである。入力は、アドレスの3つ組(x、y、y’)である。ここで、xは、最適化なしコード106中でのアドレス、yは最適化なしコード106中での関数fの先頭アドレス、y’は最適化済みコード105中での関数fの先頭アドレスであり、関数fはアドレスxの命令を一部として含む関数である。例えば、ここまで例として用いた図2のプログラムwage.cの8行目に対応する3つ組は(0x7b0,0x780,0x740)である。 FIG. 8 is a flowchart of the breakpoint setting process. The input is a triplet of addresses (x, y, y'). Here, x is an address in the non-optimized code 106, y is the start address of function f in the non-optimized code 106, y' is the start address of function f in the optimized code 105, and function f is a function that includes the instruction at address x as part of it. For example, the triplet corresponding to line 8 of the program wage.c in FIG. 2, which has been used as an example so far, is (0x7b0, 0x780, 0x740).
 ステップS801では、アドレスxに命令レベルブレークポイントを設定する。命令レベルブレークポイントの設定方法は従来どおりであり、ハードウェアブレークポイントやソフトウェアブレークポイントを用いることができる。たとえば、xが0x7b0の場合、図5の14行目と対応する命令にブレークポイントが設定される。 In step S801, an instruction-level breakpoint is set at address x. The method for setting an instruction-level breakpoint is the same as in the past, and a hardware breakpoint or a software breakpoint can be used. For example, if x is 0x7b0, a breakpoint is set at the instruction corresponding to line 14 in Figure 5.
 次に、ステップS802では先頭アドレスy’に命令レベルブレークポイントを設定する。たとえば、y’が0x740の場合、図3の2行目に対応する命令にブレークポイントが設定される。 Next, in step S802, an instruction-level breakpoint is set at the starting address y'. For example, if y' is 0x740, a breakpoint is set at the instruction corresponding to the second line in Figure 3.
 最後に、ステップS803では、補助ブレークポイントテーブルに(x,y,y’)の情報を追加する。補助ブレークポイント表111に3つ組(x,y,y’)を格納する。 Finally, in step S803, the information (x, y, y') is added to the auxiliary breakpoint table. The triplet (x, y, y') is stored in the auxiliary breakpoint table 111.
 図9は、ブレークポイントクリア処理のフローチャートである。入力は、ブレークポイント設定処理と同じである。ステップS901では、補助ブレークポイント表111から3つ組(x,y,y’)を削除する。次に、ステップS902では、最適化なしコード106中のアドレスxの命令レベルブレークポイントをクリアする。 FIG. 9 is a flowchart of the breakpoint clearing process. The input is the same as in the breakpoint setting process. In step S901, the triplet (x, y, y') is deleted from the auxiliary breakpoint table 111. Next, in step S902, the instruction-level breakpoint at address x in the non-optimized code 106 is cleared.
 次に、ステップS903では、補助ブレークポイント表111にアドレスyに対応するエントリがあるか否かを確認する。補助ブレークポイント表111に関数fのアドレスy,y’に対応するエントリが存在する場合には、ステップS904をスキップして終了する。一方、エントリが存在しない場合には、ステップS904に進む。ステップS904では最適化済みコード105における関数fの先頭アドレスyの命令レベルブレークポイントをクリアして終了する。命令レベルブレークポイントのクリアの方法は、ハードウェアブレークポイントとして実装する場合もソフトウェアブレークポイントとして実装する場合も従来どおりである。 Next, in step S903, it is confirmed whether or not there is an entry corresponding to address y in auxiliary breakpoint table 111. If there are entries corresponding to addresses y, y' of function f in auxiliary breakpoint table 111, step S904 is skipped and the process ends. On the other hand, if there is no entry, the process proceeds to step S904. In step S904, the instruction level breakpoint at the start address y of function f in optimized code 105 is cleared and the process ends. The method of clearing the instruction level breakpoint is the same as conventional, whether it is implemented as a hardware breakpoint or a software breakpoint.
 ブレークポイント設定手段120は、補助ブレークポイントを削除する場合には、前記補助ブレークポイントが共有されているか否か確認する。ステップS903で補助ブレークポイント表111にアドレスyに対応するエントリがあるか否かを確認しているのは、補助ブレークポイントyは複数のソースレベルブレークポイントが単一の補助ブレークポイントを共有できるようにするためである。 When deleting an auxiliary breakpoint, the breakpoint setting means 120 checks whether the auxiliary breakpoint is shared. In step S903, it is checked whether there is an entry corresponding to address y in the auxiliary breakpoint table 111, because auxiliary breakpoint y allows multiple source level breakpoints to share a single auxiliary breakpoint.
 例えば、図8のソースコードwage.cの8行目と9行目の二か所にソースレベルブレークポイントが設定される場合には、両方の補助ブレークポイントは、共に最適化済みコード105における関数wageの先頭アドレスとなる。このような場合、ステップS903の確認処理がない場合には、wage.cの8行目のブレークポイントをクリアすると9行目のソースレベルブレークポイントのための補助ブレークポイントもクリアされてしまう。この結果、9行目のソースレベルブレークポイントも無効化されてしまう。ステップS903の確認処理があれば、補助ブレークポイントのクリアはスキップされるため、8行目のソースレベルブレークポイントがクリアさされた後も引き続き9行目のソースレベルブレークポイントは有効となる。 For example, if two source-level breakpoints are set in lines 8 and 9 of the source code wage.c in FIG. 8, both auxiliary breakpoints will be the start address of the function wage in the optimized code 105. In this case, if there is no confirmation process in step S903, clearing the breakpoint on line 8 of wage.c will also clear the auxiliary breakpoint for the source-level breakpoint on line 9. As a result, the source-level breakpoint on line 9 will also be disabled. If there is confirmation process in step S903, the clearing of the auxiliary breakpoints is skipped, so the source-level breakpoint on line 9 will remain valid even after the source-level breakpoint on line 8 is cleared.
 実行制御手段108は、プログラムが関数fの先頭アドレスyで停止したときに、関数fの最適化済みコード105の先頭yから最適化なしコード106y’に切り替えることができる。関数呼び出しの直後では、CPUのスタックのトップには引数やリターンアドレスが積まれている状態であり、ローカル変数やレジスタ退避のためのスタックはまだ使われていない状態である。このため、最適化済みコード105が初期化したスタックフレームを引き継いで最適化済みコード105が実行を続けることができる。 When the program stops at the start address y of function f, the execution control means 108 can switch from the start address y of the optimized code 105 of function f to the non-optimized code 106y'. Immediately after a function call, arguments and a return address are stored at the top of the CPU stack, and the stack for saving local variables and registers has not yet been used. Therefore, the optimized code 105 can continue execution by taking over the stack frame initialized by the optimized code 105.
 次に、ブレークポイント管理手段107、特にブレークポイント切替手段121の動作を図10のフローチャートを用いて示す。 Next, the operation of the breakpoint management means 107, and in particular the breakpoint switching means 121, is shown using the flowchart in FIG. 10.
 ブレークポイント切替手段121は、プログラムが命令ブレークポイントで停止したときに実行される手順の手段である。図10のフローチャートの処理の入力は、プログラムが停止した命令アドレスBとすると、例えば、図3の2行目の命令レベルブレークポイントで停止した場合、Bは0x740である。 The breakpoint switching means 121 is a procedure means that is executed when the program stops at an instruction breakpoint. If the input of the process in the flowchart in FIG. 10 is the instruction address B at which the program stopped, for example, if the program stopped at the instruction level breakpoint on the second line in FIG. 3, B is 0x740.
 ステップS1001では、停止した命令アドレスBが補助ブレークポイントか否かをチェックする。この確認は補助ブレークポイント表111に3つ組の3番目の要素y’が命令アドレスBとなるエントリがあるか否かで確認できる。なお、図8のステップS803で更新した補助ブレークポイント表111のエントリの3つの組は、最適化なしコード106における命令ブレークポイントのアドレスx最適化済みコード105における関数の先頭アドレスy’と最適化なしコード106における関数の先頭アドレスyである。 In step S1001, a check is made to see if the instruction address B at which the program stopped is an auxiliary breakpoint. This can be confirmed by checking whether there is an entry in the auxiliary breakpoint table 111 where the third element y' of the triplet is the instruction address B. Note that the triplet of entries in the auxiliary breakpoint table 111 updated in step S803 of FIG. 8 is the address x of the instruction breakpoint in the non-optimized code 106, the start address y' of the function in the optimized code 105, and the start address y of the function in the non-optimized code 106.
 停止した命令アドレスBが補助ブレークポイントであれば、ステップS1002とS1003、そうでなければステップS1004を実行する。例えば、停止した命令アドレスBが0x740のとき補助ブレークポイント表111に(0x7b0,0x780,0x740)があれば、停止した命令アドレスBは補助ブレークポイントである。 If the stopped instruction address B is an auxiliary breakpoint, execute steps S1002 and S1003; if not, execute step S1004. For example, when the stopped instruction address B is 0x740, if (0x7b0, 0x780, 0x740) is in the auxiliary breakpoint table 111, then the stopped instruction address B is an auxiliary breakpoint.
 ステップS1002では、補助ブレークポイント表111から切り替え先アドレスB’を取得する。 In step S1002, the switch destination address B' is obtained from the auxiliary breakpoint table 111.
 ここでは、y’=Bとなるエントリを検索し、当該エントリの最適化なしコード106における関数の先頭アドレスyを切り替え先アドレスB’として使用する。停止した命令アドレスBが0x740で補助ブレークポイント表111から取得したエントリが(0x7b0,0x780,0x740)の場合には、切り替え先アドレスB’は0x780である。 Here, an entry where y' = B is searched for, and the start address y of the function in the non-optimized code 106 of that entry is used as the switch destination address B'. If the stopped instruction address B is 0x740 and the entry obtained from the auxiliary breakpoint table 111 is (0x7b0, 0x780, 0x740), the switch destination address B' is 0x780.
 次に、ステップS1003ではプログラム実行手段101で、デバッグ対象プログラムの現在のプログラムカウンタを停止した命令アドレスBから切り替え先アドレスB’へと切り替えて、ステップS1005に進む。 Next, in step S1003, the program execution means 101 switches the current program counter of the program to be debugged from the stopped instruction address B to the switch destination address B', and the process proceeds to step S1005.
 一方、ステップS1004では、通常のブレークポイントでの停止のため、ユーザに対話的操作を提供して対話的処理を開始する。例えば、これまで例に用いた図3のプログラムの8行目にブレークポイントが設定されている場合には、図5の14行目に相当する0x7b0番地で通常のブレークポイントとして停止する。このとき、プログラムは最適化なしコード106に既に切り替わっているため、ユーザにステップ実行、ローカル変数の表示などの操作を提供することができる。 On the other hand, in step S1004, interactive operations are offered to the user to start interactive processing in order to stop at a normal breakpoint. For example, if a breakpoint is set on line 8 of the program in Figure 3 used as an example so far, the program will stop at address 0x7b0, which corresponds to line 14 in Figure 5, as a normal breakpoint. At this point, the program has already switched to non-optimized code 106, so operations such as step execution and display of local variables can be offered to the user.
 ステップS1004が完了するとステップS1005に進む。ステップS1005では、デバッグ対象プログラム102の実行を再開する。停止した命令アドレスBが補助ブレークポイントの場合には、この時点でコード104は最適化済みコード105から最適化なしコード106に切り替わっている。そして、しばらくプログラムが実行を続けると最適化なしコード106のブレークポイントで停止し、再び処理が停止する。この一連の処理は自動的に行われるため、ユーザはプログラムが停止したことに気付くことがない。一方、ブレークポイントが補助アドレスでない場合は、実行制御手段108はユーザからの操作を待つ状態になる。この状態では、すでにデバッグ対象は最適化なしコード106に切り替わっているため、従来通りの手順で変数の値を表示したり、ステップ実行を行ったりすることができる。 When step S1004 is completed, the process proceeds to step S1005. In step S1005, execution of the debug target program 102 is resumed. If the stopped instruction address B is an auxiliary breakpoint, then at this point the code 104 has switched from optimized code 105 to non-optimized code 106. After the program continues to run for a while, it stops at the breakpoint in non-optimized code 106, and processing stops again. This series of processes is performed automatically, so the user does not notice that the program has stopped. On the other hand, if the breakpoint is not an auxiliary address, the execution control means 108 enters a state where it waits for an operation from the user. In this state, the debug target has already switched to non-optimized code 106, so variable values can be displayed and step execution can be performed in the same manner as before.
 この実施の形態では、高級言語としてC言語を例として使用したが、この発明は高級言語をC言語には限定しない。この発明では、高級言語として機械語プログラムへの変換元となるプログラムの記述言語を高級言語として想定する。変換元となる言語にはテキスト表現のプログラミング言語だけではなくビジュアルプログラミング言語も含まれる。ビジュアル言語の例としてはIEC61131-3のFBD言語、MATLAB(登録商標)/Simulinkで使用するようなブロック線図等が含まれる。 In this embodiment, C language is used as an example of a high-level language, but the present invention does not limit the high-level language to C language. In this invention, the high-level language is assumed to be the descriptive language of the program that is to be converted into a machine language program. The source language includes not only programming languages with textual expressions, but also visual programming languages. Examples of visual languages include the FBD language of IEC 61131-3 and block diagrams such as those used in MATLAB (registered trademark)/Simulink.
 本実施の形態における行番号は、ソースコード中の特定の1文を指定するための一種のアドレスである。高級言語がビジュアルプログラミング言語の場合、行番号は、ビジュアル的なプログラム要素のアドレスが相当する。例えば、高級言語がMATLAB(登録商標)/Simulinkのブロック線図の場合には、ブロックの識別子が行番号である。これに対応して、行番号表はプログラム要素のアドレスと命令アドレスとの対応を保持する。さらに、変換元の言語が機械語であってもよい。変換元の言語が異なっても再利用可能な変換単位ごとに機械語レベルのサブルーチンに変換される。この実施の形態では変換単位がC言語の関数の場合を示した。 In this embodiment, the line number is a kind of address for specifying a specific statement in the source code. If the high-level language is a visual programming language, the line number corresponds to the address of a visual program element. For example, if the high-level language is a block diagram in MATLAB (registered trademark)/Simulink, the block identifier is the line number. Correspondingly, the line number table holds the correspondence between the address of the program element and the instruction address. Furthermore, the source language may be machine language. Even if the source language is different, each reusable conversion unit is converted into a machine language level subroutine. In this embodiment, the conversion unit is a C language function.
 その他の変換単位の例としては、MATLAB(登録商標)/Simulinkのようなブロック線図の場合では、変換単位はサブシステムが考えられる。また、変換元言語が別の機械語の場合には、機械語プログラムのサブルーチンに加えて基本ブロックやスーパーブロックが変換単位として考えられる。また、この実施の形態で機械語として説明した言語は実プロセッサが存在する機械語である必要はなく仮想機械であってもよい。なお、変換元の言語が機械語の場合、機械語のアドレスが本実施の形態における行番号に対応する。 As another example of a conversion unit, in the case of a block diagram such as MATLAB (registered trademark)/Simulink, the conversion unit can be a subsystem. Furthermore, when the source language is another machine language, basic blocks and superblocks, in addition to subroutines of a machine language program, can be considered as conversion units. Furthermore, the language described as a machine language in this embodiment does not need to be a machine language with a real processor, but can also be a virtual machine. Furthermore, when the source language is a machine language, the address of the machine language corresponds to the line number in this embodiment.
 また、上記の説明では、最適化済みコード105と最適化なしコード106には同じ関数が存在することを前提とした。しかしながら、一般には最適化で関数が別の関数にインライン展開される場合がある。例えば、関数fが最適化によって関数gにインライン展開されている場合、最適化済みコード105における関数fooの先頭に補助ブレークポイントを設定することができない。また、設定できたとしてインライン展開された方のコード104が実行されるため、プログラムは補助ブレークポイントでは停止しない。このような場合に対応するためには、関数f中にブレークポイントを設定する場合、関数fをインライン展開した先である関数gの先頭に補助ブレークポイントを設定すればよい。 In addition, the above explanation is based on the assumption that the optimized code 105 and the non-optimized code 106 contain the same functions. However, there are cases in which a function is inline-expanded into another function due to optimization. For example, if function f is inline-expanded into function g due to optimization, an auxiliary breakpoint cannot be set at the beginning of function foo in optimized code 105. Even if it were possible to set a breakpoint, the inline-expanded code 104 would be executed, so the program would not stop at the auxiliary breakpoint. To deal with such cases, when setting a breakpoint in function f, an auxiliary breakpoint can be set at the beginning of function g, which is the destination of the inline expansion of function f.
 また、この実施の形態では、最適化なしコード106があらかじめ主記憶装置にロードされている場合を想定して記述したが、ユーザがブレークポイントをしたときに動的にロードしてもよい。最適化なしコード106を必要に応じて動的ロードすることで、デバッグ操作を開始するまで主記憶装置の容量を削減することができる。 In addition, this embodiment has been described assuming that the non-optimized code 106 is pre-loaded in the main memory, but it may be dynamically loaded when the user sets a breakpoint. By dynamically loading the non-optimized code 106 as needed, it is possible to reduce the capacity of the main memory until the start of debugging operations.
 以上のように、同一のソースコードに対応する最適化済みコード及び最適化なしコード並びに最適化済みコード用の行番号表及び最適化なしコード用の行番号表を備えたプログラムを実行するプログラム実行手段と、ブレークポイントがソースコードの位置で指定された場合には、最適化済みコード及び最適化なしコードの2箇所に命令レベルでブレークポイントを設定するブレークポイント設定手段と、ブレークポイント設定手段が設定した最適化済みコード中のブレークポイントでプログラムが停止した場合には、実行対象のコードを最適化済みコードから最適化なしコードに切り替えるブレークポイント切替手段とを備えたデバッグ装置である。 As described above, the debugging device is equipped with a program execution means for executing a program having optimized code and non-optimized code corresponding to the same source code, as well as a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting means for setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when a breakpoint is specified at a position in the source code, and a breakpoint switching means for switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
 また、同一のソースコードに対応する最適化済みコード及び最適化なしコード並びに最適化済みコード用の行番号表及び最適化なしコード用の行番号表を備えたプログラムを実行するプログラム実行ステップと、ブレークポイントがソースコードの位置で指定された場合には、最適化済みコード及び最適化なしコードの2箇所に命令レベルでブレークポイントを設定するブレークポイント設定ステップと、ブレークポイント設定手段が設定した最適化済みコード中のブレークポイントでプログラムが停止した場合には、実行対象のコードを最適化済みコードから最適化なしコードに切り替えるブレークポイント切替ステップとを備えたデバッグ方法である。 The debugging method also includes a program execution step for executing a program having optimized code and non-optimized code corresponding to the same source code, and a line number table for the optimized code and a line number table for the non-optimized code, a breakpoint setting step for setting breakpoints at the instruction level in two locations, the optimized code and the non-optimized code, when the breakpoints are specified at the position of the source code, and a breakpoint switching step for switching the code to be executed from the optimized code to the non-optimized code when the program stops at a breakpoint in the optimized code set by the breakpoint setting means.
 これによって、ソースコードレベルのブレークポイントが設定されるまでは、最適化済みコードでプログラムを高速に実行することができ、ブレークポイントが設定された後は、最適化なしコードを用いてステップ実行などの対話的なデバッグ操作を提供することができる。 This allows the program to run quickly with optimized code until a source code level breakpoint is set, and then provides interactive debugging operations such as step execution using non-optimized code after the breakpoint is set.
実施の形態2.
 実施の形態1では、最適化済みコード105と最適化なしコード106の関数呼び出しの構成については言及していない。関数Aから関数Bが呼び出される場合、最適化なしコード106Aにおける関数Bの呼び出しは最適化なしコード106中の関数Bの呼び出しとなるのが通常である。ところが、関数Aをソースコードの行単位でステップ実行するのに関数Bまで最適化なしコード106で実行すると実行速度が低下するという問題がある。そこで、この実施の形態では、最適化なしコード106における任意のfの呼び出しがすべて最適化済みコード105中の関数fへの呼び出しとなるような最適化なしコード106を用いる。
Embodiment 2.
In the first embodiment, no mention is made of the function call configuration of the optimized code 105 and the non-optimized code 106. When function A calls function B, the call of function B in the non-optimized code 106A usually becomes a call of function B in the non-optimized code 106. However, there is a problem that the execution speed decreases if function A is executed line by line in the non-optimized code 106 in order to execute function A in a stepwise manner up to function B. Therefore, in this embodiment, non-optimized code 106 is used in which any call of f in the non-optimized code 106 becomes a call to function f in the optimized code 105.
 このような最適化なしコード106を用いることで、関数Aをデバッグする際に関数Bの呼び出しをステップオーバで実行する場合には、この実施の形態では関数Bが最適化されている分だけ高速に実行することができる。 By using such non-optimized code 106, when a call to function B is executed by stepping over when debugging function A, function B can be executed at a high speed in this embodiment because it has been optimized.
 ここで、ステップインで関数Bの内部をステップ実行したい場合がある。そこで、ステップイン操作のときに関数Bの先頭で最適化済みコード105から最適化なしコード106に切り替える。このような切替えの実現方法の1つは、ステップイン操作をブレークポイントで実装する方法である。この場合、関数fにステップイン操作は、関数fの先頭行にブレークポイントBを設定、プログラムを実行し、ブレークポイントBで停止後にブレークポイントBをクリアという一連の処理で実現される。ブレークポイントの設定には実施の形態1で示した方法をそのまま適用することで、関数Bを最適化なしコード106としてステップ実行することができる。 Here, there may be a case where you want to step into function B. Therefore, when you step into function B, you switch from optimized code 105 to non-optimized code 106 at the beginning of function B. One way to achieve this kind of switching is to implement the step-in operation with a breakpoint. In this case, the step-in operation into function f is achieved by a series of processes: setting breakpoint B at the first line of function f, executing the program, and clearing breakpoint B after stopping at breakpoint B. By directly applying the method shown in embodiment 1 to setting the breakpoint, function B can be step-executed as non-optimized code 106.
 101 プログラム実行手段、102 デバッグ対象プログラム、103 データ、104 コード、105 最適化済みコード、106 最適化なしコード、107 ブレークポイント管理手段、108 実行制御手段、109 行番号表、110 シンボルテーブル、111 補助ブレークポイント表、120 ブレークポイント設定手段、121 ブレークポイント切替手段。 101 program execution means, 102 program to be debugged, 103 data, 104 code, 105 optimized code, 106 non-optimized code, 107 breakpoint management means, 108 execution control means, 109 line number table, 110 symbol table, 111 auxiliary breakpoint table, 120 breakpoint setting means, 121 breakpoint switching means.

Claims (5)

  1. 同一のソースコードに対応する最適化済みコード及び最適化なしコード並びに前記最適化済みコード用の行番号表及び前記最適化なしコード用の行番号表を備えたプログラムを実行するプログラム実行手段と、
    ブレークポイントが前記ソースコードの位置で指定された場合には、前記最適化済みコード及び前記最適化なしコードの2箇所に命令レベルで前記ブレークポイントを設定するブレークポイント設定手段と、
    前記ブレークポイント設定手段が設定した前記最適化済みコード中の前記ブレークポイントで前記プログラムが停止した場合には、実行対象のコードを前記最適化済みコードから前記最適化なしコードに切り替えるブレークポイント切替手段とを備えたデバッグ装置。
    a program execution means for executing a program having an optimized code and a non-optimized code corresponding to the same source code, and a line number table for the optimized code and a line number table for the non-optimized code;
    a breakpoint setting means for setting breakpoints at instruction levels at two locations, one in the optimized code and the other in the non-optimized code, when a breakpoint is specified at a location in the source code;
    and a breakpoint switching means for switching the code to be executed from the optimized code to the non-optimized code when the program stops at the breakpoint in the optimized code set by the breakpoint setting means.
  2. 請求項1に記載のデバッグ装置であって、
    前記ブレークポイント設定手段は、前記ブレークポイントが指定された場合には、
    当該ブレークポイントの前記位置を一部として含むサブルーチンよりもコールグラフで上位に位置する前記サブルーチンの先頭に補助ブレークポイントを設定することを特徴とするデバッグ装置。
    2. A debug device according to claim 1, comprising:
    When the breakpoint is specified, the breakpoint setting means
    A debugging device comprising: a step of setting an auxiliary breakpoint at the beginning of a subroutine located higher in a call graph than a subroutine that includes the location of the breakpoint as a part of the subroutine;
  3. 請求項1に記載のデバッグ装置であって、
    前記ブレークポイント設定手段は、前記ブレークポイントが指定された場合には、当該ブレークポイントの前記位置を一部として含むサブルーチンの先頭に補助ブレークポイントを設定することを特徴とするデバッグ装置。
    2. A debug device according to claim 1, comprising:
    A debugging device characterized in that, when the breakpoint is specified, the breakpoint setting means sets an auxiliary breakpoint at the beginning of a subroutine which includes the position of the specified breakpoint as a part of the subroutine.
  4. 請求項2または請求項3に記載のデバッグ装置であって、
    前記ブレークポイント設定手段は、前記補助ブレークポイントを削除する場合には、前記補助ブレークポイントが共有されているか否か確認することを特徴とするデバッグ装置。
    4. A debug device according to claim 2, further comprising:
    Debugging device according to claim 1, wherein said breakpoint setting means, when deleting said auxiliary breakpoint, checks whether said auxiliary breakpoint is shared or not.
  5. 同一のソースコードに対応する最適化済みコード及び最適化なしコード並びに前記最適化済みコード用の行番号表及び前記最適化なしコード用の行番号表を備えたプログラムを実行するプログラム実行ステップと、
    ブレークポイントが前記ソースコードの位置で指定された場合には、前記最適化済みコード及び前記最適化なしコードの2箇所に命令レベルで前記ブレークポイントを設定するブレークポイント設定ステップと、
    前記ブレークポイント設定手段が設定した前記最適化済みコード中の前記ブレークポイントで前記プログラムが停止した場合には、実行対象のコードを前記最適化済みコードから前記最適化なしコードに切り替えるブレークポイント切替ステップとを備えたデバッグ方法。
    a program execution step of executing a program having optimized code and non-optimized code corresponding to the same source code, and a line number table for the optimized code and a line number table for the non-optimized code;
    a breakpoint setting step of setting the breakpoints at an instruction level at two locations in the optimized code and the non-optimized code when the breakpoints are specified at a location in the source code;
    and a breakpoint switching step of switching a code to be executed from the optimized code to the non-optimized code when the program stops at the breakpoint in the optimized code set by the breakpoint setting means.
PCT/JP2022/035836 2022-09-27 2022-09-27 Debugging device and debugging method WO2024069730A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/JP2022/035836 WO2024069730A1 (en) 2022-09-27 2022-09-27 Debugging device and debugging method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/JP2022/035836 WO2024069730A1 (en) 2022-09-27 2022-09-27 Debugging device and debugging method

Publications (1)

Publication Number Publication Date
WO2024069730A1 true WO2024069730A1 (en) 2024-04-04

Family

ID=90476622

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/JP2022/035836 WO2024069730A1 (en) 2022-09-27 2022-09-27 Debugging device and debugging method

Country Status (1)

Country Link
WO (1) WO2024069730A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060064676A1 (en) * 2004-09-21 2006-03-23 Hewlett-Packard Development Company, L.P. Systems and methods for validating debug information for optimized code
JP2012027639A (en) * 2010-07-22 2012-02-09 Fuji Electric Co Ltd Programmable controller and debug method of programmable controller
JP2013025347A (en) * 2011-07-15 2013-02-04 Fuji Electric Co Ltd Programmable controller
JP2013084112A (en) * 2011-10-07 2013-05-09 Fuji Electric Co Ltd Programmable controller system, programming device thereof, programmable controller, program and debug method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060064676A1 (en) * 2004-09-21 2006-03-23 Hewlett-Packard Development Company, L.P. Systems and methods for validating debug information for optimized code
JP2012027639A (en) * 2010-07-22 2012-02-09 Fuji Electric Co Ltd Programmable controller and debug method of programmable controller
JP2013025347A (en) * 2011-07-15 2013-02-04 Fuji Electric Co Ltd Programmable controller
JP2013084112A (en) * 2011-10-07 2013-05-09 Fuji Electric Co Ltd Programmable controller system, programming device thereof, programmable controller, program and debug method

Similar Documents

Publication Publication Date Title
JP2795244B2 (en) Program debugging system
US6112312A (en) Method for generating functional tests for a microprocessor having several operating modes and features
KR960003137B1 (en) Improved system for jacketing cross-domain calls in a multi-code execution and debugging system within a multi-architectube environment
US5313387A (en) Re-execution of edit-compile-run cycles for changed lines of source code, with storage of associated data in buffers
US5325531A (en) Compiler using clean lines table with entries indicating unchanged text lines for incrementally compiling only changed source text lines
JP2753500B2 (en) An improved software debugging system and method for debugging code specifically in a multi-architecture environment
US20060130016A1 (en) Method of kernal-mode instruction interception and apparatus therefor
JPH11194957A (en) Debug supporting device, parallel execution information generation device and recording medium for recording program applied to the same
US6330691B1 (en) Use of dynamic translation to provide breakpoints in non-writeable object code
WO2022153024A1 (en) Load chunk instruction and store chunk instruction
WO2024069730A1 (en) Debugging device and debugging method
US20020129336A1 (en) Automatic symbol table selection in a multi-cell environment
JPH0766342B2 (en) Program test equipment
US11256479B2 (en) Dynamic updates in an interactive programming environment
JPH11110256A (en) Device and method for debugging program, and computer readable recording medium recorded with the method for the same
KR950012113B1 (en) Improved system and method for detecting cross-domain instruction calls and data referenc especially adapted for code interface jacketing in a multi code execution and debugging syste
KR101548960B1 (en) Method for making and debuging program using virtual platform and appparatus therof
Ashby et al. Design of an interactive debugger for FORTRAN: MANTIS
JP2001222447A (en) Debug method and device to be debugged under operating environment
JP2659366B2 (en) Debugging method and device
JP3077627B2 (en) Debugging method and recording medium for recording debug program
JP2002366378A (en) Method and device for debugging program and storage medium
JPH0367340A (en) Simulator
JPH05250221A (en) Simulator execution system
JPS6292032A (en) Test method for program