Program debugging method, device, equipment and storage medium

By setting the jump function code in the target program, jumping to the replacement address to execute the debugging function code, and restoring the original code, the problem of high cost and low efficiency in setting program debugging break points is solved, and a flexible and efficient debugging method is realized.

CN113742237BActive Publication Date: 2024-09-24BEIJING ESWIN COMPUTING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111070638.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-13
Publication Date
2024-09-24
Estimated Expiration
2041-09-13

AI Technical Summary

Technical Problem

During program debugging, existing technologies require high hardware costs or cumbersome code compilation to set breakpoints, resulting in high cost and low efficiency.

Method used

By setting the jump function code at the breakpoint in the target program, jumping to the replacement address to execute the debugging function code, and restoring the original code after debugging is completed, flexible breakpoint setting and efficient debugging are achieved.

Benefits of technology

Without relying on hardware participation, it achieves effective debugging of the target program, reduces costs, improves debugging efficiency, and is suitable for a variety of application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113742237B
    Figure CN113742237B
Patent Text Reader

Abstract

The embodiment of the present application discloses a program debugging method, device, equipment and storage medium, the method comprising: in the process of running a target program, if the target breakpoint in the target program is reached, the target jump function code at the target breakpoint is executed to jump to the replacement address corresponding to the target breakpoint: the target debugging function code corresponding to the target breakpoint is obtained and executed from the replacement address corresponding to the target breakpoint; after debugging is completed, the original code at the target breakpoint is restored and the target program is continued to run. By adopting the embodiment of the present application, breakpoints can be flexibly set in the target program, the program debugging efficiency is improved, and the applicability is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software, and in particular to a program debugging method, apparatus, device and storage medium. Background Art

[0002] During the program debugging process, it is often necessary to use hardware or embed breakpoints and corresponding debugging function codes in the original program code to set breakpoints for program debugging.

[0003] On the one hand, using hardware to debug a program will bring high hardware costs. On the other hand, embedding breakpoints and debugging function codes to debug a program requires recompiling the original program code, which is a cumbersome process. Therefore, how to effectively set breakpoints and improve program debugging efficiency while saving costs has become an urgent problem to be solved. Summary of the invention

[0004] The embodiments of the present application provide a program debugging method, apparatus, device, and storage medium, which can flexibly set breakpoints in a target program, improve program debugging efficiency, and have high applicability.

[0005] In a first aspect, an embodiment of the present application provides a program debugging method, the method comprising:

[0006] During the running of the target program, if the target breakpoint in the target program is reached, the target jump function code at the target breakpoint is executed to jump to the replacement address corresponding to the target breakpoint:

[0007] Obtain and execute the target debugging function code corresponding to the target breakpoint from the replacement address corresponding to the target breakpoint;

[0008] After debugging is completed, the original code at the above target breakpoint is restored and the above target program continues to run.

[0009] In a second aspect, an embodiment of the present application provides a program debugging device, the device comprising:

[0010] A jump module, used for executing a target jump function code at the target breakpoint to jump to a replacement address corresponding to the target breakpoint when the target program is run to the target breakpoint in the target program;

[0011] A debugging module, used for acquiring and executing a target debugging function code corresponding to the target breakpoint from a replacement address corresponding to the target breakpoint;

[0012] The recovery module is used to restore the original code at the target breakpoint and continue running the target program after debugging is completed.

[0013] In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, wherein the processor and the memory are connected to each other;

[0014] The memory is used to store computer programs;

[0015] The processor is configured to execute the program debugging method provided in the embodiment of the present application when calling the computer program.

[0016] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the program debugging method provided by an embodiment of the present application.

[0017] In a fifth aspect, an embodiment of the present application provides a computer program product or a computer program, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the program debugging method provided in an embodiment of the present application.

[0018] In an embodiment of the present application, breakpoints can be flexibly set in the target program through breakpoint setting instructions, and by storing the debugging function code corresponding to the breakpoint, when the target program runs to the breakpoint, it can jump directly based on the jump function code to execute the debugging function code, thereby achieving effective debugging of the target program without relying on hardware to participate in program debugging, and has high applicability. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0020] Figure 1 It is a flowchart of a program debugging method provided in an embodiment of the present application;

[0021] Figure 2 is a flow chart of a breakpoint setting method provided in an embodiment of the present application;

