Program debugging method, debugger and computing equipment

By writing glue code and setting breakpoints during the static compilation stage, the problem that the debugger cannot directly enter Foreign Func in a single step, improving the efficiency of program debugging and simplifying the debugging process.

CN119847907APending Publication Date: 2025-04-18HUAWEI TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202311329334.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-13
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

When existing debuggers handle cross-language interoperable programs, they cannot directly enter Foreign Func in Native Func, and the debugging process is complicated and inefficient.

Method used

By writing glue code between the first function and the second function during the static compilation stage of the program, and identifying and setting the second function as a breakpoint in the debugger, automatically running to the breakpoint is avoided manually stepping into and out of the glue code.

Benefits of technology

Improves the efficiency of program debugging, reduces the steps for developers to manually operate on the debugger interface, and simplifies the debugging process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847907A_ABST
    Figure CN119847907A_ABST
Patent Text Reader

Abstract

The invention discloses a program debugging method, a debugger and computing equipment. The debugger determines a next program code entering in a single step as a first glue code, the first glue code is a first-layer code in glue codes between a first function and a second function, the first function calls the second function, and the first function and the second function are obtained by compiling through different compiling languages; the debugger determines that the second function is a breakpoint of the program; and the debugger continuously executes the program to the breakpoint. For the operation steps of a developer, after entering the first function, the developer can reach the second function, and because the glue code between the first function and the second function is automatically operated in the program, the developer does not sense the operation process of the glue code and does not need to manually operate each function for operating the glue code, so that the operation efficiency is improved. And the program debugging efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a program debugging method, a debugger, and a computing device. Background Art

[0002] The debugger is a very important part of a programming language. It is a tool used to diagnose and fix code errors (or bugs). The debugger allows developers to view and analyze the state and behavior of the code step by step while the program is executing. The debugger can help developers diagnose and fix code errors, understand the behavior of the program, and optimize performance. For programming developers, the debugger is a powerful tool that can effectively improve development efficiency and code quality.

[0003] Many programming languages ​​support cross-language interoperability. If a programming language includes a runtime system, glue code is needed to perform some runtime-related processing, such as scheduling or garbage collection (GC), before making a cross-language call. That is, some additional code (glue code) is inserted between the function that performs the cross-language call (Native Func) and the target function (Foreign Func).

[0004] Since glue code is inserted between Native Func and Foreign Func, the debugger cannot step into Native Func directly to Foreign Func during debugging. The debugger needs to traverse each layer of step-in glue code (including sub-functions) before it can step-in into Foreign Func through the last layer of glue code, making the debugging process more complicated. Summary of the invention

[0005] The present application provides a program debugging method, a debugger, and a computing device for improving the efficiency of program debugging.

[0006] In the first aspect, the present application provides a method for debugging a program. In the process of debugging a program, the developer of the program often chooses to manually step into (i.e., step-in) each layer of function (including glue code) of the program through the debugger in order to facilitate the gradual viewing and analysis of the state and behavior of the code during program execution, thereby helping the developer to diagnose and fix code errors, understand the behavior of the program, and optimize performance. Among them, if step-in / step-out is performed repeatedly in the glue code, the efficiency of debugging the program will be seriously reduced.

[0007] In the present application, the debugger can identify and determine the glue code in the program. Specifically, in the present application, the first function is a calling function, the second function is a called function, and the first function and the second function are compiled by different compilation languages, for example, the first function is compiled by go language, and the second function is compiled by C language. Then in the static compilation stage of the program, it is necessary to write glue code between the first function and the second function. The first glue code in the present application is the first layer of code in the glue code between the first function and the second function. Therefore, in the present application, when the debugger is in the program and is ready to perform a single-step entry operation on the next program code, the debugger can promptly identify and determine that the next program code of the program is the first glue code (the first layer of code in the glue code).

[0008] No matter how the glue code is implemented, the second function must be called in the end. Therefore, the debugger sets the second function as a breakpoint for the program. After setting the breakpoint, the debugger can let the program run automatically until it reaches the set breakpoint position, at which point the program will be interrupted and paused.

[0009] The debugger sets the second function as the breakpoint of the program, and the debugger no longer executes single-step entry, but continuously executes the program to the set breakpoint. In the glue code between the first function and the second function, since the debugger does not execute single-step entry, the debugger will not enter the function inside the glue code (including sub-functions), and the developer does not need to manually operate the single-step entry command (step-in command) in the debugger. The program will run automatically until the breakpoint position (i.e., the second function). Therefore, for the developer's operating steps, after entering the first function, the second function will be reached, because the glue code between the first function and the second function is automatically run in the program, and the developer does not perceive the running process of the glue code, nor does it need to manually operate the various functions of the glue code, which improves the efficiency of program debugging.

