Method, system, device and medium for implementing breakpoint debugging function

By using the soft PLC controller to replace and process breakpoint instructions on the PC platform, the problem that software breakpoint debugging on the Windows X64 platform cannot capture all exceptions is solved, and the accuracy and efficiency of breakpoint debugging are improved.

CN115616973BActive Publication Date: 2024-10-11SHENZHEN INOVANCE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211321052.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-26
Publication Date
2024-10-11
Estimated Expiration
2042-10-26

AI Technical Summary

Technical Problem

Existing software breakpoint debugging cannot capture all exceptions on the Windows X64 platform, resulting in limited accuracy and efficiency of breakpoint debugging.

Method used

Through code migration technology, the breakpoint debugging function based on soft PLC is realized, using user development environment tools to obtain breakpoint information and sending it to the soft PLC controller, replacing real instructions with breakpoint instructions, triggering illegal instruction exceptions, and passing the exception handler Complete breakpoint processing and restore the breakpoint instruction to the real instruction.

Benefits of technology

The accuracy and efficiency of breakpoint debugging are improved, and the breakpoint debugging function can be implemented directly on the PC platform.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115616973B_ABST
    Figure CN115616973B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of industrial automation control technology, and discloses a method, system, device and medium for realizing a breakpoint debugging function. The method for realizing the breakpoint debugging function is applied to a system for realizing the breakpoint debugging function, and the system for realizing the breakpoint debugging function includes a user development environment tool and a soft PLC controller. The present invention obtains breakpoint information in a software program through a user development environment tool, and sends the breakpoint information to a soft PLC controller; replaces the real instruction of the current breakpoint with a breakpoint instruction according to the breakpoint information through the soft PLC controller; when the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed through the exception handler of the soft PLC controller; the running task of the software program is restarted through the user development environment tool, and the breakpoint instruction is restored to the real instruction; thereby realizing the breakpoint debugging function based on the soft PLC running directly on the PC through the code migration technology, and improving the accuracy of the breakpoint debugging.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of industrial automation control technology, and in particular to a method, system, device and medium for realizing a breakpoint debugging function. Background Art

[0002] PLC (Programmable Logic Controller) is widely used in the field of industrial control. By loading the (program) control instructions written by the user into the memory and scheduling them to be executed by the CPU according to the task cycle configured by the user, the logic control, analog control, motion control, etc. of various mechanical and electrical systems can be completed. In practical applications, PLC systems usually use breakpoint debugging to detect the correctness and completeness of program design; breakpoint debugging intervenes in the operation process of the controller's computing tasks through breakpoints in the control logic, which involves the execution mechanism of the controller on the control logic.

[0003] At present, breakpoint debugging includes software breakpoints and hardware breakpoints; hardware breakpoints usually require setting the value of the register in the processor to generate a breakpoint. Software breakpoints require modifying the running code instructions. By modifying the instructions at the breakpoint position to special breakpoint instructions (int3 soft interrupt instructions), when the program runs to the breakpoint instruction position, an interrupt signal or an abnormal event is generated, and the corresponding breakpoint service program takes over the processing. When the breakpoint is canceled, the instructions at the breakpoint position will be restored to the original byte content.

[0004] However, current software breakpoints usually use the system signal capture mechanism to implement breakpoint location exception callback processing, and the common methods of capturing exceptions are structured exceptions and uncaught exceptions. However, Windows X64 cannot capture all exceptions using the above two methods. Summary of the invention

[0005] The main purpose of the present invention is to propose a method, system, device and medium for realizing breakpoint debugging function, aiming to realize breakpoint debugging function based on soft PLC running directly on PC through code migration technology, and improve the accuracy of breakpoint debugging.

[0006] To achieve the above object, the present invention provides a method for implementing a breakpoint debugging function, the method for implementing a breakpoint debugging function is applied to a system for implementing a breakpoint debugging function, the system for implementing a breakpoint debugging function includes a user development environment tool and a soft PLC controller, and the method for implementing a breakpoint debugging function includes the following steps:

[0007] Acquiring breakpoint information in a software program through the user development environment tool, and sending the breakpoint information to the soft PLC controller;

[0008] Replacing the real instruction of the current breakpoint with the breakpoint instruction according to the breakpoint information by the soft PLC controller;

[0009] When the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed through the exception handling program of the soft PLC controller;

[0010] The running task of the software program is restarted through the user development environment tool, and the breakpoint instruction is restored to the real instruction.

[0011] Preferably, the step of obtaining breakpoint information in the software program through the user development environment tool and sending the breakpoint information to the soft PLC controller includes:

[0012] A breakpoint is set in a software program through the user development environment tool, breakpoint information corresponding to the breakpoint is obtained, and the breakpoint information is sent to the soft PLC controller through a TCP socket service interface; wherein the breakpoint information includes a memory area number of the breakpoint position, a memory offset address, a breakpoint insertion instruction, a breakpoint insertion instruction size, a breakpoint entry callback function pointer, a breakpoint exit callback function pointer, and a subsequent breakpoint memory offset address.

[0013] Preferably, the step of replacing the real instruction of the current breakpoint with the breakpoint instruction according to the breakpoint information by the soft PLC controller comprises:

[0014] When the soft PLC controller receives the breakpoint information, the real instruction of the current breakpoint is saved to the corresponding position of the heap memory pool of the soft PLC controller through memory addressing and copying, wherein the breakpoint information includes the memory offset address of the current breakpoint, the current instruction size, the breakpoint instruction byte code, and the subsequent breakpoint position offset address;

[0015] According to the breakpoint information, the byte code of the breakpoint instruction is copied to the memory offset address of the current breakpoint by the soft PLC controller through memory copy, and the processor cache of the implementation system of the breakpoint debugging function is refreshed.

