Program debugging method, debugger and computing device

By identifying the glue code and setting breakpoints, the debugger automatically runs the glue code when debugging cross-language calls, solving the problem of inefficiency of the existing debugger and achieving more efficient program debugging.

WO2025077832A1PCT designated stage expired Publication Date: 2025-04-17HUAWEI TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/124161
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-10-13
Filing Date
2024-10-11
Publication Date
2025-04-17

AI Technical Summary

Technical Problem

When existing debuggers handle cross-language calls, they cannot directly step into Foreign Func, and they need to manually operate step-in/step-out multiple times, resulting in insufficiency in debugging.

Method used

By identifying and determining the glue code in the program, the debugger sets the second function as a breakpoint and automatically runs in the glue code between the first function and the second function to avoid manual step-by-step entry and jump out operations.

Benefits of technology

Improves the efficiency of program debugging, reduces the operation steps of developers on the debugger interface, and simplifies the debugging process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024124161_17042025_PF_FP_ABST
    Figure CN2024124161_17042025_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in the present application are a program debugging method, a debugger and a computing device. The program debugging method comprises: a debugger determining a next step-in program code as a first glue code, wherein the first glue code is a first-layer code in a 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 obtained by respectively performing compilation by means of different compiling languages; the debugger determining the second function as a breakpoint of a program; and the debugger continuously executing the program until the breakpoint is reached. With regard to the operation steps of a developer, once the first function is entered, the second function is reached, because the glue code between the first function and the second function automatically runs in the program, the developer is not aware of the running process of the glue code, and also does not need to manually operate the functions for running the glue code, so that the efficiency of program debugging is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Program debugging method, debugger and computing device

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on October 13, 2023, with application number 202311329334.9 and application name “A program debugging method, debugger and computing device”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] 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

[0003] A debugger is a crucial component of any programming language. It's a tool used to diagnose and fix coding errors (or bugs). A debugger allows developers to step through and analyze the state and behavior of code as it executes. This helps developers diagnose and fix errors, understand program behavior, and optimize performance. For programmers, a debugger is a powerful tool that can effectively improve development efficiency and code quality.

[0004] Many programming languages ​​support cross-language interoperability. If a programming language includes a runtime system, glue code is required before cross-language calls can be made to perform runtime-related processing, such as scheduling and garbage collection (GC). This involves inserting additional code (called glue code) between the function executing the cross-language call (native Func) and the target function (foreign Func).

[0005] Because glue code is inserted between Native Func and Foreign Func, the debugger cannot step into Native Func directly (i.e., step-in) to reach Foreign Func during debugging. The debugger must traverse each layer of step-in glue code (including sub-functions) before stepping into Foreign Func through the last layer of glue code, making the debugging process more complicated.

[0006] Summary of the Invention

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

[0008] First, this application provides a method for debugging a program. During the debugging process, developers often manually step into (i.e., step into) each layer of the program (including glue code) using a debugger. This allows them to gradually view and analyze the code's state and behavior during program execution, thereby helping them diagnose and fix code errors, understand program behavior, and optimize performance. Repeatedly stepping in and out of the glue code can severely reduce the efficiency of debugging.

[0009] 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 the calling function, the second function is the 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).

[0010] Regardless of how the glue code is implemented, the second function must ultimately be called. Therefore, the debugger sets the second function as a breakpoint in the program. Once a breakpoint is set, the debugger automatically runs the program until it reaches the breakpoint, at which point the program stops and pauses.

[0011] The debugger sets the second function as a breakpoint for 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 runs automatically in the program, the developer does not perceive the running process of the glue code, nor does he need to manually operate the various functions that run the glue code, thereby improving the efficiency of program debugging.

[0012] 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).

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

