Implementation method and system of program debugging breakpoint based on multiple control logic languages
By creating two-level mapping tables and modifying debuggers and executors, the problems of breakpoint setting complexity and resource consumption of PLC program debugging in multiple control logic languages are solved, and efficient and convenient breakpoint debugging is achieved, which improves the execution efficiency and debugging efficiency of PLC.
Patent Information
- Application Number
- CN202510359928.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-08-15
AI Technical Summary
In the debugging of PLC programs in multiple control logic languages, the prior art cannot effectively solve the problems of complexity of breakpoint settings and excessive system resource consumption, resulting in increased debugging difficulty and reduced execution efficiency.
By creating a two-level mapping table, a mapping relationship between multiple control logic language programs and the target code is established. After receiving a user's request to set a breakpoint, a target code address is found in the mapping table, and the corresponding instructions in the target code are replaced with breakpoint instructions, and a debugger and executor are added to support the breakpoint function.
It simplifies the breakpoint setting process, improves debugging flexibility and accuracy, reduces system resource consumption, and improves the execution efficiency and debugging efficiency of PLC.
Smart Images

Figure CN120492312A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of PLC program debugging, and in particular to a method and system for implementing program debugging breakpoints based on multiple control logic languages. Background Art
[0002] Compiled soft PLCs compile user-written control logic programs (ladder diagrams, ST programming language, etc.) into target code (machine code or intermediate code), which runs directly on the target system, enabling automated control of various devices. PLC debugging can reveal problems in control logic programs. Debug breakpoints pause PLC program execution to analyze program behavior or status, helping users quickly locate and resolve issues.
[0003] Different control logic languages (such as ladder diagrams and ST languages) require their own independent compilation units. When setting breakpoints, it's impossible to directly determine where a breakpoint in the control logic language program corresponds in the target code. Accurately setting breakpoints requires a deep understanding of each language's compilation mechanisms and target code structure, significantly increasing the difficulty and complexity of debugging. For example, when programming in a mixed environment of ladder diagrams and ST languages, developers must search and set breakpoints in each compilation environment and code structure separately, a tedious and error-prone process.
[0004] Under the existing breakpoint setting method, the PLC executor scans the breakpoint information table before executing each instruction to determine whether the currently executed instruction is included in the breakpoint information table. This frequent scanning operation is even more complex when multiple control logic languages coexist, as it involves different target codes generated by multiple compilation units. This consumes a large amount of system resources and seriously affects the execution efficiency of the PLC. This slows down system response, making it difficult to complete control tasks with high real-time requirements, and reducing the performance of the entire control system. Summary of the Invention
[0005] Aiming at the problem that different target codes generated by multiple compilation units lead to huge consumption of system resources and seriously affect the execution efficiency of PLC, the present invention provides a method and system for implementing program debugging breakpoints based on multiple control logic languages.
[0006] In a first aspect, the technical solution of the present invention provides a method for implementing program debugging breakpoints based on multiple control logic languages, comprising: Create mapping relationships between multiple control logic language programs and target codes and generate mapping tables; After receiving a user's request to set a breakpoint, the target code address is searched in the mapping table according to the line number or segment number of the logical language program, and the corresponding instruction in the target code is replaced with the breakpoint instruction according to the target code address; and the target code address and the corresponding instruction are stored in the target code breakpoint information table; When a breakpoint instruction is executed, the original instruction is obtained from the target code breakpoint information table and the breakpoint instruction is restored to the original instruction.
[0007] As a further limitation of the technical solution of the present invention, the steps of creating mapping relationships between multiple control logic language programs and target codes and generating a mapping table include: Select a language as the intermediate language for compiling multiple control logic languages into target codes; Compile various control logic language programs into intermediate language programs, and establish a mapping relationship table between each line or each segment in the control logic language program and each line in the intermediate language program, i.e., a first-level mapping table; Compile the intermediate language program into target code and create a mapping table between each line of the intermediate language program and the target code instructions, that is, the second-level mapping table.
[0008] As a further limitation of the technical solution of the present invention, the specific steps of creating the first-level mapping table and the second-level mapping table include: Parse the logic control language program text to determine the logic content of each paragraph and each line; According to the grammatical and semantic rules of the selected intermediate language, corresponding code conversion rules are formulated for the logic control language; According to the conversion rules, each paragraph or each line of logic in the logic control language is converted into the intermediate language; During the code conversion process, the correspondence between the segment number or line number of the logic control language and the line number of the generated intermediate language is recorded, and the correspondence is organized into a first-level mapping table; Further process the generated intermediate language and convert it into target code; Determine the corresponding address for each line of target code after conversion; The correspondence between the line number of the intermediate language and the target code address is recorded, and the correspondence is organized into a second-level mapping table.
[0009] As a further limitation of the technical solution of the present invention, upon receiving a user request to set a breakpoint, searching a target code address in a mapping table according to a line number or segment number of a logical language program, replacing a corresponding instruction in the target code with a breakpoint instruction according to the target code address; and storing the target code address and the corresponding instruction in a target code breakpoint information table includes the following steps: After receiving a request from the user to set a breakpoint, the target code address is searched in the first-level mapping table and the second-level mapping table according to the line number or segment number of the logical language program; Save the line number or segment number and target code address to the control logic breakpoint information table; Send a breakpoint setting command to the executor, and the command parameter contains the target code address; After receiving the breakpoint setting command, the target code address and the target code instruction corresponding to the address are saved in the target code breakpoint information table; and the instruction corresponding to the target code address in the target code is replaced with the breakpoint instruction.
[0010] As a further limitation of the technical solution of the present invention, when executing a breakpoint instruction, the steps of obtaining the original instruction from the target code breakpoint information table and restoring the breakpoint instruction to the original instruction include: When the breakpoint instruction is determined to be executed according to the read target code instruction, the original instruction corresponding to the current address is searched in the target code breakpoint information table according to the current instruction address; Delete the entry corresponding to the current address from the target code breakpoint information table; Change the breakpoint instruction corresponding to the current instruction address to the original instruction.
[0011] As a further limitation of the technical solution of the present invention, the method further includes: When the breakpoint instruction is executed, the running state is changed to the debugging wait state, the execution of the target code is suspended, and the next command is received.
[0012] In a second aspect, the technical solution of the present invention further provides a system for implementing program debugging breakpoints based on multiple control logic languages, including a preprocessing module, an executor, and a debugger; A preprocessing module is used to create mapping relationships between various control logic language programs and target codes and generate mapping tables; After receiving the user's request to set a breakpoint, the debugger searches the mapping table for the target code address based on the line number or segment number of the logical language program and sends a breakpoint setting command to the executor; The executor replaces the corresponding instruction in the target code with the breakpoint instruction according to the target code address; and stores the target code address and the corresponding instruction in the target code breakpoint information table; when executing the breakpoint, the original instruction is obtained from the target code breakpoint information table and restored.
[0013] As a further limitation of the technical solution of the present invention, the preprocessing module is specifically used to select a language as an intermediate language for compiling multiple control logic languages into target codes; compile various control logic language programs into intermediate language programs, and establish a mapping relationship table between each line or each segment in the control logic language program and each line in the intermediate language program, that is, a first-level mapping table; compile the intermediate language program into target code, and establish a mapping relationship table between each line of the intermediate language program and the target code instructions, that is, a second-level mapping table.
[0014] As a further limitation of the technical solution of the present invention, the preprocessing module is specifically used to use a lexical analyzer to decompose the control logic language program text into independent lexical units to generate a lexical unit sequence; construct an abstract syntax tree based on the lexical unit sequence; formulate corresponding code conversion rules for each control logic language based on the grammatical and semantic rules of the intermediate language; according to the conversion rules, the syntax tree is converted into an intermediate language program, and during the code conversion process, the correspondence between each line or each paragraph in the control logic language program and each line in the intermediate language program is simultaneously recorded to generate a first-level mapping table.
[0015] As a further limitation of the technical solution of the present invention, the debugger is modified, including adding a control logic breakpoint information table; each table entry records the line number or segment number of the control logic program, and the target code address corresponding to the line number or segment number; the executor is modified, including adding a breakpoint instruction, adding a target code breakpoint information table, and adding a debugging wait state, each table entry in the target code breakpoint information table records the target code address and the target code instruction corresponding to the address.
[0016] As a further limitation of the technical solution of the present invention, after receiving a user's request to set a breakpoint, the debugger searches for a target code address in a first-level mapping table and a second-level mapping table based on a line number or segment number of the logical language program; saves the line number or segment number and the target code address to a control logic breakpoint information table; and sends a set breakpoint command to the executor, wherein the command parameter includes the target code address; After receiving the breakpoint setting command, the executor saves the target code address and the target code instruction corresponding to the address into the target code breakpoint information table of the executor; and replaces the instruction corresponding to the target code address in the target code with the breakpoint instruction.
[0017] As a further limitation of the technical solution of the present invention, When the executor determines to execute the breakpoint instruction based on the read target code instruction, it searches the target code breakpoint information table for the original instruction corresponding to the current address according to the current instruction address; deletes the table entry corresponding to the current address from the target code breakpoint information table; and modifies the breakpoint instruction corresponding to the current instruction address to the original instruction.
[0018] As a further limitation of the technical solution of the present invention, when a breakpoint instruction is executed, the executor changes the running state to a debugging wait state, suspends the execution of the target code, and waits to receive the next command from the debugger.
[0019] A new control logic breakpoint information table has been added to record breakpoint information set by debuggers, making it easier for them to manage and monitor breakpoints. Debuggers can clearly understand the location of each breakpoint in the control logic program and the corresponding target code instructions, allowing them to quickly locate and resolve issues, improving the flexibility and accuracy of debugging.
[0020] The added target code breakpoint information table is used to record the breakpoint information set by the debugger and the breakpoint information of the next segment or line automatically set during single-step execution by the debugger. It unifies the executor's processing logic for breakpoints from different sources and reduces the complexity of the debugger.
[0021] The present invention's complete breakpoint setting and execution process makes the debugging process more standardized and streamlined. From the user setting a breakpoint in the control logic language program to the executor accurately executing the breakpoint instruction and entering the debugging standby state, each link works closely together to provide users with a more efficient and convenient debugging environment, helping to shorten the software development cycle and improve software quality.
[0022] It can be seen from the above technical solutions that the present application has the following advantages: by creating a two-level mapping table, a mapping relationship between a variety of control logic language programs and target codes is established, making it easier and more unified to set breakpoints in a variety of control logic language programs. Regardless of which control logic language is used for programming, the target code instruction address can be quickly located based on the mapping table, reducing the difficulty of setting breakpoints due to multiple compilation units and no mapping relationship. The improvements to the executor and debugger avoid the tedious operation of the executor scanning the breakpoint information table before executing each instruction. The executor only performs relevant processing when encountering a breakpoint instruction, and by adding a debugging wait state, the execution process is reasonably controlled, reducing the interference of breakpoint processing on normal program execution, thereby significantly improving the execution efficiency of the executor during the debugging process. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for the description. 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 any creative work.
[0024] Figure 1 A flowchart of a method provided by an embodiment of the present invention.
[0025] Figure 2This is a workflow diagram of the system provided by an embodiment of the present invention.
[0026] Figure 3 4 is a flowchart of the working process of the executor in an embodiment of the present invention.
[0027] Figure 4 This is a schematic diagram of the first-level mapping in the embodiment of the present invention.
[0028] Figure 5 This is a schematic diagram of the second-level mapping in an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to make the application objectives, features, and advantages of this application more obvious and easy to understand, the technical solutions protected by this application will be clearly and completely described below using specific embodiments and drawings. Obviously, the embodiments described below are only part of the embodiments of this application, not all of them. Based on the embodiments in this patent, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this patent.
[0030] like Figure 1 As shown, an embodiment of the present invention provides a method for implementing program debugging breakpoints based on multiple control logic languages, including: S1: Create mapping relationships between multiple control logic language programs and target codes and generate a mapping table; The implementation process of this step specifically includes: S11: selecting a language as an intermediate language for compiling multiple control logic languages into target codes; S12: compile various control logic language programs into intermediate language programs, and establish a mapping relationship table between each line or each segment in the control logic language program and each line in the intermediate language program, i.e., a first-level mapping table; S13: Compile the intermediate language program into target code, and create a mapping relationship table between each line of the intermediate language program and the target code instruction, that is, a second-level mapping table.
[0031] It should be further explained that the specific steps of creating the first-level mapping table and the second-level mapping table include: S121: Parse the logic control language program text to determine the logic content of each paragraph and each line; S122: formulating corresponding code conversion rules for the logic control language based on the grammatical and semantic rules of the selected intermediate language; S123: Convert each paragraph or line of logic in the logic control language into an intermediate language according to the conversion rules; S124: During the code conversion process, the correspondence between the segment number or line number of the logic control language and the line number of the generated intermediate language is recorded, and the correspondence is organized into a first-level mapping table; S125: further processing the generated intermediate language and converting it into target code; S126: Determine the corresponding address for each line of target code after conversion; S127: Record the correspondence between the line number of the intermediate language and the target code address, and organize the correspondence into a second-level mapping table.
[0032] Creating a mapping relationship between multiple control logic language programs and target codes is the basis of the entire debugging breakpoint implementation method. This step establishes the connection between different control logic language programs and target codes, so that the breakpoint information in the control logic program can be accurately converted to the corresponding position in the target code. After the creation of the mapping relationship is completed, the corresponding rules between the control logic program and the target code are clarified. At this time, the debugger and executor can be modified based on this rule to better support the breakpoint debugging function. For example, the control logic breakpoint information table and target code breakpoint information table to be added later rely on this mapping relationship to accurately record relevant information.
[0033] Modifications to the debugger and executor are made in preparation for setting breakpoints and executing breakpoint processes. Only after completing these modifications can we ensure that when setting breakpoints, the system has the corresponding mechanism to record and process breakpoint information; when executing breakpoints, the system can correctly pause program execution and wait for debugging commands. Adding breakpoint instructions is a key instruction to implement the breakpoint function. When setting a breakpoint, the corresponding instruction in the target code will be replaced with the breakpoint instruction, thereby triggering the breakpoint when the program executes to that location. Adding a target code breakpoint information table is used to record breakpoint-related information in the target code. When setting a breakpoint, the target code address and corresponding instruction are stored in this table. When executing a breakpoint, the original instruction can be retrieved from this table and restored.
[0034] When a breakpoint is executed, the executor enters this state, pausing execution of the target code and awaiting debugging commands. This is a key state transition during breakpoint debugging. A control logic breakpoint information table is added to record breakpoint information in the control logic program. Combined with the mapping relationship, this table can convert line numbers or segment numbers in the control logic program into target code instruction addresses, facilitating accurate positioning when setting breakpoints.
[0035] For example, when the logic control language is ladder diagram and the intermediate language is STL, the specific process of creating the first-level mapping table and the second-level mapping table is as follows: Parse the ladder diagram of the logic control language to determine the logic content of each segment. For example Figure 4 In the ladder diagram, the structure is divided into different sections, and each section has specific rows to clarify the connection relationship and location of each component (such as F0000.0, X0000.0, etc.).
[0036] Convert each logic block of the ladder diagram into STL language according to the conversion rules. For example, the logical relationship between F0000.0 and X0000.0 in the first block of the ladder diagram is converted into STL language code such as "LD F0000.0 OR X0000.0 OUT G0000.0".
[0037] Record the correspondence between the segment number of the ladder diagram and the line number of the generated STL language. Figure 4 In the example, the first line of the first paragraph corresponds to the first line of the intermediate language, the fourth line of the second paragraph corresponds to the fourth line of the intermediate language, and so on. These correspondences are organized into a first-level mapping table, which contains two columns of information: "paragraph number" and "line number".
[0038] The generated STL language is further processed and converted into target code (binary form) according to specific rules. For example, an STL instruction such as "LD F0000.0" is converted into binary code such as "0030 80 c8 84 06 c8 bf c4 d0".
[0039] Determine the corresponding address for each line of target code after conversion. The address is used to locate the instruction in memory for subsequent operations.
[0040] Record the correspondence between the line number of the STL language and the target code address. Figure 5 As shown, the first line of the STL language corresponds to the target code address 0038, the fourth line corresponds to 0050, and so on. These corresponding information are organized into a second-level mapping table, which contains two columns of information: "line number" and "address".
[0041] S2: After receiving a user's request to set a breakpoint, the target code address is searched in the mapping table according to the line number or segment number of the logical language program, and the corresponding instruction in the target code is replaced with the breakpoint instruction according to the target code address; and the target code address and the corresponding instruction are stored in the target code breakpoint information table; S3: When executing the breakpoint instruction, the original instruction is obtained from the target code breakpoint information table and the breakpoint instruction is restored to the original instruction.
[0042] In some embodiments, after receiving a user request to set a breakpoint, searching a target code address in a mapping table according to a line number or segment number of a logical language program, replacing a corresponding instruction in the target code with a breakpoint instruction according to the target code address; and storing the target code address and the corresponding instruction in a target code breakpoint information table includes the following steps: S21: After receiving a request from the user to set a breakpoint, searching for a target code address in the first-level mapping table and the second-level mapping table according to the line number or segment number of the logical language program; S22: Save the line number or segment number and the target code address to the control logic breakpoint information table; S23: Send a breakpoint setting command to the executor, the command parameter includes the target code address; S24: After receiving the breakpoint setting command, the target code address and the target code instruction corresponding to the address are saved in the target code breakpoint information table; and the instruction corresponding to the target code address in the target code is replaced with the breakpoint instruction.
[0043] In some embodiments, when executing a breakpoint instruction, the steps of obtaining the original instruction from the target code breakpoint information table and restoring the breakpoint instruction to the original instruction include: S31: when determining to execute a breakpoint instruction according to the read target code instruction, searching the target code breakpoint information table for the original instruction corresponding to the current address according to the current instruction address; S32: Delete the entry corresponding to the current address from the target code breakpoint information table; S33: Modify the breakpoint instruction corresponding to the current instruction address to the original instruction.
[0044] In some embodiments, the method further comprises: When the breakpoint instruction is executed, the running state is changed to the debugging wait state, the execution of the target code is suspended, and the next command is received.
[0045] It should be noted that after the breakpoint is set, executing the breakpoint mainly includes the following key steps: the executor searches the target code breakpoint information table for the original instruction corresponding to the current instruction address. This is because when the breakpoint is set, the corresponding instruction in the target code has been replaced with the breakpoint instruction, so the original instruction needs to be obtained from the breakpoint information table. The table entry corresponding to the current address is deleted from the target code breakpoint information table. This is done to avoid repeated processing when the instruction is executed again later, ensuring the accuracy and simplicity of the breakpoint information table. The breakpoint instruction corresponding to the current instruction address is modified to the original instruction. This step is to allow the program to continue to execute normally according to the original logic and code after pausing at the breakpoint.
[0046] The executor enters the debug wait state from the running state, waiting to receive the next command from the debugger. In this state, program execution is paused, and the developer can perform debugging operations such as viewing variable values and checking program status.
[0047] Breakpoint instructions pause a program at a specific location, facilitating inspection and analysis by debuggers. However, normal program execution relies on the logic of the original instructions. If the breakpoint instruction is not replaced with the original instruction, subsequent program execution will fail, preventing the program from running according to the intended logic. This can lead to inaccurate debugging results and even system failures. The original instruction represents the core logic of the program design, and replacing it with the original instruction ensures program integrity. After debugging is complete, the program can seamlessly continue executing subsequent tasks without any impact from the breakpoint setting. During execution, when the executor encounters an instruction set as a breakpoint, a breakpoint event is triggered because the instruction has been replaced with the breakpoint instruction. Once a breakpoint instruction is detected, the executor immediately initiates the breakpoint processing flow. First, the original instruction is searched in the target code breakpoint information table based on the current instruction address and restored to the code. After the original instruction is restored, the executor enters the debugging wait state. At this point, program execution is paused, allowing the debugger to intervene. Developers can use the debugger to view information such as the current program status and variable values, and perform necessary debugging operations. Based on the debugging situation, the developer sends corresponding commands to the executor through the debugger, such as continue execution, single-step execution, etc. The executor decides the subsequent operation based on the received command, and continues to complete the execution of the program or performs other debugging-related actions.
[0048] The embodiment of the present invention also provides a system for implementing program debugging breakpoints based on multiple control logic languages, including a preprocessing module, an executor, and a debugger; A preprocessing module is used to create mapping relationships between various control logic language programs and target codes and generate mapping tables; After receiving the user's request to set a breakpoint, the debugger searches the mapping table for the target code address based on the line number or segment number of the logical language program and sends a breakpoint setting command to the executor; The executor replaces the corresponding instruction in the target code with the breakpoint instruction according to the target code address; and stores the target code address and the corresponding instruction in the target code breakpoint information table; when executing the breakpoint, the original instruction is obtained from the target code breakpoint information table and restored.
[0049] In some embodiments, the preprocessing module is specifically used to select a language as an intermediate language for compiling multiple control logic languages into target codes; compile various control logic language programs into intermediate language programs, and establish a mapping relationship table between each line or each segment in the control logic language program and each line in the intermediate language program, that is, a first-level mapping table; compile the intermediate language program into target code, and establish a mapping relationship table between each line of the intermediate language program and the target code instructions, that is, a second-level mapping table.
[0050] In some embodiments, the preprocessing module is specifically used to parse the logic control language program text to determine the logical content of each paragraph and each line; formulate corresponding code conversion rules for the logic control language based on the grammatical and semantic rules of the selected intermediate language; convert each paragraph or each line of the logic control language into the intermediate language based on the conversion rules; during the code conversion process, record the correspondence between the paragraph number or line number of the logic control language and the line number of the generated intermediate language, and organize the correspondence into a first-level mapping table; further process the generated intermediate language and convert it into target code; determine the corresponding address for each line of target code after conversion; record the correspondence between the line number of the intermediate language and the address of the target code, and organize the correspondence into a second-level mapping table.
[0051] In some embodiments, the debugger is modified, including adding a control logic breakpoint information table; each table entry records the line number or segment number of the control logic program, and the target code address corresponding to the line number or segment number; the executor is modified, including adding breakpoint instructions, adding a target code breakpoint information table, and adding a debugging wait state, and each table entry in the target code breakpoint information table records the target code address and the target code instruction corresponding to the address.
[0052] When programming in multiple control logic languages, traditional debugging and execution mechanisms cannot directly support accurate breakpoint setting and handling in programs written in multiple languages due to differences in syntax, semantics, and compilation methods. Modifying the debugger and executor establishes a mapping relationship between programs written in multiple control logic languages and the target code, enabling convenient breakpoint setting and debugging regardless of the language. For example, a control logic breakpoint information table is added to the debugger to record the locations of breakpoints set in programs written in different languages and convert them to addresses in the target code through a mapping relationship. A target code breakpoint information table is added to the executor to store breakpoint-related information in the target code, enabling accurate breakpoint setting and handling. Traditional breakpoint handling methods, such as scanning the breakpoint information table before executing each instruction, can severely reduce execution efficiency. The modified executor introduces breakpoint instructions and a debug wait state. The breakpoint handling process is triggered only when a breakpoint instruction is executed, avoiding unnecessary breakpoint scanning operations and significantly improving program execution efficiency. At the same time, the debug wait state causes the program to pause at the breakpoint, and developers can perform detailed debugging operations in this state without affecting the normal execution flow of the program.
[0053] The revised debugger and executor provide developers with a more user-friendly and efficient debugging environment. The debugger's control logic breakpoint information table allows developers to intuitively set and manage breakpoints at the control logic program level, without having to worry about the specific details of the target code. The executor's debug wait state allows developers to step through the debugger at breakpoints, viewing variable values and program status, making it easier to quickly locate and resolve issues, thereby improving the efficiency and accuracy of the entire debugging process.
[0054] The primary reason for modifying the debugger and executor is to address existing breakpoint debugging issues, including complex breakpoint setting and reduced execution efficiency when programming in multiple languages. The addition of breakpoint instructions, a target code breakpoint information table, debug wait states, and a control logic breakpoint information table aims to build a comprehensive breakpoint debugging mechanism, enabling efficient breakpoint setting and execution. Mapping relationships play a crucial supporting role in this process. Two-level mapping tables (between the control logic language program and the intermediate language program, and between the intermediate language program and the target code instructions) provide an accurate information exchange bridge for the revised debugger and executor. When setting a breakpoint, the mapping tables enable rapid location of the target code instruction address based on the line or segment number of the control logic program. This ensures that the newly added control logic breakpoint information table and target code breakpoint information table provide an accurate basis for recording information. Breakpoint execution also relies on mapping relationships to ensure that breakpoints set at the control logic program level are correctly triggered and processed during target code execution.
[0055] In some embodiments, the logic control language is a ladder diagram, and the corresponding executor and debugger are a PLC executor and a PLC debugger, respectively; Figure 2 As shown, after receiving the user's request to set a breakpoint, the PLC debugger searches for the target code address in the first-level mapping table and the second-level mapping table according to the line number or segment number of the logic language program; saves the line number or segment number and the target code address to the control logic breakpoint information table; and sends a set breakpoint command to the executor, with the command parameter including the target code address. After receiving the breakpoint setting command, the PLC executor saves the target code address and the target code instruction corresponding to the address to the target code breakpoint information table of the PLC executor; and replaces the instruction corresponding to the target code address in the target code with the breakpoint instruction.
[0056] Correspondingly, such as Figure 3 As shown, when the PLC executor determines to execute a breakpoint instruction based on the read target code instruction, it searches for the original instruction corresponding to the current address in the target code breakpoint information table according to the current instruction address; deletes the table entry corresponding to the current address from the target code breakpoint information table; and modifies the breakpoint instruction corresponding to the current instruction address to the original instruction.
[0057] When the breakpoint instruction is executed, the PLC executor changes the running state to the debugging wait state, pauses the execution of the target code, and waits to receive the next command from the PLC debugger.
[0058] In a multilingual programming environment, different control logic languages have different syntaxes and compilation methods. Without an effective mapping and management mechanism, breakpoint setting can become extremely complex. By adding a control logic breakpoint information table and a target code breakpoint information table, combined with a two-level mapping relationship (from multiple control logic language programs to intermediate language programs, and from intermediate language programs to target code instructions), breakpoints can be easily set in control logic programs in different languages and accurately mapped to the target code, significantly simplifying breakpoint setting. Traditional breakpoint setting methods require the PLC executor to scan the breakpoint information table before executing each instruction, which consumes significant system resources and severely impacts execution efficiency. The revised solution uses breakpoint instructions to trigger breakpoint events. Breakpoint processing occurs only when a breakpoint instruction is executed, avoiding unnecessary scanning operations and significantly improving PLC execution efficiency. A new debug wait state pauses program execution at a breakpoint, allowing debuggers to conduct detailed inspection and debugging of the program, such as viewing variable values and checking program status. At the same time, debuggers can send different commands to the PLC actuator as needed, such as continue execution, single-step execution, etc., which enhances the flexibility and controllability of debugging.
[0059] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for implementing program debugging breakpoints based on multiple control logic languages, characterized in that: include: Create mapping relationships between multiple control logic language programs and target codes and generate mapping tables; After receiving a user's request to set a breakpoint, the target code address is searched in the mapping table according to the line number or segment number of the logical language program, and the corresponding instruction in the target code is replaced with the breakpoint instruction according to the target code address; and the target code address and the corresponding instruction are stored in the target code breakpoint information table; When a breakpoint instruction is executed, the original instruction is obtained from the target code breakpoint information table and the breakpoint instruction is restored to the original instruction.
2. The method for implementing program debugging breakpoints based on multiple control logic languages according to claim 1, characterized in that: The steps of creating a mapping relationship between multiple control logic language programs and target codes and generating a mapping table include: Select a language as the intermediate language for compiling multiple control logic languages into target codes; Compile various control logic language programs into intermediate language programs, and establish a mapping relationship table between each line or each segment in the control logic language program and each line in the intermediate language program, i.e., a first-level mapping table; Compile the intermediate language program into target code and create a mapping table between each line of the intermediate language program and the target code instructions, that is, the second-level mapping table.
3. The method for implementing program debugging breakpoints based on multiple control logic languages according to claim 2, characterized in that: The specific steps for creating the first-level mapping table and the second-level mapping table include: Parse the logic control language program text to determine the logic content of each paragraph and each line; According to the grammatical and semantic rules of the selected intermediate language, corresponding code conversion rules are formulated for the logic control language; According to the conversion rules, each paragraph or each line of logic in the logic control language is converted into the intermediate language; During the code conversion process, the correspondence between the segment number or line number of the logic control language and the line number of the generated intermediate language is recorded, and the correspondence is organized into a first-level mapping table; Further process the generated intermediate language and convert it into target code; Determine the corresponding address for each line of target code after conversion; The correspondence between the line number of the intermediate language and the target code address is recorded, and the correspondence is organized into a second-level mapping table.
4. The method for implementing program debugging breakpoints based on multiple control logic languages according to claim 3, characterized in that: After receiving the user's request to set a breakpoint, the target code address is searched in the mapping table according to the line number or segment number of the logical language program, and the corresponding instruction in the target code is replaced with the breakpoint instruction according to the target code address; The step of storing the target code address and the corresponding instruction in the target code breakpoint information table includes: After receiving a request from the user to set a breakpoint, the target code address is searched in the first-level mapping table and the second-level mapping table according to the line number or segment number of the logical language program; Save the line number or segment number and target code address to the control logic breakpoint information table; Send a breakpoint setting command to the executor, and the command parameter contains the target code address; After receiving the breakpoint setting command, the target code address and the target code instruction corresponding to the address are saved in the target code breakpoint information table; and the instruction corresponding to the target code address in the target code is replaced with the breakpoint instruction.
5. The method for implementing program debugging breakpoints based on multiple control logic languages according to claim 4, characterized in that: When executing a breakpoint instruction, the steps of obtaining the original instruction from the target code breakpoint information table and restoring the breakpoint instruction to the original instruction include: When the breakpoint instruction is determined to be executed according to the read target code instruction, the original instruction corresponding to the current address is searched in the target code breakpoint information table according to the current instruction address; Delete the entry corresponding to the current address from the target code breakpoint information table; Change the breakpoint instruction corresponding to the current instruction address to the original instruction.
6. The method for implementing program debugging breakpoints based on multiple control logic languages according to claim 5, characterized in that: The method further includes: When the breakpoint instruction is executed, the running state is changed to the debugging wait state, the execution of the target code is suspended, and the next command is received.
7. A program debugging breakpoint implementation system based on multiple control logic languages, characterized in that: Includes pre-processing module, executor and debugger; A preprocessing module is used to create mapping relationships between various control logic language programs and target codes and generate mapping tables; After receiving the user's request to set a breakpoint, the debugger searches the mapping table for the target code address based on the line number or segment number of the logical language program and sends a breakpoint setting command to the executor; The executor replaces the corresponding instruction in the target code with the breakpoint instruction according to the target code address; and stores the target code address and the corresponding instruction in the target code breakpoint information table; when executing the breakpoint, the original instruction is obtained from the target code breakpoint information table and restored.
8. The system for implementing program debugging breakpoints based on multiple control logic languages according to claim 7, characterized in that: The preprocessing module is specifically used to select a language as the intermediate language for compiling multiple control logic languages into target code; compile various control logic language programs into intermediate language programs, and establish a mapping relationship table between each line or each segment in the control logic language program and each line in the intermediate language program, that is, the first-level mapping table; compile the intermediate language program into target code, and establish a mapping relationship table between each line of the intermediate language program and the target code instructions, that is, the second-level mapping table.
9. The system for implementing program debugging breakpoints based on multiple control logic languages according to claim 8, characterized in that: Modifications are made to the debugger, including adding a control logic breakpoint information table; each table entry records the line number or segment number of the control logic program and the target code address corresponding to the line number or segment number; modifications are made to the executor, including adding breakpoint instructions, adding a target code breakpoint information table, and adding a debugging wait state; each table entry in the target code breakpoint information table records the target code address and the target code instruction corresponding to the address.
10. The system for implementing program debugging breakpoints based on multiple control logic languages according to claim 9, characterized in that: After receiving a user's request to set a breakpoint, the debugger searches for the target code address in the first-level mapping table and the second-level mapping table based on the line number or segment number of the logical language program; saves the line number or segment number and the target code address to the control logic breakpoint information table; and sends a set breakpoint command to the executor, with the target code address included in the command parameter. After receiving the breakpoint setting command, the executor saves the target code address and the target code instruction corresponding to the address into the target code breakpoint information table of the executor; and replaces the instruction corresponding to the target code address in the target code with the breakpoint instruction.