[0022] Figure 3 It is a schematic diagram of a scenario of backing up breakpoint addresses and original codes provided in an embodiment of the present application;

[0023] Figure 4 It is a flowchart of a method for determining breakpoints and setting breakpoints provided in an embodiment of the present application;

[0024] Figure 5 It is a schematic diagram of a process of performing program debugging based on breakpoints provided in an embodiment of the present application;

[0025] Figure 6 It is a schematic diagram of a scenario of program debugging based on breakpoints provided in an embodiment of the present application;

[0026] Figure 7 is a schematic diagram of the structure of a program debugging device provided in an embodiment of the present application;

[0027] Figure 8 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0029] The program debugging method provided in the embodiment of the present application can be applied to debugging embedded programs, and can also be applied to debugging computer programs, etc. The specific method can be determined based on the actual application scenario requirements and is not limited here.

[0030] See also Figure 1 , Figure 1 Schematic diagram of the process of debugging a program provided by an embodiment of the present application. Figure 1 As shown, the program debugging method provided in the embodiment of the present application may include the following steps:

[0031] Step S11 , during the process of running the target program, if the target breakpoint in the target program is reached, the target jump function code at the target breakpoint is executed to jump to the replacement address corresponding to the target breakpoint.

[0032] In some feasible implementations, a breakpoint is an interruption location during program execution. During debugging of a target program, the target program can be run and when the target program reaches a breakpoint, the target program stops running. At this time, program debugging and other operations can be performed at the breakpoint.

[0033] The target program may include at least one breakpoint, and the positions of the breakpoints in the target program are different, which may be determined by the actual setting requirements of the breakpoints and are not limited here.

[0034] The setting methods of each breakpoint in the above target program can be found in Figure 2 , Figure 2is a flow chart of the breakpoint setting method provided in the embodiment of the present application. Figure 2 As shown, the breakpoint setting method provided in the embodiment of the present application may include the following steps:

[0035] Step S111: Obtain a breakpoint setting instruction, and determine a first breakpoint corresponding to the breakpoint setting instruction in the target program.

[0036] In some feasible implementations, the above breakpoint setting instruction may be a breakpoint setting instruction before running the target program. That is, before running the target program to debug the target program, a breakpoint setting instruction for the target program triggered by a user may be received, and then a breakpoint is set in the target program based on the breakpoint setting instruction obtained before running the target program.

[0037] Optionally, the above breakpoint setting instruction may be a preset instruction obtained during the running of the target program. The above preset instruction includes but is not limited to an interrupt instruction or a polling instruction, etc., and may also be a pre-set related instruction for setting a breakpoint, or may be a related instruction triggered by a preset address or preset symbol in the target program, etc., which may be determined based on the actual application scenario requirements and is not limited here.

[0038] For example, during the process of running the target program, preset instructions may be dynamically acquired, and then breakpoints may be dynamically set in the target program based on the acquired preset instructions during the process of running the target program.

[0039] Optionally, the above breakpoint instruction can be a breakpoint setting instruction obtained through a preset interactive method during the running of the target program. Among them, the above breakpoint setting instruction obtained through the preset interactive method can be a breakpoint setting instruction obtained based on a preset debugging interface, or a breakpoint setting instruction received based on a preset serial port. The specific instructions can be determined based on the actual application scenario requirements and are not limited here.

[0040] For example, during the process of running the target program, the user can set breakpoints for the target program based on the program debugging interface, and based on this, the breakpoint setting instructions triggered by the user can be obtained through the program debugging interface, and then breakpoints can be set in the target program based on the breakpoint setting instructions obtained through the program debugging interface during the process of running the target program.

[0041] In some feasible implementations, after obtaining the breakpoint setting instruction, the breakpoint corresponding to the breakpoint setting instruction may be determined in the target program. For ease of description, the breakpoint corresponding to the breakpoint setting instruction is referred to as the first breakpoint below. That is, after obtaining the breakpoint setting instruction, the first breakpoint may be set at a target position in the target program based on the breakpoint setting instruction. The target position is a line of code in the target program.

[0042] In some feasible implementations, the program debugging method provided in the embodiments of the present application can be applicable to processors such as Advanced Reduced Instruction Set Computing Machine (ARM), and the instruction counter (PC) value during the execution of the target program is saved through registers in the processor to indicate the address of the next program instruction of the currently running program instruction.

