Wild pointer detection method, device, equipment and storage medium
By allocating and forcibly occupying dynamic memory in a fixed memory space and adding an error release function when it is released, it solves the problem of difficult detection of wild pointers in XCode, and improves the robustness of the system.
Patent Information
- Application Number
- CN202111550576.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-12-17
AI Technical Summary
The existing wild pointer troubleshooting methods are random when debugging code in XCode, which greatly reduces the possibility of problems being discovered and makes it difficult to effectively troubleshoot.
By allocating dynamic memory in a fixed memory space and forcibly occupying it when it is released, preset object data is added to form an error release function. If an error release function is called, it will be recognized as a wild pointer and enlarged Probability of problems exposed.
Raise the originally random wild pointer problem to the probability that it is close to the inevitable, increase the probability of problem exposure, fix the problem in advance, and improve system robustness.
Smart Images

Figure CN114201407B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of research and development management, and in particular to a wild pointer troubleshooting method, device, equipment and storage medium. Background Art
[0002] A wild pointer refers to a pointer that points to a deleted object or a restricted memory area that has not been requested for access. In iOS development, the current industry solution is to enable the Enable Scribble option during debugging in XCode to check for wild pointers. However, the difficulty in checking for wild pointers is its randomness. The probability and phenomenon of problems with the same piece of code and the same data are random, which greatly reduces the possibility of discovering problems during the debugging phase. Therefore, a wild pointer checking method is urgently needed to solve the above problem. Summary of the invention
[0003] The main purpose of the present invention is to solve the technical problem that the existing wild pointer troubleshooting method can only find wild pointers with probability when debugging code in XCode.
[0004] A first aspect of the present invention provides a wild pointer checking method, which includes: allocating a first dynamic memory from a fixed memory space according to a user's memory allocation request; when the first dynamic memory is released, forcibly occupying the first dynamic memory, and adding preset object data to the forcibly occupied first dynamic memory to obtain a second dynamic memory; adding the second dynamic memory to a preset memory queue; when the second dynamic memory in the memory queue is accessed by a pointer, calling an error release function according to the object data in the accessed second dynamic memory; if the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer.
[0005] Optionally, in a first implementation method of the first aspect of the present invention, when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and preset object data is added to the forcibly occupied first dynamic memory, before obtaining the second dynamic memory, it also includes: creating a new error release function, wherein the error release function is used to throw an error; hooking the first memory release function, wherein the first memory release function is a basic function preset in the system, used to release dynamic memory; writing the error release function into the first memory release function to obtain the second memory release function.
[0006] Optionally, in a second implementation method of the first aspect of the present invention, when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and preset object data is added to the forcibly occupied first dynamic memory, to obtain the second dynamic memory, including: obtaining a release instruction of the first dynamic memory; based on the release instruction, calling the second memory release function to release the first dynamic memory; writing the error release function into the released first dynamic memory to obtain the second dynamic memory.
[0007] Optionally, in a third implementation method of the first aspect of the present invention, before adding the second dynamic memory to the preset memory queue, it also includes: determining whether the size of the dynamic memory in the memory queue exceeds a preset threshold; if so, releasing the dynamic memory in the memory queue one by one in the order in which the dynamic memory in the memory queue was added; after releasing the dynamic memory in the memory queue, returning to the step of determining whether the size of the dynamic memory in the memory queue exceeds the preset threshold, until the size of the dynamic memory in the memory queue does not exceed the preset threshold; if not, monitoring whether the second dynamic memory is accessed.
[0008] Optionally, in a fourth implementation method of the first aspect of the present invention, before determining whether the size of the dynamic memory in the memory queue exceeds a preset threshold, it also includes: creating a third memory release function, wherein the third memory release function is used to release the dynamic memory; when the second dynamic memory needs to be released, running the third memory release function.
[0009] Optionally, in a fifth implementation method of the first aspect of the present invention, if the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer, including: if the error release function is called and the program debugging throws an error, a program error log is obtained; the program error log is analyzed to obtain pointer information for accessing the second dynamic memory, wherein the pointer information includes positioning information of the corresponding pointer; and the pointer corresponding to the pointer information is identified as a wild pointer.
[0010] Optionally, in a sixth implementation manner of the first aspect of the present invention, the program error log includes the error type of the thrown error; analyzing the program error log to obtain pointer information for accessing the second dynamic memory includes: analyzing the program error log to determine whether the error thrown by program debugging is caused by the calling of the second dynamic memory; if the error thrown by program debugging is caused by the calling of the second dynamic memory, determining whether the error type of the thrown error is consistent with the error type caused by the error release function; if they are consistent, obtaining the pointer information of the second dynamic memory; if the error thrown by program debugging is not caused by the calling of the second dynamic memory or is inconsistent, the program error log does not include wild pointer information.
[0011] The second aspect of the present invention provides a wild pointer checking device, including: a memory application module, used to allocate a first dynamic memory from a fixed memory space according to a user's memory allocation request; a memory occupation module, used to force the first dynamic memory to be occupied when the first dynamic memory is released, and add preset object data to the forced occupied first dynamic memory to obtain a second dynamic memory; a queue joining module, used to add the second dynamic memory to a preset memory queue; an error release module, used to call an error release function according to the object data in the accessed second dynamic memory when the second dynamic memory in the memory queue is accessed by a pointer; a wild pointer identification module, used to identify the pointer as a wild pointer if the error release function is called and the program debugging throws an error.
[0012] Optionally, in a first implementation method of the second aspect of the present invention, the wild pointer checking device also includes a function rewriting module, which is specifically used to: create a new error release function, wherein the error release function is used to throw an error; perform a Hook operation on a first memory release function, wherein the first memory release function is a basic function preset in the system and is used to release dynamic memory; write the error release function into the first memory release function to obtain a second memory release function.
[0013] Optionally, in a second implementation method of the second aspect of the present invention, the memory occupation module is specifically used to: obtain a release instruction of the first dynamic memory; based on the release instruction, call the second memory release function to release the first dynamic memory; write the error release function into the released first dynamic memory to obtain the second dynamic memory.
[0014] Optionally, in a third implementation method of the second aspect of the present invention, the wild pointer detection device also includes an overflow determination module, and the overflow determination module is specifically used to: determine whether the size of the dynamic memory in the memory queue exceeds a preset threshold; if so, release the dynamic memory in the memory queue one by one in the order in which the dynamic memory in the memory queue is added; after releasing the dynamic memory in the memory queue, return to the step of determining whether the size of the dynamic memory in the memory queue exceeds the preset threshold, until the size of the dynamic memory in the memory queue does not exceed the preset threshold; if not, monitor whether the second dynamic memory is accessed.
[0015] Optionally, in a fourth implementation method of the second aspect of the present invention, the wild pointer checking device also includes a release function establishment module, and the release function establishment module is specifically used to: create a third memory release function, wherein the third memory release function is used to release dynamic memory; when the second dynamic memory needs to be released, run the third memory release function.
[0016] Optionally, in the fifth implementation method of the second aspect of the present invention, the wild pointer identification module is specifically used for: an error log acquisition unit, if the error release function is called and the program debugging throws an error, then a program error log is obtained; a pointer information acquisition unit, analyzing the program error log to obtain pointer information for accessing the second dynamic memory, wherein the pointer information includes the positioning information of the corresponding pointer; a wild pointer definition unit, identifying the pointer corresponding to the pointer information as a wild pointer.
[0017] Optionally, in a sixth implementation manner of the second aspect of the present invention, the pointer information acquisition unit is specifically used to: analyze the program error log to determine whether an error thrown by program debugging is caused by the calling of the second dynamic memory; if an error thrown by program debugging is caused by the calling of the second dynamic memory, then determine whether the error type of the thrown error is consistent with the error type caused by the error release function; if they are consistent, then obtain the pointer information of the second dynamic memory; if the error thrown by program debugging is not caused by the calling of the second dynamic memory or is inconsistent, then the program error log does not contain wild pointer information.
[0018] The third aspect of the present invention provides a wild pointer checking device, comprising: a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected through lines; the at least one processor calls the instructions in the memory so that the wild pointer checking device executes the steps of the above-mentioned wild pointer checking method.
[0019] A fourth aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the steps of the above-mentioned wild pointer troubleshooting method.
[0020] In the technical solution of the present invention, a first dynamic memory is allocated from a fixed memory space according to a user's memory allocation request; when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and preset object data is added to the first dynamic memory that is forcibly occupied to obtain a second dynamic memory; the second dynamic memory is added to a preset memory queue; when the second dynamic memory in the memory queue is accessed by a pointer, an error release function is called according to the object data in the accessed second dynamic memory; if the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer. This method aims at the technical problem that wild pointers can only be found with probability when debugging code in XCode. By locking the released memory area and managing it, the probability of the originally randomly occurring wild pointer problem is increased to a probability close to that of necessity, the probability of problem exposure is increased, the problem is repaired in advance, and the robustness of the system is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 This is a schematic diagram of a first embodiment of a wild pointer troubleshooting method in an embodiment of the present invention;
[0022] Figure 2 A schematic diagram of a second embodiment of a wild pointer troubleshooting method according to an embodiment of the present invention;
[0023] Figure 3 A schematic diagram of a third embodiment of a wild pointer troubleshooting method according to an embodiment of the present invention;
[0024] Figure 4 A schematic diagram of a fourth embodiment of a wild pointer troubleshooting method according to an embodiment of the present invention;
[0025] Figure 5 A schematic diagram of an embodiment of a wild pointer detection device in an embodiment of the present invention;
[0026] Figure 6 It is a schematic diagram of another embodiment of the wild pointer detection device in the embodiment of the present invention;
[0027] Figure 7 It is a schematic diagram of an embodiment of a wild pointer troubleshooting device in an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In the technical solution of the present invention, a first dynamic memory is allocated from a fixed memory space according to a user's memory allocation request; when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and preset object data is added to the first dynamic memory that is forcibly occupied to obtain a second dynamic memory; the second dynamic memory is added to a preset memory queue; when the second dynamic memory in the memory queue is accessed by a pointer, an error release function is called according to the object data in the accessed second dynamic memory; if the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer. This method aims at the technical problem that wild pointers can only be found with probability when debugging code in XCode. By locking the released memory area and managing it, the probability of the originally randomly occurring wild pointer problem is increased to a probability close to that of necessity, the probability of problem exposure is increased, the problem is repaired in advance, and the robustness of the system is improved.
[0029] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 The first embodiment of the wild pointer checking method in the embodiment of the present invention includes:
[0031] 101, allocating a first dynamic memory from a fixed memory space according to a memory allocation request of a user;
[0032] In this embodiment, a memory allocation request initiated by a user is obtained, and designated data is written into a corresponding first dynamic memory, where the first dynamic memory is a normal dynamic memory that is inevitably generated during program execution.
[0033] 102, when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and the custom class is added to the forcibly occupied first dynamic memory to obtain a second dynamic memory;
[0034] In this embodiment, when the first dynamic memory is no longer used, the dynamic memory to be released will be released through the first memory release function free(). Here, the conventional dynamic memory release action is modified to forcibly occupy the first dynamic memory, and the original data is modified in the forcibly occupied memory, and the custom class is written to obtain the second dynamic memory with the content of the custom class.
[0035] Specifically, the second dynamic memory is identified as released memory by the system.
[0036] 103, adding the second dynamic memory to a preset memory queue;
[0037] In this embodiment, the marked second dynamic memory is added to a preset memory queue, and unified management is performed on the marked second dynamic memory, thereby preventing overflow of the forcibly occupied second dynamic memory during management.
[0038] 104, when the second dynamic memory in the memory queue is accessed by the pointer, calling the error release function according to the custom class in the accessed second dynamic memory;
[0039] In this step, if the second dynamic memory is accessed by the pointer, the error release function stored in the second dynamic memory will be called, and when the error release function is called, an error prompt will inevitably be triggered.
[0040] 105, when calling the error release function throws an error, the pointer is identified as a wild pointer.
[0041] In this embodiment, the type of error thrown is not specified, and any type of error can be thrown, so that the error is identified by the system, and the pointer name that calls the second dynamic memory, that is, the wild pointer, is obtained during the identification.
[0042] In this embodiment, a first dynamic memory is allocated from a fixed memory space according to a user's memory allocation request; when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and preset object data is added to the first dynamic memory that is forcibly occupied to obtain a second dynamic memory; the second dynamic memory is added to a preset memory queue; when the second dynamic memory in the memory queue is accessed by a pointer, an error release function is called according to the object data in the accessed second dynamic memory; if the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer. This method aims at the technical problem that wild pointers can only be found with probability when debugging code in XCode. By locking the released memory area and managing it, the probability of the originally randomly occurring wild pointer problem is increased to a probability close to that of being certain to occur, thereby increasing the probability of the problem being exposed, fixing the problem in advance, and improving the robustness of the system.
[0043] See also Figure 2 The second embodiment of the wild pointer checking method in the embodiment of the present invention includes:
[0044] 201, allocating a first dynamic memory from a fixed memory space according to a memory allocation request of a user;
[0045] 202, creating a new error release function, wherein the error release function is used to throw an error;
[0046] In this embodiment, a custom class is defined in advance, and the content of the custom class is to write any error release function that can cause an error prompt.
[0047] In this embodiment, the original content of the free() function is modified into a custom class, that is, the original function is to release the dynamic memory that is no longer called, and is modified into a dynamic memory write error release function that is no longer called.
[0048] 203, performing a Hook operation on the first memory release function;
[0049] Specifically, hooking means using technical means to dynamically attach additional code to the current process at runtime, thereby achieving the purpose of replacing existing processing logic or inserting additional functions.
[0050] 204, writing the error release function into the first memory release function to obtain a second memory release function;
[0051] Specifically, by hooking the first memory release function free(), the original function of the native function is rewritten through the hook instruction. After hooking a specific system event, once the hooked event occurs, the program that hooks the event will receive a system notification, and the program can respond to the event immediately.
[0052] 205, obtaining a release instruction of the first dynamic memory;
[0053] Specifically, the so-called memory release is to release the data residing in the memory from the memory to improve the utilization rate of the system memory resources and thus improve the system performance.
[0054] 206, based on the release instruction, calling the second memory release function to release the first dynamic memory;
[0055] In this embodiment, the release instruction of the first dynamic memory generally occurs at the end of the function. If it is used in the structure of the message, it depends on the definition when writing the program. It can be automatically released by the system after processing the message, or it can be released when the specified release condition is reached.
[0056] 207, writing the error release function into the released first dynamic memory to obtain a second dynamic memory;
[0057] In this embodiment, by obtaining a release instruction, calling a memory release function that has been modified after being hooked to rewrite the memory to be released, and writing an error release function, the forced occupation of the dynamic memory is achieved.
[0058] 208, adding the second dynamic memory to a preset memory queue;
[0059] 209, when the second dynamic memory in the memory queue is accessed by the pointer, calling an error release function according to the object data in the accessed second dynamic memory;
[0060] 210. If the wrong release function is called and the program debugger throws an error, the pointer will be identified as a wild pointer.
[0061] Based on the previous embodiment, this embodiment describes in detail the process of creating a new error release function, wherein the error release function is used to throw an error; performing a Hook operation on the first memory release function, wherein the first memory release function is a basic function preset in the system and is used to release dynamic memory; and writing the error release function into the first memory release function to obtain the second memory release function. Compared with the traditional method, this embodiment refines the specific description of the Hook action, and through the Hook command, the original function of releasing dynamic memory that is no longer called is modified to writing the error release function into the dynamic memory that is no longer called.
[0062] See also Figure 3 The third embodiment of the wild pointer checking method in the embodiment of the present invention includes:
[0063] 301, allocating a first dynamic memory from a fixed memory space according to a memory allocation request of a user;
[0064] 302, when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and the preset object data is added to the forcibly occupied first dynamic memory to obtain a second dynamic memory;
[0065] 303, creating a third memory release function, where the third memory release function is used to release the dynamic memory;
[0066] In this embodiment, because the system's native memory release function has been modified after being hooked and no longer has the release function, it is necessary to create a third memory release function to realize the function of truly releasing memory and prevent memory overflow.
[0067] 304, when the second dynamic memory needs to be released, execute the third memory release function;
[0068] 305, determining whether the size of the dynamic memory in the memory queue exceeds a preset threshold;
[0069] In this embodiment, by obtaining the ratio of the capacity of the memory queue to the size of the dynamic memory in the queue, it is determined whether it exceeds the preset threshold.
[0070] 306, if yes, release the dynamic memories in the memory queue one by one in the order in which the dynamic memories in the memory queue are added;
[0071] In this embodiment, if the dynamic memory stored in the memory queue exceeds a preset threshold, the dynamic memory first added to the queue needs to be released first according to the order of adding to the memory queue.
[0072] 307, after releasing the dynamic memory in the memory queue, return to the step of determining whether the size of the dynamic memory in the memory queue exceeds a preset threshold, until the size of the dynamic memory in the memory queue does not exceed the preset threshold;
[0073] Specifically, by determining whether the memory queue has an overflow risk before adding new dynamic memory, it is possible to effectively prevent new problems from being added during the process of searching for wild pointers, thereby affecting the test progress.
[0074] 308, if not, monitoring whether the second dynamic memory is accessed;
[0075] In this embodiment, when there is no overflow risk for the memory queue, it remains silent, waiting for the wild pointer to access the second dynamic memory, and then calls out a preset error prompt.
[0076] 309, adding the second dynamic memory to a preset memory queue;
[0077] 310, when the second dynamic memory in the memory queue is accessed by the pointer, calling an error release function according to the object data in the accessed second dynamic memory;
[0078] 311. If the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer.
[0079] Based on the previous embodiment, this embodiment describes in detail the process of determining whether the size of the dynamic memory in the memory queue exceeds a preset threshold; if so, releasing the dynamic memory in the memory queue one by one in the order in which the dynamic memory in the memory queue is added; after releasing the dynamic memory in the memory queue, returning to the step of determining whether the size of the dynamic memory in the memory queue exceeds the preset threshold, until the size of the dynamic memory in the memory queue does not exceed the preset threshold; if not, monitoring whether the second dynamic memory is accessed. Compared with the traditional method, this embodiment can effectively prevent the addition of new problems in the process of searching for wild pointers by first determining whether the memory queue has an overflow risk before adding new dynamic memory, thereby affecting the test progress.
[0080] See also Figure 4 The fourth embodiment of the wild pointer checking method in the embodiment of the present invention includes:
[0081] 401, allocating a first dynamic memory from a fixed memory space according to a memory allocation request of a user;
[0082] 402, when the first dynamic memory is released, the first dynamic memory is forcibly occupied, and the preset object data is added to the forcibly occupied first dynamic memory to obtain a second dynamic memory;
[0083] 403, adding the second dynamic memory to a preset memory queue;
[0084] 404, when the second dynamic memory in the memory queue is accessed by the pointer, calling an error release function according to the object data in the accessed second dynamic memory;
[0085] 405, if the error release function is called and the program debugging throws an error, a program error log is obtained;
[0086] In this embodiment, the error log is different from the access log in both format and content. However, the error log, like the access log, also provides rich information, which we can use to analyze the operation of the server and where problems occur.
[0087] 406, analyzing the program error log to determine whether the error thrown by the program debugging is caused by the calling of the second dynamic memory;
[0088] Specifically, the error result can be accurately judged by analyzing multiple dimensions such as error type, error cause, and error location.
[0089] 407, if the error thrown by the program debugging is caused by the second dynamic memory being called, determine whether the error type of the thrown error is consistent with the error type caused by the error release function;
[0090] Specifically, because of the consideration of the error type caused by the non-wild pointer, a comparison and judgment step of the error type and the preset error release function is added here.
[0091] 408, if they are consistent, obtaining the pointer information of the second dynamic memory;
[0092] 409, if the error thrown by the program debugging is not caused by the second dynamic memory being called or inconsistent, the program error log does not contain wild pointer information;
[0093] Specifically, it means that the error that occurred this time is highly likely to be irrelevant to our goal and the troubleshooting of wild pointers. We need to use other methods to study and modify this error.
[0094] 410, identifying the pointer corresponding to the pointer information as a wild pointer.
[0095] Based on the previous embodiment, this embodiment describes in detail the process of obtaining a program error log if the error release function is called and the program debugging throws an error; analyzing the program error log to obtain pointer information for accessing the second dynamic memory, wherein the pointer information includes the location information of the corresponding pointer; and identifying the pointer corresponding to the pointer information as a wild pointer. Because the error log is different from the access log in both format and content. However, the error log, like the access log, also provides rich information, which can be used to analyze the operation of the server and where the problem occurred.
[0096] The above describes the wild pointer detection method in the embodiment of the present invention. The following describes the wild pointer detection device in the embodiment of the present invention. Figure 5 In one embodiment of the present invention, a wild pointer checking device includes:
[0097] The memory application module 501 is used to allocate a first dynamic memory from a fixed memory space according to a memory allocation request of a user;
[0098] A memory occupation module 502, configured to forcibly occupy the first dynamic memory when the first dynamic memory is released, and add preset object data to the forcibly occupied first dynamic memory to obtain a second dynamic memory;
[0099] A queue adding module 503, used for adding the second dynamic memory to a preset memory queue;
[0100] An error release module 504 is used to call an error release function according to object data in the accessed second dynamic memory when the second dynamic memory in the memory queue is accessed by a pointer;
[0101] The wild pointer identification module 505 is used to identify the pointer as a wild pointer if the error release function is called and the program debugging throws an error.
[0102] In an embodiment of the present invention, a wild pointer checking device runs the above-mentioned wild pointer checking method, including: allocating a first dynamic memory from a fixed memory space according to a user's memory allocation request; when the first dynamic memory is released, forcibly occupying the first dynamic memory, and adding preset object data to the first dynamic memory that is forcibly occupied to obtain a second dynamic memory; adding the second dynamic memory to a preset memory queue; when the second dynamic memory in the memory queue is accessed by a pointer, calling an error release function according to the object data in the accessed second dynamic memory; if the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer. This method aims at the technical problem that wild pointers can only be found with probability when debugging code in XCode. By locking the released memory area and managing it, the probability of the originally randomly occurring wild pointer problem is increased to a probability close to that of being certain to occur, thereby increasing the probability of the problem being exposed, repairing the problem in advance, and improving the robustness of the system.
[0103] See also Figure 6 The second embodiment of the wild pointer checking device in the embodiment of the present invention includes:
[0104] A memory application module 501, configured to allocate a first dynamic memory from a fixed memory space according to a memory allocation request of a user;
[0105] A memory occupation module 502, configured to forcibly occupy the first dynamic memory when the first dynamic memory is released, and add preset object data to the forcibly occupied first dynamic memory to obtain a second dynamic memory;
[0106] A queue adding module 503, used for adding the second dynamic memory to a preset memory queue;
[0107] An error release module 504 is used to call an error release function according to object data in the accessed second dynamic memory when the second dynamic memory in the memory queue is accessed by a pointer;
[0108] The wild pointer identification module 505 is used to identify the pointer as a wild pointer if the error release function is called and the program debugging throws an error.
[0109] In this embodiment, the wild pointer checking device further includes a function rewriting module 506, and the function rewriting module 506 is specifically used for:
[0110] A new error release function is created, wherein the error release function is used to throw an error; a first memory release function is hooked, wherein the first memory release function is a basic function preset in the system and is used to release dynamic memory; the error release function is written into the first memory release function to obtain a second memory release function.
[0111] In this embodiment, the memory usage module 502 is specifically used for:
[0112] Obtain a release instruction of the first dynamic memory; based on the release instruction, call the second memory release function to release the first dynamic memory; write the error release function into the released first dynamic memory to obtain the second dynamic memory.
[0113] In this embodiment, the wild pointer detection device further includes an overflow determination module 507, and the overflow determination module 507 is specifically used for:
[0114] Determine whether the size of the dynamic memory in the memory queue exceeds a preset threshold; if so, release the dynamic memory in the memory queue one by one in the order in which the dynamic memory in the memory queue is added; after releasing the dynamic memory in the memory queue, return to the step of determining whether the size of the dynamic memory in the memory queue exceeds the preset threshold, until the size of the dynamic memory in the memory queue does not exceed the preset threshold; if not, monitor whether the second dynamic memory is accessed.
[0115] In this embodiment, the wild pointer detection device further includes a release function establishment module 508, and the release function establishment module 508 is specifically used to:
[0116] A third memory release function is newly created, wherein the third memory release function is used to release the dynamic memory; when the second dynamic memory needs to be released, the third memory release function is executed.
[0117] In this embodiment, the wild pointer identification module 505 is specifically used for:
[0118] The error log acquisition unit 5051 obtains a program error log if the error release function is called and the program debugging throws an error; the pointer information acquisition unit 5052 analyzes the program error log to obtain pointer information for accessing the second dynamic memory, wherein the pointer information includes the location information of the corresponding pointer; and the wild pointer definition unit identifies the pointer corresponding to the pointer information as a wild pointer.
[0119] In this embodiment, the pointer information obtaining unit 5052 is specifically used for:
[0120] Analyze the program error log to determine whether the error thrown by program debugging is caused by the calling of the second dynamic memory; if the error thrown by program debugging is caused by the calling of the second dynamic memory, determine whether the error type of the thrown error is consistent with the error type caused by the error release function; if they are consistent, obtain the pointer information of the second dynamic memory; if the error thrown by program debugging is not caused by the calling of the second dynamic memory or is inconsistent, the program error log does not include wild pointer information.
[0121] Based on the previous embodiment, this embodiment describes in detail the specific functions of each module and the unit composition of some modules. Through the newly added modules, a function rewriting module, a memory occupation module, an overflow judgment module, and a release function establishment module are added. Through the above modules and the specific functions of the original modules are refined, the operation of the wild pointer detection device is improved, the reliability during operation is improved, the actual logic between each step is clarified, and the practicability of the device is improved.
[0122] above Figure 5 and Figure 6 The wild pointer checking device in the embodiment of the present invention is described in detail from the perspective of modular functional entities, and the wild pointer checking device in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0123] Figure 7 It is a structural diagram of a wild pointer checking device provided by an embodiment of the present invention. The wild pointer checking device 700 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 710 (for example, one or more processors) and a memory 720, and one or more storage media 730 (for example, one or more massive storage devices) storing application programs 733 or data 732. Among them, the memory 720 and the storage medium 730 may be short-term storage or permanent storage. The program stored in the storage medium 730 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the wild pointer checking device 700. Furthermore, the processor 710 may be configured to communicate with the storage medium 730, and execute a series of instruction operations in the storage medium 730 on the wild pointer checking device 700 to implement the steps of the above-mentioned wild pointer checking method.
[0124] The wild pointer detection device 700 may also include one or more power supplies 740, one or more wired or wireless network interfaces 750, one or more input and output interfaces 760, and / or one or more operating systems 731, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Figure 7 The wild pointer troubleshooting device structure shown does not constitute a limitation on the wild pointer troubleshooting device provided in the present application, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0125] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the wild pointer checking method.
[0126] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system, device, or unit can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0127] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0128] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A wild pointer detection method, characterized in that: The wild pointer troubleshooting method includes: Allocating a first dynamic memory from a fixed memory space according to a memory allocation request of a user; When the first dynamic memory is released, the first dynamic memory is forcibly occupied, and the preset object data is added to the first dynamic memory forcibly occupied to obtain a second dynamic memory; Adding the second dynamic memory to a preset memory queue; When the second dynamic memory in the memory queue is accessed by the pointer, calling an error release function according to the object data in the accessed second dynamic memory; If the error release function is called and the program debugging throws an error, the pointer is identified as a wild pointer; When the first dynamic memory is released, the first dynamic memory is forcibly occupied, and the preset object data is added to the first dynamic memory that is forcibly occupied, before obtaining the second dynamic memory, the method further includes: creating a new error release function, wherein the error release function is used to throw an error; performing a Hook operation on the first memory release function, wherein the first memory release function is a basic function preset in the system and is used to release the dynamic memory; and writing the error release function into the first memory release function to obtain the second memory release function; If the program debugging throws an error when the error release function is called, the pointer is identified as a wild pointer, including: if the program debugging throws an error when the error release function is called, a program error log is obtained; the program error log is analyzed to obtain pointer information for accessing the second dynamic memory, wherein the pointer information includes positioning information of the corresponding pointer; and the pointer corresponding to the pointer information is identified as a wild pointer.
2. The wild pointer detection method according to claim 1 is characterized in that: When the first dynamic memory is released, the first dynamic memory is forcibly occupied, and the preset object data is added to the forcibly occupied first dynamic memory to obtain the second dynamic memory, which includes: Obtaining a release instruction of the first dynamic memory; Based on the release instruction, calling the second memory release function to release the first dynamic memory; The error release function is written into the released first dynamic memory to obtain the second dynamic memory.
3. The wild pointer detection method according to claim 1 is characterized in that: Before adding the second dynamic memory to the preset memory queue, the method further includes: Determine whether the size of the dynamic memory in the memory queue exceeds a preset threshold; If yes, then releasing the dynamic memories in the memory queue one by one according to the order in which the dynamic memories in the memory queue are added; After releasing the dynamic memory in the memory queue, returning to the step of determining whether the size of the dynamic memory in the memory queue exceeds a preset threshold, until the size of the dynamic memory in the memory queue does not exceed the preset threshold; If not, monitor whether the second dynamic memory is accessed.
4. The wild pointer detection method according to claim 3 is characterized in that: Before determining whether the size of the dynamic memory in the memory queue exceeds a preset threshold, the method further includes: Create a third memory release function, wherein the third memory release function is used to release dynamic memory; When the second dynamic memory needs to be released, the third memory release function is executed.
5. The wild pointer detection method according to claim 1 is characterized in that: The program error log includes the error type of the thrown error; and the analyzing the program error log to obtain the pointer information for accessing the second dynamic memory includes: Analyze the program error log to determine whether the program debugging error is caused by the calling of the second dynamic memory; If the error thrown by the program debugging is caused by the calling of the second dynamic memory, determining whether the error type of the thrown error is consistent with the error type caused by the error release function; If they are consistent, the pointer information of the second dynamic memory is obtained; If the error thrown by program debugging is not caused by the calling of the second dynamic memory or the inconsistency, the program error log does not include wild pointer information.
6. A wild pointer detection device, characterized in that: The wild pointer checking device comprises: A memory application module, used for allocating a first dynamic memory from a fixed memory space according to a memory allocation request of a user; A memory occupation module, used for forcibly occupying the first dynamic memory when the first dynamic memory is released, and adding preset object data to the forcibly occupied first dynamic memory to obtain a second dynamic memory; A queue adding module, used for adding the second dynamic memory to a preset memory queue; An error release module, configured to call an error release function according to object data in the accessed second dynamic memory when the second dynamic memory in the memory queue is accessed by a pointer; A wild pointer identification module, used for identifying the pointer as a wild pointer if the error release function is called and the program debugging throws an error; The wild pointer troubleshooting device also includes a function rewriting module, which is specifically used to: create a new error release function, wherein the error release function is used to throw an error; perform a Hook operation on a first memory release function, wherein the first memory release function is a basic function preset in the system and is used to release dynamic memory; write the error release function into the first memory release function to obtain a second memory release function; The wild pointer identification module is specifically used for: an error log acquisition unit, if the error release function is called and the program debugging throws an error, then a program error log is obtained; a pointer information acquisition unit, analyzing the program error log to obtain pointer information for accessing the second dynamic memory, wherein the pointer information includes the location information of the corresponding pointer; a wild pointer definition unit, identifying the pointer corresponding to the pointer information as a wild pointer.
7. A wild pointer detection device, characterized in that: The wild pointer checking device comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instruction in the memory so that the wild pointer detection device executes each step of the wild pointer detection method as described in any one of claims 1-5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the wild pointer detection method as described in any one of claims 1 to 5 is implemented.