[0016] Preferably, the breakpoint instruction includes a memory offset address of the current breakpoint, and when the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the step of completing the breakpoint processing through the process exception handler of the soft PLC controller includes:

[0017] When the software program runs to the breakpoint instruction, the breakpoint instruction is executed by the processor of the soft PLC controller, an illegal instruction exception is triggered, and the operating system of the soft PLC controller distributes the exception to the exception handling program of the soft PLC controller;

[0018] The current environment context is saved by the exception handling program, the current task information is obtained, and according to the IP register value of the current environment context being equal to the memory offset address of the current breakpoint, the breakpoint information corresponding to the breakpoint instruction is found from the heap area memory pool; wherein the current environment context includes the IP register value, the SP register value and the BP register value;

[0019] The current software program state is set to breakpoint pause, and the task scheduler of the soft PLC controller is notified to stop scheduling the current task, and the task of the current software program enters a debugging loop; wherein the software program stops at the current breakpoint.

[0020] Preferably, the step of restarting the running task of the software program through the user development environment tool comprises:

[0021] Restarting the task or single-step running of the software program through the user development environment tool, switching the current task state to the running state, and the task of the current software program exits the debugging loop;

[0022] The task scheduler of the soft PLC controller is notified to resume the scheduling of the current task, and the software program is controlled to leave the breakpoint processing.

[0023] Preferably, the step of restoring the breakpoint instruction to the real instruction comprises:

[0024] According to the subsequent breakpoint position offset address in the heap area memory pool, the byte code of the breakpoint instruction is copied to the subsequent breakpoint position offset address in a memory copy manner through the soft PLC controller, and the processor cache of the implementation system of the breakpoint debugging function is refreshed to replace the real instruction of the subsequent breakpoint with the next breakpoint instruction;

[0025] According to the memory offset address of the current breakpoint in the heap area memory pool and the current instruction size, the memory offset address of the current breakpoint is written by memory copying to restore the breakpoint instruction of the current breakpoint to the real instruction.

[0026] Preferably, after the step of restarting the running task of the software program through the user development environment tool and restoring the breakpoint instruction to the real instruction, the method further includes:

[0027] Enter the next breakpoint debugging and return to step: obtain the breakpoint information in the software program through the user development environment tool, and send the breakpoint information to the soft PLC controller.

[0028] In addition, to achieve the above-mentioned purpose, the present invention also provides a system for implementing a breakpoint debugging function, and the system for implementing a breakpoint debugging function comprises:

[0029] A user development environment tool for obtaining breakpoint information in a software program and sending the breakpoint information to a soft PLC controller;

[0030] A soft PLC controller, used for replacing the real instruction at the breakpoint with the breakpoint instruction according to the breakpoint information;

[0031] It is also used to trigger an illegal instruction exception when the software program runs to the breakpoint instruction, and complete the breakpoint processing through the exception handling program of the soft PLC controller;

[0032] The user development environment tool is also used to restart the running task of the software program and restore the breakpoint instruction to the real instruction.

[0033] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer device comprising: a memory, a processor, and an implementation program of a breakpoint debugging function stored in the memory and executable on the processor, wherein the implementation program of the breakpoint debugging function, when executed by the processor, implements the steps of the implementation method of the breakpoint debugging function as described above.

[0034] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a program for implementing a breakpoint debugging function is stored. When the program for implementing the breakpoint debugging function is executed by a processor, the steps of the method for implementing the breakpoint debugging function as described above are implemented.

[0035] The present invention proposes a method, system, device and medium for implementing a breakpoint debugging function; the method for implementing a breakpoint debugging function is applied to a system for implementing a breakpoint debugging function, and the system for implementing a breakpoint debugging function includes a user development environment tool and a soft PLC controller. The present invention first obtains breakpoint information in a software program through a user development environment tool, and sends the breakpoint information to a soft PLC controller; the real instruction of the current breakpoint is replaced with a breakpoint instruction by the soft PLC controller according to the breakpoint information; when the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed by the exception handler of the soft PLC controller; the running task of the software program is restarted by the user development environment tool, and the breakpoint instruction is restored to the real instruction; thus, the breakpoint debugging function is realized by running directly on a PC based on the soft PLC through the code migration technology, and the accuracy of breakpoint debugging is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention;

[0037] Figure 2 It is a flowchart of a first embodiment of a method for implementing a breakpoint debugging function of the present invention;

[0038] Figure 3 A schematic diagram of the breakpoint debugging interaction process of the user development environment (IDE) tool and the soft PLC controller in combination with the method for implementing the breakpoint debugging function of the present invention;

[0039] Figure 4 A schematic diagram of the breakpoint debugging processing steps of the method for realizing the breakpoint debugging function of the present invention;

[0040] Figure 5 It is a flow chart of a second embodiment of a method for implementing a breakpoint debugging function of the present invention;

[0041] Figure 6 A schematic flow chart of a third embodiment of a method for implementing a breakpoint debugging function of the present invention;

[0042] Figure 7 A schematic flow chart of a fourth embodiment of a method for implementing a breakpoint debugging function of the present invention;

[0043] Figure 8 A flowchart of a fifth embodiment of a method for implementing a breakpoint debugging function of the present invention;

[0044] Fig. 9 A flowchart of a sixth embodiment of a method for implementing a breakpoint debugging function of the present invention;

[0045] Fig.10 This is a functional module diagram of the first embodiment of the system for implementing the breakpoint debugging function of the present invention.

[0046] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0047] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0048] like Figure 1 As shown, Figure 1 It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention.

[0049] The device in the embodiment of the present invention may be a mobile terminal or a server device.

[0050] like Figure 1As shown, the device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also 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 1005 may be a high-speed RAM memory, or it may be a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0051] Those skilled in the art will understand that Figure 1 The device structure shown in the figure does not constitute a limitation of the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0052] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a program for implementing a breakpoint debugging function.

