Method and system for tracking target variables in an executable program
By reading the description information of the target variable, it can effectively track the target variables in the executable program, solving the problems of large amount of data and complex user operations in traditional methods, simplifying user operations and reducing performance overhead.
Patent Information
- Application Number
- CN202110817103.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-20
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2041-07-20
AI Technical Summary
In complex operating systems, the amount of data collected by traditional processor tracking modules is too large, resulting in a large performance overhead of analysis software, and users need a comprehensive and profound understanding of the code to track changes in target variables. This method Invasive and inconvenient.
By reading the description information of the target variable, obtaining the base address and address offset of the area to which it belongs, determining the actual address of the target variable, and reading its data changes from the actual address, including reading the data and instruction flow information of the target variable. Implements tracking of target variables in executable programs without the need for user to add debug statements or source code support.
It realizes efficient tracking of target variables when executable programs are executed, reduces performance overhead, and simplifies user operations, and can track any target variable without a deep understanding of the code.
Smart Images

Figure CN113672499B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to operating system flow domains, and more particularly, to a method and system for tracing target variables in an executable program. Background Art
[0002] The traditional processor trace module collects data about program flow, memory read / write, and bus events. In more complex operating systems such as Linux, some task structures with complex structures are often defined, and then some dynamically generated buffers, locks, state machines, configurations, and other data are placed in this structure. The traditional processor / bus trace module can be used to trace this structure during program execution.
[0003] However, the processor tracking module will collect a large amount of data (tens of MB to GB). Due to the large amount of data, the performance overhead of the analysis software to process the data is large. In addition, in order to obtain the required data in the received data, the user needs to have a comprehensive and deep understanding of the code. For example, if a process lock state error or scheduling error is found, and you want to view the changes of each lock when the process is running, you need to have a comprehensive and deep understanding of all lock definitions and lock access codes in the code, and insert debugging statements before and after the lock access code. However, this intrusive code insertion requires too much from the user and is not convenient.
[0004] Therefore, it is necessary to provide a simpler technical solution for tracking target variables during program execution. Summary of the invention
[0005] In view of this, an object of the present disclosure is to provide a method and system for tracking target variables in an executable program, so as to make it more convenient for users to track changes in target variables when the executable program is executed.
[0006] In a first aspect, an embodiment of the present disclosure provides a method for tracking a target variable in an executable program, comprising:
[0007] Reading description information, the description information identifies a source for obtaining a base address of a region to which the target variable belongs and an address offset of the target variable in the region to which the target variable belongs;
[0008] Using the process identifier of the executable program, obtaining the base address of the region to which the target variable belongs from the acquisition source identified by the description information;
[0009] Determining the actual address of the target variable according to the base address and the address offset; and
[0010] The target variable is read from the actual address.
[0011] Optionally, reading the target variable includes: reading data of the target variable and collecting instruction flow information that causes changes in the data.
[0012] Optionally, the acquisition source specifies whether to obtain the base address of the area to which the target variable belongs from a process register or from a specified memory.
[0013] Optionally, the description information further specifies whether a next-level address exists and whether the next-level address is to be tracked, and the reading of the target variable includes:
[0014] When a next-level address exists and tracking of the next-level address is specified, the next-level address is read from the actual address, and the target variable is read from the next-level address.
[0015] Optionally, the base address is a base address of a process space of the executable program or a base address of a specific area in the process space of the executable program.
[0016] Optionally, the method further includes: loading and parsing the executable program to construct the description information.
[0017] Optionally, the method further includes: determining the target variable according to a user instruction.
[0018] Optionally, the loading and parsing the executable program to obtain description information of the target variable includes:
[0019] Determine the function path to which the target variable belongs;
[0020] Determine the data type definition to which the target variable belongs;
[0021] The description information is constructed according to the function path and data type definition.
[0022] Optionally, if the data type to which the target variable belongs is defined as a multi-level data structure, the address offset of each level passed through to reach the target variable is calculated according to the multi-level data structure and the address offset of each level passed through to reach the target variable is accumulated to obtain the address offset of the target variable in the area to which it belongs.
[0023] Optionally, the data type of the target variable includes: numeric type, character type, data structure, class, pointer to data structure or class.
[0024] In a second aspect, an embodiment of the present disclosure provides a system for tracing a target variable in an executable program, including: an analysis module of a software part and a processor tracing module executed by hardware, wherein the analysis module includes:
[0025] Loading and parsing the executable program to obtain description information of the target variable;
[0026] The description information is stored in a designated register of the processor tracking module, wherein the description information identifies a source of obtaining a base address of a region to which the target variable belongs and an address offset of the target variable in the region to which the target variable belongs, and the region to which the target variable belongs is located in the process space of the executable program;
[0027] The processor tracking module includes:
[0028] Read the description information in the specified register;
[0029] Using the process identifier of the executable program, obtaining the base address of the region to which the target variable belongs from the acquisition source identified by the description information;
[0030] Determining the actual address of the target variable according to the base address and the address offset; and
[0031] The target variable is read from the actual address.
[0032] Optionally, the acquisition source specifies whether to obtain the base address of the area to which the target variable belongs from a process register or from a specified memory.
[0033] In a third aspect, an embodiment of the present disclosure provides a computing device, including:
[0034] A processing unit, configured to execute an executable program and store description information of a target variable in the executable program in a designated register of the processor tracking module, wherein the description information describes a source of obtaining a base address of a region to which the target variable belongs and an address offset of the target variable in the region to which the target variable belongs, and the region to which the target variable belongs is located in a process space of the executable program;
[0035] A processor tracking module is used to read the description information in the specified register; use the process identifier of the executable program to obtain the base address of the area to which the target variable belongs from the acquisition source identified by the description information; determine the actual address of the target variable based on the base address and the address offset; and read the target variable from the actual address.
[0036] In summary, the method and system provided by the embodiments of the present disclosure determine the actual address of the target variable in the process space of the executable program through the address offset of the target variable, and track the data changes at the address without the need for the user to add debugging statements or source code support, and can track any target variable in the executable program. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The above and other objects, features and advantages of the present disclosure will become more apparent through the description of the embodiments of the present disclosure with reference to the following drawings, in which:
[0038] Figure 1 is a schematic diagram of the structure of a system provided by an embodiment of the present disclosure;
[0039] Figure 2 Shown is a simple example of access path information implementation;
[0040] Figure 3 It is a flowchart of the method provided by the embodiment of the present disclosure.
[0041] Figure 4 is a schematic diagram of the structure of a general computer system used in an embodiment of the present disclosure;
[0042] Figure 5 It is a schematic diagram of the structure of an embedded system applied in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0043] The present disclosure is described below based on embodiments, but the present disclosure is not limited to these embodiments. In the detailed description of the present disclosure below, some specific details are described in detail. It is possible for a person skilled in the art to fully understand the present disclosure without the description of these details. In order to avoid confusing the essence of the present disclosure, well-known methods, processes, and procedures are not described in detail. In addition, the drawings are not necessarily drawn to scale.
[0044] Before introducing various embodiments of the present disclosure, some terms or concepts used in the present disclosure are explained and clarified.
[0045] Data tracing (trace): The processor outputs data to the encoder through the pin. The encoder encodes the data, adds a header and compresses it according to a certain format. After compression, it is output to the host computer or analysis software through the memory or external interface. The analysis software reconstructs the data according to the running program and the trace package, and restores the complete process of program operation, including program flow changes, data access, etc.
[0046] Lock: When operating in multiple threads, the lock mechanism is used to ensure that internal resources are mutually exclusive when accessed, and no two threads access the same variable at the same time. Each thread attempts to lock the resource before operating it. It can only operate after the lock is successfully acquired, and unlocks the resource after the operation is completed. This avoids logical errors caused by simultaneous modifications.
[0047] Instruction pipeline, the instruction pipeline is to improve the efficiency of the processor to execute instructions, divide the operation of an instruction into multiple small steps, and each step is completed by a dedicated circuit. The current mainstream instruction pipeline technologies include three-level, four-level, five-level, seven-level and super instruction pipelines, etc. For example, the five-level instruction pipeline in the textbook example includes instruction fetch, decoding, execution, memory access and write back.
[0048] Pointer register: Different instruction sets use different registers to store process-related address information, so when the present invention is disclosed, the corresponding register needs to be selected according to the instruction set. For example, in RISC-V, fp is used as the top register of the stack, and sp is used to obtain data in the stack.
[0049] System for implementing the present invention
[0050] Figure 1 1 is a schematic diagram of the structure of the system 100 for implementing the present invention. Figure 1 As shown, the system 100 includes a hardware part 101. The hardware part 101 includes coupling various components and a processing unit 106 together based on a bus 102. According to the requirements of the software and hardware structure, the bus 102 can be various types of buses. For example, it is an AXI bus, an OCP (Open Core Protocol) bus protocol, or a dedicated bus independently developed in a specific field. In addition, the bus structure may or may not include a bridging unit such as an AHB / APB bridge. The AXI bus is the most important part of the AMBA (Advanced MicrocontrollerBus Architecture) 3.0 and above protocols proposed by ARM. It is an on-chip bus oriented to high performance, high bandwidth, and low latency.
[0051] The high-speed memory 103 and the input-output interface 104 are coupled to the processing unit 106 via the bus 102. The high-speed memory 103 is, for example, a random access memory and / or a read-only memory, for example, the high-speed memory 103 is a static random access memory (SRAM) or a DRAM (dynamic random access memory). The interface 104 is used to perform data conversion and transmission between the system 101 and the external device 111. The external device 111 can be some input-output devices or storage devices. The hardware part 101 can also include a DMA controller for directly accessing an external storage device.
[0052] The system 100 also includes a software part. As shown in the figure, the software part shows an operating system kernel 121 and an application AN. When the system is running, the operating system kernel 121 and the application AN can be copied to the high-speed memory 104 through the interface 104, so that the processing unit 106 can read and execute program instructions from the high-speed memory 104. The operating system kernel 121 can also be hard-copied to the cache 103 (e.g., a read-only memory) before the product leaves the factory.
[0053] The processing unit 106 is also coupled to the processor tracking module 105. The processor tracking module 105 is an extension of the processor architecture, which uses dedicated hardware facilities to track the information of software execution. The processor tracking module 105 collects various information during the program running process and organizes it into a data packet output in a certain format. Since this method has only a small performance loss for the executable program being tracked, this method can be used to track the dynamically generated target structure. Specifically, the processor tracking module 105 first outputs the tracking data packet, and then the analysis software reconstructs the data packet to restore the complete process of the executable program running, including program flow changes, data access, etc., and performs data preprocessing, including information filtering, associating program flow and data access, and then obtaining the tracking information of the target structure from the preprocessed data. However, as the background technology indicates, this method causes the analysis software to require a large performance overhead and requires the user to have a comprehensive and profound understanding of the code.
[0054] In order to solve this problem, the present disclosure provides a technical solution for tracking target variables when an executable program is executed, so as to track any target variable (including but not limited to the dynamically generated structure described in the background technology) without requiring the user to have a comprehensive and profound understanding of the code.
[0055] As shown in the reference figure, the analysis program 131 is used to load and parse an executable program to obtain the description information of the target variable. The target variable can be any data type supported by the processor, which can be a single type, such as an integer, a floating point type, a character, or a string type, a pointer to an integer, a floating point type, a character, or a string data, or a composite type, such as an array, a data structure, a pointer to a data structure, a class, etc., wherein the data structure can also be a multi-level data structure, for example, in a more complex operating system such as Linux, some task structures with complex structures will be defined, and then some dynamically generated buffers, locks, state machines, configurations and other data will be placed in this structure, and the target variable can also be a certain item in the data structure, such as the lock in the above-mentioned task structure. The description information of the target variable is used to describe the address offset of the target variable based on a base address, which is usually the base address of the process space provided by the processor for the executable program, and the base address can also be the base address of a specific area (where the target variable is located) contained in the process space provided by the processor for the executable program. The description information of the target variable should also include the source of the base address, for example, the base address can be read from a specified register or a memory address. On the basis of meeting the above conditions, the description information of the target variable can be organized in any appropriate format.
[0056] In order to obtain the address offset of the target variable, it is necessary to consider the function (or class or class method) to which the target variable belongs and the data structure to which it belongs. For example, for a C / C++ program, there is a sub-function func in the main function main, and struct file*file_fp is defined in the sub-function func. When you want to track file_fp, the description information of file_fp obtained must take into account the function relationship (main->func) and the data structure definition of struct file.
[0057] The analysis program 131 sends the description information and process identifier to the control unit 1051 in the processor tracking module 105 via the driver 1211. The driver 1211 is the driver of the processor tracking module 105. The operating system kernel 121 serves as a bridge between hardware and software, including not only the driver of the processor tracking module 105, but also the drivers of other hardware such as the processing unit 106, the memory 103, and the storage, and also provides basic system services to various applications (such as the application AN). In addition, since the operating system kernel 121 maintains a process register for each process, the operating system kernel 121 can also provide the process identifier to be tracked to the control unit 1051 in the processor tracking module 105.
[0058] The control unit 1051 receives the description information and the process identifier, obtains the actual address of the target variable in the process space according to the process identifier and the description information, and obtains the data change of the target variable according to the actual address access and the instruction stream information causing the data change. The processor tracking module 105 includes: an instruction stream tracking unit 1053 and a data tracking unit 1054. The instruction stream tracking unit 1053 records the branch information in the program execution, thereby helping to construct the control flow graph during the program running process. The data tracking unit 1054 records the data changes of each memory access address.
[0059] Optionally, as shown in the figure, a trigger register 1052 is set in the control unit 1051, and the trigger register 1052 is used to store the description information of the target variable. The control unit obtains the actual address of the target variable in the process space according to the process identifier and the description information. When a data change indicated by the actual address is detected, the instruction stream tracking unit 1053 and the data tracking unit 1054 are triggered, and all operations that cause data changes are recorded and a data packet is generated and output to the analysis program 131.
[0060] After receiving the data packet, the analysis program 131 restores all operation information for the target variable and can further locate the operation record that causes the data change of the target variable. Of course, if the data packet only contains the operation record that causes the data change of the target variable, the operation record can be directly obtained.
[0061] The system provided by the embodiment of the present disclosure parses the executable program to construct description information of the target variable and transmits it to the processor tracing module. The processor tracing module collects data changes of the target variable and instruction stream information that causes the data changes of the target variable and outputs it as tracing information. The tracing information thus obtained is only about the target variable, so the tracing information obtained in this way is more targeted and can better meet user needs. Moreover, since the system does not require source code support of the executable program, it can be used to test and verify the code quality of software products that only have executable programs.
[0062] In some embodiments, the processor tracking module 105 can be configured to be turned off or on. Optionally, a register is set inside the processor tracking module 105 or the processing unit 106, and a one-bit flag is stored in the register. When the flag is, for example, 0, it indicates that the processor tracking module 105 is turned off, and the system does not generate tracking information. When the flag is, for example, 1, it indicates that the processor tracking module 105 works normally. The flag can also be associated with a register storing a process identifier. The analysis program 131 can store the process identifier to be tracked in the register, so that the processor tracking module 105 only outputs the tracking information of a specific process.
[0063] As mentioned above, the target variable can be any data type supported by the processor. The following specifically introduces several types and how to define the description information. We know that when the executable program is executed, the system will allocate a process space for it. Usually, the process space is divided into different areas according to different functions. For example, the space occupied by the executable program compiled by C / C++ is divided into: stack area, heap area, global area (static area), text constant area, and program code area. Except for the heap area, the remaining areas are allocated by the compiler during the compilation stage.
[0064] The following is a very simple C / C++ source code, and different types of data are annotated with the area they belong to.
[0065]
[0066]
[0067] Therefore, the address offsets of objects in various areas except the heap area can be obtained by parsing the executable file. For example, char*p1 and *p2 are both stored on the stack. If the compiler uses one byte to store the data types of int, char, and char*, it can be calculated that the address offset of b is 0 bytes, the address offset of s is 4 bytes, and the address offset of p1 is 8 bytes.
[0068] That is to say, the analysis module can obtain the address offset of each target variable by parsing the executable program. When the processor tracking module 105 receives the process identifier and the address offset of the target variable, it obtains the process space of the executable program or the first address of a specific area (such as a stack area) in the process space of the executable program according to the process identifier, and then calculates the actual address of the target variable according to the address offset, reads the data of the actual address, and collects the instruction stream information that causes the data change. For example, when the processor tracking module 105 tracks the data change of the string space pointed to by p1, it needs to obtain the address of the string space from the actual address, obtain the data change in the address, and collect the instruction stream information that causes the data change.
[0069] In actual engineering, the source code will not be as simple as the above example, and the target variable will be more complex. In one embodiment, a trigger register (PC trigger register) is set in the processor tracking module 105 to store the description information of the target variable. The analysis module 131 can write the description information of the target variable to the trigger register according to the address offset of each target variable in a prescribed format, or the control unit 1051 can write the description information of the target variable to the trigger register according to the prescribed format according to the address offset of each target variable.
[0070] In actual engineering, there are many designs for the data format of the trigger register. Figure 2 One example is shown. Figure 2 In, four flags R, A, C and L and the address offset specified by OFF are specified. The four flags can be stored in one bit, and their values can be set to 1 or 0. OFF can be stored in 32 bits or 64 bits. When R is set to 1, it means to obtain the base address from the specified process register, and when A is set to 1, it means to obtain the base address based on the specified memory. Since the compiler can specify that the base address of the process space or the specific area contained in the process space of the executable program when it is running is stored in the process register or in the specified memory when compiling the source code into an executable program, if the compiler specifies that the base address of the process space or the specific area contained in the process space of the executable program when it is running is stored in the process register, R is set to 1, and if the compiler specifies that the base address of the process space or the specific area contained in the process space of the executable program when it is running is stored in the specified memory, A is set to 1. C indicates whether to track only the target of this level (0 means yes, 1 means no). L indicates whether there is a link address of the next level (0 means no, 1 means yes).
[0071] Figure 2 Four examples are given in the first example: R=1, OFF=+1024 (equivalent to R=1, A=0, C=0, OFF=+1024), then the processor tracking module 105 first obtains the base address of the process space or a specific area contained in the process space through the process register (TP), and then obtains the target variable to be tracked (+1024).
[0072] The second example is: A=1, OFF=+64 (equivalent to R=0, A=1, C=0, L=0, OFF=+64), then the processor tracking module 105 first obtains the base address of the process space or a specific area contained in the process space by specifying the memory address, and then obtains the target variable to be tracked (+64).
[0073] The third example is: A=1, OFF=+32 (equivalent to R=0, A=1, C=0, L=0, OFF=+32), then the processor tracking module 105 first obtains the base address of the process space or a specific area contained in the process space by specifying the memory address, and then obtains the target variable to be tracked (+32).
[0074] The fourth example is: A=1, C=1, L=1, OFF=+64 (equivalent to R=0, A=1, C=1, L=1, OFF=+64), then the processor tracking module 105 first obtains the base address of the process space or a specific area contained in the process space by specifying the memory address, and then obtains the target variable to be tracked (+32). Since C indicates that not only the target of this level but also the next level target of this level should be tracked, and L indicates the existence of the next level link address, the target variable of the current level will be obtained based on the base address +32. Then, when tracking the target, not only the target variable of the current level will be tracked, but also data will be taken out from the target variable of the current level as the target variable of the next level to be tracked.
[0075] Next, continue to combine Figure 2 The design of the data format of the trigger register shown is illustrated with the following C / C++ source code.
[0076] struct process{
[0077] int pid;
[0078] struct task*child;
[0079] int cpu;
[0080] };
[0081] struct task{
[0082] int tid;
[0083] struct task*next;
[0084] struct spin_lock*rq_lock;
[0085] };
[0086] struct spin_lock{
[0087] int lock;
[0088] };
[0089] int main{
[0090] struct*process*a; / / variable a
[0091] a=(struct*process)malloc(sizeof(struct process)); / / apply for space
[0092] a->child=(struct*task)malloc(sizeof(struct task)); / / apply for space
[0093] }
[0094] Assume that when the executable program corresponding to the above C / C++ source code is running, the target variable to be tracked is rq_lock.
[0095] Then the data that needs to be written into the trigger register is as follows: A=1, C=1, L=1, OFF=offset1. The calculation steps of offset1 are as follows: first, the first offset of structtask*child in struct process needs to be calculated according to the data structure struct process, and then the second offset of rq_lock in struct task needs to be calculated according to the data structure struct task, and the first offset and the second offset are added to obtain offset1. In this way, when tracking the target variable according to this example, the steps are as follows: the processor tracking module 105 first obtains the base address of the process space or the specific area through the process register (TP), and then obtains rq_lock through offset1, and then tracks rq_lock and the target variable of the next level of rq_lock.
[0096] Figure 3 is a flow chart of the method provided by the embodiment of the present disclosure. The flow chart includes steps S301-S304. Steps S301-S302 can be executed by a software program including an operating system. Steps S303-S304 are executed by a processor tracking module of the hardware.
[0097] Step S301 is to parse the executable program to obtain description information of the target variable, wherein the description information describes the acquisition source of the base address of the region to which the target variable belongs and the address offset of the target variable in the region to which it belongs.
[0098] Step S302 is to send the process identification and description information of the executable program when the executable program is executed.
[0099] Step S303 is to read the description information, and obtain the base address of the area to which the target variable belongs according to the reading mode and the process identifier of the executable program.
[0100] Step S304 is to calculate the actual address according to the base address and address offset of the area to which the target variable belongs, and read the data change of the target variable from the process space according to the actual address and collect the instruction flow information causing the data change.
[0101] In this embodiment, the target variable is determined by user instructions. For example, if the user indicates a data type, the target variable is all variables belonging to the data type. Alternatively, the user may specify a function. For example, the user may input a regular expression (for example, fp*, indicating all variables starting with the character fp).
[0102] In this embodiment, when loading and parsing the executable program, the software program obtains the function where the target variable is located, the data structure where the target variable is located, and the address offset of the target variable in the data structure through a series of operations such as searching for functions, searching for data structures, and searching for variable paths, and constructs description information of the target variable based on this information and stores the constructed description information in the trigger register of the processor tracking module of the hardware. Among them, since the compiler will place the base address of the process space or a specific area of the process space in the process register or the specified memory address based on the configuration during compilation, the description information needs to specify whether to obtain the base address of the process space or the specific area of the process space from the process register or from the specified memory address.
[0103] In this embodiment, after discovering that there is new data in the trigger register, the processor tracking module of the hardware obtains the base address of the process space or the corresponding area of the process space from the corresponding process register or from the specified memory address according to the corresponding flag and process identifier in the new data, and then adds the address offset to the base address to obtain the address to be accessed, and then monitors the data changes indicated by the address and collects the instruction flow information that causes the data changes.
[0104] In actual engineering, description information can be represented in a variety of formats. In the embodiment of the present disclosure, a format such as Figure 2The setting format shown in the figure includes four flags R, A, C and L and an offset OFF. Each of the four flags R, A, C and L can be stored in one bit, and its value can be set to 1 or 0. OFF can be stored in 32 bits or 64 bits. When R is set to 1, it means to obtain the base address from the process register, and when A is set to 1, it means to obtain the base address based on the specified memory address. Since the compiler can specify that the base address of the process space (or different areas included in the process space) of the executable program is stored in the process register when the source code is compiled into an executable program, it can also specify that it is stored in a specified memory address. Therefore, if the compiler specifies that the base address of the process space (or a specific area included in the process space) of the executable program is stored in the process register when the executable program is running, R is set to 1. If the compiler specifies that the base address of the process space (or different areas included in the process space) of the executable program is stored in the specified memory address when the executable program is running, A is set to 1. C indicates whether to track only the target of this level (0 means yes, 1 means no). L indicates whether the next-level link address exists (0 for no, 1 for yes).
[0105] In some embodiments, the data type of the target variable includes: numeric type, character type, data structure, class, pointer to data structure or class.
[0106] In some embodiments, the parsing executable program includes the following operations: determining the function path where the target variable is located; determining the data type definition related to the target variable; and constructing the description information according to the function path and the data type definition. If the data type of the target variable is a multi-level data structure, the path information to the target variable is determined according to the definition of the multi-level data structure, and the address offset of each level of the multi-level data structure is reflected in the description information.
[0107] Since the method and system provided by the present disclosure for tracking a target variable during execution of an executable program are corresponding, various embodiments of the method are introduced in a relatively simple manner herein.
[0108] Specific application of the processor provided by the embodiment of the present disclosure
[0109] Figure 4 The general computer architecture used in the embodiments of the present disclosure is shown. As shown in the figure, the computer system 400 may include one or more processors 12 and a memory 14. The processor 101 provided in the above embodiment is used as the processor 12.
[0110] The memory 14 in the computer system 400 may be a main memory (hereinafter referred to as main memory or internal memory), which is used to store instruction information and / or data information represented by data signals, such as storing data (such as calculation results) provided by the processor 12, and may also be used to implement data exchange between the processor 12 and an external storage device 16 (also referred to as auxiliary memory or external memory).
[0111] In some cases, the processor 12 may need to access the memory 14 to obtain data in the memory 14 or modify the data in the memory 14. Since the access speed of the memory 14 is slow, in order to alleviate the speed gap between the processor 12 and the memory 14, the computer system 400 also includes a cache memory 18 coupled to the bus 11, and the cache memory 18 is used to cache some program data or message data in the memory 14 that may be repeatedly called. The cache memory 18 is implemented by a storage device of the type of static random access memory (SRAM) for example. The cache memory 18 can be a multi-level structure, such as a three-level cache structure with a first-level cache (L1Cache), a second-level cache (L2Cache) and a third-level cache (L3Cache), or a cache structure of more than three levels or other types of cache structures. In some embodiments, a portion of the cache memory 18 (such as a first-level cache, or a first-level cache and a second-level cache) can be integrated inside the processor 12 or integrated with the processor 12 in the same system on a chip.
[0112] Based on this, the processor 12 may include an instruction execution unit 121, a memory management unit 122, and other parts. The instruction execution unit 121 initiates a write access request when executing some instructions that need to modify the memory. The write access request specifies the write data and the corresponding physical address that need to be written into the memory; the memory management unit 122 is used to translate the virtual addresses specified by these instructions into the physical addresses mapped by the virtual addresses. The physical address specified by the write access request may be consistent with the physical address specified by the corresponding instruction.
[0113] The information exchange between the memory 14 and the cache memory 18 is usually organized in blocks. In some embodiments, the cache memory 18 and the memory 14 can be divided into data blocks according to the same spatial size, and the data block can be used as the minimum unit of data exchange between the cache memory 18 and the memory 14 (including one or more data of a preset length). For the sake of simplicity and clarity, the data blocks in the cache memory 18 are referred to as cache blocks (which can be called cache lines or cache lines), and different cache blocks have different cache block addresses; the data blocks in the memory 14 are referred to as memory blocks, and different memory blocks have different memory block addresses. The cache block address includes, for example, a physical address tag for locating the data block.
[0114] Due to space and resource limitations, the cache memory 18 cannot cache all the contents in the memory 14, that is, the storage capacity of the cache memory 18 is usually smaller than that of the memory 14, and the cache block addresses provided by the cache memory 18 cannot correspond to all the memory block addresses provided by the memory 14. When the processor 12 needs to access the memory, it first accesses the cache memory 18 via the bus 11 to determine whether the content to be accessed has been stored in the cache memory 18. If so, the cache memory 18 hits, and the processor 12 directly calls the content to be accessed from the cache memory 18; if the content that the processor 12 needs to access is not in the cache memory 18, the cache memory 18, the processor 12 needs to access the memory 14 via the bus 11 to find the corresponding information in the memory 14. Because the access rate of the cache memory 18 is very fast, when the cache memory 18 hits, the efficiency of the processor 12 can be significantly improved, thereby improving the performance and efficiency of the entire computer system 400.
[0115] In addition, the computer system 400 may also include input / output devices such as a storage device 16, a display device 13, an audio device 19, and a mouse / keyboard 15. The storage device 16 is, for example, a hard disk, an optical disk, a flash memory, and other devices for information access coupled to the bus 11 through a corresponding interface. The display device 13 is, for example, coupled to the bus 11 through a corresponding graphics card, and is used to display according to a display signal provided by the bus 11.
[0116] The computer system 400 also typically includes a communication device 17, so that it can communicate with a network or other devices in various ways. The communication device 17 may include, for example, one or more communication modules. As an example, the communication device 17 may include a wireless communication module suitable for a specific wireless communication protocol. For example, the communication device 17 may include a WLAN module for implementing Wi-FiTM communication in accordance with the 402.11 standard established by the Institute of Electrical and Electronics Engineers (IEEE); the communication device 17 may also include a WWAN module for implementing wireless wide area communication in accordance with cellular or other wireless wide area protocols; the communication device 17 may also include a communication module using other protocols such as a Bluetooth module, or other custom types of communication modules; the communication device 17 may also be a port for serial transmission of data.
[0117] Of course, the structure of different computer systems may vary according to the motherboard, operating system and instruction set architecture. For example, many computer systems are currently provided with an input / output control center connected between the bus 11 and various input / output devices, and the input / output control center can be integrated into the processor 12 or independent of the processor 12.
[0118] The computer system also includes various software not shown, such as a computer operating system and various application programs, and the program for implementing the method provided by the present disclosure is included in the computer system.
[0119] Figure 5 The processor 101 provided in the above embodiment can be used as the processor 501.
[0120] Although embedded systems are highly similar to computer systems in hardware structure, the characteristics of embedded system applications make them quite different from general computer systems in hardware composition and implementation.
[0121] First, in order to meet the requirements of the embedded system 500 in terms of speed, volume and power consumption, the operating system, application software, special data and other data that need to be stored for a long time usually do not use storage media such as disks with large capacity and slow speed, but mostly use random access memory 502 or flash memory (Flash Memory) 503.
[0122] In addition, in the embedded system 500, an A / D (analog / digital conversion) interface 505 and a serial interface 506 are required for the needs of measurement and control, which are rarely used in general-purpose computers. The A / D interface 505 mainly completes the conversion of analog signals to digital signals and the conversion of digital signals to analog signals required in the test. When the embedded system 500 is applied to industrial production, it often needs to be tested. Since the single-chip microcomputer generates digital signals, it needs to be converted into analog signals for testing during testing. Therefore, unlike general-purpose computers, an A / D (analog / digital conversion) interface 505 is required to complete the relevant conversion. In addition, in industry, multiple embedded systems are often required to be connected in series to complete relevant functions, so a serial interface 506 is required for connecting multiple embedded systems in series, which is mostly not required in general-purpose computers.
[0123] In addition, as a basic processing unit, the embedded system 500 often needs to connect multiple embedded systems 500 into a network in industrial design, so it is necessary to connect the embedded system 500 to the network interface 507. This is also not required in general-purpose computers. In addition, according to the actual application and scale, some embedded systems 500 need to use external buses 504. With the rapid expansion of the application field of embedded systems 500, embedded systems 500 are becoming more and more personalized, and the types of buses used according to their own characteristics are also increasing. In addition, in order to test the internal circuits of the embedded processor 501, the processor chip generally adopts boundary scan test technology. In order to adapt to this test, a debugging interface 508 is adopted.
[0124] With the rapid development of very large scale integration (VLSI) and semiconductor technology, part or all of the above embedded systems can be implemented on a silicon chip, namely, an embedded system on chip (SoC).
[0125] The above-mentioned embedded system also includes various software not shown, such as an embedded operating system and various application programs, and the program for implementing the method provided by the present disclosure is included in the above-mentioned embedded system.
[0126] The commercial value of the disclosed embodiments
[0127] The system and method provided by the embodiments of the present disclosure have application scenarios, and are mainly used to test various applications and operating system kernels that do not have source code, and can track the target variables therein in a targeted manner. Therefore, the system and method have commercial and economic value.
[0128] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example but not limited to, an electrical, magnetic, optical, electromagnetic, infrared or semiconductor system, device or device, or any combination thereof. More specific examples of computer-readable storage media include: an electrical connection of one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this article, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by a processing unit, a device or a device, or used in combination with the program.
[0129] Computer readable signal media may include data signals propagated in baseband or as part of a chopped wave, which carry computer readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any other suitable combination. Computer readable signal media may also be any computer readable medium other than a computer readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction system, apparatus, or device.
[0130] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., and any suitable combination of the foregoing.
[0131] The computer program code for executing the disclosed embodiments may be written in one or more programming languages or combinations. The programming languages include object-oriented programming languages, such as JAVA, C++, and may also include conventional procedural programming languages, such as C. The program code may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet).
[0132] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. For those skilled in the art, the present disclosure may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for tracking target variables in an executable program, implemented by an analysis module of a software part and a processor tracking module, wherein the processor tracking module is an extension of a processor architecture and uses a dedicated hardware facility to track the execution information of the software program. The analysis module performs: Loading and parsing the executable program to obtain description information of the target variable; The description information and the process identifier of the executable program are stored in a designated register of the processor tracking module, wherein the description information describes a source of obtaining a base address of a region to which the target variable belongs and an address offset of the target variable in the region to which the target variable belongs, and the region to which the target variable belongs is located in the process space of the executable program; The processor tracking module performs: Read the description information in the specified register; Using the process identifier of the executable program, obtaining the base address of the region to which the target variable belongs from the acquisition source identified by the description information; Determining the actual address of the target variable according to the base address and the address offset; as well as The target variable is read from the actual address.
2. The method according to claim 1, wherein: The reading of the target variable includes: reading data of the target variable and collecting instruction flow information that causes changes in the data.
3. The method according to claim 1, wherein: The acquisition source specifies whether to obtain the base address of the area to which the target variable belongs from a process register or a specified memory.
4. The method according to claim 1, wherein: The description information further specifies whether there is a next-level address and whether to track the next-level address, and the reading of the target variable further includes: When a next-level address exists and tracking of the next-level address is specified, the next-level address is read from the actual address, and the target variable is read from the next-level address.
5. The method according to claim 1, wherein: The base address is the base address of the process space of the executable program or the base address of a specific area in the process space of the executable program.
6. The method according to claim 1, further comprising: The target variable is determined according to a user instruction.
7. The method according to claim 1, wherein: The loading and parsing of the executable program to obtain description information of the target variable includes: Determine the function path to which the target variable belongs; Determine the data type definition to which the target variable belongs; The description information is constructed according to the function path and data type definition.
8. The method according to claim 7, wherein: If the data type to which the target variable belongs is defined as a multi-level data structure, the address offset of each level passed through by the target variable is calculated according to the multi-level data structure and the address offset of each level passed through by the target variable is accumulated to obtain the address offset of the target variable in the corresponding area.
9. The method according to any one of claims 1 to 8, wherein: The data types of the target variable include: numeric type, character type, data structure, class, and pointer to data structure or class.
10. A computing device comprising: A processing unit, configured to execute an executable program and store description information of a target variable in the executable program in a designated register of the processor tracking module, wherein the description information describes a source of obtaining a base address of a region to which the target variable belongs and an address offset of the target variable in the region to which the target variable belongs, and the region to which the target variable belongs is located in a process space of the executable program; A processor tracking module is used to read the description information in the specified register; use the process identifier of the executable program to obtain the base address of the area to which the target variable belongs from the acquisition source identified by the description information; and determine the actual address of the target variable according to the base address and the address offset; The target variable is read from the actual address.
11. A system for tracking target variables in an executable program, comprising: The analysis module of the software part and the processor tracking module executed by the hardware, the analysis module includes: Loading and parsing the executable program to obtain description information of the target variable; The description information is stored in a designated register of the processor tracking module, wherein the description information describes a source of obtaining a base address of a region to which the target variable belongs and an address offset of the target variable in the region to which the target variable belongs, and the region to which the target variable belongs is located in the process space of the executable program; The processor tracking module includes: Read the description information in the specified register; Using the process identifier of the executable program, obtaining the base address of the region to which the target variable belongs from the acquisition source identified by the description information; Determining the actual address of the target variable according to the base address and the address offset; and The target variable is read from the actual address.
12. The system according to claim 11, wherein: The acquisition source specifies whether to obtain the base address of the area to which the target variable belongs from a process register or a specified memory.
Citation Information
Patent Citations
On-line real-time debugging method for panoramic data on basis of denomination variation
CN102063368A
Variable debugging method of embedded program dynamic storage allocation
CN103136107A
Parsing method and device of MATLAB model variable
CN103150445A
Data flow analysis in processor trace logs using compiler-type information method and apparatus
CN107025167A
Memory access method, computer system and processing device
CN109710544A