[0010] Based on the first aspect, in an optional implementation, the program debugging method of the present application can also be applied to return from the called function (second function) to the calling function (first function). As can be seen from the above, in the static compilation stage of the program, glue code needs to be written between the first function and the second function. Among them, the first glue code is the first layer of code in the glue code between the first function and the second function, and the second glue code in the present application is the last layer of code in the glue code between the first function and the second function. Therefore, in the present application, when the debugger is in the program and is ready to perform a single-step jump operation on the next program code, the debugger can promptly identify and determine that the next program code of the program is the second glue code (the last layer of code in the glue code).

[0011] Since the code to be executed later in the program is glue code, in this application, the debugger can automatically step out of the program N times in a row until returning to the first function, where N is an integer greater than or equal to 2. Therefore, the developer does not need to manually initiate a step-out operation for each layer of glue code on the debugger's operation interface, thereby improving the efficiency of program debugging.

[0012] Based on the first aspect, in an optional implementation, the content of the glue code is pre-written into the program in the static compilation stage, so the function name of the glue code can be predicted in advance, such as the name of the first layer function and the name of the last layer function in the glue code. In this application, the debugger can first obtain the function name of the glue code (including the function name of the first glue code). When the function name corresponding to the next program code that the debugger enters in a single step (i.e., step-in) matches the function name of the first glue code, the debugger determines that the next program code of the program step-in is the first glue code.

[0013] Based on the first aspect, in an optional implementation, since the names of the first layer functions and the last layer functions in the glue code are predictable. In this application, the debugger can first obtain the function name of the glue code (including the function name of the second glue code). When the function name corresponding to the next program code that the debugger steps out (i.e., step-out) matches the function name of the second glue code, the debugger determines that the next program code of the program step-out is the second glue code.

[0014] Based on the first aspect, in an optional implementation, when the debugger executes N single-step jumps to reach the first function, it will first go through N-1 single-step jumps in the glue code. In other words, the debugger will programmatically single-step jump N-1 times from the second function until it reaches the first glue code. Then, after the debugger executes a single-step jump at the location of the first glue code, it can reach the first function.

[0015] Based on the first aspect, in an optional implementation, the debugger steps out of the program N-1 times in a row. If the function name corresponding to the current instruction to be executed matches the function name of the first glue code, the debugger can determine that it has returned to the first glue code.

[0016] Based on the first aspect, in an optional implementation, in order to set the second function as a breakpoint of the program, the debugger needs to obtain the address stored in the second function (ie, the target address). After the debugger obtains the target address of the second function, it sets the second function as a breakpoint through the target address.

[0017] Based on the first aspect, in an optional implementation, the target address of the second function is stored on the stack. The debugger obtains the stack pointer (SP), and the target address is the address indicated by the stack pointer and the offset, and the second function can be obtained from the target address on the stack.

[0018] Based on the first aspect, in an optional implementation, the target address of the second function is stored in a target variable. The debugger obtains the target variable, and the variable value of the target variable includes the target address of the second function.

[0019] In a second aspect, the present application provides a debugger, the debugger comprising:

[0020] A determination unit, used to determine that the next program code entered by a single step is a first glue code, wherein the first glue code is a first layer of code in the glue code between a first function and a second function, the first function calls the second function, and the first function and the second function are compiled by different compilation languages ​​respectively;

[0021] The determination unit is further used to determine that the second function is a breakpoint of the program;

[0022] Execution unit, used to continuously execute the program to the breakpoint.

[0023] Based on the second aspect, in an optional implementation, the determination unit is further used to determine that the next program code to be jumped out of the single step is the second glue code, wherein the second glue code is the last layer of code in the glue code between the first function and the second function;

[0024] The execution unit is further used to single-step out of the program N times in succession until returning to the first function, where N is an integer greater than or equal to 2.

[0025] Based on the second aspect, in an optional implementation manner, the determining unit is specifically configured to:

[0026] When the function name corresponding to the next program code entered by single step matches the function name of the first glue code, it is determined that the next program code entered by single step is the first glue code.

[0027] Based on the second aspect, in an optional implementation manner, the determining unit is specifically configured to:

[0028] When the function name corresponding to the next program code jumped out by single step matches the function name of the second glue code, the debugger determines that the next program code jumped out by single step is the second glue code.

[0029] Based on the second aspect, in an optional implementation manner, the execution unit is specifically configured to:

[0030] Single-step out of the program N-1 times in a row until the first glue code is reached;

[0031] Execute a single step out based on the first glue code and return to the first function.

[0032] Based on the second aspect, in an optional implementation manner, the execution unit is specifically configured to:

[0033] Single-step out of the program N-1 times in a row;

