Debugging method for heterogeneous architecture
By uniformly handling debugging commands, managing symbol tables and dynamically setting breakpoints, the problem of frequent switching in heterogeneous program debugging is solved, and efficient heterogeneous debugger performance optimization and cross-platform compatibility is achieved.
Patent Information
- Application Number
- CN202510368295.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-26
- Publication Date
- 2025-07-11
AI Technical Summary
When debugging heterogeneous executable programs in traditional way, users need to frequently switch between the host and device debuggers, resulting in inadequate debugging efficiency.
Design a heterogeneous debugging method, which realizes heterogeneous program debugging under the same debug window by uniformly processing debugging commands, managing symbol tables, dynamically setting breakpoints, and identifying the device architecture.
It realizes automatic switching between the host and device side, improves debugging efficiency, optimizes debugger performance, ensures response speed and stability, and provides cross-platform compatibility.
Smart Images

Figure CN120295895A_ABST
Abstract
Description
Technical Field
[0001] The present invention mainly relates to the technical field of program debugging, and specifically discloses a debugging method for heterogeneous architectures. Background Art
[0002] A heterogeneous debugger is a debugger for debugging heterogeneous executable programs. Heterogeneous executable programs contain host code and device code, and the host code and device code are codes of different platform architectures. The traditional method for debugging heterogeneous executable programs is to use the host-side debugger and the device-side debugger to debug the heterogeneous program separately. This debugging method is relatively cumbersome for users. When there are many kernel function calls in the heterogeneous executable program, the user needs to frequently switch between the host-side debugger and the device-side debugger, reducing the user's debugging efficiency.
[0003] In order to improve the user's debugging efficiency, a debugging method for heterogeneous architectures needs to be designed to realize the automatic switching between the host-side debugger and the device-side debugger. Summary of the Invention
[0004] The purpose of the present invention is to provide a debugging method for heterogeneous architectures, which realizes the debugging of the same heterogeneous executable program in the same debugging window through means such as unified processing and distribution of debugging commands, unified management of symbol tables, dynamic setting and management of breakpoints, device architecture identification, and register information parsing.
[0005] To achieve the above purpose, the present invention provides a debugging method for heterogeneous architectures, including:
[0006] In the heterogeneous debugger, a set of basic debugging structures applicable to both the host and device sides is defined, and on this basis, the following contents are included:
[0007] S1. In the data structures involved in the basic structure of the heterogeneous debugger, a field is set to distinguish whether the current structure belongs to the host side or the device side;
[0008] S2. When the device is connected, the heterogeneous debugger parses the device architecture information to obtain information such as the registers of the device;
[0009] S3. In the heterogeneous debugger, two targets, namely the host and the device, are set, and debugging commands for the device side or the host side are set based on keywords;
[0010] S4. When the device is connected, symbol tables for the host side and the device side are constructed;
[0011] S5. In the breakpoint command, keywords are used to mark whether the breakpoint is set in the host program or the device program;
[0012] S6. Define a unified interface that is adapted to the relevant codes of all possible access devices, and enable different accessed devices to implement this interface.
[0013] Further, the length of the field in S1 is 1 bit. If the value is 1, it is device data; otherwise, it is host data.
[0014] Further, in S1, when debugging a device, a specific keyword needs to be added before the corresponding debug command for differentiation. If no keyword is added, it is defaulted to a host debug command.
[0015] Further, S4 includes that when the heterogeneous debugger starts, it registers a device event listener with the driver, and then loads the heterogeneous executable program. At this time, it will first identify the host code in the heterogeneous executable program and build a host symbol table. When the user clicks to run, the heterogeneous debugger receives a symbol loading event. At this time, it calls the driver interface to obtain the device code, and then performs code device symbol processing to obtain a device symbol table.
[0016] Further, S5 includes that the heterogeneous debugger receives a host-side debug command or a device-side debug command, and sets breakpoints at the specified positions in the program. The breakpoints are specified by address, symbol, or file plus line number.
[0017] When setting breakpoints:
[0018] If it is an address breakpoint, the heterogeneous debugger differentiates whether it is a host or device address through the keyword in the breakpoint setting command, and thus sets the corresponding breakpoint.
[0019] If it is a file plus line number breakpoint, the heterogeneous debugger differentiates whether it is a file in the host program or the device program through the keyword in the breakpoint setting command, and thus sets the corresponding breakpoint.
[0020] If it is a symbol breakpoint, the heterogeneous debugger will traverse all the current host symbol tables and device symbol tables, and thus resolve whether the breakpoint should be set on the host or the device.
[0021] The present invention proposes a heterogeneous architecture debugging method. First, the unified processing and distribution of debugging commands are realized through keyword hint technology; second, the unified management of symbol tables is completed; third, the dynamic setting and management of breakpoints are completed according to breakpoint keywords; fourth, the identification of device architectures and the parsing of register information are realized based on state recognition and data stream interaction technology; fifth, the performance optimization of the debugger is realized through debugging task reuse and memory optimization; finally, cross-platform compatibility is realized through a unified device debugging interface method. The proposed heterogeneous architecture debugging method combines host-side debugging and device-side debuggers, enabling users to debug the same heterogeneous executable program in the same debugging window. By using extended heterogeneous debugger front-end commands, the heterogeneous debugger can automatically identify whether the debugging target is a host or a device, thus debugging the same heterogeneous executable program in the same debugging window. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is the architecture diagram of the heterogeneous debugger in the embodiment of the present invention.
[0023] Figure 2 It is the schematic diagram of the debugging command distribution of the heterogeneous debugger in the embodiment of the present invention;
[0024] Figure 3 It is the schematic diagram of the Target processing of the heterogeneous debugger in the embodiment of the present invention;
[0025] Figure 4 It is the schematic diagram of the Arch processing of the heterogeneous debugger in the embodiment of the present invention;
[0026] Figure 5 It is the schematic diagram of the symbol processing of the heterogeneous debugger in the embodiment of the present invention;
[0027] Figure 6 It is the schematic diagram of the breakpoint processing of the heterogeneous debugger in the embodiment of the present invention;
[0028] Figure 7 It is the schematic diagram of the interface setting of the heterogeneous debugger in the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0029] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the embodiments of the present invention and the accompanying drawings.
[0030] In the embodiment of the present invention, based on the technical solution of the present invention, a heterogeneous debugger capable of simultaneously processing the debugging tasks of the host and the device in the same debugging window is realized. The logical framework of the heterogeneous debugger is basically as Figure 1 shown. The implementation processes of the functions in each aspect in the figure will be introduced below.
[0031] First, handling the debugging tasks of both the host and the device simultaneously in the same debugging window may increase the load on the debugger, especially when debugging large-scale heterogeneous programs. The difficulty lies in how to optimize the performance of the debugger, ensure the response speed and stability during the debugging process, and avoid performance degradation caused by frequent context switching or processing a large amount of debugging information.
[0032] Therefore, in the heterogeneous debugger in this example, only one set of the same debugging infrastructure is defined for the host and the device, rather than one set for each of the host and device sides; at this time, there are fields in these infrastructures to distinguish whether the current structure belongs to the host side or the device side. For example, in the breakpoint location structure, there is a field named device_breakpoint specifically used to distinguish the current breakpoint. If the value is 1, it is a device breakpoint; otherwise, it is a host breakpoint.
[0033] Supporting the debugging commands of both the host side and the device side simultaneously in the same debugging window requires designing an efficient command distribution mechanism. The difficulty lies in how to accurately distinguish the debugging commands of the host side and the device side and ensure that these commands can be correctly passed to the corresponding back-end for processing. Especially when the host and the device use different instruction set architectures, the command parsing and distribution logic will be more complex.
[0034] As Figure 2 shown, the heterogeneous debugger in this example distinguishes between host debugging commands and device debugging commands by the type of debugging commands. When debugging the device, the keyword "device" needs to be added before the corresponding debugging command for distinction. By using the keyword "device", it is possible to obtain whether the current focus is on the host side or the device side, and then call different architectures of the back-end to achieve debugging support for heterogeneous architectures. For example, when viewing the register information of the device side, enter the command "device i r" in the command line window to view all the register information visible to the user on the device side. For host-side debugging commands, the keyword "device" does not need to be added.
[0035] Therefore, as Figure 3 shown, the Target of the heterogeneous debugger includes two targets: the host and the device; the heterogeneous debugger will dispatch the target operation commands input by the user at the front-end to the internal for processing, so as to control the running operations of the two targets of the host and the device, such as sending commands like single-step, run, pause, etc. to the host side or the device side for processing.
[0036] A heterogeneous executable program contains host code and device code, and the symbol information of both may come from different compilers and platforms. The difficulty lies in how to efficiently load, parse, and manage this symbol information, and be able to quickly locate the symbols of the host and device code during the debugging process. Especially when frequently switching contexts during debugging, the synchronization and update of the symbol table need to be efficiently processed.
[0037] As Figure 4 shown, when the heterogeneous debugger in this example starts, it registers a device event listener with the driver, and then loads the heterogeneous executable program. At this time, it will first identify the host code in the heterogeneous executable program and build a host symbol table; when the user clicks to run, the heterogeneous debugger receives a symbol loading event. At this time, it calls the driver interface to obtain the device code, and then performs code device symbol processing.
[0038] On the other hand, the architecture on the device side may be completely different from that on the host side, and there may be differences in the registers, pointer sizes, data types, etc. of different devices. The difficulty lies in how to dynamically identify the device architecture and correctly parse the register information and other hardware-related information of the device to ensure that the debugger can accurately display the state of the device.
[0039] As Figure 5 shown, in the Arch processing of the heterogeneous debugger in this example, the processing of the host architecture and the device architecture is added. Based on the state recognition and data flow interaction technology, the heterogeneous debugger can identify the registers of the host and the device, as well as architecture-related information such as pointers and int lengths on the device; according to different Arch information, the heterogeneous debugger will display different register names, addresses, and other information.
[0040] In a heterogeneous architecture, the breakpoint setting mechanisms for the host and device code may be completely different. The difficulty lies in how to dynamically set breakpoints in the host program or device program according to the debugging command, and ensure that the triggering and execution of the breakpoints can be seamlessly connected. Especially in the device-side code, setting breakpoints may involve hardware support or specific debugging interfaces, increasing the complexity of implementation.
[0041] As Figure 6As shown, the heterogeneous debugger in this example receives a host - side debugging command or a device - side debugging command, and sets breakpoints at specified positions in the program according to the debugging command. Breakpoints are usually specified by address, symbol, or file plus line number. When setting breakpoints, if it is an address breakpoint, the heterogeneous debugger distinguishes whether it is a host or a device address through keywords in the breakpoint - setting command, and thus sets the corresponding breakpoint; if it is a file - plus - line - number breakpoint, the heterogeneous debugger distinguishes whether it is a file in the host program or the device program through keywords in the breakpoint - setting command, and thus sets the corresponding breakpoint; if it is a symbol breakpoint, the heterogeneous debugger will traverse all current host symbol tables and device symbol tables to resolve whether the breakpoint should be set on the host or the device.
[0042] For example, let "b" be the breakpoint - setting command, there are:
[0043] "b*0x12345" is to set the host - address breakpoint "0x12345", and "device b*0x23456" is to set the device - address breakpoint "0x22345";
[0044] "b host_function_name" is to set the symbol breakpoint "host_function_name";
[0045] "b file_name:12" is to set the host - line - number breakpoint "ile_name:12", and "device b file_name:13" is to set the device - line - number breakpoint "file_name:13";
[0046] Heterogeneous architectures usually involve multiple operating systems and hardware platforms, and the debugger needs to have good cross - platform compatibility. The difficulty lies in how to implement a unified debugging interface between different platforms and ensure that the debugger can run stably in various environments.
[0047] In this example, as Figure 7 shown, set unified interfaces such as initialize, finalize, run, step, stop, readReg, writeReg, readMemory, writeMemory, etc. for any connected device. Different devices only need to implement this interface and then register as the current device. At this time, the front - end operations of the heterogeneous debugger do not need to make any changes, and a new device can be debugged in the heterogeneous debugger.
[0048] The above are only the preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions falling within the concept of the present invention belong to the protection scope of the present invention. It should be noted that for those of ordinary skill in the art, several improvements and refinements made without departing from the principle of the present invention should be regarded as within the protection scope of the present invention.
Claims
1. A debugging method for a heterogeneous architecture, comprising: In a heterogeneous debugger, a set of basic debugging structures applicable to both the host and device sides are defined. Specifically, it includes the following: S1. In the data structures involved in the basic structure of the heterogeneous debugger, a field is set to distinguish whether the current structure belongs to the host side or the device side. S2. When a device is connected, the heterogeneous debugger parses the device architecture information to obtain information such as the device's registers. S3. In the heterogeneous debugger, two targets, namely the host and the device, are set, and debugging commands for the device side or the host side are distinguished based on keywords. S4. When a device is connected, symbol tables for the host side and the device side are constructed. S5. In the breakpoint command, keywords are used to mark whether the breakpoint is set in the host program or the device program. S6. A unified interface compatible with the relevant codes of the devices that may be connected is defined, and different connected devices all implement this interface.
2. The method according to claim 1, wherein The length of the field in S1 is 1 bit. If the value of this field is 1, it is device data; otherwise, it is host data.
3. The method according to claim 1, wherein S1 includes that when debugging a device, a specific keyword needs to be added before the corresponding debugging command for distinction. If no keyword is added, it is defaulted to a host debugging command.
4. The method according to claim 1, wherein S4 includes that when the heterogeneous debugger starts, it registers a device event listener with the driver, and then loads the heterogeneous executable program. At this time, it will first identify the host code in the heterogeneous executable program and construct the host symbol table. When the user clicks to run, the heterogeneous debugger receives a symbol loading event. At this time, it calls the driver interface to obtain the device code, and then performs device symbol processing to obtain the device symbol table.