Code debugging method and device, equipment and medium
By generating source code that matches the compiler in the target simulation environment and setting breakpoints, pausing the simulation engine process, and attaching a debugger for real-time debugging, the problem of deep integration of C code is solved, achieving efficient source code-level debugging and problem handling.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-27
- Publication Date
- 2026-04-10
AI Technical Summary
The generated C code is difficult to integrate deeply with the compiler and debugger, making it impossible for developers to perform real-time source code-level observation, which affects problem localization and overall development efficiency.
By generating source code that matches the target compiler in the target simulation environment, setting breakpoints in the compiler, pausing the simulation engine process, and attaching a debugger for real-time debugging.
It enables real-time, source code-level step-by-step debugging, improving the efficiency of problem location and handling, and enhancing overall development efficiency.
Smart Images

Figure CN121833469A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code debugging method, apparatus, device, and medium. Background Technology
[0002] In model-based design processes, graphical modeling and simulation software (such as GCKontrol) can automatically generate C code and perform simulations based on the model, which has become an important development tool in fields such as embedded systems and control systems.
[0003] However, the generated C code is difficult to integrate deeply with the compiler's debugger (such as Visual Studio), which prevents developers from observing the code execution at the source code level in real time during simulation. When simulation behavior is abnormal, troubleshooting the C code heavily relies on indirect analysis and manual trial and error, thus affecting problem-solving efficiency and further reducing overall development efficiency. Summary of the Invention
[0004] To address the aforementioned issues, this application provides a code debugging method, apparatus, device, and medium that can improve the efficiency of problem location and problem handling, thereby enhancing overall development efficiency.
[0005] The embodiments of this application disclose the following technical solutions: In a first aspect, this application discloses a code debugging method, the method comprising: By configuring the compiler in the target simulation environment, source code that matches the target compiler is generated; Set a breakpoint at a specified location in the source code within the target compiler; Start running the simulation engine process corresponding to the target simulation environment to execute the source code, and immediately pause the running of the simulation engine process corresponding to the target simulation environment after the source code starts executing. Attach the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment; Resume running the simulation engine process corresponding to the target simulation environment, and when the process reaches the breakpoint, debug the source code using the debugger of the target compiler.
[0006] Optionally, the step of generating source code matching the target compiler by configuring the compiler in the target simulation environment includes: By selecting a target editor from the list of compilers in the target simulation environment, source code that includes debugging information and is compatible with the syntax and calling rules of the target compiler is generated.
[0007] Optionally, pausing the simulation engine process corresponding to the target simulation environment immediately after the source code begins execution includes: By using a preset instruction, the simulation engine process corresponding to the target simulation environment is paused after the simulation engine process corresponding to the target simulation environment completes initialization and before the source code begins executing the first simulation step.
[0008] Optionally, attaching the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment includes: The debugger of the target compiler is attached to the simulation engine process corresponding to the target simulation environment by performing the attach to process operation from the integrated development environment menu of the target compiler and selecting the executable file of the simulation engine process corresponding to the target simulation environment from the process list.
[0009] Optionally, before executing the simulation engine process corresponding to the target simulation environment to execute the source code, the method further includes: Reduce the simulation speed of the target simulation environment.
[0010] Secondly, this application discloses a code debugging device, the device comprising: a generation module, a setting module, a pause module, an attachment module, and a resumption module; The generation module is used to generate source code that matches the target compiler by configuring the compiler in the target simulation environment; The setting module is used to set breakpoints at specified locations in the source code of the target compiler; The pause module is used to start running the simulation engine process corresponding to the target simulation environment to execute the source code, and immediately pause the running of the simulation engine process corresponding to the target simulation environment after the source code starts executing. The additional module is used to attach the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment; The recovery module is used to restore the simulation engine process corresponding to the target simulation environment and, when the breakpoint is reached, to debug the source code through the debugger of the target compiler.
[0011] Optionally, the generation module is specifically used to: generate source code that includes debugging information and is compatible with the syntax and calling rules of the target compiler by selecting a target editor from the compiler list of the target simulation environment.
[0012] Optionally, the pause module is specifically used to: pause the running of the simulation engine process corresponding to the target simulation environment after the simulation engine process corresponding to the target simulation environment has completed initialization and before the source code starts executing the first simulation step, by means of a preset instruction.
[0013] Optionally, the additional module is specifically used to: attach the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment by performing an attach to process operation from the integrated development environment menu of the target compiler and selecting the executable file of the simulation engine process corresponding to the target simulation environment from the process list.
[0014] Optionally, the device further includes: a lowering module; The reduction module is used to reduce the simulation running speed of the target simulation environment.
[0015] Thirdly, this application discloses a code debugging device, the device comprising: a memory and a processor; The memory is used to store programs; The processor is used to execute the program and implement the various steps of the code debugging method as described in the first aspect.
[0016] Fourthly, this application discloses a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the various steps of the code debugging method as described in the first aspect.
[0017] Compared with the prior art, this application has the following beneficial effects: This application discloses a code debugging method, apparatus, device, and medium. The code debugging method includes: configuring a compiler in a target simulation environment to generate source code matching the target compiler; setting breakpoints at specified locations in the source code within the target compiler; starting the execution of the simulation engine process corresponding to the target simulation environment to execute the source code, and immediately pausing the execution of the simulation engine process after the source code execution begins; attaching the debugger of the target compiler to the simulation engine process; resuming the execution of the simulation engine process, and debugging the source code using the debugger of the target compiler when the breakpoint is reached. Therefore, this code debugging method integrates the target simulation environment with the debugger of the target compiler, enabling real-time, source-code-level step-by-step debugging by directly calling the debugger during simulation execution. Furthermore, developers can set breakpoints at specified locations in the source code within the target compiler, and when the breakpoint is reached, directly debug the source code using the debugger of the target compiler, thereby improving the efficiency of problem location and handling, and ultimately improving overall development efficiency. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A flowchart illustrating a code debugging method provided in an embodiment of this application; Figure 2 A schematic diagram of a code debugging device provided in an embodiment of this application; Figure 3 This is a schematic diagram of a computer-readable medium provided in an embodiment of this application. Detailed Implementation
[0020] As described earlier, the generated C code is difficult to integrate deeply with the compiler's debugger (such as Visual Studio), which prevents developers from observing the code execution at the source code level in real time during simulation. When simulation behavior is abnormal, troubleshooting the C code heavily relies on indirect analysis and manual trial and error, thus affecting problem-solving efficiency and further reducing overall development efficiency.
[0021] Through research, the inventors have proposed a code debugging method, apparatus, device, and medium. This code debugging method integrates the target simulation environment with the target compiler's debugger, enabling real-time, source-code-level step-by-step debugging by directly invoking the target compiler's debugger during simulation execution. Furthermore, developers can set breakpoints at specified locations in the source code within the target compiler. When a breakpoint is reached, the source code can be directly debugged using the target compiler's debugger, thereby improving the efficiency of problem localization and handling, and ultimately enhancing overall development efficiency.
[0022] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0023] See Figure 1 The figure is a flowchart of a code debugging method provided in an embodiment of this application. The code debugging method includes: S101: Generate source code that matches the target compiler by configuring the compiler in the target simulation environment.
[0024] The target simulation environment refers to graphical modeling and simulation software, such as the GCCornrol simulation engine. The target compiler refers to the integrated development environment (IDE), such as Visual Studio 2015.
[0025] After completing the graphical modeling in the target simulation environment, the target editor is selected from the list of compilers in the target simulation environment to generate source code that is compatible with the target compiler's syntax rules (such as the C language syntax standard) and calling rules (such as __cdecl, __stdcall), including debugging information (such as .pdb files).
[0026] Understandably, the source code is fully compatible with the target compiler, can be opened directly in the target compiler, and supports breakpoint setting and symbol debugging.
[0027] S102: Sets a breakpoint at a specified location in the source code of the target compiler.
[0028] You can drag the source code file directly into the target compiler's window, or open the source code file through the target compiler's file menu, to display the source code in the target compiler's editing window with highlighted syntax. Then, you can set breakpoints at specified locations in the source code within the target compiler's editing window.
[0029] The specified location in the source code refers to the line of code that needs to be observed or debugged, and the choice of this line of code depends entirely on the debugging purpose. For example, a line of code can be a logical starting point, such as the entry point of the main function or a key sub-function, used to observe the initial state of the program; a line of code can be a control flow critical point, such as before the entry point of a loop statement (e.g., for, while), used to track changes in variables in each iteration; a line of code can be a conditional branch point, such as before conditional statements (e.g., if, switch), used to verify whether the program enters the expected branch; a line of code can be a data manipulation point, such as before statements that assign values to important variables, perform calculations, or call functions, used to check whether the input and output values meet expectations; a line of code can be a point of suspected anomaly, such as near a potentially erroneous code segment inferred from abnormal simulation behavior. Specifically, you can click the mouse in the left edge area of the line number of the specified line of code in the source code; when a prominent red dot appears, it indicates that the breakpoint has been successfully set.
[0030] Understandably, breakpoint information is maintained by the target compiler. Once the target simulation engine reaches a breakpoint in the source code, the target compiler's debugger will immediately take over control, pausing the entire process.
[0031] S103: Start running the simulation engine process corresponding to the target simulation environment to execute the source code, and immediately pause the running of the simulation engine process corresponding to the target simulation environment after the source code starts executing.
[0032] In the graphical interface of the target simulation environment, the simulation command is initiated by clicking the "Start Simulation" or "Run" button. This simulation command will trigger the initialization of the target simulation environment and start running its corresponding simulation engine process (such as the QSimEngine.exe process) to execute the source code.
[0033] Furthermore, to facilitate the subsequent attachment of the target compiler's debugger, it is necessary to pause the execution of the target simulation environment's simulation engine process after the target simulation environment's simulation engine process has completed initialization and before the source code begins executing the first simulation step (i.e., before the first model step function is called) by using preset instructions (such as DebugBreak() or __asm int 3).
[0034] Understandably, pausing the simulation engine process corresponding to the target simulation environment can avoid timing issues or even crashes caused by attaching the target compiler's debugger to the simulation engine process during dynamic execution. Furthermore, pausing the simulation engine process before the source code begins executing the first simulation step allows execution to resume from the absolute starting point, ensuring that no initial state observations are missed.
[0035] In one specific implementation, the simulation speed of the target simulation environment can be reduced first (e.g., by increasing the simulation step size in simulation settings, or by enabling "slow simulation" mode), and then the simulation engine process corresponding to the target simulation environment can be run to execute the source code. This reduces the rate of process state changes, allowing for more flexibility in the debugger's commands and responses, thereby improving the overall controllability and stability of the subsequent debugging process.
[0036] S104: Attach the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment.
[0037] By executing the "Attach to Process" operation from the target compiler's integrated development environment (IDE) menu, and selecting the executable file of the simulation engine process corresponding to the target simulation environment from the process list, the target compiler's debugger is attached to the simulation engine process corresponding to the target simulation environment. Understandably, at this point, the target compiler's debugger can receive and process all debugging events it issues (such as breakpoint exceptions, thread creation / exit, etc.).
[0038] S105: Resume the simulation engine process corresponding to the target simulation environment and debug the source code through the target compiler's debugger when the process reaches a breakpoint.
[0039] In the debugging interface of the target compiler, click the "Continue" button or press F5 to resume the simulation engine process corresponding to the target simulation environment. The simulation engine process corresponding to the target simulation environment will then exit from the paused state at step S103 or the previous breakpoint and continue its main simulation loop, executing the source code normally. When the next breakpoint set in the source code is reached, the simulation engine process corresponding to the target simulation environment will automatically pause. At this time, developers can intuitively view all variable values, call stacks, memory states, etc. at the time of the pause, achieving true source code-level, real-time interactive debugging, which greatly improves the efficiency of locating specific code defects from simulation anomalies.
[0040] In summary, this application discloses a code debugging method that integrates the target simulation environment with the target compiler's debugger, enabling real-time, source-code-level step-by-step debugging by directly invoking the target compiler's debugger during simulation execution. Furthermore, developers can set breakpoints at specified locations in the source code within the target compiler; when a breakpoint is reached, the source code can be directly debugged using the target compiler's debugger, thereby improving problem location and resolution efficiency, and ultimately enhancing overall development efficiency.
[0041] See Figure 2 The figure is a schematic diagram of a code debugging device provided in an embodiment of this application. The code debugging device 200 includes: a generation module 201, a setting module 202, a pause module 203, an attachment module 204, and a resumption module 205.
[0042] The generation module 201 is used to generate source code that matches the target compiler by configuring the compiler in the target simulation environment; Module 202 is configured to set breakpoints at specified locations in the source code of the target compiler. The pause module 203 is used to start running the simulation engine process corresponding to the target simulation environment to execute the source code, and to immediately pause the running of the simulation engine process corresponding to the target simulation environment after the source code starts executing. Additional module 204 is used to attach the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment; Recovery module 205 is used to restore the simulation engine process corresponding to the target simulation environment and debug the source code through the target compiler's debugger when the execution reaches a breakpoint.
[0043] In one specific implementation, the generation module 201 is specifically used to: generate source code that includes debugging information and is compatible with the syntax and calling rules of the target compiler by selecting a target editor from the list of compilers of the target simulation environment.
[0044] In one specific implementation, the pause module 203 is specifically used to: pause the running of the simulation engine process corresponding to the target simulation environment after the simulation engine process corresponding to the target simulation environment has completed initialization and before the source code starts executing the first simulation step, by means of a preset instruction.
[0045] In one specific implementation, the adder module 204 is specifically used to: attach the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment by performing an attach to process operation from the integrated development environment menu of the target compiler and selecting the executable file of the simulation engine process corresponding to the target simulation environment from the process list.
[0046] In one specific implementation, the code debugging device 200 further includes: a reduction module; the reduction module is used to reduce the simulation running speed of the target simulation environment.
[0047] In summary, this application discloses a code debugging device that integrates the target simulation environment with the debugger of the target compiler. This device enables real-time, source-code-level step-by-step debugging by directly invoking the debugger during simulation execution. Furthermore, developers can set breakpoints at specified locations in the source code within the target compiler. When a breakpoint is reached, the source code can be debugged directly using the target compiler's debugger, thereby improving problem location and resolution efficiency, and ultimately enhancing overall development efficiency.
[0048] This application also provides corresponding code debugging equipment and computer-readable media for implementing the code debugging method provided in this application.
[0049] The code debugging device includes a memory and a processor. The memory is used to store instructions or code, and the processor is used to execute the instructions or code so that the device performs a code debugging method according to any embodiment of this application.
[0050] See Figure 3 This figure is a schematic diagram of a computer-readable medium provided in an embodiment of this application. The computer-readable medium 300 stores a computer program 311, which, when executed by a processor, implements the above-described... Figure 1 The steps for debugging code.
[0051] It should be noted that, in the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0052] It should be noted that the machine-readable medium described above in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0053] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0054] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
[0055] While several specific implementation details are included in the foregoing discussion, these should not be construed as limiting the scope of this application. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0056] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A method of debugging code, characterized by, The method comprises: generating source code matched with a target compiler by performing compiler configuration in a target simulation environment; setting a breakpoint at a specified position of the source code in the target compiler; starting to run a simulation engine process corresponding to the target simulation environment to execute the source code, and pausing the running of the simulation engine process corresponding to the target simulation environment immediately after the source code starts to execute; attaching a debugger of the target compiler to the simulation engine process corresponding to the target simulation environment; resuming the running of the simulation engine process corresponding to the target simulation environment, and debugging the source code by the debugger of the target compiler when running to the breakpoint.
2. The method of claim 1, wherein, The generating source code matched with a target compiler by performing compiler configuration in a target simulation environment comprises: generating source code compatible with syntax rules and calling rules of the target compiler and including debugging information by selecting a target editor from a compiler list of the target simulation environment.
3. The method of claim 1, wherein, The pausing the running of the simulation engine process corresponding to the target simulation environment immediately after the source code starts to execute comprises: pausing the running of the simulation engine process corresponding to the target simulation environment by a preset instruction after the simulation engine process corresponding to the target simulation environment completes initialization and before the source code starts to execute a first simulation step.
4. The method of claim 1, wherein, The attaching a debugger of the target compiler to the simulation engine process corresponding to the target simulation environment comprises: attaching the debugger of the target compiler to the simulation engine process corresponding to the target simulation environment by performing an attaching-to-process operation in an integrated development environment menu of the target compiler and selecting an executable file of the simulation engine process corresponding to the target simulation environment from a process list.
5. The method of claim 1, wherein, Before the starting to run a simulation engine process corresponding to the target simulation environment to execute the source code, the method further comprises: lowering a simulation running speed of the target simulation environment.
6. A code debugging apparatus characterized by comprising: The apparatus comprises a generating module, a setting module, a pausing module, an attaching module and a resuming module. The generating module is configured to generate source code matched with a target compiler by performing compiler configuration in a target simulation environment. The setting module is configured to set a breakpoint at a specified position of the source code in the target compiler. The pausing module is configured to start to run a simulation engine process corresponding to the target simulation environment to execute the source code, and pause the running of the simulation engine process corresponding to the target simulation environment immediately after the source code starts to execute. The attaching module is configured to attach a debugger of the target compiler to the simulation engine process corresponding to the target simulation environment. The resuming module is configured to resume the running of the simulation engine process corresponding to the target simulation environment, and debug the source code by the debugger of the target compiler when running to the breakpoint.
7. The apparatus of claim 6, wherein, The generating module is specifically configured to generate source code compatible with syntax rules and calling rules of the target compiler and including debugging information by selecting a target editor from a compiler list of the target simulation environment.
8. The apparatus of claim 6, wherein, The pausing module is specifically configured to pause running of the simulation engine process corresponding to the target simulation environment through a preset instruction after the simulation engine process corresponding to the target simulation environment completes initialization and before the source code starts to execute a first simulation step.
9. A code debugging device characterized by comprising: The device comprises a memory and a processor; The memory is configured to store a program; The processor is configured to execute the program to implement each step of the code debugging method according to any one of claims 1 to 5.
10. A computer readable medium having stored thereon a computer program, characterized in that, The computer program, when executed by a processor, implements each step of the code debugging method according to any one of claims 1 to 5.