[0034] When the function name corresponding to the current instruction to be executed matches the function name of the first glue code, it is determined that the first glue code has been reached.

[0035] Based on the second aspect, in an optional implementation manner, the debugger further includes:

[0036] The acquisition unit is used to acquire a target address of the second function, wherein the target address is used by the debugger to determine that the second function is a breakpoint.

[0037] Based on the second aspect, in an optional implementation manner, the acquiring unit is specifically configured to:

[0038] Get the stack pointer SP;

[0039] According to the instruction of SP, the target address of the second function is determined.

[0040] Based on the second aspect, in an optional implementation manner, the acquiring unit is specifically configured to:

[0041] A target variable is obtained, wherein the variable value of the target variable includes the target address of the second function.

[0042] The information interaction and execution process and other contents of the embodiment shown in this aspect are based on the same concept as the embodiment shown in the first aspect. Therefore, for the description of the beneficial effects shown in this aspect, please refer to the above-mentioned first aspect, and the details will not be repeated here.

[0043] In a third aspect, an embodiment of the present application provides a computing device, comprising: a processor, the processor is coupled to a memory, the memory is used to store instructions, when the instructions are executed by the processor, the computing device implements the method in the above-mentioned first aspect, or any possible implementation of the first aspect.

[0044] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having instructions stored thereon, which, when executed, causes a computer to execute the method in the above-mentioned first aspect, or any possible implementation of the first aspect.

[0045] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program code. When the computer program code runs on a computer, it enables the computer to execute the method in the above-mentioned first aspect or any possible implementation manner of the first aspect.

[0046] In a sixth aspect, an embodiment of the present application provides a chip, comprising: a processor, the processor is coupled to a memory, the memory is used to store instructions, and when the instructions are executed by the processor, the chip implements the method in the above-mentioned first aspect and any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0048] Figure 1 This is a flow chart of the debugger stepping into the glue code;

[0049] Figure 2 A flow chart showing the debugger executing step-out in glue code;

[0050] Figure 3 It is a schematic diagram of a scene when a debugger processes glue code in the prior art;

[0051] Figure 4 This is a schematic diagram of a scenario in which a debugger processes glue code in an embodiment of the present application;

[0052] Figure 5 A flowchart of a program debugging method in an embodiment of the present application;

[0053] Figure 6 Another flowchart of the program debugging method in the embodiment of the present application;

[0054] Figure 7 A schematic diagram of the structure of a debugger provided in an embodiment of the present application;

[0055] Figure 8 A schematic diagram of the logical structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] The embodiments of the present application provide a program debugging method, a debugger, and a computing device for improving the efficiency of program debugging.

[0057] The embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation mode of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the embodiments of the present application. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0058] In the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.

[0059] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0060] Some nouns or terms used in the embodiments of the present application are explained below, and these nouns or terms are also considered as part of the content of the invention.

[0061] Runtime: The runtime is the operating environment of an object-oriented programming language (OOP). The runtime indicates which program is running at a certain time. The runtime is a stage in the life cycle of a computer program. Other stages include compile time, link time, and load time.

[0062] Glue code: In computer programming, glue code is executable code (usually source code) that is used only to "adjust" different parts of code that would otherwise be incompatible.

[0063] Native Func: A function that calls a target language function during cross-language interoperation.

[0064] Foreign Func: The function of the target language that is called during cross-language interoperation.

[0065] step-in: When debugging with a debugger, step into a sub-function from the current location (usually the source code line with a function call).

[0066] step-out: When debugging with a debugger, return from the current location to the parent function.

[0067] Breakpoint: When debugging, the debugger can only perform operations on the debugged process, such as observing memory contents, when the debugged process is suspended. If the debugged process does not stop, the debugger can do nothing. In order to stop the debugged process, except for a few debugging events that occur at specific times, the only way is to cause an exception. Breakpoints are exceptions used to achieve the above purpose. Although breakpoints are an exception, they do not mean that there is a problem with the debugged process. They are just a means of debugging, so the debugger will clearly distinguish breakpoints (breakpoint exceptions) from other exceptions.

[0068] Stack Pointer (SP) register: The SP register is a special register used to store the stack address when the program is running. During the program running process, function calls, interrupt processing and other operations all need to push and pop data into the stack. The SP register is used to store the address pointer of the stack to ensure the normal operation of the program. The SP register is part of the central processing unit (CPU) and is stored in the control register of the CPU. The role of the SP register can be summarized in two points: one is to store the stack pointer, and the other is to manage the stack space. When data needs to be pushed into the stack, the program will automatically store the data in the stack and move the SP pointer down to facilitate the storage of the next data. Similarly, when data needs to be popped, the program will take the data from the stack and move the SP pointer up to facilitate the retrieval of the next data.

