Simulation debugging system and method for 51 single-chip microcomputer simulator with double threads
By introducing dual-thread design and debugger communication functions into the 51 microcontroller emulator, the problem of the lack of debugging functions of existing emulators is solved, and the debugging function and development efficiency of the emulator are improved.
Patent Information
- Application Number
- CN202411636808.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-11-15
AI Technical Summary
The existing 51 microcontroller emulator lacks debugging functions, which makes it difficult for developers to discover and locate program errors in time, reducing the efficiency of microcontroller development.
Design a 51 microcontroller emulator with dual threads, establish a communication connection between the debugger and the emulator. The emulator creates the main thread and the listening thread. The main thread executes the 51 microcontroller program, the monitoring thread receives debug commands and performs debugging operations, and realizes debugging functions such as breakpoint setting, single-step operation, variable viewing, etc.
The debugging function of the 51 microcontroller emulator is realized, allowing developers to directly locate program errors, improve the microcontroller development efficiency, and improve the processing capability and response speed of the simulator.
Smart Images

Figure CN119644790A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of simulation debugging, and in particular to a simulation debugging system and method of a 51 single-chip computer simulator with dual threads. Background Art
[0002] A single-chip microcomputer is an integrated circuit chip that uses ultra-large-scale integrated circuit technology to integrate a central processing unit (CPU) with data processing capabilities, memory, multiple I / O ports and interrupt systems, timers / counters and other functions on a silicon chip, thus forming a small and complete microcomputer system. Among them, the 51 single-chip microcomputer is widely used in various fields due to its simple instruction system, small size, low power consumption and rich on-chip resources. In the industrial field, it can be used for PLC, sensor interface, data acquisition, etc.; in the home appliance field, it is often used to control home appliances such as washing machines, air conditioners, and microwave ovens; in the education field, it can be used as a teaching tool for professional courses such as computer science and electronic engineering. Therefore, the 51 single-chip microcomputer has a high development demand. Among them, the emulator of the 51 single-chip microcomputer is a tool that provides a simulation environment for the 51 single-chip microcomputer and its related circuit design. It can perform virtual simulation of the 51 single-chip microcomputer system at the software level, including: virtual simulation of the 51 single-chip microcomputer central processing unit, various registers, memory and other components, and realize the running of the 51 single-chip microcomputer program on the emulator, so that the developed single-chip microcomputer program can still be verified and tested without the 51 single-chip microcomputer hardware.
[0003] See also Figure 1 In order to fully simulate the functions of a 51 chip, the existing 51 MCU simulator must complete the simulation function of the chip's central processing unit, including the simulation of the processor core's instruction fetching, instruction translation, instruction execution, memory access and data write-back functions. However, since the existing 51 MCU simulator does not have a debugging function and does not support online debugging, it is difficult to directly obtain the values of each register in the program, the values of each program variable, and the code location that the program is currently running to during the running of the MCU program. As a result, it is difficult for developers to grasp the causes of the problems found in time during the development of the MCU program, and it is also difficult to directly locate the location of the problem code, which greatly slows down the development progress of the MCU program and reduces the development efficiency of the 51 MCU.
[0004] Therefore, a dual-thread simulation debugging system and method are needed that can realize the debugging function of the 51 single-chip microcomputer simulator and improve the development efficiency of the single-chip microcomputer. Summary of the invention
[0005] The present invention provides a simulation debugging system and method for a 51 single-chip microcomputer simulator with dual threads, which are mainly used to solve the problems that the existing 51 single-chip microcomputer simulator does not have a debugging function, resulting in the inability to timely discover and correct errors in the program and the low efficiency of single-chip microcomputer development, thereby achieving the effect of realizing the debugging function of the 51 single-chip microcomputer simulator and improving the efficiency of single-chip microcomputer development.
[0006] The present invention achieves the above-mentioned purpose through the following technical solutions:
[0007] A simulation debugging system of a 51 single-chip microcomputer simulator with dual threads, comprising:
[0008] A debugger and an emulator that establish a data communication connection with each other, the debugger is used to input debugging commands, and parses the debugging commands and sends them to the emulator through a communication port. The main program of the emulator is a 51 single-chip microcomputer program to be simulated and tested, and its main control program is also provided with a number of debugging functions for implementing the debugging commands and a checking program for checking interrupt signals. The emulator creates a main thread and a listening thread, the main thread is used to load and execute the 51 single-chip microcomputer program, and checks through the checking program whether the current instruction address of the 51 single-chip microcomputer program will trigger a breakpoint or whether there is a manually input interrupt signal, and feeds back the current instruction address and breakpoint information to the debugger according to the checking result; the listening thread is used to exchange information with the debugger, and parses the received debugging command and calls the corresponding debugging function to perform debugging operations, and feeds back the debugging results to the debugger.
[0009] A further solution is that a TCP communication connection is established between the simulator and the debugger via a TCP communication port, and the simulator waits for the debugging command by continuously monitoring its TCP communication port.
[0010] A further solution is that the debugging commands are used to view and modify program status in real time, including but not limited to: breakpoint commands, single-step run commands, variable view commands, memory view commands, and register view commands.
[0011] A further solution is that the breakpoint command is: break+instruction address.
[0012] The memory viewing command is: readmemory+memory address.
[0013] The register viewing command is: regvalues.
[0014] A further solution is that the debugging functions correspond one-to-one to the debugging commands, including but not limited to: breakpoint functions, single-step running functions, variable viewing functions, memory viewing functions, and register viewing functions.
[0015] A further solution is that the emulator configures the program counter PC and nPC values in the "fetch instruction" stage of the 51 single-chip microcomputer program, which are used to indicate the address locations of the current instruction and the next instruction of the 51 single-chip microcomputer program in the main memory respectively, and the checking program is used to check whether the address of the current instruction will trigger a breakpoint or whether there is a manually input interrupt signal.
[0016] A further solution is that when the checking program checks that the current instruction address will trigger a breakpoint or whether there is a manually input interrupt signal, the main program is suspended and the emulator feeds back the current instruction address and breakpoint information as the debugging result to the debugger.
[0017] A further solution is that the debugger encapsulates and displays the debugging result in a standard data format.
[0018] A simulation debugging method for a 51 single-chip microcomputer simulator with dual threads, applied to a simulation debugging system for a 51 single-chip microcomputer simulator with dual threads, comprising:
[0019] S1: The debugging function and the checking program are set in the main program of the simulator, and a main thread and a listening thread are created, wherein the main thread loads and executes the 51 single-chip computer program, and the listening thread establishes a TCP communication connection with the debugger.
[0020] S2: The listening thread continues to listen to the TCP port, waiting for a debugging command from the debugger.
[0021] S3: After receiving the debugging command, the listening thread parses the debugging command and calls the corresponding debugging function to perform debugging operations according to the parsed structure.
[0022] S4: The monitoring thread sends the debugging result to the debugger and repeats step S2.
[0023] A further solution is that when the main thread in step S1 executes the 51 single-chip computer program, it also includes:
[0024] S11: The main thread checks whether the current instruction address triggers a breakpoint or whether there is a manually input interrupt signal.
[0025] S12: If yes, the main program is suspended, and the current instruction address and breakpoint information are sent to the debugger as the debugging result. If no, repeat step S11.
[0026] It can be seen that the present invention has the following beneficial effects:
[0027] 1. The present invention establishes a communication connection between a debugger and an emulator, and creates a dual thread through the emulator, so that the emulator has parallel processing capabilities. While the emulator executes the 51 single-chip microcomputer program of the main thread, it receives debugging commands and completes various debugging operations on the 51 single-chip microcomputer program through a listening thread, thereby facilitating developers to directly locate the code position of the problem in the 51 single-chip microcomputer program, and can greatly reduce the difficulty of finding the cause of the problem by checking variables, registers and other debugging operations. The dual-thread task processing also improves the overall processing capability and response speed of the program, thereby improving the development efficiency of the 51 single-chip microcomputer as a whole.
[0028] 2. The present invention adds a check program to the main program of the emulator. The check program checks whether the current instruction address of the main program will trigger breakpoints and other operations. If the breakpoint is triggered, the main program will pause and feed back the current instruction address, breakpoint information and other information to the debugger as debugging results. The developer can obtain the debugging information on the debugger. The present invention enables the emulator to correctly identify breakpoint marks and correctly complete corresponding debugging operations.
[0029] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 It is a schematic diagram of the instruction processing process of the emulator of the prior art 51 single-chip microcomputer.
[0031] Figure 2 It is a schematic diagram of a simulation debugging system according to an embodiment of the present invention.
[0032] Figure 3 It is a flow chart of the simulation debugging method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0034] A simulation debugging system embodiment of a 51 single-chip microcomputer simulator with dual threads
[0035] See also Figure 2 The present invention relates to a simulation debugging system of a 51 single-chip microcomputer simulator with dual threads, comprising:
[0036] A debugger 10 and an emulator 20 that establish a data communication connection with each other, the debugger 10 is used to input debugging commands, and parse the debugging commands and send them to the emulator 20 through the communication port. The main program of the emulator 20 is a 51 single-chip microcomputer program to be simulated and tested, and its main control program is also provided with a number of debugging functions for implementing the debugging commands and a checking program for checking interrupt signals. The emulator 20 creates a main thread and a listening thread, the main thread is used to load and execute the 51 single-chip microcomputer program, and check through the checking program whether the current instruction address of the 51 single-chip microcomputer program will trigger a breakpoint or whether there is a manually input interrupt signal, and feed back the current instruction address and breakpoint information to the debugger 10 according to the check result; the listening thread is used to exchange information with the debugger 10, and call the corresponding debugging function to perform debugging operations after parsing the received debugging commands, and feed back the debugging results to the debugger 10.
[0037] Specifically, the debugger 10 of this embodiment can establish a communication connection with the 51 single-chip microcomputer system, and is provided with a main program for initializing various debugging functions, including for interacting with the emulator 20, setting breakpoints, single-step execution, viewing register and memory information, etc., and controls and tracks the program execution process of the emulator 20 through the system debugging instructions provided by the operating system. It can single-step execute code, set and trigger breakpoints, check variable values and track the stack, and can modify memory contents and register values, etc., so as to observe different execution paths and results of the program.
[0038] Specifically, the debugger 10 of this embodiment can be customized in the integrated development environment (IDE), and the customized debugging program can be placed in a specified directory to perform corresponding configuration.
[0039] In this embodiment, a TCP communication connection is established between the emulator 20 and the debugger 10 via a TCP communication port, and the emulator 20 waits for the debugging command by continuously monitoring its TCP communication port.
[0040] Specifically, the present embodiment adopts the byte stream-based transport layer communication protocol TCP. Before sending the debugging instruction, the emulator 20 and the debugger 10 need to establish a communication connection first, specifically: initialize the communication connection through a three-way handshake process, and release the connection through a four-wave handshake process after the data transmission is completed. In addition, TCP ensures reliable data transmission through mechanisms such as confirmation response and timeout retransmission, and can ensure that data reaches the receiving end even when the communication link changes, thereby achieving reliable data transmission.
[0041] In this embodiment, the debugging commands are used to view and modify the program status in real time, including but not limited to: breakpoint commands, single-step run commands, variable view commands, memory view commands, and register view commands.
[0042] In this embodiment, the breakpoint command is: break+instruction address.
[0043] The memory viewing command is: readmemory+memory address.
[0044] The register viewing command is: regvalues.
[0045] In this embodiment, the debugging functions correspond one-to-one to the debugging commands, including but not limited to: breakpoint function: break_handler, single-step running function: step_handler / next_handler, variable viewing function: read_var_handler, memory viewing function: read_memory_handler, register viewing function: read_reg_handler.
[0046] Specifically, the debugging function described in this embodiment also includes: a continuous operation function: continue_handler, a pause operation function: stop_handler, a breakpoint check function: break_list_handler, a breakpoint deletion function: break_delete_handler, a register write function: write_reg_handler, a memory write function: write_memory_handler, and a variable write function: write_var_handler.
[0047] In this embodiment, the emulator 20 configures the program counter PC and nPC values in the "fetch instruction" stage of the 51 single-chip microcomputer program, which are respectively used to indicate the address positions of the current instruction and the next instruction of the 51 single-chip microcomputer program in the main memory. The check program is used to check whether the address of the current instruction will trigger a breakpoint or whether there is a manually input interrupt signal.
[0048] In this embodiment, when the checking program checks that the current instruction address will trigger a breakpoint or whether there is a manually input interrupt signal, the main program is suspended and the emulator 20 feeds back the current instruction address and breakpoint information to the debugger 10 as the debugging result.
[0049] Specifically, in this embodiment, when the simulator 20 receives a breakpoint command, a breakpoint mark is set at the line or function entry of the specified address of the breakpoint command, and the check program checks that the current instruction address will trigger a breakpoint.
[0050] At the same time, when the main program in the emulator 20 attempts to fetch the instruction at the address during execution, a breakpoint is triggered and the operation is suspended, and the current instruction address and breakpoint information are fed back to the debugger 10 as the debugging result.
[0051] Specifically, the debugger 10 of this embodiment can integrate all functions used for debugging into an executable program through software, and start the program on the PC for debugging, and output debugging commands to the emulator 20 by manually inputting debugging signals, such as sending an interrupt signal by pressing the ctrl+c keys.
[0052] In this embodiment, the debugger 10 encapsulates and displays the debugging result in a standard data format.
[0053] Specifically, this embodiment can improve the readability, maintainability and reusability of data code by encapsulating the debugging results. It can also hide the data inside the class through encapsulation and only provide necessary access interfaces to the outside, thereby protecting the security of the data and facilitating program development.
[0054] A simulation debugging method embodiment of a 51 single-chip microcomputer simulator 20 with dual threads
[0055] See also Figure 3 The present invention relates to a simulation debugging method of a 51 single-chip microcomputer simulator 20 with dual threads, which is applied to a simulation debugging system of a 51 single-chip microcomputer simulator 20 with dual threads, and comprises:
[0056] S1: The debugging function and the checking program are set in the main program of the simulator 20, and a main thread and a listening thread are created. The main thread loads and executes the MCU program 51. The listening thread establishes a TCP communication connection with the debugger 10.
[0057] S2: The monitoring thread continues to monitor the TCP port, waiting for a debugging command from the debugger 10.
[0058] S3: After receiving the debugging command, the listening thread parses the debugging command and calls the corresponding debugging function to perform debugging operations according to the parsed structure.
[0059] S4: The monitoring thread sends the debugging result to the debugger 10 and repeats step S2.
[0060] In this embodiment, when the main thread in step S1 executes the 51 single-chip computer program, it also includes:
[0061] S11: The main thread checks whether the current instruction address triggers a breakpoint or whether there is a manually input interrupt signal.
[0062] S12: If yes, the main program is suspended, and the current instruction address and breakpoint information are sent as the debugging result to the debugger 10. If no, repeat step S11.
[0063] Specifically, the simulation debugging method of this embodiment further includes, at the debugger 10 end:
[0064] a. The main program of the debugger 10 loads and parses the CDB (directory database) file, and establishes a TCP communication connection with the emulator 20 through the TCP port.
[0065] Specifically, this embodiment can utilize a program written using TCP to execute data sending, receiving or monitoring.
[0066] b. The debugger 10 waits for a debug command to be input.
[0067] c. After receiving the input debugging command, the debugger 10 parses the debugging command and sends the parsed debugging command to the emulator 20 through the TCP port.
[0068] d. The main program of the debugger 10 receives the debugging result returned by the simulator 20 after executing the debugging command, and returns the debugging result to the user after packaging it in a standard data format.
[0069] e. Repeat step b until the main program in the simulator 20 is executed.
[0070] The above-mentioned embodiments are only preferred embodiments of the present invention and cannot be used to limit the scope of protection of the present invention. Any non-substantial changes and substitutions made by technicians in this field on the basis of the present invention shall fall within the scope of protection required by the present invention.
Claims
1. A simulation debugging system for a 51 single-chip microcomputer simulator with dual threads, characterized in that: include: A debugger and an emulator that establish a data communication connection with each other, the debugger is used to input debugging commands, and parses the debugging commands and sends them to the emulator through a communication port. The main program of the emulator is a 51 single-chip microcomputer program to be simulated and tested, and its main control program is also provided with a number of debugging functions for implementing the debugging commands and a checking program for checking interrupt signals. The emulator creates a main thread and a listening thread, the main thread is used to load and execute the 51 single-chip microcomputer program, and checks through the checking program whether the current instruction address of the 51 single-chip microcomputer program will trigger a breakpoint or whether there is a manually input interrupt signal, and feeds back the current instruction address and breakpoint information to the debugger according to the checking result; the listening thread is used to exchange information with the debugger, and parses the received debugging command and calls the corresponding debugging function to perform debugging operations, and feeds back the debugging results to the debugger.
2. The simulation debugging system of the 51 single-chip microcomputer simulator with dual threads according to claim 1, characterized in that: A TCP communication connection is established between the simulator and the debugger via the TCP communication port, and the simulator waits for the debugging command by continuously monitoring its TCP communication port.
3. The simulation debugging system of the 51 single-chip microcomputer simulator with dual threads according to claim 1, characterized in that: The debugging commands are used to view and modify the program status in real time, and include but are not limited to: breakpoint commands, single-step running commands, variable viewing commands, memory viewing commands, and register viewing commands.
4. The simulation debugging system of the 51 single-chip microcomputer simulator with dual threads according to claim 3 is characterized in that: The breakpoint command is: break+instruction address; The memory viewing command is: readmemory+memory address; The register viewing command is: regvalues.
5. The simulation debugging system of the 51 single-chip microcomputer simulator with dual threads according to claim 3 is characterized in that: The debugging functions correspond to the debugging commands one by one, including but not limited to: a breakpoint function, a single-step running function, a variable viewing function, a memory viewing function, and a register viewing function.
6. The simulation debugging system of the 51 single-chip microcomputer simulator with dual threads according to claim 1, characterized in that: The simulator configures the program counter PC and nPC values in the "fetch instruction" phase of the 51 single-chip microcomputer program, which are used to indicate the address locations of the current instruction and the next instruction of the 51 single-chip microcomputer program in the main memory, respectively. The check program is used to check whether the address of the current instruction will trigger a breakpoint or whether there is a manually input interrupt signal.
7. The simulation debugging system of the 51 single-chip microcomputer simulator with dual threads according to claim 6, characterized in that: When the checking program checks that the current instruction address will trigger a breakpoint or whether there is a manually input interrupt signal, the main program is suspended, and the simulator feeds back the current instruction address and breakpoint information as the debugging result to the debugger.
8. The simulation debugging system of the 51 single-chip computer simulator with dual threads according to claim 7, characterized in that: The debugger encapsulates and displays the debugging result in a standard data format.
9. A simulation debugging method for a 51 single-chip microcomputer simulator with dual threads, characterized in that: A simulation debugging system for a 51 single-chip microcomputer simulator with dual threads as claimed in any one of claims 1 to 8, comprising: S1: Setting the debugging function and the checking program in the main program of the simulator, and creating the main thread and the listening thread, wherein the main thread loads and executes the 51 single-chip computer program; the listening thread establishes a TCP communication connection with the debugger; S2: the listening thread continuously listens to the TCP port, waiting for a debugging command from the debugger; S3: After receiving the debugging command, the listening thread parses the debugging command and calls the corresponding debugging function to perform the debugging operation according to the parsed structure; S4: The monitoring thread sends the debugging result to the debugger and repeats step S2.
10. The simulation debugging method of a 51 single-chip microcomputer simulator with dual threads according to claim 9, characterized in that: When the main thread in step S1 executes the 51 single-chip computer program, it also includes: S11: The main thread checks whether the current instruction address triggers a breakpoint or whether there is a manual input interrupt signal; S12: If yes, the main program is suspended, and the current instruction address and breakpoint information are sent to the debugger as the debugging result; if no, repeat step S11.
Citation Information
Patent Citations
Simulation method of emulator chip
CN101354730A
Embedded on-line emulation debugging system for microcontroller
CN101458652A
Simulation debugging method and system based on ARM inner core 51 simulator
CN106066809A
Pipelined processor and power-saving method
CN111475010A
Information processing method, information processing device and terminal equipment
CN112783556A