[0053] Among them, the operating system is a program for managing and controlling terminal devices and software resources, supporting the operation of network communication modules, user interface modules, breakpoint debugging function implementation programs and other programs or software; the network communication module is used to manage and control the network interface 1002; the user interface module is used to manage and control the user interface 1003.

[0054] exist Figure 1 In the device shown, the device calls the implementation program of the breakpoint debugging function stored in the memory 1005 through the processor 1001, and executes the operations in each embodiment of the implementation method of the breakpoint debugging function described below.

[0055] Based on the above hardware structure, an embodiment of a method for realizing the breakpoint debugging function of the present invention is proposed.

[0056] Reference Figure 2 , Figure 2 This is a flow chart of a first embodiment of a method for implementing a breakpoint debugging function of the present invention. The method for implementing a breakpoint debugging function includes:

[0057] Step S10, obtaining breakpoint information in the software program through the user development environment tool, and sending the breakpoint information to the soft PLC controller;

[0058] Step S20, replacing the real instruction of the current breakpoint with the breakpoint instruction according to the breakpoint information by the soft PLC controller;

[0059] Step S30, when the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed through the exception handling program of the soft PLC controller;

[0060] Step S40, restarting the running task of the software program through the user development environment tool, and restoring the breakpoint instruction to the real instruction.

[0061] This embodiment obtains breakpoint information in the software program through a user development environment tool, and sends the breakpoint information to a soft PLC controller; the real instruction of the current breakpoint is replaced with a breakpoint instruction by the soft PLC controller according to the breakpoint information; when the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed through the exception handler of the soft PLC controller; the running task of the software program is started again through the user development environment tool, and the breakpoint instruction is restored to the real instruction; thereby, the breakpoint debugging function is realized by running directly on a PC based on the soft PLC through the code migration technology, and the accuracy of breakpoint debugging is improved.

[0062] The following is a detailed description of each step:

[0063] Step S10, obtaining breakpoint information in the software program through the user development environment tool, and sending the breakpoint information to the soft PLC controller.

[0064] In this embodiment, the implementation method of the breakpoint debugging function is applied to the implementation system of the breakpoint debugging function, and the implementation system of the breakpoint debugging function includes a user development environment tool and a soft PLC controller. Among them, the user development environment (Integrated Development Environment, IDE) tool is connected to the soft PLC controller, and the soft PLC controller and the user development environment (IDE) tool can run on the same PC or different PCs at the same time. The user development environment (IDE) tool is mainly used for user program editing, compilation, downloading, debugging and monitoring. The soft PLC controller uses code transplantation technology to transplant the controller core running in the real PLC device to the Windows X64 platform; the soft PLC controller inserts the UD2 instruction at the breakpoint position, and the processor interrupt is triggered when the software program runs to the UD2 instruction position. The exception at the breakpoint position uses vectorized exception registration, which can normally capture the software and hardware exceptions generated by the processor or system.

[0065] Reference Figure 3 , Figure 3The schematic diagram of the breakpoint debugging interaction process combining the user development environment (IDE) tool and the soft PLC controller; the implementation method of the breakpoint debugging function of the present invention proposes a method of vectorized exception capture to implement breakpoint processing, wherein the exception mentioned is to replace the normal instruction with the UD2 instruction by finding the breakpoint position, thereby triggering the CPU to generate an exception of illegal instructions. In addition, the breakpoint debugging functions such as breakpoint setting, breakpoint deletion, single step and run are completed in combination with the user development environment (IDE) tool. In addition, the soft PLC controller and the user development environment (IDE) tool run on the same PC at the same time, which can be used more conveniently in teaching demonstrations and other scenarios.

[0066] Reference Figure 4 , Figure 4 This is a schematic diagram of the breakpoint debugging process steps; for details, refer to Figure 4 The method further comprises: obtaining breakpoint information (21) in the software program through a user development environment (IDE) tool, wherein the breakpoint information includes a memory area number of the breakpoint position, a memory offset address, a breakpoint insertion instruction, a breakpoint insertion instruction size, a breakpoint entry callback function pointer, a breakpoint exit callback function pointer, and a subsequent breakpoint memory offset address; and sending the obtained breakpoint information to the soft PLC controller.

[0067] Step S20: replacing the real instruction of the current breakpoint with the breakpoint instruction according to the breakpoint information by the soft PLC controller.

[0068] In this embodiment, refer to Figure 4 , Figure 4 This is a schematic diagram of the breakpoint debugging process steps; for details, refer to Figure 4 The breakpoint instruction in (23) is replaced; when the soft PLC controller receives the above breakpoint information, the UD2 instruction is inserted at the breakpoint position corresponding to the breakpoint information. When the software program runs to the UD2 instruction position, the processor interrupt is triggered. The exception at the breakpoint position uses vectorized exception registration, which can normally capture the software and hardware exceptions generated by the processor or system; wherein the real instruction refers to the original instruction at the current breakpoint; the UD2 instruction is also the breakpoint instruction, and the breakpoint instruction refers to the interrupt signal or abnormal event generated when the software program reaches the breakpoint instruction position.

[0069] Step S30, when the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed through the exception handling program of the soft PLC controller.

[0070] In this embodiment, refer to Figure 4 , Figure 4 This is a schematic diagram of the breakpoint debugging process steps; for details, refer to Figure 4UD2 instruction exception capture and breakpoint processing (24) in the program; when the software program runs to the position of the breakpoint instruction, the processor of the implementation system of the breakpoint debugging function will execute the replaced breakpoint instruction, triggering an illegal instruction exception; the operating system distributes the exception to the soft PLC controller process exception handler, and the exception breakpoint processing of the exception is completed by the exception handler of the soft PLC controller; wherein the breakpoint processing refers to setting the current software program to a breakpoint pause, notifying the task scheduler to stop the scheduling of the current task, and the current task enters a debugging loop (LOOP), wherein the debugging loop (LOOP) refers to the software program jumping in place, looping to execute the current breakpoint instruction, and the software program stops at the current breakpoint position.