[0069] The debugger is a very important part of a programming language. It is a tool used to diagnose and fix code errors (or bugs). The debugger allows developers to view and analyze the state and behavior of the code step by step while the program is executing. The debugger can help developers diagnose and fix code errors, understand the behavior of the program, and optimize performance. For programming developers, the debugger is a powerful tool that can effectively improve development efficiency and code quality.

[0070] Many programming languages ​​support cross-language interoperability. If a programming language includes a runtime system, glue code is needed to perform some runtime-related processing, such as scheduling or garbage collection (GC), before making a cross-language call. That is, some additional code (glue code) is inserted between the function that performs the cross-language call (Native Func) and the target function (Foreign Func).

[0071] Glue code is inserted between Native Func and Foreign Func. Since the debugger executes according to the code logic during the debugging process, the glue layer itself is the code logic. Therefore, when debugging, the debugger cannot directly reach Foreign Func by stepping into Native Func (i.e. step-in). The debugger needs to traverse each layer of function (including sub-functions) of the step-in glue code before it can step-in into Foreign Func through the function of the last layer of the glue code. On the other hand, when it is necessary to step-out from the last layer of the glue code to Native Func, the developer is also required to manually click the step-out instruction in the debugger interface so as to step-out from the last layer of the glue code to Native Func through the functions of each layer of the glue code.

[0072] Take the Go language as an example. The main function main (i.e. Native Func) of the Go code calls the C language function add (i.e. Foreign Func) across languages. The details are as follows:

[0073]

[0074] At this time, because var sum = C.add(1,2), the main function main of the Go code calls the C language function add across languages. Therefore, 6 layers of glue code that users do not care about will be inserted in the middle of the main program's call stack, as shown below:

[0075] (lldb)bt

[0076] *thread#1,name='test',stop reason=breakpoint 1.1

[0077] *frame#0:0x000000000047f810 test`add

[0078] frame#1:0x000000000047f839 test`_cgo_45f8faab1e14_Cfunc_add+25

[0079] frame#2:0x000000000045bc50 test`runtime.asmcgocall.abi0+112

[0080] frame#3:0x0000000000459da9 test`runtime.systemstack.abi0+73

[0081] frame#4:0x000000000045e449 test`runtime.newproc.abi0+41

[0082] frame#5:0x00000000004801d0 test`crosscall_amd64+34

[0083] frame#6:0x000000000047f6ac test`main._Cfunc_add.abi0+76

[0084] frame#7:0x000000000047f76b test`main.main+43

[0085] frame#8:0x00000000004332e7 test`runtime.main+551

[0086] frame#9:0x000000000045bf61 test`runtime.goexit.abi0+1

[0087] Among them, frame#7 is the code of Native Func, frame#0 is the code of Foreign Func, and the code of frame#1 to frame#6 between the two is the glue code. After the debugger finishes running frame#7, it needs to step-in into each layer of code from frame#6 to frame#1, and finally step-in into the Foreign Func of frame#0 through the code of frame#1.

[0088] The glue code of frame#1 to frame#6 is only an exemplary description. Since the function call logic of the glue code depends on the specific implementation, in actual applications, the glue code is often more complicated, and the debugging process of the debugger will also become more complicated.