[0043] In this case, when determining the first breakpoint based on the breakpoint setting instruction, it is necessary to avoid the push instruction in the target program to ensure the normal operation of the target program during the program debugging process. For example, when using the lr register in the ARM architecture to save the PC value corresponding to the application, it is necessary to avoid the lr push instruction in the target program when determining the first breakpoint to ensure the normal operation of the target program.

[0044] Based on this, after obtaining the breakpoint setting instruction to be set, the initial breakpoint corresponding to the breakpoint setting instruction of the target program can be determined first, and the initial breakpoint is the breakpoint that the breakpoint setting instruction expects to set in the target program. If the above breakpoint setting instruction is a terminal instruction obtained during the running of the target program, then the initial breakpoint corresponding to the breakpoint setting instruction in the target program is the code corresponding to the target program interruption moment. If the above breakpoint setting instruction is a user-triggered breakpoint setting instruction obtained through the program debugging interface during the running of the target program, then the breakpoint that the user expects to set in the target program can be used as the initial breakpoint corresponding to the breakpoint setting instruction.

[0045] Further, after determining the initial breakpoint corresponding to the breakpoint setting instruction, it can be determined whether the original code corresponding to the initial breakpoint in the target program includes a push instruction. If the original code corresponding to the initial breakpoint in the target program includes a push instruction, the position of the initial breakpoint can be adjusted to a position in the initial code that does not include the push instruction, and the adjusted breakpoint is determined as the first breakpoint corresponding to the breakpoint setting instruction.

[0046] If the original code corresponding to the initial breakpoint in the target program does not include a push instruction, the initial breakpoint can be directly determined as the first breakpoint corresponding to the breakpoint setting instruction.

[0047] Among them, for any breakpoint, the original code corresponding to the breakpoint can be the code corresponding to the breakpoint, or it can be the code associated with the breakpoint before and after in the target program. The specific code can be determined based on the actual application scenario requirements and is not limited here.

[0048] Step S112: determine a first debugging function code corresponding to the first breakpoint, and store the first debugging function code to a replacement address corresponding to the first breakpoint.

[0049] In some feasible implementations, after determining the first breakpoint corresponding to the breakpoint setting instruction in the target program, the first debugging function code corresponding to the first breakpoint can be determined. The first debugging function code corresponding to the first breakpoint is the code corresponding to the debugging function performed after the target runs to the first breakpoint and interrupts. That is, after determining the first breakpoint corresponding to the breakpoint setting instruction in the target program, the debugging function executed at the breakpoint can be determined, and the first debugging function code corresponding to the debugging function can be determined.

[0050] Among them, the debugging function corresponding to the above-mentioned first debugging function code includes but is not limited to displaying the current function stack, printing register information, displaying page information or setting breakpoints, etc., which can be determined based on the actual application scenario requirements and are not limited here. That is, the first debugging function code corresponding to the first breakpoint can be a debugging code that implements any function. For example, after the target program runs to the first breakpoint and stops running, the functions of displaying the current function stack, printing register information, displaying page information, and setting breakpoints in the target program can be implemented based on the first function code.

[0051] Further, after determining the first debugging function code corresponding to the first breakpoint, the first debugging function code may be stored in the replacement address corresponding to the first breakpoint, that is, the first debugging function code may be stored in the storage space corresponding to the replacement address corresponding to the first breakpoint.

[0052] Among them, the storage space corresponding to the above-mentioned replacement address can be a physical memory unit or a logical storage space, such as the internal storage space of a dynamic random access memory (DRAM) or a static random access memory (SRAM), etc., which can be determined based on the application scenario requirements and is not limited here.

[0053] For example, the replacement address may be a predetermined replacement address, which may be an address of 0x2000000 pointing to a DRAM or SRAM.

[0054] Among them, the replacement addresses corresponding to different breakpoints in the target program can be the same or different. For example, the debugging function codes corresponding to different breakpoints can be stored together or separately. The specific details can be determined based on the actual application scenario requirements and are not limited here.

[0055] Step S113: Replace the original code corresponding to the first breakpoint in the target program with the first jump function code.