[0071] Step S40, restarting the running task of the software program through the user development environment tool, and restoring the breakpoint instruction to the real instruction.

[0072] In this embodiment, refer to Figure 4 , Figure 4 This is a schematic diagram of the breakpoint debugging process steps; for details, refer to Figure 4 The breakpoint instruction in the program is restored (25); the running task of the software program is started again through the user development environment (IDE) tool, the current task state is switched to the running state, and the breakpoint instruction at the current breakpoint position is restored to the original instruction at the current breakpoint, that is, the breakpoint instruction at the current breakpoint position is restored to the real instruction; thereby realizing the breakpoint debugging function.

[0073] Furthermore, in one embodiment, after step S40, the method for implementing the breakpoint debugging function further includes:

[0074] Step S50, enter the next breakpoint debugging, and return to the execution step: obtain the breakpoint information in the software program through the user development environment tool, and send the breakpoint information to the soft PLC controller.

[0075] In this embodiment, after the current breakpoint instruction is restored to the real instruction, according to the above breakpoint information, the breakpoint information includes the subsequent breakpoint memory offset address, that is, the position of the next breakpoint; enter the next breakpoint debugging, and execute the steps: obtain the breakpoint information in the software program through the user development environment tool, and send the breakpoint information to the soft PLC controller. According to the subsequent breakpoint memory offset address, the user development environment tool obtains the next breakpoint information in the software program, and sends the next breakpoint information to the soft PLC controller; after receiving the next breakpoint information, the soft PLC controller inserts the instruction position of the next breakpoint into the UD2 instruction; after the software program resumes running, the current instruction is executed normally, and the breakpoint exception processing is triggered by the next instruction, so that the software program stops at the next breakpoint position; by repeating the above operations, the breakpoint debugging in the software program is completed; thereby improving the efficiency of breakpoint debugging.

[0076] This embodiment obtains breakpoint information in the software program through the user development environment tool, and sends the breakpoint information to the soft PLC controller; the real instruction of the current breakpoint is replaced with the breakpoint instruction by the soft PLC controller according to the breakpoint information; when the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed through the exception handler of the soft PLC controller; the running task of the software program is started again through the user development environment tool, and the breakpoint instruction is restored to the real instruction; thereby, the breakpoint debugging function is realized by running directly on the PC based on the soft PLC through the code migration technology, and the accuracy of breakpoint debugging is improved.

[0077] Furthermore, based on the first embodiment of the method for implementing the breakpoint debugging function of the present invention, a second embodiment of the method for implementing the breakpoint debugging function of the present invention is proposed.

[0078] The difference between the second embodiment of the method for implementing the breakpoint debugging function and the first embodiment of the method for implementing the breakpoint debugging function is that this embodiment is a refinement of step S10, obtaining breakpoint information in the software program through the user development environment tool, and sending the breakpoint information to the soft PLC controller, referring to Figure 5 , the step specifically includes:

[0079] Step S11, setting a breakpoint in the software program through the user development environment tool, obtaining breakpoint information corresponding to the breakpoint, and sending the breakpoint information to the soft PLC controller through the TCP socket service interface; wherein the breakpoint information includes the memory area number of the breakpoint position, the memory offset address, the breakpoint insertion instruction, the breakpoint insertion instruction size, the breakpoint entry callback function pointer, the breakpoint exit callback function pointer and the subsequent breakpoint memory offset address.

[0080] In this embodiment, a breakpoint is set in a software program through a user development environment tool, breakpoint information corresponding to the breakpoint is obtained, and the breakpoint information is sent to the soft PLC controller through a TCP socket service interface; wherein the breakpoint information includes a memory area number of the breakpoint position, a memory offset address, a breakpoint insertion instruction, a breakpoint insertion instruction size, a breakpoint entry callback function pointer, a breakpoint exit callback function pointer, and a subsequent breakpoint memory offset address; thereby, breakpoint debugging is implemented through a breakpoint debugging interaction process combining the user development environment tool with the soft PLC controller, so as to realize breakpoint debugging through the soft PLC controller.

[0081] The following is a detailed description of each step:

[0082] Step S11, setting a breakpoint in the software program through the user development environment tool, obtaining breakpoint information corresponding to the breakpoint, and sending the breakpoint information to the soft PLC controller through the TCP socket service interface; wherein the breakpoint information includes the memory area number of the breakpoint position, the memory offset address, the breakpoint insertion instruction, the breakpoint insertion instruction size, the breakpoint entry callback function pointer, the breakpoint exit callback function pointer and the subsequent breakpoint memory offset address.

[0083] In this embodiment, refer to Figure 4 , Figure 4 This is a schematic diagram of the breakpoint debugging process steps; for details, refer to Figure 4 After debugging starts, breakpoints are set in the software program through a user development environment (IDE) tool, wherein the position and number of the breakpoints can be set according to actual conditions, and each breakpoint has a unique breakpoint address; and breakpoint information corresponding to the breakpoint is obtained; wherein the breakpoint information includes a memory area number of the breakpoint position, a memory offset address, a breakpoint insertion instruction, a breakpoint insertion instruction size, a breakpoint entry callback function pointer, a breakpoint exit callback function pointer, and a subsequent breakpoint memory offset address.

[0084] The breakpoint information is sent to the soft PLC controller through the TCP socket service interface, so that after receiving the breakpoint information, the soft PLC controller replaces the breakpoint instruction of the current breakpoint according to the breakpoint information.