[0089] For ease of understanding, the following is an illustrative introduction to the debugging process of the current debugger with reference to the accompanying drawings. Figure 1 , Figure 1 The following is a flow chart of the debugger stepping into the glue code. Figure 1 As shown, when executing step-in from the debugger NativeFunc, it first enters the first layer function in the glue code ( Figure 1 If there is a sub-function in the glue code, it will step-in into its sub-function. At this time, it is necessary to step out (i.e., step-out), and then continue step-in / step-out, ..., and so on. After the glue code has undergone multiple step-in / step-out operations, the last layer of function ( Figure 1 FuncN in the final entry into ForeignFunc.

[0090] See also Figure 2 , Figure 2 The following is a flow chart of the debugger executing step-out in glue code. Figure 2 As shown in the figure, when the debugger executes step-out from Foreign Func, it will first return to the last layer of function in the glue code, and then execute step-out again, ..., after multiple step-outs, it will finally return to Native Func.

[0091] As can be seen from the above, the debugging process is relatively complicated and inefficient when the current debugger processes glue code. Figure 3 , Figure 3 FIG. 1 is a schematic diagram of a scene in which a debugger processes glue code in the prior art. Figure 3 As shown, in Figure 3 From the internal perspective of the debugger processing glue code, it is necessary to go through multiple step-in / step-out operations before entering the Foreign Func or returning to the Native Func. On the other hand, from the developer's user perspective, the debugger cannot step into the Foreign Func or step out and return to the Native Func.

[0092] In view of this, the embodiments of the present application provide a program debugging method, a debugger, and a computing device to improve the efficiency of program debugging. Figure 4 , Figure 4 Schematic diagram of the scene when the debugger processes glue code in the embodiment of the present application. Figure 4 As shown, in Figure 4 In the internal perspective of the debugger processing glue code shown, the debugger can enter Foreign Func or return to Native Func by executing the program debugging method provided in the embodiment of the present application when facing the glue code. On the other hand, from the user perspective of the developer, the program debugging method provided in the embodiment of the present application is equivalent to stepping into Foreign Func or stepping out and returning to Native Func.

[0093] Next, the program debugging method in the embodiment of the present application is introduced. Figure 5 , Figure 5 It is a flowchart of the program debugging method in the embodiment of the present application. Figure 5 In the example, the debugger is used as the execution subject of the program debugging method to illustrate the method, but the present application does not limit the execution subject of the program debugging method. Figure 5 The debugger in the method may also be a chip, a chip system, or a processor that supports the debugger to implement the method, or a logic node, a logic module, or software that can implement all or part of the debugger functions. Figure 5 As shown, the program debugging method in the embodiment of the present application includes but is not limited to steps 101 to 103.

[0094] 101. The debugger determines that the next program code to be stepped into is the first glue code.

[0095] When debugging a program, the developer of the program often chooses to manually step into (i.e., step-in) each layer of the program's function (including glue code) through the debugger in order to gradually view and analyze the code's status and behavior during program execution, thereby helping the developer to diagnose and fix code errors, understand program behavior, and optimize performance. If the debugger repeatedly steps in and out of the glue code, the efficiency of debugging the program will be seriously reduced.

[0096] In an embodiment of the present application, the debugger can identify and determine the glue code in the program. Specifically, in an embodiment of the present application, the first function is a calling function (equivalent to the aforementioned Native Func), the second function is a called function (equivalent to the aforementioned Foreign Func), and the first function and the second function are compiled by different compilation languages, for example, the first function is compiled by go language, and the second function is compiled by C language. Then in the static compilation stage of the program, it is necessary to write glue code between the first function and the second function. The first glue code in the embodiment of the present application is the first layer of code in the glue code between the first function and the second function. Therefore, in an embodiment of the present application, when the debugger is in the program and is ready to perform a single-step entry operation on the next program code, the debugger can promptly identify and determine that the next program code of the program is the first glue code (the first layer of code in the glue code).

[0097] Specifically, the content of the glue code is pre-written into the program during the static compilation phase, so the function names of the glue code can be predicted in advance, such as the names of the first layer of functions and the last layer of functions in the glue code. In an embodiment of the present application, the debugger can first obtain the function names of the glue code (including the function names of the first glue code). When the function name corresponding to the next program code that the debugger steps into (i.e., steps-in) matches the function name of the first glue code, the debugger determines that the next program code of the program step-in is the first glue code.

[0098] In the embodiments of the present application, the type of debugger is not limited. Exemplarily, the debugger may be a DeBugger debugger, an IDE debugger, a JDK debugger, or other debuggers, which are not specifically limited here.

[0099] The program debugging method of the embodiment of the present application is applicable to the scenario of cross-language calling, but is not limited to the compilation language used by the first function (calling function) and the second function (called function). For example, Objective-C language, go language or C language, etc. can be used, and no specific limitation is made here.

[0100] 102. The debugger determines the second function as a breakpoint of the program.

[0101] No matter how the glue code is implemented, the second function (Foreign Func) must be called in the end. Therefore, the debugger sets the second function as a breakpoint for the program. After setting the breakpoint, the debugger can let the program run automatically until it reaches the set breakpoint position, at which point the program will be interrupted and paused.

[0102] Specifically, in order to set the second function as a breakpoint of the program, the debugger needs to obtain the address (ie, the target address) stored in the second function. After the debugger obtains the target address of the second function, it sets the second function as a breakpoint through the target address.

[0103] In actual applications, before Native Func steps into the glue code, there must be a mechanism to save the target address of the second function (Foreign Func), so the debugger can also obtain the target address of the second function according to the implementation mechanism of the compiled language.

[0104] In a possible implementation, the target address of the second function is stored on the stack. The debugger obtains the stack pointer (SP), and the target address is the address indicated by the stack pointer and the offset, and the second function can be obtained from the target address on the stack.

[0105] In a possible implementation, the target address of the second function is stored in a target variable. The debugger obtains the target variable, and the variable value of the target variable includes the target address of the second function.

[0106] 103. The debugger continues to execute the program to the breakpoint.

[0107] The debugger sets the second function as the breakpoint of the program, and the debugger no longer executes single-step entry, but continuously executes the program to the set breakpoint. In the glue code between the first function and the second function, since the debugger does not execute single-step entry, the debugger will not enter the function inside the glue code (including sub-functions), and the developer does not need to manually operate the single-step entry command (step-in command) in the debugger. The program will run automatically until the breakpoint position (i.e., the second function). Therefore, for the developer's operating steps, after entering the first function, the second function will be reached, because the glue code between the first function and the second function is automatically run in the program, and the developer does not perceive the running process of the glue code, nor does it need to manually operate the various functions of the glue code, which improves the efficiency of program debugging.

[0108] Taking the DeBugger debugger as an example, in actual application, the command used for "continuous execution" of the DeBugger debugger is the continue command. Therefore, in the embodiment of the present application, after the debugger sets the second function as the breakpoint of the program, the DeBugger debugger executes the continue command, and the program will automatically run continuously to the breakpoint position (i.e., the second function).

[0109] The program debugging method of the embodiment of the present application can also be applied to return from the called function (the second function) to the calling function (the first function). Figure 6 , Figure 6 Another flowchart of the program debugging method in the embodiment of the present application is shown in FIG. Figure 6 In the example, the debugger is used as the execution subject of the program debugging method to illustrate the method, but the present application does not limit the execution subject of the program debugging method. Figure 6 The debugger in the method may also be a chip, a chip system, or a processor that supports the debugger to implement the method, or a logic node, a logic module, or software that can implement all or part of the debugger functions. Figure 6 As shown, the program debugging method in the embodiment of the present application includes but is not limited to steps 201 to 202.

[0110] 201. The debugger determines that the next program code to be stepped out is the second glue code.

[0111] As can be seen from the above, in the static compilation stage of the program, glue code needs to be written between the first function and the second function. Among them, the first glue code is the first layer of code in the glue code between the first function and the second function, and the second glue code in the embodiment of the present application is the last layer of code in the glue code between the first function and the second function. Therefore, in the embodiment of the present application, when the debugger is in the program and is ready to perform a single-step jump operation on the next program code, the debugger can promptly identify and determine that the next program code is the second glue code (the last layer of code in the glue code).

[0112] 202. The debugger steps out of the program N times in succession until returning to the first function.

[0113] Since the code to be executed later in the program is glue code, in the embodiment of the present application, the debugger can automatically step out of the program N times in a row until returning to the first function, where N is an integer greater than or equal to 2. Therefore, the developer does not need to manually initiate a step-out operation for each layer of glue code on the operation interface of the debugger, thereby improving the efficiency of program debugging.

[0114] As can be seen from the above, in the glue code, the names of the first layer functions and the last layer functions are predictable. In the embodiment of the present application, the debugger can first obtain the function name of the glue code (including the function name of the second glue code). When the function name corresponding to the next program code that the debugger steps out (i.e., step-out) matches the function name of the second glue code, the debugger determines that the next program code of the program step-out is the second glue code.

[0115] In one possible implementation, when the debugger executes N single-step jumps to reach the first function, it will first go through N-1 single-step jumps in the glue code. In other words, the debugger single-steps out N-1 times in a row starting from the second function in the program until it reaches the first glue code. Then the debugger executes a single-step jump at the location of the first glue code and can reach the first function. Specifically, the debugger single-steps out N-1 times in a row in the program. If the function name corresponding to the current instruction to be executed matches the function name of the first glue code, the debugger can determine that it has returned to the first glue code.

[0116] Accordingly, the present application also provides a related device for implementing the above solution. Figure 7 , Figure 7 A schematic diagram of the structure of a debugger provided in an embodiment of the present application. The device may be a debugger, or a component of a debugger (such as a processor, a chip, or a chip system, etc.), or a logical node, a logical module, or software that can implement all or part of the debugger functions. Figure 7 As shown, the debugger includes a determination unit 301 , an acquisition unit 302 , and an execution unit 303 .

[0117] The determining unit 301 is used to determine that the next program code entered by the single step is the first glue code, wherein the first glue code is the first layer of code in the glue code between the first function and the second function, the first function calls the second function, and the first function and the second function are compiled by different compilation languages ​​respectively;

[0118] The determining unit 301 is further used to determine that the second function is a breakpoint of the program;

[0119] The execution unit 303 is used to continuously execute the program to the breakpoint.

[0120] In a possible design, the determination unit 301 is further used to determine that the next program code to be jumped out of the single step is the second glue code, wherein the second glue code is the last layer of code in the glue code between the first function and the second function;

[0121] The execution unit 303 is further used to single-step out of the program N times in succession until returning to the first function, where N is an integer greater than or equal to 2.

[0122] In a possible design, the determining unit 301 is specifically configured to:

[0123] When the function name corresponding to the next program code entered by single step matches the function name of the first glue code, it is determined that the next program code entered by single step is the first glue code.

[0124] In a possible design, the determining unit 301 is specifically configured to:

[0125] When the function name corresponding to the next program code jumped out by single step matches the function name of the second glue code, the debugger determines that the next program code jumped out by single step is the second glue code.

[0126] In a possible design, the execution unit 303 is specifically configured to:

[0127] Single-step out of the program N-1 times in a row until the first glue code is reached;

[0128] Execute a single step out based on the first glue code and return to the first function.

[0129] In a possible design, the execution unit 303 is specifically configured to:

[0130] Single-step out of the program N-1 times in a row;

[0131] When the function name corresponding to the current instruction to be executed matches the function name of the first glue code, it is determined that the first glue code has been reached.

[0132] In one possible design, the debugger also includes:

[0133] The acquisition unit 302 is used to acquire a target address of the second function, wherein the target address is used by the debugger to determine that the second function is a breakpoint.

[0134] In a possible design, the acquisition unit 302 is specifically configured to:

[0135] Get the stack pointer SP;

[0136] According to the instruction of SP, the target address of the second function is determined.

[0137] In a possible design, the acquisition unit 302 is specifically configured to:

[0138] A target variable is obtained, wherein the variable value of the target variable includes the target address of the second function.

[0139] It should be noted that the information interaction and execution process between the modules / units in the debugger are the same as those in this application. Figure 5 or Figure 6 The corresponding method embodiments are based on the same concept. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.

[0140] See also Figure 8 , Figure 8A schematic diagram of a logical structure of a computing device 40 provided in an embodiment of the present application. The computing device 40 may be a debugger, or a component of a debugger (such as a processor, a chip, or a chip system, etc.), or a logical node, a logical module, or software that can implement all or part of the debugger function. Figure 7 The debugger described in the corresponding embodiment is used to implement Figure 5 or Figure 6 The functions implemented by the debugger in the corresponding embodiment. The computer device 40 includes: a memory 401, a processor 402, a communication interface 403 and a bus 404. The memory 401, the processor 402 and the communication interface 403 are connected to each other through the bus 404.

[0141] The memory 401 may be a read only memory (ROM), a static storage device, a dynamic storage device or a random access memory (RAM). The memory 401 may store a program. When the program stored in the memory 401 is executed by the processor 402, the processor 402 and the communication interface 403 are used to execute steps 101-103 of the above data processing method embodiment.

[0142] The processor 402 may be a central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), a graphics processing unit (GPU), a digital signal processor (DSP), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components or any combination thereof, for executing related programs to implement one or more steps of steps 101-103 of the data processing method embodiment in the present application. The steps of the data processing method disclosed in the embodiment of the present application may be executed by a compiler and an executor, wherein the compiler and the executor may be executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 401, and the processor 402 reads the information in the memory 401, and executes one or more steps of steps 101-103 of the data processing method embodiment in the present application in combination with its hardware.

[0143] The communication interface 403 uses a transceiver device such as but not limited to a transceiver to implement communication between the computer device 40 and other devices or a communication network.

[0144] The bus 404 can realize the path for transmitting information between the various components of the computer device 40 (for example, the memory 401, the processor 402 and the communication interface 403). The bus 404 can be a peripheral component interconnect standard (PCI) bus or an extended industry standard architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For convenience of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0145] It should be noted that the information interaction and execution process between the modules / units in the computing device are the same as those in this application. Figure 5 or Figure 6The corresponding method embodiments are based on the same concept. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.