[0056] After the first debugging function code corresponding to the first breakpoint is stored in the corresponding replacement address, the original code corresponding to the first breakpoint in the target program can be replaced with the corresponding jump function code. For the convenience of description, the jump function code corresponding to the first breakpoint is referred to as the first jump function code below. Among them, the first jump function code corresponding to the first breakpoint is used to jump to the replacement address corresponding to the first breakpoint. When the target program runs to the first breakpoint, the first jump function code at the first breakpoint can be executed to jump to the corresponding replacement address, and the first debugging function code corresponding to the first breakpoint is obtained and executed from the corresponding replacement address, thereby completing the operation of the debugging function corresponding to the first breakpoint.

[0057] In some feasible implementations, after determining the first breakpoint corresponding to the breakpoint setting instruction in the target program, or before replacing the original code corresponding to the first breakpoint with the first jump function code, the breakpoint address of the first breakpoint can be determined, and the original code corresponding to the first breakpoint in the target program is stored in the backup address corresponding to the first breakpoint. For the convenience of description, the breakpoint address of the first breakpoint is referred to as the first breakpoint address below. The first breakpoint address is used to determine the specific location of the first breakpoint in the target program, that is, to indicate the location of the original code corresponding to the first breakpoint in the target program.

[0058] Furthermore, after the original code corresponding to the first breakpoint is stored in the backup address corresponding to the first breakpoint, the first breakpoint address of the first breakpoint can also be stored in the backup address corresponding to the first breakpoint. The first breakpoint address is used to jump to the corresponding replacement address based on the first jump function code at the first breakpoint, obtain and execute the debugging function code corresponding to the first breakpoint, and restore the first jump function code located at the first breakpoint address based on the original code corresponding to the first breakpoint in the backup address.

[0059] Among them, the storage space corresponding to the above-mentioned backup address can also be a physical memory unit or a logical storage space, such as DRAM or SRAM internal storage space, etc., which can be determined based on the application scenario requirements and is not limited here.

[0060] Among them, the backup addresses corresponding to different breakpoints in the target program can be the same or different. For example, the original code and breakpoint addresses corresponding to different breakpoints can be stored together or separately. The specific details can be determined based on the actual application scenario requirements and are not limited here.

[0061] See also Figure 3 , Figure 3 Schematic diagram of a scenario for backing up the breakpoint address and the original code provided by an embodiment of the present application. Figure 3As shown, the target program includes multiple code segments. After determining the first breakpoint corresponding to the target program breakpoint setting instruction, the original code corresponding to the first breakpoint can be determined, such as Figure 3 In the example, the two lines of code after the first breakpoint are determined as the corresponding original code, and the two lines of code after the first breakpoint can be determined as the original code corresponding to the first breakpoint. At the same time, the breakpoint address corresponding to the first breakpoint can be determined, and then the breakpoint address of the first breakpoint and the corresponding original code are stored in the backup address for backup.

[0062] Based on Figure 2 After setting at least one breakpoint in the target program, the breakpoint setting method shown can start running the target program and debug the target program based on the breakpoints in the target program. During the running of the target program, if it runs to any breakpoint in the target program (for the convenience of description, the breakpoint is referred to as the target breakpoint below), the target jump function code at the target breakpoint is executed to jump to the replacement address corresponding to the target breakpoint.

[0063] Combine the following Figure 4 The breakpoint setting method provided in the embodiment of the present application is further explained. Figure 4 It is a flow chart of the method for determining breakpoints and setting breakpoints provided by an embodiment of the present application. After determining the initial breakpoint corresponding to the breakpoint setting instruction in the target program, it can be determined whether the original code corresponding to the initial breakpoint includes a stack push instruction. If a stack push instruction is included, the breakpoint position of the initial breakpoint is adjusted to obtain the final breakpoint corresponding to the breakpoint setting instruction. If a stack push instruction is not included, the initial breakpoint is directly determined as the final breakpoint corresponding to the breakpoint setting instruction. Further, the breakpoint address of the final breakpoint and the corresponding original code can be stored in a backup address for backup, and the original code corresponding to the final breakpoint is replaced with a jump function code, so that when the target program runs to the final breakpoint, the jump function code is executed to jump to the corresponding backup address, and the corresponding debugging function code is obtained and executed from the backup address.

[0064] Step S12: acquiring and executing the target debugging function code corresponding to the target breakpoint from the replacement address corresponding to the target breakpoint.