[0014] Based on the first aspect, in an optional implementation, the content of the glue code is pre-written into the program during the static compilation phase. Therefore, 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 this 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 enters (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.

[0015] 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 names of the glue code (including the function names of the second glue code). When the function name corresponding to the next program code that the debugger steps out (i.e., steps 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.

[0016] Based on the first aspect, in one optional implementation, when the debugger executes N single-step jumps to reach the first function, it first executes N-1 single-step jumps within the glue code. In other words, the debugger programmatically single-steps out N-1 times, starting from the second function, until it reaches the first glue code. The debugger then executes a single single-step jump at the location of the first glue code, ultimately reaching the first function.

[0017] 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.

[0018] 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 (i.e., the target address). After obtaining the target address of the second function, the debugger sets the second function as a breakpoint using the target address.

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

[0020] 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.

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

[0022] a determining 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 using different compilation languages;

[0023] The determination unit is further configured to determine the second function as a breakpoint of the program;

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

[0025] Based on the second aspect, in an optional implementation, the determining unit is further configured to determine that the next program code to be jumped to in a 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;

[0026] The execution unit is further configured 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.

[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 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.

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

[0030] 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.

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

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

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

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

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

[0036] 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.

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

[0038] The acquiring unit is configured 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.

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

[0040] Get the stack pointer SP;

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

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

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

[0044] 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.

[0045] In a third aspect, an embodiment of the present application provides a computing device, comprising: a processor, the processor being coupled to a memory, the memory being used to store instructions, and 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.

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

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

[0048] In a sixth aspect, an embodiment of the present application provides a chip, comprising: a processor, the processor being coupled to a memory, the memory being 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

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

[0050] Figure 1 is a schematic diagram of the process of a debugger stepping into the glue code;

[0051] Figure 2 is a schematic diagram of the debugger's process of executing step-out in glue code;

[0052] FIG3 is a schematic diagram of a scene in which a debugger processes glue code in the prior art;

[0053] FIG4 is a schematic diagram of a scenario in which a debugger processes glue code according to an embodiment of the present application;

[0054] FIG5 is a flow chart of a program debugging method according to an embodiment of the present application;

[0055] FIG6 is another flowchart of a program debugging method according to an embodiment of the present application;

[0056] FIG7 is a schematic diagram of the structure of a debugger provided in an embodiment of the present application;

[0057] FIG8 is a schematic diagram of a logical structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

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

[0059] 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 methods 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.

[0060] In the embodiments of the present application, "at least one" refers to one or more, and "more" 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 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.

[0061] The terms "first," "second," "third," "fourth," etc. (if any) in the specification and claims of the present application and in the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential sequence. It should be understood that the numbers used in this way are 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 variations thereof, are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or apparatus.

[0062] The following is an explanation of some nouns or terms used in the embodiments of the present application, which are also considered part of the content of the invention.

[0063] Runtime: The runtime is the operating environment for object-oriented programming languages ​​(OOP). It indicates which program is currently running at any given time. The runtime is one of the stages in the lifecycle of a computer program, along with compile time, link time, and load time.

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

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

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

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

[0068] step-out: Return to the parent function from the current location during debugging using the debugger.

[0069] Breakpoints: During debugging, the debugger can only perform operations on the debugged process, such as observing memory contents, when the debugged process is paused. If the debugged process does not stop, the debugger is unable to perform any actions. Aside from a few debugging events that occur only at specific times, the only way to stop the debugged process is to raise an exception. Breakpoints are exceptions used to achieve this purpose. Although a breakpoint is an exception, it does not indicate a problem with the debugged process; it is simply a debugging tool. Therefore, the debugger clearly distinguishes breakpoints (breakpoint exceptions) from other exceptions.

[0070] Stack Pointer (SP) register: The SP register is a special register used to store the stack address when the program is running. During program execution, function calls, interrupt handling, and other operations require pushing and popping data from the stack. The SP register is used to store the stack address pointer to ensure the normal operation of the program. The SP register is part of the Central Processing Unit (CPU) and is stored in the CPU's control register. The functions of the SP register can be summarized in two points: one is to store the stack pointer, and the other is to manage stack space. When data needs to be pushed into the stack, the program automatically stores the data in the stack and moves the SP pointer down to facilitate the storage of the next data. Similarly, when data needs to be popped, the program retrieves the data from the stack and moves the SP pointer up to facilitate the retrieval of the next data.

[0071] A debugger is a crucial component of any programming language. It's a tool used to diagnose and fix coding errors (or bugs). A debugger allows developers to step through and analyze the state and behavior of code as it executes. This helps developers diagnose and fix errors, understand program behavior, and optimize performance. For programmers, a debugger is a powerful tool that can effectively improve development efficiency and code quality.

[0072] Many programming languages ​​support cross-language interoperability. If a programming language includes a runtime system, glue code is required before cross-language calls can be made to perform runtime-related processing, such as scheduling and garbage collection (GC). This involves inserting additional code (called glue code) between the function executing the cross-language call (native Func) and the target function (foreign Func).

[0073] 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 single-stepping into (i.e., step-in) in Native Func. 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 function 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 function of the glue code, through the functions of each layer of the glue code, to Native Func.

[0074] Taking the Go language as an example, the main function (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:

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

[0076] Frame #7 contains the code for the Native Func, and frame #0 contains the code for the Foreign Func. The code between frames #1 and #6 is the glue code. After the debugger finishes running frame #7, it needs to step into each layer of code from frame #6 to frame #1, and finally step into the Foreign Func in frame #0 through the code in frame #1.

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

[0078] For ease of understanding, the following is an exemplary introduction to the debugging process of the current debugger in conjunction with the accompanying drawings. Please refer to Figure 1, which is a schematic diagram of the process of the debugger stepping into the glue code. As shown in Figure 1, when executing step-in from the debugger Native Func, it first enters the first layer function in the glue code (Func1 in Figure 1) and continues to step-in. If there is a sub-function in the glue code, it will also step-in into its sub-function. At this time, it is necessary to jump out in a single step (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, it will finally enter the Foreign Func from the last layer function in the glue code (FuncN in Figure 1).

[0079] Please refer to Figure 2, which illustrates the debugger's step-out process in glue code. As shown in Figure 2, when the debugger steps out of a Foreign Func, it first returns to the last function in the glue code, then steps out again, and so on. After multiple step-outs, it finally returns to the Native Func.

[0080] As can be seen from the above, the debugging process of current debuggers when processing glue code is relatively complex and inefficient. Please refer to Figure 3, which is a schematic diagram of the scene when a debugger processes glue code in the prior art. As shown in Figure 3, from the internal perspective of the debugger processing glue code shown in Figure 3, multiple step-in / step-out operations are required to enter the Foreign Func or return 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 to return to the Native Func.

[0081] In view of this, an embodiment of the present application provides a program debugging method, a debugger and a computing device for improving the efficiency of program debugging. Please refer to Figure 4, which is a schematic diagram of the scene of the debugger when processing glue code in an embodiment of the present application. As shown in Figure 4, in the internal perspective of the debugger processing glue code shown in Figure 4, the debugger faces the glue code and can enter Foreign Func by executing the program debugging method provided by the embodiment of the present application, or return to Native Func. On the other hand, from the user perspective of the developer, the program debugging method provided by the embodiment of the present application is equivalent to stepping into Foreign Func, or stepping out and returning to Native Func.

[0082] Next, the program debugging method in the embodiment of the present application is introduced. Please refer to Figure 5, which is a schematic flow chart of the program debugging method in the embodiment of the present application. Figure 5 uses a debugger as an example to illustrate the method, but the present application does not limit the execution subject of the program debugging method. For example, the debugger in Figure 5 can also be a chip, chip system, or processor that supports the debugger to implement the method, or a logical node, logic module, or software that can implement all or part of the debugger function. As shown in Figure 5, the program debugging method in the embodiment of the present application includes but is not limited to steps 101 to 103.

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

[0084] When debugging a program, developers often manually step into (or step-in into) each layer of the program (including glue code) to facilitate viewing and analyzing the code's state and behavior during execution. This helps them diagnose and fix errors, understand program behavior, and optimize performance. However, repeatedly stepping in and out of glue code can significantly reduce debugging efficiency.

[0085] 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), and the second function is a called function (equivalent to the aforementioned Foreign Func). 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).

[0086] Specifically, the content of the glue code is pre-written into the program during the static compilation phase. Therefore, 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., 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.

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

[0088] 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 can be used, and no specific limitation is made here.

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

[0090] Regardless of how the glue code is implemented, it ultimately needs to call the second function (Foreign Func). Therefore, the debugger sets the second function as a breakpoint in the program. Once the breakpoint is set, the debugger automatically runs the program until it reaches the breakpoint, at which point the program will stop and pause.

[0091] Specifically, 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 obtaining the target address of the second function, the debugger sets the second function as a breakpoint through the target address.

[0092] 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). Then the debugger can also obtain the target address of the second function based on the implementation mechanism of the compiled language.

[0093] In one 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. The second function can be obtained from the target address on the stack.

[0094] 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.

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

[0096] The debugger sets the second function as a breakpoint for 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 runs automatically in the program, the developer does not perceive the running process of the glue code, nor does he need to manually operate the various functions that run the glue code, thereby improving the efficiency of program debugging.

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

[0098] The program debugging method of the present application embodiment can also be applied to return from the called function (second function) to the calling function (first function). Refer to Figure 6, Figure 6 is another flow diagram of the program debugging method in the present application embodiment. In Figure 6, the debugger is used as the execution subject of the program debugging method as an example to illustrate the method, but the application does not limit the execution subject of the program debugging method. For example, the debugger in Figure 6 can also be a chip, a chip system, or a processor that supports the debugger to realize the method, or can be a logical node, a logic module or software that can realize all or part of the debugger function. As shown in Figure 6, the program debugging method in the present application embodiment includes but is not limited to step 201 to step 202.

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

[0100] As can be seen from the above, during the static compilation phase 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).

[0101] 202. The debugger steps out of the program N times in a row until it returns to the first function.

[0102] Because the subsequent code to be executed 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 it returns to the first function, where N is an integer greater than or equal to 2. As a result, the developer does not need to manually initiate a step-out operation for each layer of glue code in the debugger's operation interface, thereby improving the efficiency of program debugging.

[0103] As can be seen from the above, the names of the first layer functions and the last layer functions in the glue code are predictable. 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 second glue code). When the function name corresponding to the next program code that the debugger steps out (i.e., steps 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.

[0104] In one possible implementation, when the debugger executes N single-step jumps to reach the first function, it will first single-step jump out of the glue code N-1 times. In other words, the debugger will single-step out of the program N-1 times starting 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 will be able to reach the first function. Specifically, if the debugger single-steps out of the program N-1 times in a row and 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.

[0105] Accordingly, the embodiment of the present application also provides a related device for implementing the above scheme. Specifically, refer to Figure 7, a structural diagram of the debugger provided by Figure 7 for the embodiment of the present application. The device can be a debugger, or it can be a component (such as a processor, chip, or chip system, etc.) of the debugger, or it can be a logical node, logic module or software that can realize all or part of the debugger function. As shown in Figure 7, the debugger includes a determination unit 301, an acquisition unit 302 and an execution unit 303.

[0106] a determining unit 301 configured 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 using different compilation languages;

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

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

[0109] In one possible design, the determining unit 301 is further configured to determine that the next program code to be jumped to in a 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;

[0110] The execution unit 303 is further configured 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.

[0111] In one possible design, the determining unit 301 is specifically configured to:

[0112] 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.

[0113] In one possible design, the determining unit 301 is specifically configured to:

[0114] 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.

[0115] In one possible design, the execution unit 303 is specifically configured to:

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

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

[0118] In one possible design, the execution unit 303 is specifically configured to:

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

[0120] 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.

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

[0122] The acquiring unit 302 is configured 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.

[0123] In one possible design, the acquiring unit 302 is specifically configured to:

[0124] Get the stack pointer SP;

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

[0126] In one possible design, the acquiring unit 302 is specifically configured to:

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

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

[0129] Refer to Figure 8, Figure 8 is a kind of logical structure diagram of the computing device 40 that the present application embodiment provides.The computing device 40 can be a debugger, it can also be a component of the debugger (such as a processor, a chip, or a chip system, etc.), it can also be a logical node, a logical module or software that can realize all or part of the debugger function. The debugger described in the corresponding embodiment of Figure 7 can be deployed on the computing device 40, for realizing the function realized by the debugger in the corresponding embodiment of Figure 5 or Figure 6. The computer device 40 includes: a memory 401, a processor 402, a communication interface 403 and a bus 404. Wherein, the memory 401, the processor 402, the communication interface 403 realize the communication connection between each other through the bus 404.

[0130] 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 programs. 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 perform steps 101-103 of the above-described data processing method embodiment.

[0131] The processor 402 can 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 device, a discrete gate or transistor logic device, a discrete hardware component or any combination thereof, used to execute relevant programs to implement one or more steps 101-103 of the data processing method embodiment in this application. The steps of the data processing method disclosed in the embodiment of the present application can be executed by a compiler and an executor, wherein the compiler and the executor can be executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, registers, 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 101-103 of the data processing method embodiment in this application in combination with its hardware.

[0132] 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.

[0133] Bus 404 provides a pathway for transmitting information between the various components of computer device 40 (e.g., memory 401, processor 402, and communication interface 403). Bus 404 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. Buses can be categorized as address buses, data buses, control buses, and the like. For ease of illustration, FIG8 shows a single thick line, but this does not imply that there is only one bus or only one type of bus.

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

[0135] The present application also provides a computer program product comprising instructions. The computer program product may be software or a program product comprising instructions that can be run on a computing device or stored on any available medium. When the computer program product is run on at least one computing device, the computer program product causes the at least one computing device to perform the method described in the embodiment shown in FIG. 5 or FIG. 6 .

[0136] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can 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). The computer-readable storage medium includes instructions that instruct the computing device to execute the above-mentioned method for executing the embodiment described in Figure 5 or Figure 6.