[0085] In this embodiment, a breakpoint is set in a software program through a user development environment tool, breakpoint information corresponding to the breakpoint is obtained, and the breakpoint information is sent to the soft PLC controller through a TCP socket service interface; wherein the breakpoint information includes a memory area number of the breakpoint position, a memory offset address, a breakpoint insertion instruction, a breakpoint insertion instruction size, a breakpoint entry callback function pointer, a breakpoint exit callback function pointer, and a subsequent breakpoint memory offset address; thereby, breakpoint debugging is implemented through a breakpoint debugging interaction process combining the user development environment tool with the soft PLC controller, so as to realize breakpoint debugging through the soft PLC controller.

[0086] Furthermore, based on the first and second embodiments of the method for implementing the breakpoint debugging function of the present invention, a third embodiment of the method for implementing the breakpoint debugging function of the present invention is proposed.

[0087] The third embodiment of the method for implementing the breakpoint debugging function is different from the first and second embodiments of the method for implementing the breakpoint debugging function in that the present embodiment is a refinement of step S20, in which the real instruction of the current breakpoint is replaced with the breakpoint instruction by the soft PLC controller according to the breakpoint information, referring to Figure 6 , the step specifically includes:

[0088] Step S21, when the soft PLC controller receives the breakpoint information, the real instruction of the current breakpoint is saved to the corresponding position of the heap memory pool of the soft PLC controller through memory addressing and copying, wherein the breakpoint information includes the memory offset address of the current breakpoint, the current instruction size, the breakpoint instruction byte code, and the subsequent breakpoint position offset address;

[0089] Step S22, according to the breakpoint information, the byte code of the breakpoint instruction is copied to the memory offset address of the current breakpoint by the soft PLC controller through memory copy, and the processor cache of the implementation system of the breakpoint debugging function is refreshed.

[0090] In this embodiment, when the soft PLC controller receives breakpoint information, the real instruction of the current breakpoint is saved to the corresponding position of the heap memory pool of the soft PLC controller through memory addressing and copying, wherein the breakpoint information includes the memory offset address of the current breakpoint, the current instruction size, the breakpoint instruction byte code, and the subsequent breakpoint position offset address; according to the breakpoint information, the byte code of the breakpoint instruction is copied to the memory offset address of the current breakpoint through memory copying by the soft PLC controller, and the processor cache of the implementation system of the breakpoint debugging function is refreshed; thereby, the real position of the current breakpoint is replaced by the breakpoint instruction through the soft PLC controller.

[0091] The following is a detailed description of each step:

[0092] Step S21, when the soft PLC controller receives the breakpoint information, the real instruction of the current breakpoint is saved to the corresponding position of the heap memory pool of the soft PLC controller through memory addressing and copying, wherein the breakpoint information includes the memory offset address of the current breakpoint, the current instruction size, the breakpoint instruction byte encoding, and the subsequent breakpoint position offset address.

[0093] In this embodiment, after the soft PLC controller receives the breakpoint information, wherein the breakpoint information specifically includes the memory offset address of the current breakpoint, the current instruction size, the breakpoint instruction byte encoding, and the subsequent breakpoint position offset address; the breakpoint information is uniformly managed in the heap area memory pool of the soft PLC, specifically: each breakpoint information is saved in the corresponding memory structure in the heap area memory pool, and the real instruction of the current breakpoint is saved to the corresponding position of the memory structure through memory addressing and copying.

[0094] Step S22, according to the breakpoint information, the byte code of the breakpoint instruction is copied to the memory offset address of the current breakpoint by the soft PLC controller through memory copy, and the processor cache of the implementation system of the breakpoint debugging function is refreshed.

[0095] In this embodiment, according to the above breakpoint information, the byte code of the UD2 instruction (i.e., the breakpoint instruction) is copied to the memory offset address corresponding to the current breakpoint through the soft PLC controller by memory copying; then, the processor cache of the system implementing the breakpoint debugging function is refreshed; after completing the above steps, the real instruction of the current breakpoint is replaced with the breakpoint instruction; thus, when the software program runs to the position of the breakpoint instruction, the processor of the system implementing the breakpoint debugging function will execute the replaced breakpoint instruction, triggering an illegal instruction exception.

[0096] In this embodiment, when the soft PLC controller receives breakpoint information, the real instruction of the current breakpoint is saved to the corresponding position of the heap memory pool of the soft PLC controller through memory addressing and copying, wherein the breakpoint information includes the memory offset address of the current breakpoint, the current instruction size, the breakpoint instruction byte code, and the subsequent breakpoint position offset address; according to the breakpoint information, the byte code of the breakpoint instruction is copied to the memory offset address of the current breakpoint through memory copying by the soft PLC controller, and the processor cache of the implementation system of the breakpoint debugging function is refreshed; thereby, the real position of the current breakpoint is replaced by the breakpoint instruction through the soft PLC controller.

[0097] Furthermore, based on the first, second and third embodiments of the method for implementing the breakpoint debugging function of the present invention, a fourth embodiment of the method for implementing the breakpoint debugging function of the present invention is proposed.

[0098] The fourth embodiment of the method for implementing the breakpoint debugging function is different from the first, second and third embodiments of the method for implementing the breakpoint debugging function in that the present embodiment is a refinement of step S30, when the software program runs to the breakpoint instruction, triggering an illegal instruction exception, and completing the breakpoint processing through the process exception handling program of the soft PLC controller, referring to Figure 7 , the step specifically includes:

[0099] Step S31, when the software program runs to the breakpoint instruction, the breakpoint instruction is executed by the processor of the soft PLC controller, an illegal instruction exception is triggered, and the operating system of the soft PLC controller distributes the exception to the exception handling program of the soft PLC controller;

[0100] Step S32, saving the current environment context through the exception handling program, obtaining the current task information, and finding the breakpoint information corresponding to the breakpoint instruction from the heap area memory pool according to the IP register value of the current environment context being equal to the memory offset address of the current breakpoint; wherein the current environment context includes the IP register value, the SP register value and the BP register value;