[0065] In some feasible implementations, after the target jump function code at the target breakpoint jumps to the replacement address corresponding to the target breakpoint, the target debugging function code corresponding to the target breakpoint can be obtained from the storage space corresponding to the replacement address, and the target debugging function code can be executed at the replacement address to implement the corresponding function, or the target debugging function code can be executed based on the function code springboard corresponding to the replacement address to implement the corresponding debugging function.

[0066] Optionally, after obtaining the target debugging function code corresponding to the target breakpoint from the replacement address, the target debugging function code may be added to the target breakpoint, and then the target debugging function code may be executed at the target breakpoint to implement the corresponding debugging function.

[0067] It should be noted that the above implementation method of executing the target debugging function code is only an example, and the specific method can be determined based on the actual application scenario requirements and is not limited here.

[0068] Step S13: After debugging is completed, restore the original code at the target breakpoint and continue running the target program.

[0069] In some feasible implementations, after executing the target debugging function code corresponding to the target breakpoint and implementing the corresponding debugging function, it can be determined that the program debugging at the target breakpoint is completed. At this time, the original code at the target breakpoint can be restored and the target program can continue to run.

[0070] Specifically, after debugging is completed, the target breakpoint address corresponding to the target breakpoint and the original code at the target breakpoint can be obtained from the backup address corresponding to the target breakpoint. The original code at the target breakpoint can be further used to restore the target jump function code at the target breakpoint address located at the target breakpoint, that is, the target jump function code at the target breakpoint is restored to the original code of the target breakpoint, thereby realizing the code restoration at the target breakpoint. Moreover, after restoring the target jump function code at the target breakpoint to the original code, the program after the target breakpoint in the target program can be run, and then when the target program runs to any breakpoint, the corresponding breakpoint can be stopped based on the above implementation method and the corresponding debugging function code can be run.

[0071] See also Figure 5 , Figure 5 It is a flow chart of program debugging based on breakpoints provided by an embodiment of the present application. When the target program runs to the first breakpoint, the jump function code can be executed to jump to the corresponding replacement address, and the save site operation can be performed to save the running progress and status of the current target program. Further based on the function code springboard, the corresponding debugging function code is obtained and executed to realize the corresponding debugging function, and the original code corresponding to the first breakpoint is restored after the debugging is completed. Specifically, based on the original code corresponding to the first breakpoint stored in the backup address and the breakpoint address, the jump function code corresponding to the first breakpoint can be restored to the corresponding original code. After the original code corresponding to the first breakpoint is restored, the restore site operation is performed to restore the running progress and status of the target program before the program debugging.

[0072] Combine the following Figure 6 right Figure 5 For further explanation, Figure 6Schematic diagram of a scenario of program debugging based on breakpoints provided in an embodiment of the present application. Figure 6 The PC value corresponding to the application is saved through the lr register. When the target program runs to the first breakpoint and executes the jump function code to jump to the corresponding replacement address, the stack push instruction (push) can be executed on the registers other than lr to save the running progress and status of the target program, realizing the save scene step.

[0073] Furthermore, when the most basic serial port is used to output debugging information, since breakpoints cannot be set in the serial port driver, the serial port cache needs to be cleared after saving the scene, and then the corresponding debugging function code is executed. After the corresponding debugging function is implemented, the code at the first breakpoint in the target program can be restored based on the original code and breakpoint address corresponding to the first breakpoint stored in the backup address. And further, the breakpoint address of the first breakpoint is assigned to the lr register to adjust the corresponding PC value.

[0074] Further, the serial port buffer is continuously cleared, and a pop instruction (pop) is executed on registers other than the lr register to restore the running progress and state of the target program. After the scene is restored, the program after the first breakpoint can be run.

[0075] In the embodiment of the present application, breakpoints can be set dynamically without the participation of additional debugging hardware through breakpoint setting instructions, which is highly flexible. By backing up the original code and breakpoint address corresponding to each breakpoint, the target program can be restored after running to any breakpoint and executing the corresponding debugging function code, without the need to recompile the target program, which improves the efficiency of program debugging and has high applicability.

[0076] See also Figure 7 , Figure 7 : is a schematic diagram of the structure of a program debugging device provided in an embodiment of the present application. The program debugging device provided in an embodiment of the present application includes:

[0077] The jump module 71 is used for executing the target jump function code at the target breakpoint to jump to the replacement address corresponding to the target breakpoint when the target program is run to the target breakpoint in the target program;