[0137] The communication device provided in the embodiments of the present application may specifically 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 computer-executable instructions stored in the storage unit so that the chip performs the method described in the embodiment shown in FIG5 or FIG6. Optionally, the storage unit is a storage unit within the chip, such as a register, a cache, etc. The storage unit may also be a storage unit located outside the chip within the wireless access device, such as a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM), etc.

[0138] It should be 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 across 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 drawings of the device embodiments provided in the embodiments of the present application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.

[0139] Through the description of the above embodiments, it is clear to those skilled in the art that the embodiments of the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by dedicated hardware including application-specific integrated circuits, dedicated CPUs, dedicated memories, dedicated components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be various, such as analog circuits, digital circuits, or application-specific circuits, etc. However, for the embodiments of the present application, software program implementation is a better implementation method in most cases. Based on such an understanding, the technical solutions of the embodiments of the present application are essentially or partly contributed 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's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.

[0140] 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.

[0141] 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 can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can 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 can be transmitted from a website, 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, a computer, a training device or a data center. The computer-readable storage medium can 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 can 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)).

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 determining 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

Patent Citations

  • Program debugging method, debugger and computing equipment

    CN119847907A

  • Debugging method and debugging system for configuration program of PLC

    CN111142469A

  • Program debugging method and device, equipment and storage medium

    CN113742237A

  • Code debugging method and device, electronic equipment and readable storage medium

    CN114816973A

  • Scenario-based code trimming and code reduction

    US9436449B1