[0146] The present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the above-mentioned Figure 5 or Figure 6 The illustrated embodiments describe the method.

[0147] The present application also provides a computer-readable storage medium. The computer-readable storage medium may be any available medium that can be stored by a computing device or a data storage device such as a data center that contains one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the computing device to execute the above application to execute the above application. Figure 5 or Figure 6 The illustrated embodiments describe the method.

[0148] The communication device provided in the embodiment of the present application may be a chip, which includes: a processing unit and a communication unit. The processing unit may be, for example, a processor, and the communication unit may be, for example, an input / output interface, a pin or a circuit. The processing unit may execute the computer execution instructions stored in the storage unit to enable the chip to execute the above Figure 5 or Figure 6 Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit may also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.

[0149] It should be further noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the device embodiment drawings provided in the embodiments of the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0150] Through the description of the above implementation mode, the technicians in the field can clearly understand that the embodiments of the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the embodiments of the present application, software program implementation is a better implementation method in more cases. Based on such an understanding, the technical solution of the embodiments of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0151] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0152] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A program debugging method, characterized in that: The method comprises: The debugger determines that the next program code to be entered by single stepping is the first glue code, wherein the first glue code is the first layer of code in the glue code between the first function and the second function, the first function calls the second function, and the first function and the second function are compiled by different compilation languages ​​respectively; The debugger determines that the second function is a breakpoint of the program; The debugger continuously executes the program to the breakpoint.