[0078] The debugging module 72 is used to obtain and execute the target debugging function code corresponding to the target breakpoint from the replacement address corresponding to the target breakpoint;

[0079] The recovery module 73 is used to restore the original code at the target breakpoint and continue running the target program after debugging is completed.

[0080] In some feasible implementations, the debugging module 72 is used to:

[0081] Obtaining a breakpoint setting instruction, and determining a first breakpoint corresponding to the breakpoint setting instruction in the target program;

[0082] Determine a first debugging function code corresponding to the first breakpoint, and store the first debugging function code to a replacement address corresponding to the first breakpoint;

[0083] The original code corresponding to the first breakpoint in the target program is replaced with a first jump function code, where the first jump function code is used to jump to a replacement address corresponding to the first breakpoint.

[0084] In some feasible implementations, the debugging module 72 is further used to:

[0085] Determine a first breakpoint address of the first breakpoint;

[0086] The original code corresponding to the first breakpoint in the target program and the first breakpoint address are stored in the backup address corresponding to the first breakpoint.

[0087] In some feasible implementations, the recovery module 73 is used to:

[0088] Acquire a target breakpoint address corresponding to the target breakpoint and an original code corresponding to the target breakpoint from a backup address corresponding to the target breakpoint;

[0089] Based on the target breakpoint address, the target jump function code is restored to the original code corresponding to the target breakpoint, and the program after the target breakpoint continues to run.

[0090] In some feasible implementations, the above breakpoint setting instruction includes at least one of the following:

[0091] The breakpoint setting instruction obtained before running the above target program;

[0092] Preset instructions obtained during the running of the above target program;

[0093] The breakpoint setting instructions are obtained through a preset interactive mode during the running of the above target program.

[0094] In some feasible implementations, the preset instruction includes at least one of an interrupt instruction or a polling instruction.

[0095] In some feasible implementations, the debugging function corresponding to the first debugging function code includes at least one of displaying a current function stack, printing register information, displaying page table information, or setting a breakpoint.

[0096] In some feasible implementations, the breakpoint debugging module 72 is used to:

[0097] Determining an initial breakpoint corresponding to the breakpoint setting instruction in the target program;

[0098] If the original code corresponding to the initial breakpoint includes a push instruction, the position of the initial breakpoint is adjusted, and the adjusted breakpoint is determined as the first breakpoint corresponding to the breakpoint setting instruction, and the original code corresponding to the adjusted breakpoint does not include a push instruction;

[0099] If the original code corresponding to the initial breakpoint does not include a push instruction, the initial breakpoint is determined as the first breakpoint corresponding to the breakpoint setting instruction.

[0100] In a specific implementation, the program debugging device can execute the above-mentioned Figure 1 and / or Figure 2 For the implementation methods provided in each step, please refer to the implementation methods provided in the above steps for details, which will not be repeated here.

[0101] See also Figure 8 , Figure 8 Schematic diagram of the structure of the electronic device provided in the embodiment of the present application. Figure 8 As shown, the electronic device 1000 in this embodiment may include: a processor 1001, a network interface 1004 and a memory 1005. In addition, the above-mentioned electronic device 1000 may also include: a user interface 1003, and at least one communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. Among them, the user interface 1003 may include a display screen (Display), a keyboard (Keyboard), and the user interface 1003 may optionally include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1004 may be a high-speed RAM memory, or it may be a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 1005 may optionally also be at least one storage device located away from the aforementioned processor 1001. As Figure 8 As shown, the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a device control application program.

[0102] exist Figure 8 In the electronic device 1000 shown, the network interface 1004 can provide a network communication function; the user interface 1003 is mainly used to provide an input interface for the user; and the processor 1001 can be used to call the device control application stored in the memory 1005 to achieve:

[0103] During the process of running the target program, if the target breakpoint in the target program is reached, the target jump function code at the target breakpoint is executed to jump to the replacement address corresponding to the target breakpoint:

[0104] Acquire and execute the target debugging function code corresponding to the target breakpoint from the replacement address corresponding to the target breakpoint;

[0105] After debugging is completed, the original code at the target breakpoint is restored and the target program continues to run.

[0106] In some feasible implementations, the processor 1001 is configured to:

[0107] Obtain a breakpoint setting instruction, and determine a first breakpoint corresponding to the breakpoint setting instruction in the target program;

[0108] Determine a first debugging function code corresponding to the first breakpoint, and store the first debugging function code to a replacement address corresponding to the first breakpoint;

[0109] The original code corresponding to the first breakpoint in the target program is replaced with a first jump function code, where the first jump function code is used to jump to a replacement address corresponding to the first breakpoint.

[0110] In some feasible implementations, the processor 1001 is further configured to:

[0111] Determine a first breakpoint address of the first breakpoint;

[0112] The original code corresponding to the first breakpoint in the target program and the first breakpoint address are stored in the backup address corresponding to the first breakpoint.

[0113] In some feasible implementations, the processor 1001 is configured to:

[0114] Obtaining a target breakpoint address corresponding to the target breakpoint and an original code corresponding to the target breakpoint from a backup address corresponding to the target breakpoint;

[0115] Based on the target breakpoint address, the target jump function code is restored to the original code corresponding to the target breakpoint, and the program after the target breakpoint continues to run.

[0116] In some feasible implementations, the above breakpoint setting instruction includes at least one of the following:

[0117] The breakpoint setting instruction obtained before running the above target program;

[0118] Preset instructions obtained during the running of the above target program;

[0119] The breakpoint setting instructions are obtained through a preset interactive mode during the running of the above target program.

[0120] In some feasible implementations, the preset instruction includes at least one of an interrupt instruction or a polling instruction.

[0121] In some feasible implementations, the debugging function corresponding to the first debugging function code includes at least one of displaying a current function stack, printing register information, displaying page table information, or setting a breakpoint.

[0122] In some feasible implementations, the processor 1001 is configured to:

[0123] Determining an initial breakpoint corresponding to the breakpoint setting instruction in the target program;

[0124] If the original code corresponding to the initial breakpoint includes a push instruction, the position of the initial breakpoint is adjusted, and the adjusted breakpoint is determined as the first breakpoint corresponding to the breakpoint setting instruction, and the original code corresponding to the adjusted breakpoint does not include a push instruction;

[0125] If the original code corresponding to the initial breakpoint does not include a push instruction, the initial breakpoint is determined as the first breakpoint corresponding to the breakpoint setting instruction.

[0126] It should be understood that in some feasible implementations, the processor 1001 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.

[0127] In a specific implementation, the electronic device 1000 can execute the above-mentioned functions through its built-in functional modules. Figure 1 and / or Figure 2For the implementation methods provided in each step, please refer to the implementation methods provided in the above steps for details, which will not be repeated here.

[0128] The present application also provides a computer-readable storage medium, which stores a computer program and is executed by a processor to implement Figure 1 and / or Figure 2 For the methods provided in each step, please refer to the implementation methods provided in the above steps for details, which will not be repeated here.

[0129] The above-mentioned computer-readable storage medium may be an internal storage unit of the aforementioned program debugging device or electronic device, such as a hard disk or memory of an electronic device. The computer-readable storage medium may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device. The above-mentioned computer-readable storage medium may also include a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc. Further, the computer-readable storage medium may also include both an internal storage unit of the electronic device and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the electronic device. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.

[0130] The embodiment of the present application provides a computer program product or a computer program, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes Figure 1 and / or Figure 2 The methods provided in each step.

[0131] The terms "first", "second", etc. in the claims, specification and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. 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 electronic device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or electronic devices. Mentioning "embodiment" in this article means that the specific features, structures or characteristics described in conjunction with the embodiment may be included in at least one embodiment of the present application. Displaying the phrase at various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments. The term "and / or" used in the present application specification and the attached claims refers to any combination of one or more of the items listed in association and all possible combinations, and includes these combinations.

[0132] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Professional and technical personnel may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0133] The above disclosure is only the preferred embodiment of the present application, which cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.

Claims

