Variable debugging method and device, electronic equipment, storage medium and program product
By setting an entry variable in the first device, the storage address of the variable in the second device can be directly determined, which solves the problem of low debugging efficiency between the first and second device variables and achieves a more efficient debugging process.
Patent Information
- Application Number
- CN202511086267.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-04
- Publication Date
- 2025-11-21
AI Technical Summary
In computer system and device interaction scenarios, the first device has low efficiency in debugging variables for the second device, mainly because it needs to frequently interact with the second device, resulting in long communication round trip times.
An entry variable is set in the first device, which contains the variable debugging information of the second device. By determining the device to which the target variable belongs and using the preset entry variable, the target storage address is directly determined, thereby reading the target data for debugging.
This reduces communication round trips between the first and second devices, shortens the time required to obtain specific data corresponding to variables, and improves variable debugging efficiency.
Smart Images

Figure CN120994528A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more particularly to a method, apparatus, electronic device, storage medium, and program product for debugging variables. Background Technology
[0002] In computer system and device interaction scenarios, variable debugging between devices is a crucial step in ensuring stable system operation. The first device debugs the variables in the second device to ensure that the program or system of the second device can run stably and correctly as expected.
[0003] In related technologies, when the first device performs variable debugging on the second device, it first needs to obtain the data corresponding to the variable. Typically, the first device first sends a request to the second device to obtain the storage address of the variable, and then the second device sends the storage address of the variable to the first device. After obtaining the storage address, the first device parses the specific data corresponding to the variable from the storage address, and then debugs the variable based on the specific data.
[0004] However, the above method results in low debugging efficiency when the first device performs variable debugging on the second device. Summary of the Invention
[0005] This application provides a method, apparatus, electronic device, storage medium, and program product for debugging variables, in order to solve the technical problem of low debugging efficiency when the first device performs variable debugging on the second device side in related technologies.
[0006] In a first aspect, this application provides a method for debugging variables, applied to a first device, comprising:
[0007] Obtain the target variable to be debugged, where the target variable is either a non-thread debugging variable or a thread debugging variable;
[0008] Based on the address of the target variable read by the debugger, determine whether the target variable is a variable of the second device;
[0009] If the target variable is a variable of the second device, then the target storage address is determined according to the preset entry variable. The target storage address stores the target data corresponding to the target variable, and the entry variable stores the debugging information of the variable in the second device.
[0010] The target data is read from the target storage address and is used for debugging the target variable.
[0011] In this application, the target variable to be debugged is obtained, and the device to which the target variable belongs is determined by the address read by the debugger, thus clarifying the debugging scope. When it is confirmed that the target variable belongs to the second device, the target storage address is directly determined using the preset entry variable of the first device, and the target data is then directly read from that address for subsequent debugging. By setting an entry variable in the first terminal, the storage address of the target variable in the second device can be directly determined based on the debugging information of the second device variable stored in the entry variable. This method reduces the communication round trips between the first and second devices, shortens the time spent by the first device to obtain the specific data corresponding to the variable in the second device, and thus improves the debugging efficiency of the first device for the second device variable.
[0012] Optionally, in the method described above, the debugging information of the entry variable includes a cache area and a thread area, the cache area includes the storage addresses of multiple non-thread debugging variables of the second device, and the thread area includes the storage addresses of multiple thread debugging variables of the second device;
[0013] The step of determining the target storage address based on preset entry variables includes:
[0014] Based on the identification information of the target variable, determine whether the cache region includes the target variable;
[0015] If the cache region includes the target variable, then the target storage address corresponding to the target variable is determined according to the preset mapping relationship in the cache region. The preset mapping relationship is the mapping relationship between the identification information of the variable and the storage address. The target variable is a non-thread debugging variable.
[0016] If the target variable is not included in the cache region, the target storage address is determined based on the thread region.
[0017] In this application, the entry variable integrates the variable debugging information of the second device into two areas: a cache area and a thread area. The cache area centrally stores the addresses of non-thread debugging variables, while the thread area manages the addresses of thread debugging variables. This partitioned management mechanism improves the efficiency of variable retrieval. In determining the target storage address, the cache area is first quickly searched based on the target variable's identifier information. If the cache area is matched, the preset mapping relationship between identifier information and storage addresses is used to determine the storage address corresponding to the target variable. If the cache area is not matched, the storage address of the target variable is determined based on the thread area. This method improves the stability and efficiency of the target variable addressing process.
[0018] Optionally, in the method described above, determining the target storage address based on the thread region includes:
[0019] Obtain the runtime environment information of the target variable, which includes the target thread accessing the target variable and the thread identifier information of the target thread;
[0020] Based on the thread identifier information, determine whether the target thread is included in the thread region;
[0021] If the thread region includes the target thread, then the target storage address corresponding to the target variable is determined according to the variable storage address corresponding to the target thread that is pre-stored in the thread region. The target variable is the thread debugging variable.
[0022] If the target thread is not included in the thread region, the target storage address is determined according to the variable type of the target variable.
[0023] In this application, within the thread region, the storage addresses of variables for each thread are pre-indexed, forming a correspondence between thread identifiers and variable addresses. When the debugger obtains the thread identifier of a target variable, it can directly locate the storage address of the variable corresponding to the target thread through this correspondence, without traversing the entire memory space. By transforming a global scan of the memory space into thread-local targeted access, debugging efficiency is significantly improved, especially in multi-threaded environments. If the thread region does not include the target thread, the addressing strategy based on variable type can also provide a fallback solution, thereby improving the completeness of the debugging process.
[0024] Optionally, in the method described above, the debugging information of the entry variable further includes: a global base address, a common base address, and a stack base address storing the addresses of each variable of the second device; determining the target storage address based on the variable type of the target variable includes:
[0025] Obtain the flag information of the target variable;
[0026] If the flag information indicates that the variable type of the target variable is a public variable, then the target storage address is determined from the preset global base address or the public base address that stores public variables according to the identification information of the target variable.
[0027] If the flag information indicates that the variable type of the target variable is a non-public variable, then the target storage address is determined from the preset stack base address where non-public variables are stored, based on the identification information of the target variable.
[0028] In this application, the entry variable pre-stores the global base address, common base address, and stack base address corresponding to each variable in the second device, constructing a three-level address indexing system. Common variables are directly mapped to the global or common base address space, while non-common variables are directed to the stack base address space. When the target thread is not included in the thread region, the target storage address is determined based on flag bits. If the flag bit information indicates a common variable, the target storage address is determined from the preset global or common base address storing common variables. If the flag bit information indicates that the target variable is a non-common variable, the target storage address is determined from the preset stack base address storing non-common variables. This method improves the speed of target variable addressing through a hierarchical base address indexing mechanism.
[0029] Optionally, in the method described above, if the target variable is the non-thread debugging variable, after determining the target storage address, the method further includes:
[0030] If the target variable is not included in the cache area, the identification information of the target variable is stored in the thread area, and the access count of the target variable is set to a preset initial value.
[0031] If the target variable is included in the cache area, a preset value is added to the current access count of the target variable to obtain a new access count;
[0032] If the new access count is greater than the preset access count threshold, the target storage address is stored in the thread area.
[0033] In this application, if the target variable is not included in the cache region, the identification information of the target variable is stored in the thread region and the access count is initialized, thus laying the foundation for subsequent popularity evaluation. If the target variable is included in the cache region, the access count is accumulated each time a hit occurs, forming a continuous popularity metric. This metric serves as the basis for caching strategy decisions, enabling the differentiation between infrequent and high-frequency access to variables. By implementing a caching strategy based on the access count of non-thread-debugged variables, the storage addresses of frequently accessed variables are preferentially cached in the thread region, forming a fast access path for high-frequency data, thereby improving the access speed of high-frequency variables.
[0034] Optionally, in the method described above, if the target variable is the thread debugging variable, after determining the target storage address, the method further includes:
[0035] If the target thread is not included in the thread region, then the thread identifier information of the target thread is obtained from the runtime environment information of the target variable;
[0036] The thread identifier information and the target storage address are stored in the thread area.
[0037] In this application, when the target thread is accessed for the first time, the thread identifier is extracted from the runtime environment information and bound to the variable storage address, then stored in the thread region. This method allows the debugger to quickly locate the variable's storage address directly through the thread index when accessing variables within the same thread subsequently, without needing to repeatedly obtain environment information.
[0038] Secondly, this application provides a data debugging device for variables, applied to a first device, comprising:
[0039] The acquisition module is used to acquire the target variable to be debugged, wherein the target variable is a non-thread debugging variable or a thread debugging variable;
[0040] The determination module is used to determine whether the target variable is a variable of the second device based on the address of the target variable read by the debugger;
[0041] The determining module is further configured to, if the target variable is a variable of the second device, determine a target storage address based on a preset entry variable, wherein the target storage address stores the target data corresponding to the target variable, and the entry variable stores debugging information of the variable in the second device;
[0042] A reading module is used to read the target data from the target storage address, and the target data is used for debugging the target variable.
[0043] In this application, different functions are assigned to the acquisition module, determination module, and reading module through the variable debugging and acquisition device. This modular design with clear division of labor improves the efficiency of determining the target data corresponding to the variable, thereby improving the debugging efficiency.
[0044] Thirdly, this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0045] The memory stores computer-executed instructions;
[0046] The processor executes computer execution instructions stored in the memory to implement the method as described in any of the first aspects.
[0047] In this application, an electronic device is provided to provide the hardware conditions for executing the variable debugging method of this application.
[0048] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any of the first aspects.
[0049] In this application, a computer-readable storage medium is provided to provide storage medium conditions for executing the debugging method of the variables of this application.
[0050] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method described in any of the first aspects.
[0051] In this application, a computer program product is provided to provide program product conditions for executing the debugging method of the variables of this application.
[0052] The debugging method, apparatus, electronic device, storage medium, and program product provided in this application obtain the target variable to be debugged, and determine whether the target variable is a variable of a second device based on the address of the target variable read by the debugger. If the target variable is a variable of the second device, the target storage address is determined according to a preset entry variable. The target storage address stores the target data corresponding to the target variable, and the entry variable stores the debugging information of the variable in the second device. The target data is then read from the target storage address and used for debugging the target variable. The method of this application, by setting an entry variable in a first terminal and using the debugging information of the second device variable stored in the entry variable, can directly determine the storage address of the target variable in the second device. This method reduces the communication round trips between the first and second devices, shortens the time required for the first device to obtain the specific data corresponding to the variable in the second device, and thus improves the debugging efficiency of the first device for the variable in the second device. Attached Figure Description
[0053] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0054] Figure 1 This application provides an illustration of an application scenario.
[0055] Figure 2 A flowchart illustrating a variable debugging method provided in an embodiment of this application;
[0056] Figure 3 A schematic diagram of an entry variable stored in a first device, provided as an embodiment of this application;
[0057] Figure 4 A flowchart illustrating a method for determining a target storage address provided in an embodiment of this application;
[0058] Figure 5 A flowchart illustrating a method for determining a target storage address provided in an embodiment of this application;
[0059] Figure 6 A flowchart illustrating another variable debugging method provided in this application embodiment;
[0060] Figure 7 A schematic diagram of the structure of a variable debugging device provided in an embodiment of this application;
[0061] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0062] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation
[0063] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0064] Parallel computing frameworks are software architectures that help electronic devices quickly complete complex tasks. Their main function is to break down a large task into many smaller tasks, which are then distributed among multiple processors or accelerators. This approach significantly improves processing speed, performing particularly well in scientific research, artificial intelligence, and large-scale computing. However, as task complexity increases, programs generated by these frameworks may encounter problems during runtime. Therefore, how to conveniently and efficiently debug these programs becomes an important issue.
[0065] Most debuggers in parallel computing frameworks employ a common workflow: the debugger first reads the debugging information embedded in the program. This debugging information is generated during program compilation and records the variables in the program and their related information. Using this debugging information, the debugger can locate the specific data corresponding to the variables.
[0066] In one scenario, the first device needs to debug variables in the second device to ensure that the program or system of the second device can run stably and correctly as expected. However, debugging variables in both the first and second devices typically relies on debugging information from their respective working domains. Debugging the first device depends on the debugging information generated by the first device, while debugging the second device depends on the debugging information generated by the second device.
[0067] Therefore, in the relevant technology, when the first device debugs the variable in the second device, since the first device does not contain the relevant debugging information of the variable in the second device, the first device needs to first send a request to the second device to obtain the storage address of the variable. Then the second device sends the storage address of the variable to the first device. After obtaining the storage address, the first device parses the specific data corresponding to the variable from the storage address and then debugs the variable based on the specific data.
[0068] However, in the above method, when the first device obtains the specific data of the variables in the second device, it needs to frequently interact with the second device. The data needs to frequently switch between the first device and the second device, which makes the process of the first device obtaining the specific data of the variables in the second device time-consuming, thus resulting in low debugging efficiency of the variables in the second device.
[0069] Therefore, addressing the problems in the aforementioned related technologies, it was discovered during the research process that if an entry variable is inserted into the debugging information of the first terminal, and this entry variable includes the debugging information of the variables in the second device, then when the first terminal obtains the debugging information of the variables in the second device, it can directly obtain it through the information in the entry variable, thereby improving the debugging efficiency of the first terminal for the variables in the second terminal. Specifically, the target variable to be debugged is obtained, and the device to which the variable belongs is determined based on the address of the target variable read by the debugger. If it is confirmed that the target variable is located in the second device, the target storage address is directly obtained using a preset entry variable. This entry variable integrates the debugging information of the variables in the second device, thereby eliminating the need for interaction between the first and second devices in the related technologies. Finally, the target data corresponding to the target variable is directly read according to the determined target storage address for debugging. Based on this, this application proposes a variable debugging method, device, electronic device, storage medium, and program product.
[0070] To facilitate understanding of the methods in this application, through Figure 1 For a brief description of exemplary application scenarios, please refer to [link / reference]. Figure 1 , Figure 1 This application provides an application scenario diagram, which includes a first device 01 and a second device 02. The first device 01 can communicate with the second device 02 via a wired network or a wireless network.
[0071] In this process, after the first device 01 obtains the variable to be debugged, it first determines whether the variable is a variable in the second device 02. If it is a variable in the second device 02, it determines the storage address of the variable to be debugged based on the preset entry variable. After determining the storage address, it obtains the specific data corresponding to the variable to be debugged based on the storage address, so that the first device 01 can debug the variable to be debugged based on the specific data.
[0072] It is understood that this application does not limit the type, quantity, or function of the first and second devices, which can be determined based on the actual application situation.
[0073] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0074] Please see Figure 2 , Figure 2 This is a flowchart illustrating a variable debugging method provided in an embodiment of this application. The execution entity of this method can be a variable debugging device, which can be implemented through a computer program; it can also be implemented through a medium storing the relevant computer program, such as a USB flash drive and / or optical disc; or it can be implemented through a physical device integrating or installing the relevant computer program, such as an electronic device. The electronic device can be a server, server cluster, smart terminal, etc. The method can include the following steps:
[0075] S201. Obtain the target variable to be debugged.
[0076] In this embodiment, the executing entity can be a first device, which can be a server, a laptop computer, or a mobile smart terminal, etc.
[0077] The first device responds to the user's operation and obtains the target variable to be debugged.
[0078] Optionally, the target variable can be a non-thread debugging variable or a thread debugging variable. A non-thread debugging variable is a variable that is not bound to a specific thread, while a thread debugging variable is a variable that is strongly bound to a specific thread.
[0079] S202. Determine whether the target variable is a variable of the second device based on the address of the target variable read by the debugger.
[0080] In this embodiment, the second device can be a server, a laptop computer, or a mobile smart terminal, etc.
[0081] One possible implementation is that the first device determines that the target variable is a variable of the second device if it determines that the address of the target variable read by the debugger does not belong to the address range preset by the first device.
[0082] Another possible implementation is to use the pre-defined entry variables of the first device to store debugging information about variables in the second device. This debugging information includes the start and end addresses of the second device. If the address of the target variable to be read is included between the start and end addresses, then the target variable is determined to be a variable of the second device. The start address of the second device can indicate the beginning of its working domain, helping the debugger quickly identify the operating range of the second device. The end address of the second device can indicate the end of its working domain.
[0083] S203. If the target variable is a variable of the second device, then determine the target storage address according to the preset entry variable.
[0084] The target storage address stores the target data corresponding to the target variable, and the entry variable stores the debugging information of the variable in the second device.
[0085] In this embodiment, the entry variable, in addition to including the start address and end address of the second device, may also include, in the debugging information of the variables stored in the second device, the following: Figure 3 The content shown, Figure 3 This is a schematic diagram of an entry variable stored in a first device, as provided in an embodiment of this application.
[0086] exist Figure 3 In the entry variable, a cache area may also be included. The cache area includes the storage address of multiple non-threaded debugging variables of the second device, the identification information of the variables, and the number of times the variables are accessed. The identification information of the variables may be the name or number of the variables.
[0087] The entry variable may also include a thread region, which includes the storage addresses of multiple thread debugging variables of the second device, thread identification information, or the start and end addresses of the threads. The thread identification information can be the thread identifier (ID).
[0088] The entry variables may also include a global base address, a common base address, and a stack base address storing the addresses of various variables of the second device. The global base address stores the base address of the global variables of the second device, allowing the debugger to quickly locate their storage location. The common base address stores the storage location of common variables shared by the first and second devices, enabling the debugger to directly locate their storage location. The stack base address stores the starting location of the second device's stack memory, allowing the debugger to locate the storage location of local variables.
[0089] By storing the above information in the entry variable, it is ensured that the first device can directly obtain the debugging information of the variables in the second device from the entry variable. It is understood that the entry variable may include other information besides the above, and this application does not impose any limitations on this; the specific limitations can be determined based on the actual application situation, etc.
[0090] If the first device determines that the target variable is a variable of the second device, it can determine the target storage address containing the specific data of the target variable based on the information in the above-mentioned entry variables.
[0091] S204. Read the target data from the target storage address. The target data is used for debugging the target variable.
[0092] After determining the target storage address, the first device reads the target data stored in the target address and then debugs the target variable based on the target data.
[0093] Optionally, when the first device is debugging based on the target data of the target variable to be debugged, it is necessary to first clarify the deviation between its current state and the expected target based on the target data. This can be done by comparing data distribution and key indicators, such as the mean and extreme values, to pinpoint whether outliers or sources of fluctuation are caused by abnormal input data, unreasonable parameter settings, or logical loopholes. Then, targeted adjustment strategies can be developed to address the identified problems, such as revising input data validation rules, optimizing parameter values, or modifying logic code. After adjustment, the variable's performance needs to be verified using new or historical data to confirm whether the deviation has been reduced to an acceptable range. If not, the analysis and adjustment steps are repeated until the variable meets expectations.
[0094] In the above embodiments of this application, by obtaining the target variable to be debugged, and based on the address of the target variable read by the debugger, it is determined whether the target variable is a variable of the second device. If the target variable is a variable of the second device, then a target storage address is determined based on a preset entry variable, wherein the target storage address stores the target data corresponding to the target variable, and the entry variable stores the debugging information of the variable in the second device; then the target data is read from the target storage address, and the target data is used for debugging the target variable. In this method, when the first device starts debugging the variable in the second device, it is not necessary to first obtain the debugging information of the variable from the second device. Instead, the first terminal can directly determine the storage address of the target variable in the second device based on the debugging information of the second device variable stored in the set entry variable. This method reduces the communication round trips between the first and second devices, shortens the time spent by the first device to obtain the specific data corresponding to the variable in the second device, thereby improving the debugging efficiency of the first device for the variable in the second device.
[0095] Furthermore, based on the above embodiments, the following embodiments illustrate the process of determining the target storage address according to preset entry variables. Please refer to [link to relevant documentation]. Figure 4 , Figure 4 This application provides a flowchart illustrating a method for determining a target storage address, which may include the following steps:
[0096] S401. Based on the identification information of the target variable, determine whether the cache region includes the target variable.
[0097] Optionally, the first device compares the name of the target variable with the name of the variable stored in the cache area based on the identification information of the target variable, such as the name of the target variable. If the comparison matches, it is determined that the cache area includes the target variable; if the comparison does not match, it is determined that the cache area does not include the target variable.
[0098] S402. If the cache region includes the target variable, then the target storage address corresponding to the target variable is determined according to the preset mapping relationship in the cache region.
[0099] In this embodiment, a mapping relationship is pre-set, which is the mapping relationship between the identification information of variables and their storage addresses. The target variable is a non-thread debugging variable.
[0100] If the first device matches the variable stored in the cache area, it means that the cache area contains the target variable. Then, based on the preset mapping relationship between variables and storage addresses in the cache area, the target storage address corresponding to the target variable is determined.
[0101] S403. If the target variable is not included in the cache region, the target storage address shall be determined according to the thread region.
[0102] If the first device does not find a match in the variables stored in the cache area, it means that the cache area does not include the target variable. In order to improve the hit rate, the target storage address corresponding to the target variable can be determined based on the thread area in the entry variable.
[0103] In the above embodiments of this application, the method determines whether the target variable is included in the cache region based on the target variable's identification information. If the target variable is included in the cache region, the target storage address corresponding to the target variable is determined according to a preset mapping relationship in the cache region. If the target variable is not included in the cache region, the target storage address is determined according to the thread region. In determining the target storage address, this method first quickly searches the cache region based on the target variable's identification information. If the cache region is hit, the storage address corresponding to the target variable is determined using the preset mapping relationship between the identification information and the storage address. If the cache region is not hit, the storage address of the target variable is determined according to the thread region. This method improves the stability and efficiency of the target variable addressing process.
[0104] Furthermore, based on any of the above embodiments, the process of determining the target storage address according to the thread region is illustrated by the following examples. Please refer to [link to relevant documentation]. Figure 5 , Figure 5 This application provides a flowchart illustrating a method for determining a target storage address, which may include the following steps:
[0105] S501. Obtain the runtime environment information of the target variable, which includes the target thread accessing the target variable and the thread identifier information of the target thread.
[0106] The first device obtains the runtime environment information of the target variable, which includes, but is not limited to: the target thread accessing the target variable and the thread identification information of the target thread, such as the thread ID.
[0107] S502. Based on the thread identifier information, determine whether the thread region includes the target thread.
[0108] The first device can compare the thread ID with the thread IDs stored in the thread region. If the comparison matches, it is determined that the thread region includes the target thread that can access the target variable. If the comparison does not match, it is determined that the thread region does not include the target thread that can access the target variable.
[0109] S503. If the thread region includes the target thread, then determine the target storage address corresponding to the target variable based on the variable storage address corresponding to the target thread that is pre-stored in the thread region.
[0110] If the first device matches the thread region, it means that the thread region contains a target thread that can access the target variable. Then, based on the pre-stored variable storage address of the target thread in the thread region, the target storage address of the target variable is determined. Here, the target variable is a thread debugging variable.
[0111] In this embodiment, since the thread region also includes the start address and end address of the thread, if the first device matches the target thread in the thread region, it can also determine the target storage address based on the start address and end address of the thread corresponding to the target thread.
[0112] Optionally, the starting address can be added to a preset offset to determine the target storage address. Alternatively, the ending address can be subtracted from a preset offset to determine the target storage address. Or, the target storage address can be determined based on the starting address, the ending address, and a preset artificial intelligence algorithm for determining the storage address.
[0113] S504. If the target thread is not included in the thread region, the target storage address is determined according to the variable type of the target variable.
[0114] If the first device does not find a match in the thread region, it means that the thread region does not contain the target thread that can access the target variable. In order to improve the hit rate, the target storage address can be determined according to the variable type of the target variable.
[0115] One possible implementation is that the first device acquires the flag information of the target variable. If the flag information indicates that the target variable's variable type is a public variable, then the target storage address is determined from a preset global base address or public base address storing public variables based on the target variable's identification information. Specifically, the first device determines whether the target variable's variable type is a public variable based on the acquired flag information. If it is a public variable, it determines whether the public variable is a global variable. If it is a global variable, the target storage address is determined from a preset global base address storing global variables based on its identification information. If it is not a global variable, the target storage address is determined from a preset public base address storing public variables based on its identification information. If the flag information indicates that the target variable's variable type is a non-public variable, the target storage address is determined from a preset stack base address storing non-public variables based on the target variable's identification information.
[0116] Taking common variables as an example, compared to related technologies where the first device first obtains debugging information of common variables from the second device and then obtains the storage address of common variables by parsing the debugging information, this embodiment can quickly determine the target storage address by directly storing the common base address of common variables in the entry variables. This reduces multiple data interactions between the first and second devices, simplifies the cumbersome interaction process between devices, and significantly improves debugging efficiency.
[0117] In the above embodiments of this application, by obtaining the runtime environment information of the target variable, which includes the target thread accessing the target variable and the thread identifier information of the target thread, the method determines whether the thread region includes the target thread based on the thread identifier information. If the target thread is included, the target storage address corresponding to the target thread is determined based on the variable storage address corresponding to the target thread pre-stored in the thread region. If the target thread is not included, the target storage address is determined based on the variable type of the target variable. In this embodiment, the variable storage address of each thread is pre-indexed in the thread region, forming a correspondence between thread identifiers and variable addresses. When the debugger obtains the thread identifier of the target variable, it can directly locate the storage address of the variable corresponding to the target thread through this correspondence, without traversing the entire memory space. By transforming the global scanning of the memory space into thread-local targeted access, especially in a multi-threaded environment, debugging efficiency can be significantly improved. If the thread region does not include the target thread, the addressing strategy based on variable type can also provide a fallback solution, thereby improving the integrity of the debugging process.
[0118] Furthermore, after determining the target storage address of the target variable according to any of the above embodiments, if the target variable is a non-thread debugging variable and the target variable is not included in the cache area, the identification information of the target variable is stored in the thread area, and the access count of the target variable is set to a preset initial value, such as 0.
[0119] If the cache region includes the target variable, a preset value is incremented by the current access count of the target variable, for example, by 1, to obtain a new access count. If the new access count is greater than the preset access count threshold, the target storage address is stored in the thread region. This way, when the variable is accessed subsequently, the corresponding storage address can be directly determined from the cache region, reducing the need for recalculation of that storage address and thus improving debugging efficiency.
[0120] Accordingly, after determining the target storage address of the target variable according to any of the above embodiments, if the target variable is a thread debugging variable and the target thread is not included in the thread region, then the thread identifier information of the target thread is obtained from the runtime environment information of the target variable, and the thread identifier information and the target storage address are stored in the thread region. In this way, in the case of multi-threaded concurrency, when the thread accesses the variable again later, the storage address corresponding to the variable can be directly determined from the thread region, thereby saving the time of multi-threaded access and improving debugging efficiency.
[0121] In this application, in addition to determining the storage address of a variable through the mapping relationship between the variable's identification information and its storage address, a hash value can also be introduced to determine the storage address in the storage area. Specifically, the hash value of the variable is determined based on the variable's identification information according to a preset hash algorithm. In the entry variable, the hash value of the variable is used as the key of the hash table, and the storage address of the corresponding variable is stored as the value of the hash table. When the first device determines the storage address of the variable to be debugged, it can calculate the hash value through the target variable's identification information and quickly locate the corresponding storage location through the established hash table. This eliminates the need to compare each variable in the storage area one by one, thus significantly reducing the search time.
[0122] Alternatively, this can be determined by adding an index table. An index table is pre-built in the storage area, associating variable attributes (such as type or range) with the variable's storage address and arranging them into ordered entries. During a search, the corresponding entry is quickly matched in the index table based on the target variable's attributes, and then the target data of the variable is directly accessed through the storage address pointed to by the entry. This leverages the ordered or categorical nature of the index to shorten the location path and improve debugging efficiency.
[0123] To facilitate a better understanding of the variable debugging method in this application, a brief description is provided below using a complete embodiment. Please refer to [link / reference]. Figure 6 , Figure 6 A flowchart illustrating another variable debugging method provided in this application embodiment, the method may include the following steps:
[0124] S601. Obtain the target variable to be debugged. The target variable can be a non-thread debugging variable or a thread debugging variable.
[0125] S602. Based on the address of the target variable read by the debugger, determine whether the target variable is a variable of the second device.
[0126] S603. If it is not a variable of the second device, then it is a variable of the first device. Determine whether it is a global variable of the first device based on the flag information of the target variable.
[0127] S604. If it is a global variable, the corresponding target storage address is determined from the preset first device global base address.
[0128] S605. If it is a non-global variable or a local variable, then the corresponding target storage address is determined from the preset first device stack base address.
[0129] S606. If the target variable is a variable of the second device, then obtain the preset entry variable.
[0130] S607. Based on the identification information of the target variable, determine whether the cache region included in the entry variable includes the target variable.
[0131] S608. If the cache region includes the target variable, then the target storage address corresponding to the target variable is determined according to the preset mapping relationship in the cache region.
[0132] S609. If the target variable is not included in the cache area, obtain the runtime environment information of the target variable. The runtime environment information includes the target thread accessing the target variable and the thread identifier information of the target thread.
[0133] S610. Based on the thread identifier information, determine whether the target thread is included in the thread region included in the entry variable.
[0134] S611. If the thread region includes the target thread, then determine the target storage address corresponding to the target variable based on the variable storage address corresponding to the target thread that is pre-stored in the thread region.
[0135] S612. If the target thread is not included in the thread region, then obtain the flag information of the target variable.
[0136] S613. Determine whether the flag information indicates that the variable type of the target variable is a public variable.
[0137] S614. If the flag information indicates that the variable type of the target variable is a public variable, then the target storage address is determined from the preset global base address or public base address where the public variable is stored, based on the identification information of the target variable.
[0138] S615. If the flag information indicates that the variable type of the target variable is a non-public variable, then the target storage address is determined from the preset stack base address where non-public variables are stored, based on the identification information of the target variable.
[0139] S616. After determining the target storage address corresponding to the target variable, determine whether the target variable is a thread variable.
[0140] S617. If it is a thread variable and the target thread is not included in the thread area, then obtain the thread identifier information of the target thread from the runtime environment information of the target variable, and store the thread identifier information and the target storage address in the thread area.
[0141] S618. If it is a non-threaded debugging variable, determine whether the target variable is included in the cache area.
[0142] S619. If the target variable is not included in the cache area, the identification information of the target variable is stored in the thread area, and the access count of the target variable is set to a preset initial value.
[0143] S620. If the cache area includes the target variable, then the current access count of the target variable is increased by a preset value to obtain a new access count.
[0144] S621. Determine whether the new number of visits exceeds the preset number of visits threshold.
[0145] S622. If the new access count exceeds the preset access count threshold, the target storage address is stored in the thread area.
[0146] S623. If the new number of visits is less than or equal to the preset number of visits threshold, no action is taken and the process ends.
[0147] For specific implementation examples of each step, please refer to the above-mentioned multiple embodiments. To avoid redundancy, the descriptions will not be repeated.
[0148] In the above embodiments of this application, by inserting an entry variable into the first device, the debugging information of the variables of the second device is stored in the entry variable, thereby allowing the debugging information of the variables of the second device to be stored in the first device. Through centralized management of the debugging information of the variables in the second device, the first device can complete the debugging of the variables of the second device without needing to retrieve the debugging information from the second device. Simultaneously, this method also ensures that even if the second device lacks debugging information, the first device can still determine the storage address of the variables of the second device through the entry variable, thereby improving the robustness of debugging.
[0149] This application also provides a variable debugging device; please refer to [link to relevant documentation]. Figure 7 , Figure 7 This is a schematic diagram of a variable debugging device provided in an embodiment of this application. The device includes:
[0150] The acquisition module 701 is used to acquire the target variable to be debugged, which can be a non-threaded debugging variable or a threaded debugging variable.
[0151] The determination module 702 is used to determine whether the target variable is a variable of the second device based on the address of the target variable read by the debugger.
[0152] The determination module 702 is also used to determine the target storage address according to the preset entry variable if the target variable is a variable of the second device. The target storage address stores the target data corresponding to the target variable, and the entry variable stores the debugging information of the variable in the second device.
[0153] The read module 703 is used to read target data from the target storage address. The target data is used for debugging the target variable.
[0154] One possible implementation is that the debugging information of the entry variable includes a cache region and a thread region. The cache region includes the storage addresses of multiple non-threaded debugging variables of the second device, and the thread region includes the storage addresses of multiple threaded debugging variables of the second device. The determination module 702 is specifically used for:
[0155] Based on the identifier information of the target variable, determine whether the cache region contains the target variable.
[0156] If the cache region includes the target variable, the target storage address corresponding to the target variable is determined according to the preset mapping relationship in the cache region. The preset mapping relationship is the mapping relationship between the variable's identification information and the storage address. The target variable is a non-thread debugging variable.
[0157] If the target variable is not included in the cache region, the target storage address is determined based on the thread region.
[0158] One possible implementation is to determine module 702, specifically for:
[0159] Obtain the runtime environment information of the target variable, which includes the target thread accessing the target variable and the thread identifier information of the target thread.
[0160] Based on the thread identifier information, determine whether the thread region includes the target thread.
[0161] If the thread region includes the target thread, then the target storage address corresponding to the target variable is determined based on the pre-stored variable storage address of the target thread in the thread region. The target variable is the thread debugging variable.
[0162] If the target thread is not included in the thread region, the target storage address is determined based on the variable type of the target variable.
[0163] One possible implementation is that the debugging information for the entry variables also includes: the second device stores the global base address, common base address, and stack base address of each variable. The determination module 702 is specifically used for:
[0164] Obtain the flag information of the target variable.
[0165] If the flag information indicates that the variable type of the target variable is a public variable, then the target storage address is determined from the preset global base address or public base address where public variables are stored, based on the identification information of the target variable.
[0166] If the flag information indicates that the variable type of the target variable is a non-public variable, then the target storage address is determined from the preset stack base address where non-public variables are stored, based on the identification information of the target variable.
[0167] One possible implementation is that, if the target variable is not a thread debugging variable, after determining the target storage address, module 702 is also used for:
[0168] If the target variable is not included in the cache area, the identification information of the target variable is stored in the thread area, and the access count of the target variable is set to a preset initial value.
[0169] If the cache region includes the target variable, then the current access count of the target variable is increased by a preset value to obtain a new access count.
[0170] If the new access count exceeds the preset access count threshold, the target storage address will be stored in the thread area.
[0171] One possible implementation is that, if the target variable is a thread debugging variable, after determining the target storage address, module 702 is also used for:
[0172] If the target thread is not included in the thread region, the thread identifier information of the target thread is obtained from the runtime environment information of the target variable.
[0173] Store the thread identifier information and the target storage address in the thread area.
[0174] For a description of the features in the embodiment corresponding to the variable debugging device, please refer to the relevant description of the embodiment corresponding to the variable debugging device method, which will not be repeated here.
[0175] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 8 As shown, the electronic device provided in this embodiment includes at least one processor 801 and a memory 802. Optionally, the electronic device further includes a communication component 803. The processor 801, memory 802, and communication component 803 are connected via a bus 804.
[0176] In a specific implementation, at least one processor 801 executes computer execution instructions stored in memory 802, causing at least one processor 801 to execute the above-described variable debugging method embodiment.
[0177] The specific implementation process of processor 801 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0178] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this application can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.
[0179] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.
[0180] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0181] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in the debugging method embodiments of any of the above variables at runtime.
[0182] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0183] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in the debugging method embodiments of any of the above-described variables.
[0184] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in the debugging method embodiments of any of the above variables.
[0185] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0186] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A method for debugging variables, characterized in that, Applied to the first device, including: Obtain the target variable to be debugged, where the target variable is either a non-thread debugging variable or a thread debugging variable; Based on the address of the target variable read by the debugger, determine whether the target variable is a variable of the second device; If the target variable is a variable of the second device, then the target storage address is determined according to the preset entry variable. The target storage address stores the target data corresponding to the target variable, and the entry variable stores the debugging information of the variable in the second device. The target data is read from the target storage address and is used for debugging the target variable.
2. The method according to claim 1, characterized in that, The debugging information of the entry variable includes a cache area and a thread area. The cache area includes the storage addresses of multiple non-thread debugging variables of the second device, and the thread area includes the storage addresses of multiple thread debugging variables of the second device. The step of determining the target storage address based on preset entry variables includes: Based on the identification information of the target variable, determine whether the cache region includes the target variable; If the cache region includes the target variable, then the target storage address corresponding to the target variable is determined according to the preset mapping relationship in the cache region. The preset mapping relationship is the mapping relationship between the identification information of the variable and the storage address. The target variable is a non-thread debugging variable. If the target variable is not included in the cache region, the target storage address is determined based on the thread region.
3. The method according to claim 2, characterized in that, Determining the target storage address based on the thread region includes: Obtain the runtime environment information of the target variable, which includes the target thread accessing the target variable and the thread identifier information of the target thread; Based on the thread identifier information, determine whether the target thread is included in the thread region; If the thread region includes the target thread, then the target storage address corresponding to the target variable is determined according to the variable storage address corresponding to the target thread that is pre-stored in the thread region. The target variable is the thread debugging variable. If the target thread is not included in the thread region, the target storage address is determined according to the variable type of the target variable.
4. The method according to claim 3, characterized in that, The debugging information of the entry variable also includes: a global base address, a common base address, and a stack base address storing the addresses of each variable of the second device; determining the target storage address based on the variable type of the target variable includes: Obtain the flag information of the target variable; If the flag information indicates that the variable type of the target variable is a public variable, then the target storage address is determined from the preset global base address or the public base address that stores public variables according to the identification information of the target variable. If the flag information indicates that the variable type of the target variable is a non-public variable, then the target storage address is determined from the preset stack base address where non-public variables are stored, based on the identification information of the target variable.
5. The method according to claim 2, characterized in that, If the target variable is the non-thread debugging variable, after determining the target storage address, the process further includes: If the target variable is not included in the cache area, the identification information of the target variable is stored in the thread area, and the access count of the target variable is set to a preset initial value. If the target variable is included in the cache area, a preset value is added to the current access count of the target variable to obtain a new access count; If the new access count is greater than the preset access count threshold, the target storage address is stored in the thread area.
6. The method according to claim 3, characterized in that, If the target variable is the thread debugging variable, after determining the target storage address, the process further includes: If the target thread is not included in the thread region, then the thread identifier information of the target thread is obtained from the runtime environment information of the target variable; The thread identifier information and the target storage address are stored in the thread area.
7. A device for debugging variables, characterized in that, Applied to the first device, including: The acquisition module is used to acquire the target variable to be debugged, wherein the target variable is a non-thread debugging variable or a thread debugging variable; The determination module is used to determine whether the target variable is a variable of the second device based on the address of the target variable read by the debugger; The determining module is further configured to, if the target variable is a variable of the second device, determine a target storage address based on a preset entry variable, wherein the target storage address stores the target data corresponding to the target variable, and the entry variable stores debugging information of the variable in the second device; A reading module is used to read the target data from the target storage address, and the target data is used for debugging the target variable.
8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 6.
10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-6.
Citation Information
Patent Citations
Variable debugging method of embedded program dynamic storage allocation
CN103136107A
Method and system for obtaining vehicle debugging data
CN103699332A