Null pointer access detection method and device, equipment and storage medium
By obtaining the error information of abnormal interruption of the memory protection unit MPU and positioning the specific location of the null pointer access, the limitations and performance overhead of the existing technology of hollow pointer access detection and debugging are solved, and the effect of rapid positioning and repair is achieved, and the detection efficiency and system stability are improved.
Patent Information
- Application Number
- CN202510129754.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-05
- Publication Date
- 2025-06-03
AI Technical Summary
The existing technology has limitations in hollow pointer access detection and debugging, requiring hardware support, and has a large performance overhead. It is prone to restart and cannot locate, no errors reported, and the problem of not being able to locate the function position when there is a problem with the debugging machine.
By detecting that the current program has a null pointer access, the error information of the memory protection unit MPU is obtained; the error type and error position are determined based on the error information; and the specific location of the access to the null pointer is located according to the error type and error position.
It can quickly locate the specific location of the problem, facilitate debugging and repairing, help developers quickly locate the points and causes of the problem, improve the speed and efficiency of null pointer access detection, prevent write values or perform operations on zero addresses, and protect the stability and security of the system.
Smart Images

Figure CN120086117A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer programming, and particularly to a method, apparatus, device and storage medium for detecting null pointer access. Background Art
[0002] In computer programming, a pointer is a variable used to store a memory address; through a pointer, a program can directly access and operate on data in memory; however, if a pointer is not initialized correctly or points to an invalid memory address (i.e., a null pointer), when the program attempts to access memory through this pointer, a null pointer access error will occur; such an error may lead to serious consequences, such as program crashes, data corruption, system failures, etc.; therefore, detecting null pointer access is a crucial part of the software development process.
[0003] With the wide application of embedded systems, the requirements for software reliability and stability are getting higher and higher. In embedded systems, due to resource constraints and real-time requirements, null pointer access errors may bring more serious consequences; therefore, null pointer access detection technologies for embedded systems have been widely studied and applied. Currently, common null pointer access detection methods include performing pointer checks during coding, compiler warnings, and static analysis tools, etc.; these methods can help developers detect and avoid null pointer access errors to a certain extent, but there are still some limitations.
[0004] In addition to the above common null pointer access detection methods, there are also some other competing technologies, such as dynamic analysis tools, hardware-assisted detection technologies, etc.
[0005] Dynamic analysis tools detect null pointer access errors by monitoring the usage of pointers during program execution. This method can provide more accurate detection results, but usually brings a large performance overhead.
[0006] Hardware-assisted detection technologies utilize the characteristics of hardware to detect null pointer access errors; for example, some processors provide special instructions or registers to detect null pointer access. This method can provide efficient detection without affecting performance, but requires hardware support.
[0007] Common null pointer access detection methods can only play a monitoring role. If the static code or compilation warning results are not detected, unexpected problems may occur during debugging, such as the program restarting directly without being able to locate the reason, not reporting any errors, and not being able to directly locate the specific function position when the debugging machine has problems, which brings difficulties for developers to quickly locate and solve problems. Summary of the Invention
[0008] The main object of the present invention is to provide a null pointer access detection method, apparatus, device and storage medium, aiming to solve the technical problems in the prior art that null pointer access detection and debugging have limitations, require hardware support, have a large performance overhead, are prone to restart without being able to locate, do not report any errors, and are unable to locate the function position when the debugging machine has problems.
[0009] In a first aspect, the present invention provides a null pointer access detection method, and the null pointer access detection method includes the following steps:
[0010] When it is detected that a null pointer access occurs in the current program, obtain the error information of the memory protection unit MPU exception interrupt;
[0011] Determine the error type and error location according to the error information;
[0012] Locate the specific location of the null pointer access according to the error type and the error location.
[0013] Optionally, before obtaining the error information of the memory protection unit MPU exception interrupt when it is detected that a null pointer access occurs in the current program, the null pointer access detection method further includes:
[0014] Use the memory protection unit MPU to set the null pointer exception access permission for the zero address to implement the control of memory access.
[0015] Optionally, the use of the memory protection unit MPU to set the null pointer exception access permission for the zero address to implement the control of memory access includes:
[0016] Use the registers related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address to implement the control of memory access.
[0017] Optionally, the use of the registers related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address to implement the control of memory access includes:
[0018] Use the registers related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address, so that the zero address is readable in the privileged mode and the user mode, but not executable and not writable, to implement the control of memory access.
[0019] Optionally, the obtaining of the error information of the memory protection unit MPU exception interrupt when it is detected that a null pointer access occurs in the current program includes:
[0020] When a null pointer access occurs in the current program, obtain the error information that causes the memory protection unit (MPU) exception interrupt, save the error information, and print a log.
[0021] Optionally, the determining the error type and error location according to the error information includes:
[0022] Obtain the error identifier corresponding to the error information, the current pointer position of the program counter pointer when the positioning problem occurs, the memory address accessed when the positioning problem occurs, and the return address of the null pointer function when the positioning problem occurs;
[0023] Determine the error type according to the error identifier, and determine the error location according to the current pointer position, the memory address, and the return address.
[0024] Optionally, the positioning the specific position of the null pointer access according to the error type and the error location includes:
[0025] Determine the counter pointer position and the null pointer function return address of the current error according to the error type and the error location;
[0026] Locate the null pointer access according to the counter pointer position and the null pointer function return address, and determine the specific position of the null pointer access.
[0027] In a second aspect, to achieve the above object, the present invention also proposes a null pointer access detection device, where the null pointer access detection device includes:
[0028] An information acquisition module, configured to obtain error information of a memory protection unit (MPU) exception interrupt when it is detected that a null pointer access occurs in the current program;
[0029] An error determination module, configured to determine an error type and an error location according to the error information;
[0030] A position location module, configured to locate the specific position of the null pointer access according to the error type and the error location.
[0031] In a third aspect, to achieve the above object, the present invention also proposes a null pointer access detection device, where the null pointer access detection device includes: a memory, a processor, and a null pointer access detection program stored on the memory and executable on the processor, and the null pointer access detection program is configured to implement the steps of the null pointer access detection method as described above.
[0032] Fourthly, to achieve the above object, the present invention further provides a storage medium, on which an empty pointer access detection program is stored. When the empty pointer access detection program is executed by a processor, the steps of the empty pointer access detection method as described above are implemented.
[0033] In the empty pointer access detection method proposed by the present invention, when it is detected that an empty pointer access occurs in the current program, the error information of the memory protection unit MPU exception interrupt is obtained; the error type and error position are determined according to the error information; and the specific position of accessing the empty pointer is located according to the error type and the error position. This can prevent writing values or executing operations on the zero address, protect the stability and security of the system, quickly locate the specific position where the problem occurs, facilitate debugging and repair, help developers quickly locate the problem occurrence point and cause, and improve the speed and efficiency of empty pointer access detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a schematic diagram of the device structure of the hardware operating environment related to the solution of the embodiment of the present invention;
[0035] Figure 2 It is a schematic flowchart of the first embodiment of the empty pointer access detection method of the present invention;
[0036] Figure 3 It is a schematic flowchart of the second embodiment of the empty pointer access detection method of the present invention;
[0037] Figure 4 It is a schematic flowchart of the third embodiment of the empty pointer access detection method of the present invention;
[0038] Figure 5 It is a schematic flowchart of the fourth embodiment of the empty pointer access detection method of the present invention;
[0039] Figure 6 It is a schematic flowchart of the fifth embodiment of the empty pointer access detection method of the present invention;
[0040] Figure 7 It is a functional module diagram of the first embodiment of the empty pointer access detection device of the present invention.
[0041] The implementation, functional features and advantages of the object of the present invention will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0042] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0043] The solution of the embodiment of the present invention is mainly as follows: when it is detected that a null pointer access occurs in the current program, the error information of the memory protection unit MPU exception interruption is obtained; the error type and the error position are determined according to the error information; the specific position of the null pointer access is located according to the error type and the error position, which can prevent writing values or performing operations on the zero address, protect the stability and security of the system, can quickly locate the specific position where the problem occurs, facilitate debugging and repair, help developers quickly locate the problem occurrence point and reason, improve the speed and efficiency of null pointer access detection, and solve the technical problems in the prior art that the null pointer access detection and debugging have limitations, require hardware support, have a large performance overhead, are prone to restart and unable to locate, do not report any errors, and are unable to locate the function position when the debugging machine has problems.
[0044] Refer to Figure 1 , Figure 1 which is a schematic diagram of the device structure of the hardware operating environment involved in the solution of the embodiment of the present invention.
[0045] As Figure 1 shown, the device may include: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard). Optionally, the user interface 1003 may further include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed RAM memory or a stable memory (Non-Volatile Memory), such as a disk memory. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0046] Those skilled in the art can understand that Figure 1 the device structure shown in
[0047] does not constitute a limitation to the device, and may include more or fewer components than shown in the figure, or combine some components, or have different component arrangements. Figure 1 As
[0048] shown, the memory 1005, as a storage medium, may include an operating device, a network communication module, a user interface module, and a null pointer access detection program.
[0049] When a null pointer access occurs in the current program, obtain the error information of the memory protection unit MPU exception interrupt;
[0050] Determine the error type and error location according to the error information;
[0051] Locate the specific location of the null pointer access according to the error type and the error location.
[0052] The device of the present invention calls the null pointer access detection program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0053] Use the memory protection unit MPU to set the null pointer exception access permission for the zero address to control the memory access.
[0054] The device of the present invention calls the null pointer access detection program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0055] Use the register related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address to control the memory access.
[0056] The device of the present invention calls the null pointer access detection program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0057] Use the register related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address, so that the zero address is readable in the privileged mode and the user mode, but not executable and not writable, to control the memory access.
[0058] The device of the present invention calls the null pointer access detection program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0059] When a null pointer access occurs in the current program, obtain the error information that causes the memory protection unit MPU exception interrupt, save the error information, and print the log.
[0060] The device of the present invention calls the null pointer access detection program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0061] Obtain the error identifier corresponding to the error information, the current pointer position of the program counter pointer when the positioning problem occurs, the memory address accessed when the positioning problem occurs, and the return address of the null pointer function when the positioning problem occurs;
[0062] Determine the error type according to the error identifier, and determine the error location according to the current pointer position, the memory address, and the return address.
[0063] The device of the present invention calls the null pointer access detection program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0064] Determine the counter pointer position and the null pointer function return address of the current error according to the error type and the error location;
[0065] Locate the access to the null pointer according to the counter pointer position and the null pointer function return address, and determine the specific position of the access to the null pointer.
[0066] Through the above solution in this embodiment, when it is detected that the current program has a null pointer access, the error information of the memory protection unit MPU exception interruption is obtained; the error type and the error location are determined according to the error information; the specific position of the access to the null pointer is located according to the error type and the error location, which can prevent writing values or performing operations on the zero address, protect the stability and security of the system, can quickly locate the specific position where the problem occurs, is convenient for debugging and repair, helps developers quickly locate the problem occurrence point and reason, and improves the speed and efficiency of null pointer access detection.
[0067] Based on the above hardware structure, an embodiment of the null pointer access detection method of the present invention is proposed.
[0068] Refer to Figure 2 , Figure 2 is a schematic flowchart of the first embodiment of the null pointer access detection method of the present invention.
[0069] In the first embodiment, the null pointer access detection method includes the following steps:
[0070] Step S10: When it is detected that the current program has a null pointer access, obtain the error information of the memory protection unit MPU exception interruption.
[0071] It should be noted that when it is detected that the current program has a null pointer access, the error information of the memory protection unit (Memory Protection Unit, MPU) exception interruption can be obtained.
[0072] Step S20: Determine the error type and the error location according to the error information.
[0073] It should be understood that according to the error information, the error type and the error location located by the error information can be determined.
[0074] Step S30: Locate the specific position of the null pointer access according to the error type and the error position.
[0075] It can be understood that the specific position of the null pointer access can be located according to the error type and the error position.
[0076] In this embodiment, through the above solution, when it is detected that a null pointer access occurs in the current program, the error information of the memory protection unit MPU exception interrupt is obtained; the error type and the error position are determined according to the error information; the specific position of the null pointer access is located according to the error type and the error position, which can prevent writing values or performing operations on the zero address, protect the stability and security of the system, can quickly locate the specific position where the problem occurs, facilitate debugging and repair, help developers quickly locate the problem occurrence point and reason, and improve the speed and efficiency of null pointer access detection.
[0077] Furthermore, Figure 3 is a flowchart of the second embodiment of the null pointer access detection method of the present invention. As Figure 3 shown, based on the first embodiment, the second embodiment of the null pointer access detection method of the present invention is proposed. In this embodiment, before the step S10, the null pointer access detection method further includes the following steps:
[0078] Step S01: Use the memory protection unit MPU to set the null pointer exception access permission for the zero address to implement the control of memory access.
[0079] It should be noted that the memory protection unit MPU can be used to set the null pointer exception access permission for the zero address, and the control of memory access can be implemented.
[0080] Furthermore, the step S01 specifically includes the following steps:
[0081] Use the registers related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address to implement the control of memory access.
[0082] It can be understood that the access permission of a specific address can be set through the MPU-related registers to implement the fine control of memory access.
[0083] Furthermore, the step of using the registers related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address to implement the control of memory access specifically includes the following steps:
[0084] Perform preset access permission settings for null pointer exception access to the zero address using registers related to the Memory Protection Unit (MPU), so that the zero address is readable in both privileged mode and user mode, but not executable and not writable, in order to achieve control over memory access.
[0085] In a specific implementation, for example, on RH850, the null pointer exception access permission settings for the zero address can be performed using the MPU memory protection method. Configure the MPU-related registers, set the access permission for the 0 address, with the range from 0x00000000 to 0x00000003, and the access permission is SR, UR (readable in privileged mode / user mode, not executable, not writable). SR is readable in privileged mode, and UR is readable in user mode, that is, readable in both privileged mode and user mode, but not executable and not writable. Of course, in a specific implementation, more types of chips can be used compatibly, corresponding adaptation versions can be provided for different types of chips, and the scheme can be automatically adjusted according to the detection result by automatically detecting whether the chip has the MPU function, so as to improve the generality of the scheme. Of course, it can also not rely on the MPU function and provide a similar protection effect for other types of chips. This embodiment does not limit this.
[0086] Through the above scheme, this embodiment realizes the control of memory access by setting the null pointer exception access permission for the zero address using the Memory Protection Unit (MPU), which can quickly realize the control of memory access and improve the speed and efficiency of null pointer access detection.
[0087] Furthermore, Figure 4 This is a schematic flowchart of the third embodiment of the null pointer access detection method of the present invention. As Figure 4 shown, based on the first embodiment, the third embodiment of the null pointer access detection method of the present invention is proposed. In this embodiment, the step S10 specifically includes the following steps:
[0088] Step S11: When it is detected that a null pointer access occurs in the current program, obtain the error information that causes the Memory Protection Unit (MPU) exception interrupt, save the error information, and print a log.
[0089] It should be noted that during the operation of the system, if a null pointer access (writing a value or performing an operation on the zero address) occurs, an MPU exception interrupt will be generated, and the error information when the error occurs in the MPU exception interrupt can be saved.
[0090] It is understandable that when a null pointer access occurs, the error information can be saved in a timely manner and the log can be printed, which is convenient for subsequent problem troubleshooting and location. To implement the saving of error reports, the MPU exception interruption mechanism can be used to capture and handle the null pointer access error in a timely manner, save the error information for subsequent analysis and location of the problem, so that developers can locate the specific location of the null pointer access according to the error report, and thus quickly solve the problem.
[0091] Through the above solution in this embodiment, when it is detected that a null pointer access occurs in the current program, the error information that causes the memory protection unit MPU exception interruption is obtained, the error information is saved, and the log is printed, so that multi-dimensional information in various scenarios can be quickly obtained, and the speed and efficiency of null pointer access detection are improved.
[0092] Furthermore, Figure 5 FIG. is a schematic flowchart of the fourth embodiment of the null pointer access detection method of the present invention. As Figure 5 shown, based on the first embodiment, the fourth embodiment of the null pointer access detection method of the present invention is proposed. In this embodiment, the step S20 specifically includes the following steps:
[0093] Step S21, obtain the error identifier corresponding to the error information, the current pointer position of the program counter pointer when the positioning problem occurs corresponding to the error information, the memory address accessed when the positioning problem occurs, and the return address of the null pointer function when the positioning problem occurs.
[0094] It should be noted that after an MPU exception interrupt occurs, the error information when an error occurs during the interrupt process can be saved, including FEIC (Oserror type), FEPC (the position of the PC pointer when the problem occurs), MEA (the memory address accessed when the problem occurs), MEI (the error information of the problem that occurs, bit0: 0: read, 1: write), LR (the return address of the function when the problem occurs), and the log is printed; the Fault Error Identification Code (FEIC) is an error identifier of the Oserror type, and OSError is an exception type in Python; when a fault or problem event occurs, the position where the program counter is located at that time (Fault Event Program Counter, FEPC) is the position of the program counter (PC) pointer when the problem occurs. PC is a register in the computer processor used to store the memory address of the next instruction to be executed. The Memory Accessed Address (MEA) is the memory address accessed when the problem occurs; the Memory Error Information (MEI) is the error information of the problem that occurs, where bit0 indicates a read or write operation; the Link Register (LR): the return address of the function when the problem occurs.
[0095] Step S22: Determine the error type according to the error identifier, and determine the error location according to the current pointer position, the memory address, and the return address.
[0096] It can be understood that the error type can be determined through the error identifier, that is, the problem type can be seen according to FEIC: executing a null pointer function or assigning a value to a null pointer error; the error location can be determined through the current pointer position, the memory address, and the return address, that is, the position where the problem occurs can be located according to FEPC and LR; correspondingly, it can be seen from MEA and MEI whether the error is a write value access error to a zero address.
[0097] Through the above solution in this embodiment, by obtaining the error identifier corresponding to the error information, the current pointer position for positioning the program counter pointer when the problem occurs corresponding to the error information, the memory address accessed when the problem occurs is positioned, and the return address of the null pointer function when the problem occurs is positioned; the error type is determined according to the error identifier, and the error location is determined according to the current pointer position, the memory address, and the return address, so that the error information can be determined, and the speed and efficiency of null pointer access detection are improved.
[0098] Furthermore, Figure 6This is a flowchart of the fifth embodiment of the null pointer access detection method of the present invention. As Figure 6 shown, the fifth embodiment of the null pointer access detection method of the present invention is proposed based on the first embodiment. In this embodiment, the step S30 specifically includes the following steps:
[0099] Step S31: Determine the counter pointer position and the null pointer function return address of the current error according to the error type and the error position.
[0100] It should be noted that the current error can be determined according to the error type, and the counter pointer position and the null pointer function return address of the current error can be determined according to the error position.
[0101] Step S32: Locate the access to the null pointer according to the counter pointer position and the null pointer function return address, and determine the specific position of the access to the null pointer.
[0102] It can be understood that the position where the interruption problem occurs can be located according to the counter pointer position and the null pointer function return address, that is, the access to the null pointer is located, and then the specific position of the access to the null pointer is determined. The specific position of the access to the null pointer is located according to the error message, which helps the developer quickly locate the problem occurrence point and cause, and solve the problem in time.
[0103] In this embodiment, through the above solution, the counter pointer position and the null pointer function return address of the current error are determined by the error type and the error position; the access to the null pointer is located according to the counter pointer position and the null pointer function return address, and the specific position of the access to the null pointer is determined, which can prevent writing values or performing operations on the zero address, protect the stability and security of the system, can quickly locate the specific position where the problem occurs, facilitate debugging and repair, help the developer quickly locate the problem occurrence point and cause, and improve the speed and efficiency of null pointer access detection.
[0104] Correspondingly, the present invention further provides a null pointer access detection device.
[0105] Referring to Figure 7 , Figure 7 This is a functional module diagram of the first embodiment of the null pointer access detection device of the present invention.
[0106] In the first embodiment of the null pointer access detection device of the present invention, the null pointer access detection device includes:
[0107] An information acquisition module 10, configured to acquire error information of an MPU exception interruption when it is detected that a null pointer access occurs in the current program.
[0108] An error determination module 20, configured to determine an error type and an error location according to the error information.
[0109] A position location module 30, configured to locate a specific location where the null pointer is accessed according to the error type and the error location.
[0110] The information acquisition module 10 is further configured to use a memory protection unit MPU to set null pointer exception access permissions for a zero address, so as to implement control over memory access.
[0111] The information acquisition module 10 is further configured to use registers related to the memory protection unit MPU to perform preset access permission settings for null pointer exception access to the zero address, so as to implement control over memory access.
[0112] The information acquisition module 10 is further configured to use registers related to the memory protection unit MPU to perform preset access permission settings for null pointer exception access to the zero address, so that the zero address is readable in privileged mode and user mode, but not executable and not writable, so as to implement control over memory access.
[0113] The information acquisition module 10 is further configured to, when detecting that a null pointer access occurs in the current program, acquire error information that causes an exception interrupt of the memory protection unit MPU, save the error information, and print a log.
[0114] The error determination module 20 is further configured to acquire an error identifier corresponding to the error information, a current pointer position of a program counter pointer when the positioning problem occurs, a memory address accessed when the positioning problem occurs, and a return address of a null pointer function when the positioning problem occurs; determine an error type according to the error identifier, and determine an error location according to the current pointer position, the memory address, and the return address.
[0115] The position location module 30 is further configured to determine a counter pointer position and a null pointer function return address of the current error according to the error type and the error location; locate the null pointer access according to the counter pointer position and the null pointer function return address, and determine a specific location where the null pointer is accessed.
[0116] Wherein, the steps implemented by each functional module of the null pointer access detection device may refer to each embodiment of the null pointer access detection method of the present invention, and will not be elaborated herein.
[0117] In addition, an embodiment of the present invention further provides a storage medium, on which a null pointer access detection program is stored. When the null pointer access detection program is executed by a processor, the following operations are implemented:
[0118] When a null pointer access occurs in the current program, obtain the error information of the memory protection unit MPU exception interrupt;
[0119] Determine the error type and error location according to the error information;
[0120] Locate the specific location of the null pointer access according to the error type and the error location.
[0121] Furthermore, when the null pointer access detection program is executed by the processor, the following operations are also implemented:
[0122] Use the memory protection unit MPU to set the null pointer exception access permission for the zero address to control memory access.
[0123] Furthermore, when the null pointer access detection program is executed by the processor, the following operations are also implemented:
[0124] Use the register related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address to control memory access.
[0125] Furthermore, when the null pointer access detection program is executed by the processor, the following operations are also implemented:
[0126] Use the register related to the memory protection unit MPU to set the preset access permission for the null pointer exception access to the zero address, making it readable but not executable and not writable in privileged mode and user mode to control memory access.
[0127] Furthermore, when the null pointer access detection program is executed by the processor, the following operations are also implemented:
[0128] When a null pointer access occurs in the current program, obtain the error information that causes the memory protection unit MPU exception interrupt, save the error information, and print a log.
[0129] Furthermore, when the null pointer access detection program is executed by the processor, the following operations are also implemented:
[0130] Obtain the error identifier corresponding to the error information, the current pointer position of the program counter pointer when the problem is located, the memory address accessed when the problem is located, and the return address of the null pointer function when the problem is located;
[0131] Determine the error type according to the error identifier, and determine the error location according to the current pointer position, the memory address, and the return address.
[0132] Further, when the null pointer access detection program is executed by a processor, the following operations are also implemented:
[0133] Determine the counter pointer position and the null pointer function return address of the current error according to the error type and the error position;
[0134] Locate the access to the null pointer according to the counter pointer position and the null pointer function return address, and determine the specific position of the access to the null pointer.
[0135] Those skilled in the art can understand that all or part of the steps in the above implementation methods can be completed by instructing relevant hardware through a program. This program is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the methods described in various embodiments of the present application; and the foregoing storage medium is a computer-readable storage medium, including but not limited to: USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks or optical discs and other media that can store program codes.
[0136] It should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including that element.
[0137] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments.
[0138] The above are only the preferred embodiments of the present invention, and do not limit the patent scope of the present invention accordingly. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied to other related technical fields, shall be equally included in the patent protection scope of the present invention.
Claims
1. A method for detecting null pointer access, characterized in that: The null pointer access detection method comprises: When a null pointer access is detected in the current program, the error information of the abnormal interrupt of the memory protection unit MPU is obtained; Determine the error type and error location according to the error information; The specific position of the access null pointer is located according to the error type and the error position.
2. The method for detecting null pointer access as claimed in claim 1, wherein: When a null pointer access is detected in the current program, before obtaining error information of an abnormal interrupt of a memory protection unit MPU, the null pointer access detection method further includes: The memory protection unit MPU is used to set the null pointer exception access permission for the zero address to achieve control over memory access.
3. The method for detecting null pointer access as claimed in claim 2, wherein: The method of using the memory protection unit MPU to set the null pointer exception access permission for the zero address to achieve the control of memory access includes: The preset access permission setting for null pointer exception access to zero address is performed using registers related to the memory protection unit MPU to achieve control over memory access.
4. The method for detecting null pointer access as claimed in claim 3, wherein: The method uses the registers related to the memory protection unit MPU to set the preset access rights for performing a null pointer exception access to the zero address to achieve control over the memory access, including: The preset access permission setting for null pointer exception access to the zero address is performed using registers related to the memory protection unit MPU, so that the zero address is readable in privileged mode and user mode, but not executable or writable, so as to realize the control of memory access.
5. The method for detecting null pointer access as claimed in claim 1, wherein: The step of obtaining error information of an abnormal interrupt of a memory protection unit MPU when a null pointer access is detected in the current program includes: When a null pointer access is detected in the current program, error information causing an abnormal interruption of the memory protection unit MPU is obtained, the error information is saved, and a log is printed.
6. The method for detecting null pointer access as claimed in claim 1, wherein: The determining the error type and the error location according to the error information includes: Obtaining an error identifier corresponding to the error information, a current pointer position of a program counter pointer when a positioning problem corresponding to the error information occurs, a memory address accessed when the positioning problem occurs, and a return address of a null pointer function when the positioning problem occurs; The error type is determined according to the error identifier, and the error position is determined according to the current pointer position, the memory address and the return address.
7. The method for detecting null pointer access as claimed in claim 1, wherein: The locating the specific position of the access null pointer according to the error type and the error position includes: Determine the counter pointer position of the current error and the null pointer function return address according to the error type and the error position; The access null pointer is located according to the counter pointer position and the null pointer function return address, and the specific position of the access null pointer is determined.
8. A null pointer access detection device, characterized in that: The null pointer access detection device comprises: An information acquisition module is used to acquire error information of abnormal interruption of a memory protection unit MPU when a null pointer access is detected in the current program; An error determination module, used to determine an error type and an error location according to the error information; A position locating module is used to locate the specific position of the access null pointer according to the error type and the error position.
9. A null pointer access detection device, characterized in that: The null pointer access detection device comprises: a memory, a processor, and a null pointer access detection program stored in the memory and executable on the processor, wherein the null pointer access detection program is configured to implement the steps of the null pointer access detection method as described in any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores a null pointer access detection program, which, when executed by a processor, implements the steps of the null pointer access detection method according to any one of claims 1 to 7.