1. A program debugging method, characterized in that: The method comprises: Obtaining a breakpoint setting instruction, wherein the breakpoint setting instruction is used to set each breakpoint in the target program, and the breakpoint setting instruction includes at least one of the following: a preset instruction obtained during the running of the target program; a breakpoint setting instruction obtained through a preset interactive method during the running of the target program; During the running of the target program, if the target breakpoint in the target program is reached, the target jump function code at the target breakpoint is executed to jump to the replacement address corresponding to the target breakpoint; Acquire and execute the target debugging function code corresponding to the target breakpoint from the replacement address corresponding to the target breakpoint; After debugging is completed, restoring the original code at the target breakpoint and continuing to run the target program; The target breakpoint is determined in the following manner: If the original code corresponding to the initial breakpoint corresponding to the breakpoint setting instruction includes a push instruction, adjusting the position of the initial breakpoint, determining the adjusted breakpoint as the target breakpoint, and the original code corresponding to the adjusted breakpoint does not include a push instruction; If the original code corresponding to the initial breakpoint corresponding to the breakpoint setting instruction does not include a push instruction, the initial breakpoint is determined as the target breakpoint.

2. The method according to claim 1, characterized in that Each breakpoint in the target program is set based on the following method: Obtaining a breakpoint setting instruction, and determining a first breakpoint corresponding to the breakpoint setting instruction in the target program; Determine a first debugging function code corresponding to the first breakpoint, and store the first debugging function code to a replacement address corresponding to the first breakpoint; The original code corresponding to the first breakpoint in the target program is replaced with a first jump function code, where the first jump function code is used to jump to a replacement address corresponding to the first breakpoint.

3. The method according to claim 2, characterized in that After determining the first breakpoint corresponding to the breakpoint setting instruction in the target program, the method further includes: determining a first breakpoint address of the first breakpoint; The original code corresponding to the first breakpoint in the target program and the first breakpoint address are stored in a backup address corresponding to the first breakpoint.

4. The method according to claim 3, characterized in that Restoring the original code at the target breakpoint and continuing to run the target program includes: Acquire a target breakpoint address corresponding to the target breakpoint and an original code corresponding to the target breakpoint from a backup address corresponding to the target breakpoint; Based on the target breakpoint address, the target jump function code is restored to the original code corresponding to the target breakpoint, and the program after the target breakpoint continues to run.

5. The method according to claim 2, characterized in that: The breakpoint setting instruction also includes: The breakpoint setting instruction is obtained before running the target program.

6. The method according to claim 5, characterized in that The preset instruction includes at least one of an interrupt instruction or a polling instruction.

7. The method according to claim 2, characterized in that The debugging function corresponding to the first debugging function code includes at least one of displaying a current function stack, printing register information, displaying page table information, or setting a breakpoint.

8. The method according to claim 2, characterized in that: The step of determining in the target program a first breakpoint corresponding to the breakpoint setting instruction comprises: Determining an initial breakpoint corresponding to the breakpoint setting instruction in the target program; If the original code corresponding to the initial breakpoint includes a push instruction, the position of the initial breakpoint is adjusted, and the adjusted breakpoint is determined as the first breakpoint corresponding to the breakpoint setting instruction, and the original code corresponding to the adjusted breakpoint does not include a push instruction; If the original code corresponding to the initial breakpoint does not include a push instruction, the initial breakpoint is determined as the first breakpoint corresponding to the breakpoint setting instruction.

9. A program debugging device, characterized in that: The device comprises: A debugging module, used to obtain breakpoint setting instructions, wherein the breakpoint setting instructions are used to set each breakpoint in the target program, and the breakpoint setting instructions include at least one of the following: a preset instruction obtained during the running of the target program; a breakpoint setting instruction obtained through a preset interactive method during the running of the target program; A jump module, used for executing a target jump function code at the target breakpoint to jump to a replacement address corresponding to the target breakpoint if the target breakpoint in the target program is reached during the running of the target program; The debugging module is further used to obtain and execute the target debugging function code corresponding to the target breakpoint from the replacement address corresponding to the target breakpoint; A recovery module, used for recovering the original code at the target breakpoint and continuing to run the target program after debugging is completed; The target breakpoint is determined in the following manner: If the original code corresponding to the initial breakpoint corresponding to the breakpoint setting instruction includes a push instruction, adjusting the position of the initial breakpoint, determining the adjusted breakpoint as the target breakpoint, and the original code corresponding to the adjusted breakpoint does not include a push instruction; If the original code corresponding to the initial breakpoint corresponding to the breakpoint setting instruction does not include a push instruction, the initial breakpoint is determined as the target breakpoint.

10. An electronic device, characterized in that: comprising a processor and a memory, wherein the processor and the memory are connected to each other; The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 8 when calling the computer program.

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