2. The method according to claim 1, characterized in that: The method further comprises: The debugger determines that the next program code to be stepped out is the second glue code, wherein the second glue code is the last layer of code in the glue code between the first function and the second function; The debugger steps out of the program N times in succession until returning to the first function, where N is an integer greater than or equal to 2.

3. The method according to claim 1 or 2, characterized in that: The debugger determines that the next program code entered in a single step is the first glue code, including: If the function name corresponding to the next program code entered by single step matches the function name of the first glue code, the debugger determines that the next program code entered by single step is the first glue code.

4. The method according to claim 2, characterized in that: The debugger determines that the next program code to be jumped out of the single step is the second glue code, including: If the function name corresponding to the next program code jumped out by single step matches the function name of the second glue code, the debugger determines that the next program code jumped out by single step is the second glue code.

5. The method according to claim 2 or 4, characterized in that: The debugger steps out of the program N times in a row until returning to the first function, including: The debugger steps out of the program N-1 times in a row until the first glue code is reached; The debugger executes a single step out based on the first glue code and returns to the first function.

6. The method according to claim 5, characterized in that The debugger steps out of the program N-1 times in a row until the first glue code is reached, including: The debugger steps out of the program N-1 times in a row; If the function name corresponding to the current instruction to be executed matches the function name of the first glue code, the debugger determines that the first glue code has been reached.