[0101] Step S33, setting the current software program state to breakpoint pause, and notifying the task scheduler of the soft PLC controller to stop scheduling the current task, and the task of the current software program enters a debugging loop; wherein the software program stops at the current breakpoint.

[0102] In this embodiment, when the software program runs to a breakpoint instruction, the breakpoint instruction is executed by the processor of the soft PLC controller, triggering an illegal instruction exception, and the breakpoint processing is completed by the process exception handler of the soft PLC controller; thereby realizing the breakpoint debugging function through the soft PLC controller.

[0103] The following is a detailed description of each step:

[0104] Step S31, when the software program runs to the breakpoint instruction, the breakpoint instruction is executed by the processor of the soft PLC controller, triggering an illegal instruction exception, and the operating system of the soft PLC controller distributes the exception to the exception handler of the soft PLC controller.

[0105] In this embodiment, when the software program runs normally to the current breakpoint position, the processor of the soft PLC controller executes the replaced UD2 instruction (i.e., the breakpoint instruction), triggering an illegal instruction exception; and the operating system of the soft PLC controller distributes the exception to the exception handler of the soft PLC controller, and then completes the breakpoint processing in the exception handler.

[0106] Step S32, saving the current environment context through the exception handler, obtaining the current task information, and finding the breakpoint information corresponding to the breakpoint instruction from the heap memory pool based on the IP register value of the current environment context being equal to the memory offset address of the current breakpoint; wherein the current environment context includes the IP register value, the SP register value and the BP register value.

[0107] In this embodiment, the current environment context is saved through the exception handler of the soft PLC controller, where the current environment context includes the IP register value, the SP register value and the BP register value; the current task information is obtained; and since the IP register value of the current environment context is equal to the memory offset address of the current breakpoint, the breakpoint information corresponding to the breakpoint instruction can be found from the heap memory pool of the soft PLC controller.

[0108] Step S33, setting the current software program state to breakpoint pause, and notifying the task scheduler of the soft PLC controller to stop scheduling the current task, and the task of the current software program enters a debugging loop; wherein the software program stops at the current breakpoint.

[0109] In this embodiment, the current software program state is set to breakpoint pause, and the task scheduler of the soft PLC controller is notified to stop scheduling the current task. At the same time, the task of the current software program enters the debugging loop; wherein, after the task of the current software program enters the debugging loop, the software program stops at the current breakpoint.

[0110] In this embodiment, when the software program runs to a breakpoint instruction, the breakpoint instruction is executed by the processor of the soft PLC controller, triggering an illegal instruction exception, and the breakpoint processing is completed by the process exception handler of the soft PLC controller; thereby realizing the breakpoint debugging function through the soft PLC controller.

[0111] Furthermore, based on the first, second, third and fourth embodiments of the method for implementing the breakpoint debugging function of the present invention, a fifth embodiment of the method for implementing the breakpoint debugging function of the present invention is proposed.

[0112] The fifth embodiment of the method for implementing the breakpoint debugging function is different from the first, second, third and fourth embodiments of the method for implementing the breakpoint debugging function in that the present embodiment is a refinement of step S40, in which the running task of the software program is restarted by the user development environment tool, referring to Figure 8 , the step specifically includes:

[0113] Step A10, restarting the task or single-step running of the software program again through the user development environment tool, switching the current task state to the running state, and the task of the current software program exits the debugging loop;

[0114] Step A20, notifying the task scheduler of the soft PLC controller to resume the scheduling of the current task, and controlling the software program to leave the breakpoint processing.

[0115] This embodiment restarts the task or single-step operation of the software program through the user development environment tool, switches the current task state to the running state, and the task of the current software program exits the debugging loop; notifies the task scheduler of the soft PLC controller to resume the scheduling of the current task, and controls the software program to leave the breakpoint processing; thereby, after the soft PLC controller completes the breakpoint processing, the running task of the software program is restarted through the user development environment tool.

[0116] The following is a detailed description of each step:

[0117] Step A10, restarting the task or single-step running of the software program through the user development environment tool, switching the current task state to the running state, and the task of the current software program exits the debugging loop.

[0118] In this embodiment, after the exception handler of the soft PLC controller completes the breakpoint processing, the task of the software program is started again or the single-step operation is started through the user development environment (IDE) tool to switch the current task state of the software program to the running state; at the same time, the task of the current software program exits the debugging loop (LOOP).

[0119] Step A20, notifying the task scheduler of the soft PLC controller to resume the scheduling of the current task, and controlling the software program to leave the breakpoint processing.

[0120] In this embodiment, after the task of the current software program exits the debugging loop (LOOP), the task scheduler of the soft PLC controller is notified to resume the scheduling of the current task, and the soft PLC controller controls the software program to leave the breakpoint processing; thus, after the soft PLC controller completes the breakpoint processing, the running task of the software program is started again through the user development environment tool, and the software program is continued to be executed through the soft PLC controller.

[0121] In this embodiment, the task of the software program is restarted or single-stepped through the user development environment tool, the current task state is switched to the running state, and the task of the current software program exits the debugging loop; the task scheduler of the soft PLC controller is notified to resume the scheduling of the current task, and the software program is controlled to leave the breakpoint processing; thus, after the soft PLC controller completes the breakpoint processing, the running task of the software program is restarted through the user development environment tool.

[0122] Furthermore, based on the first, second, third, fourth and fifth embodiments of the method for implementing the breakpoint debugging function of the present invention, a sixth embodiment of the method for implementing the breakpoint debugging function of the present invention is proposed.

[0123] The sixth embodiment of the method for implementing the breakpoint debugging function is different from the first, second, third, fourth and fifth embodiments of the method for implementing the breakpoint debugging function in that the present embodiment is a refinement of step S40, restoring the breakpoint instruction to the real instruction, referring to Fig. 9 , the step specifically includes:

[0124] Step B10, according to the subsequent breakpoint position offset address in the heap area memory pool, copying the byte code of the breakpoint instruction to the subsequent breakpoint position offset address in a memory copy manner through the soft PLC controller, and refreshing the processor cache of the implementation system of the breakpoint debugging function to replace the real instruction of the subsequent breakpoint with the next breakpoint instruction;

[0125] Step B20, according to the memory offset address of the current breakpoint in the heap memory pool and the current instruction size, write the memory offset address of the current breakpoint by memory copying to restore the breakpoint instruction of the current breakpoint to the real instruction.

[0126] This embodiment copies the byte code of the breakpoint instruction to the subsequent breakpoint position offset address in the heap area memory pool through the soft PLC controller in the form of memory copy, and refreshes the processor cache of the system implementing the breakpoint debugging function to replace the real instruction of the subsequent breakpoint with the next breakpoint instruction; writes the memory offset address of the current breakpoint in the heap area memory pool and the current instruction size through the memory copy to restore the breakpoint instruction of the current breakpoint to the real instruction; after completing the breakpoint processing, the breakpoint instruction at the current breakpoint is restored to the real instruction through the user development environment tool.

[0127] The following is a detailed description of each step:

[0128] Step B10, according to the subsequent breakpoint position offset address in the heap area memory pool, the byte encoding of the breakpoint instruction is copied to the subsequent breakpoint position offset address in the form of memory copy through the soft PLC controller, and the processor cache of the system implementing the breakpoint debugging function is refreshed to replace the real instruction of the subsequent breakpoint with the next breakpoint instruction.

[0129] In this embodiment, according to the subsequent breakpoint position offset address in the breakpoint information stored in the heap memory pool, the byte code of the UD2 instruction (i.e., the breakpoint instruction) is copied to the subsequent breakpoint position offset address in the form of memory copy through the soft PLC controller, so as to replace the real instruction of the subsequent breakpoint with the next breakpoint instruction; and after the position instruction of the subsequent breakpoint is replaced, the processor cache of the implementation system of the breakpoint debugging function is refreshed; after completing the above steps, the replacement of the real instruction of the subsequent breakpoint with the breakpoint instruction is completed; therefore, when the software program runs to the position of the breakpoint instruction of the subsequent breakpoint, the processor of the implementation system of the breakpoint debugging function will execute the replaced breakpoint instruction, triggering an illegal instruction exception.

[0130] Step B20, according to the memory offset address of the current breakpoint in the heap memory pool and the current instruction size, write the memory offset address of the current breakpoint by memory copying to restore the breakpoint instruction of the current breakpoint to the real instruction.

[0131] In this embodiment, according to the memory offset address and the current instruction size of the current breakpoint in the heap memory pool of the soft PLC controller, the memory offset address and the current instruction size of the current breakpoint are written into the memory offset address of the current breakpoint by memory copying, so as to restore the breakpoint instruction of the current breakpoint to the real instruction; after the breakpoint instruction of the current breakpoint is restored to the real instruction, the breakpoint is deleted; thus, after the breakpoint processing is completed, the breakpoint instruction at the current breakpoint is restored to the real instruction through the user development environment tool.

[0132] In this embodiment, according to the subsequent breakpoint position offset address in the heap area memory pool, the byte encoding of the breakpoint instruction is copied to the subsequent breakpoint position offset address in a memory copy manner through the soft PLC controller, and the processor cache of the system implementing the breakpoint debugging function is refreshed to replace the real instruction of the subsequent breakpoint with the next breakpoint instruction; according to the memory offset address of the current breakpoint in the heap area memory pool and the current instruction size, the memory offset address of the current breakpoint is written in a memory copy manner to restore the breakpoint instruction of the current breakpoint to the real instruction; after the breakpoint processing is completed, the breakpoint instruction at the current breakpoint is restored to the real instruction through the user development environment tool.

[0133] The present invention also provides a device for implementing the breakpoint debugging function. Fig.10 , the implementation device of the breakpoint debugging function of the present invention includes:

[0134] A user development environment tool 10, for obtaining breakpoint information in a software program and sending the breakpoint information to the soft PLC controller;

[0135] The soft PLC controller 20 is used to replace the real instruction at the breakpoint with the breakpoint instruction according to the breakpoint information;

[0136] It is also used to trigger an illegal instruction exception when the software program runs to the breakpoint instruction, and complete the breakpoint processing through the exception handling program of the soft PLC controller;

[0137] The user development environment tool 10 is also used to restart the running task of the software program and restore the breakpoint instruction to the real instruction.

[0138] In addition, the present invention also provides a computer-readable storage medium on which a program for implementing a breakpoint debugging function is stored. When the program for implementing the breakpoint debugging function is executed by a processor, the steps of the method for implementing the breakpoint debugging function as described above are implemented.

[0139] The method implemented when the program for implementing the breakpoint debugging function running on the processor is executed can refer to the various embodiments of the method for implementing the breakpoint debugging function of the present invention, which will not be described in detail here.

[0140] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0141] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0142] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0143] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for implementing a breakpoint debugging function, characterized in that: The implementation method of the breakpoint debugging function is applied to the implementation system of the breakpoint debugging function, the implementation system of the breakpoint debugging function includes a user development environment tool and a soft PLC controller, and the implementation method of the breakpoint debugging function includes the following steps: Acquiring breakpoint information in a software program through the user development environment tool, and sending the breakpoint information to the soft PLC controller; Replacing the real instruction of the current breakpoint with the breakpoint instruction according to the breakpoint information by the soft PLC controller; When the software program runs to the breakpoint instruction, an illegal instruction exception is triggered, and the breakpoint processing is completed through the exception handling program of the soft PLC controller; Restarting the running task of the software program through the user development environment tool, and restoring the breakpoint instruction to the real instruction; The breakpoint instruction includes a memory offset address of the current breakpoint, and when the software program runs to the breakpoint instruction, triggering an illegal instruction exception, and completing the breakpoint processing through the process exception handler of the soft PLC controller includes: When the software program runs to the breakpoint instruction, the breakpoint instruction is executed by the processor of the soft PLC controller, an illegal instruction exception is triggered, and the operating system of the soft PLC controller distributes the exception to the exception handling program of the soft PLC controller; The current environment context is saved through the exception handling program, the current task information is obtained, and according to the IP register value of the current environment context being equal to the memory offset address of the current breakpoint, the breakpoint information corresponding to the breakpoint instruction is found from the heap area memory pool of the soft PLC controller; wherein the current environment context includes the IP register value, the SP register value and the BP register value; The current software program state is set to breakpoint pause, and the task scheduler of the soft PLC controller is notified to stop scheduling the current task, and the task of the current software program enters a debugging loop; wherein the software program stops at the current breakpoint.

2. The method for implementing the breakpoint debugging function according to claim 1, characterized in that: The step of obtaining breakpoint information in the software program through a user development environment tool and sending the breakpoint information to the soft PLC controller includes: A breakpoint is set in a software program through the user development environment tool, breakpoint information corresponding to the breakpoint is obtained, and the breakpoint information is sent to the soft PLC controller through a TCP socket service interface; wherein the breakpoint information includes a memory area number of the breakpoint position, a memory offset address, a breakpoint insertion instruction, a breakpoint insertion instruction size, a breakpoint entry callback function pointer, a breakpoint exit callback function pointer, and a subsequent breakpoint memory offset address.

3. The method for implementing the breakpoint debugging function according to claim 1, characterized in that: The step of replacing the real instruction of the current breakpoint with the breakpoint instruction according to the breakpoint information by the soft PLC controller comprises: When the soft PLC controller receives the breakpoint information, the real instruction of the current breakpoint is saved to the corresponding position of the heap memory pool of the soft PLC controller through memory addressing and copying, wherein the breakpoint information includes the memory offset address of the current breakpoint, the current instruction size, the breakpoint instruction byte code, and the subsequent breakpoint position offset address; According to the breakpoint information, the byte code of the breakpoint instruction is copied to the memory offset address of the current breakpoint by the soft PLC controller through memory copy, and the processor cache of the implementation system of the breakpoint debugging function is refreshed.

4. The method for implementing the breakpoint debugging function according to claim 1, characterized in that: The step of restarting the running task of the software program through the user development environment tool comprises: Restarting the task or single-step running of the software program through the user development environment tool, switching the current task state to the running state, and the task of the current software program exits the debugging loop; The task scheduler of the soft PLC controller is notified to resume the scheduling of the current task, and the software program is controlled to leave the breakpoint processing.

5. The method for implementing the breakpoint debugging function according to claim 3, characterized in that: The step of restoring the breakpoint instruction to the real instruction comprises: According to the subsequent breakpoint position offset address in the heap area memory pool, the byte code of the breakpoint instruction is copied to the subsequent breakpoint position offset address in a memory copy manner through the soft PLC controller, and the processor cache of the implementation system of the breakpoint debugging function is refreshed to replace the real instruction of the subsequent breakpoint with the next breakpoint instruction; According to the memory offset address of the current breakpoint in the heap area memory pool and the current instruction size, the memory offset address of the current breakpoint is written by memory copying to restore the breakpoint instruction of the current breakpoint to the real instruction.

6. The method for implementing the breakpoint debugging function according to claim 1, characterized in that: After the step of restarting the running task of the software program through the user development environment tool and restoring the breakpoint instruction to the real instruction, the method further includes: Enter the next breakpoint debugging and return to the execution step: obtain the breakpoint information in the software program through the user development environment tool, and send the breakpoint information to the soft PLC controller.

7. A system for implementing a breakpoint debugging function, characterized in that: The implementation system of the breakpoint debugging function includes: A user development environment tool for obtaining breakpoint information in a software program and sending the breakpoint information to a soft PLC controller; A soft PLC controller, used for replacing the real instruction at the breakpoint with the breakpoint instruction according to the breakpoint information; It is also used to trigger an illegal instruction exception when the software program runs to the breakpoint instruction, and complete the breakpoint processing through the exception handling program of the soft PLC controller; The user development environment tool is also used to restart the running task of the software program and restore the breakpoint instruction to the real instruction; The breakpoint instruction includes a memory offset address of the current breakpoint, and the soft PLC controller is further used for: When the software program runs to the breakpoint instruction, the breakpoint instruction is executed by the processor of the soft PLC controller, an illegal instruction exception is triggered, and the operating system of the soft PLC controller distributes the exception to the exception handling program of the soft PLC controller; The current environment context is saved through the exception handling program, the current task information is obtained, and according to the IP register value of the current environment context being equal to the memory offset address of the current breakpoint, the breakpoint information corresponding to the breakpoint instruction is found from the heap area memory pool of the soft PLC controller; wherein the current environment context includes the IP register value, the SP register value and the BP register value; The current software program state is set to breakpoint pause, and the task scheduler of the soft PLC controller is notified to stop scheduling the current task, and the task of the current software program enters a debugging loop; wherein the software program stops at the current breakpoint.

8. A computer device, characterized in that: The computer device includes a processor, a memory, and a program for implementing a breakpoint debugging function stored in the memory. When the program for implementing the breakpoint debugging function is executed by the processor, the steps of the method for implementing the breakpoint debugging function according to any one of claims 1 to 6 are implemented.

9. A computer storage medium, characterized in that The computer storage medium stores a program for implementing the breakpoint debugging function. When the program for implementing the breakpoint debugging function is executed by the processor, the steps of the method for implementing the breakpoint debugging function according to any one of claims 1 to 6 are implemented.