7. The method according to any one of claims 1 to 6, characterized in that The method further comprises: The debugger obtains a target address of the second function, wherein the target address is used by the debugger to determine that the second function is a breakpoint.

8. The method according to claim 7, characterized in that The target address of the second function is stored on the stack, and the debugger obtains the target address of the second function, including: The debugger obtains a stack pointer SP; The debugger determines the target address of the second function according to the instruction of the SP.

9. The method according to claim 7, characterized in that: The target address of the second function is stored in a target variable, and the debugger obtains the target address of the second function, including: The debugger obtains a target variable, wherein a variable value of the target variable includes a target address of the second function.

10. A debugger, characterized in that: The debugger comprises: a determination unit, configured to determine that the next program code entered in a single step is a first glue code, wherein the first glue code is a first layer of code in the glue code between a first function and a second function, the first function calls the second function, and the first function and the second function are compiled by different compilation languages; The determining unit is further configured to determine that the second function is a breakpoint of the program; The execution unit is used for continuously executing the program to the breakpoint.

11. The debugger according to claim 10, characterized in that: The determining unit is further used to determine that the next program code to be jumped out of the single step is a second glue code, wherein the second glue code is the last layer of code in the glue code between the first function and the second function; The execution unit is further used to single-step out of the program N times in succession until returning to the first function, where N is an integer greater than or equal to 2.

12. The debugger according to claim 10 or 11, characterized in that: The determining unit is specifically configured to: When the function name corresponding to the next program code entered by single step matches the function name of the first glue code, it is determined that the next program code entered by single step is the first glue code.

13. The debugger according to claim 11, characterized in that: The determining unit is specifically configured to: When the function name corresponding to the next program code jumped out by single step matches the function name of the second glue code, the debugger determines that the next program code jumped out by single step is the second glue code.

14. The debugger according to claim 11 or 13, characterized in that: The execution unit is specifically used for: Single-step out of the program N-1 times continuously until the first glue code is reached; A single step out is performed based on the first glue code to return to the first function.

15. The debugger according to claim 14, characterized in that: The execution unit is specifically used for: Single-step out of the program N-1 times in succession; When the function name corresponding to the current instruction to be executed matches the function name of the first glue code, it is determined that the first glue code has been reached.

16. The debugger according to any one of claims 10 to 15, characterized in that: The debugger also includes: An acquisition unit is used to acquire a target address of the second function, wherein the target address is used by the debugger to determine that the second function is a breakpoint.

17. The debugger according to claim 16, wherein: The acquisition unit is specifically used for: Get the stack pointer SP; According to the instruction of the SP, a target address of the second function is determined.

18. The debugger according to claim 16, wherein: The acquisition unit is specifically used for: A target variable is obtained, wherein the variable value of the target variable includes the target address of the second function.

19. A computing device, characterized in that comprising a processor coupled to a memory, The memory is used to store instructions; The processor is configured to execute instructions in the memory so that the computing device performs the method according to any one of claims 1 to 9.

20. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.

21. A computer program product, characterized in that The computer program product stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the method according to any one of claims 1 to 9 is implemented.

Citation Information

Cited By

  • Program debugging method, debugger and computing device

    EP4787169A1

  • Program debugging method, debugger and computing device

    WO2025077832A1