Method, device, equipment and readable storage medium for recording program abnormal information
By allocating memory space for user space in microkernel memory and recording thread exception information, the problem of insufficient recording of thread exception information in the existing technology is solved, effective analysis and positioning of thread exceptions is realized, and work efficiency and user experience are improved.
Patent Information
- Application Number
- CN202111645076.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2041-12-29
AI Technical Summary
The existing technology lacks mature methods to record thread operation exception information in user space, making it difficult to analyze and locate problems, and reduces work efficiency and user experience.
The microkernel pre-allocates memory space for threads in user space in its own memory, obtains exception information when monitoring exceptions and writes it to memory space, and records thread numbers and exception information through exception handling threads (only read permissions) to ensure that It does not affect the security of the microkernel.
It realizes that without affecting the security of the microkernel, through recording thread numbers and exception information, it can effectively analyze and locate thread operation abnormal problems, thereby improving work efficiency and user experience.
Smart Images

Figure CN114328114B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of controllers, and in particular to a method for recording program exception information. The present invention also relates to a device, equipment and computer-readable storage medium for recording program exception information. Background Art
[0002] Controllers are widely used in the field of process control and are very important automation control equipment. Currently, there are controllers based on the microkernel operating system kernel (referred to as microkernel, such as the microkernel developed based on the domestic MIPS (Microprocessor without Interlocked Piped Stages architecture) architecture processor) on the market. The microkernel runs in the kernel space of the CPU, while the related software of the controller runs in the user space of the CPU.
[0003] Among them, there is a possibility that threads in user space will run abnormally. When threads in user space run abnormally, it will cause some work to stagnate. The existing technology lacks a mature recording method to record relevant abnormal information when threads in user space run abnormally. This makes it difficult to analyze and locate the problem of thread operation abnormality, which makes it difficult to eliminate the problem, reducing work efficiency and user experience.
[0004] Therefore, how to provide a solution to the above technical problems is a problem that those skilled in the art need to solve at present. Summary of the Invention
[0005] The purpose of the present invention is to provide a method for recording program exception information, which can analyze and locate the problem of thread operation exception based on the recorded thread number and exception information to eliminate the problem without affecting the security of the microkernel, thereby improving work efficiency and user experience; another purpose of the present invention is to provide a device, equipment and computer-readable storage medium for recording program exception information, which can analyze and locate the problem of thread operation exception based on the recorded thread number and exception information to eliminate the problem without affecting the security of the microkernel, thereby improving work efficiency and user experience.
[0006] To solve the above technical problems, the present invention provides a method for recording program exception information, comprising:
[0007] The microkernel allocates corresponding memory space for each thread in the user space in its own memory in advance;
[0008] When the microkernel detects that an exception occurs in a thread running in the user space of the CPU, it obtains exception information of a preset type of the abnormal thread;
[0009] The microkernel writes the exception information into the memory space corresponding to the abnormal thread;
[0010] The microkernel sends an exception notification message including the thread number of the abnormal thread to the exception handling thread in the user space;
[0011] The exception handling thread records the exception information and the thread number in the memory space corresponding to the thread number in the exception notification message;
[0012] The exception handling thread only has read permission for the memory space.
[0013] Preferably, when the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the exception information of the preset type of the abnormal thread is obtained specifically as follows:
[0014] When the microkernel detects an exception in a thread running in the user space of the CPU, it obtains the register values of all memories corresponding to the abnormal thread.
[0015] Preferably, when the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the register values of all memories corresponding to the abnormal thread are obtained as follows:
[0016] When the microkernel detects an exception in a thread running in the user space of the CPU, it uses assembly commands to obtain the register values of all memory devices corresponding to the abnormal thread.
[0017] Preferably, the priority of the exception handling thread is second only to the system's clock interrupt thread.
[0018] Preferably, the exception handling thread records the thread number and the exception information as follows:
[0019] The exception handling thread records the thread number and the exception information as a log.
[0020] Preferably, the microkernel allocates corresponding memory space for each thread in the user space in its own memory in advance as follows:
[0021] Adding a pointer field to the data structure of the microkernel thread in advance, so that when the microkernel creates a thread in the user space, the pointer field is used to allocate corresponding memory space for the created thread;
[0022] The pointer field is used to point to a special memory segment allocated by the microkernel for the thread.
[0023] Preferably, after the microkernel sends the message to be sent to the exception handling thread in the user space through the inter-thread communication mechanism of the microkernel, the method for recording program exception information further includes:
[0024] In response to the exception information query instruction, the exception handling thread feeds back the thread number of the thread specified by the exception information query instruction and the exception information.
[0025] To solve the above technical problems, the present invention further provides a method for recording program exception information, comprising:
[0026] The pre-allocation module is used by the microkernel to allocate corresponding memory space for each thread in the user space in its own memory in advance;
[0027] An acquisition module, configured for the microkernel to acquire exception information of a preset type of the abnormal thread when detecting an exception in a thread running in the user space of the CPU;
[0028] A writing module, configured for the microkernel to write the exception information into the memory space corresponding to the exception thread;
[0029] A sending module, configured for the microkernel to send an exception notification message including the thread number of the abnormal thread to the exception handling thread in the user space;
[0030] A recording module, configured for the exception handling thread to record the exception information and the thread number in the memory space corresponding to the thread number in the exception notification message;
[0031] The exception handling thread only has read permission for the memory space.
[0032] To solve the above technical problems, the present invention further provides a device for recording program exception information, comprising:
[0033] memory for storing computer programs;
[0034] A processor is used to implement the steps of the method for recording program exception information as described above when executing the computer program.
[0035] To solve the above technical problems, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for recording program exception information as described above are implemented.
[0036] The present invention provides a method for recording program exception information. Considering that the microkernel cannot directly write data to the user space, the microkernel in the present application allocates corresponding memory space for each thread in the user space in its own memory in advance. Then, the microkernel can store the acquired exception information of the exception thread in the memory space corresponding to the exception thread, and send the thread number of the exception thread to the exception handling thread in the user space. The exception handling thread can read the exception information from the memory space according to the thread number and record it together with the thread number. Since the exception handling thread only has the read permission of the memory space, it will not affect the security of the microkernel. According to the recorded thread number and exception information, the problem of thread operation abnormality can be analyzed and located to eliminate the problem, thereby improving work efficiency and user experience.
[0037] The present invention also provides a device, apparatus and computer-readable storage medium for recording program exception information, which have the same beneficial effects as the above method for recording program exception information. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the prior art and the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 A flowchart of a method for recording program exception information provided by the present invention;
[0040] Figure 2 A schematic diagram of the structure of a device for recording program abnormality information provided by the present invention;
[0041] Figure 3 A schematic structural diagram of a device for recording program exception information provided by the present invention. DETAILED DESCRIPTION
[0042] The core of the present invention is to provide a method for recording program exception information. Without affecting the security of the microkernel, the problem of thread operation exception can be analyzed and located based on the recorded thread number and exception information to eliminate the problem, thereby improving work efficiency and user experience; another core of the present invention is to provide a device, equipment and computer-readable storage medium for recording program exception information. Without affecting the security of the microkernel, the problem of thread operation exception can be analyzed and located based on the recorded thread number and exception information to eliminate the problem, thereby improving work efficiency and user experience.
[0043] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0044] Please refer to Figure 1 , Figure 1 This is a flow chart of a method for recording program exception information provided by the present invention, the method for recording program exception information comprising:
[0045] S101: The microkernel allocates corresponding memory space for each thread in the user space in its own memory in advance;
[0046] Specifically, considering the technical problems in the above background technology, and considering that the microkernel can monitor the abnormally running threads and obtain the address where the abnormal thread is running when the abnormal thread occurs, but due to the isolation of the kernel space and the user space, it is impossible to pass the information directly to the user space where the controller software is located through the memory. Therefore, the present application intends to first store the obtained abnormal information of the abnormal thread in the specific memory space allocated for each thread in the kernel space, and then actively read the abnormal information in the memory space corresponding to the abnormal thread through the exception handling thread in the user space to achieve the purpose of "passing the abnormal information to the user space". Therefore, in this step, the microkernel needs to allocate corresponding memory space for each thread in the user space in its own memory (that is, the kernel space memory) in advance, so that when a thread exception occurs later, the obtained exception information will be stored in the memory space corresponding to the abnormal thread.
[0047] Among them, the exception handling thread in the user space only has read permission of the memory space, which ensures the security of the kernel space.
[0048] S102: When the microkernel detects that an exception occurs in a thread running in the user space of the CPU, it obtains exception information of a preset type of the abnormal thread;
[0049] Specifically, in order to successfully pass the exception information of the abnormal thread to the user space, the microkernel can first obtain the preset type of exception information of the abnormal thread when detecting an exception in the thread running in the user space of the CPU, and use it as the data basis for subsequent steps.
[0050] The preset type can be set independently, and the embodiment of the present invention does not limit this.
[0051] S103: The microkernel writes the exception information into the memory space corresponding to the abnormal thread;
[0052] Specifically, after the exception information is obtained, the exception information can be written into the memory space corresponding to the exception thread so that the exception handling thread can read it in subsequent steps.
[0053] S104: The microkernel sends an exception notification message including the thread number of the abnormal thread to the exception handling thread in the user space;
[0054] Specifically, since the purpose of writing the exception information into the memory space is to allow the exception handling thread to read it into the user space, in this step, the microkernel needs to inform the exception handling thread in the user space which thread has the exception so that the exception handling thread can read the exception information. The thread number can simply and directly reflect which thread has the exception.
[0055] S105: The exception handling thread records the exception information and the thread number in the memory space corresponding to the thread number in the exception notification message;
[0056] Among them, the exception handling thread only has the read permission of the memory space.
[0057] Specifically, after receiving the exception notification message, the exception handling thread can find the corresponding memory space of the thread corresponding to the thread number according to the thread number therein, and obtain the exception information therefrom.
[0058] Among them, after the abnormal thread is determined according to the thread number, the memory space corresponding to the abnormal thread can be determined according to the preset corresponding relationship. This method is relatively fast and efficient.
[0059] The present invention provides a method for recording program exception information. Considering that the microkernel cannot directly write data to the user space, the microkernel in the present application allocates corresponding memory space for each thread in the user space in its own memory in advance. Then, the microkernel can store the acquired exception information of the exception thread in the memory space corresponding to the exception thread, and send the thread number of the exception thread to the exception handling thread in the user space. The exception handling thread can read the exception information from the memory space according to the thread number and record it together with the thread number. Since the exception handling thread only has the read permission of the memory space, it will not affect the security of the microkernel. According to the recorded thread number and exception information, the problem of thread operation abnormality can be analyzed and located to eliminate the problem, thereby improving work efficiency and user experience.
[0060] Based on the above embodiment:
[0061] As a preferred embodiment, when the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the exception information of the preset type of the abnormal thread is obtained as follows:
[0062] When the microkernel detects an exception in a thread running in the user space of the CPU, it obtains the register values of all memories corresponding to the abnormal thread.
[0063] Specifically, each thread has corresponding registers used when an exception occurs. The register values in these registers can reflect a lot of information related to the exception. Therefore, the embodiment of the present invention uses them as the preset type of exception information.
[0064] Of course, in addition to the above information, the preset type of abnormal information may also be other types, which is not limited in the embodiment of the present invention.
[0065] As a preferred embodiment, when the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the register values of all memories corresponding to the abnormal thread are obtained as follows:
[0066] When the microkernel detects an exception in a thread running in the user space of the CPU, it uses assembly commands to obtain the register values of all memory devices corresponding to the abnormal thread.
[0067] Specifically, using the assembly command can accurately and quickly obtain the register values of all registers corresponding to the abnormal thread.
[0068] Of course, in addition to this, register values of all registers corresponding to the abnormal thread may also be obtained in other ways, which are not limited in this embodiment of the present invention.
[0069] As a preferred embodiment, the priority of the exception handling thread is second only to the system clock interrupt thread.
[0070] Specifically, after the exception handling thread is created, it will enter an infinite waiting state until the system shuts down. In this way, when an exception occurs, the exception handling thread will quickly receive and process the message containing the exception information sent by the microkernel, avoiding the loss of messages due to untimely processing.
[0071] Of course, in addition to this, the priority of the exception handling thread may also be other specific situations, which are not limited in this embodiment of the present invention.
[0072] As a preferred embodiment, the exception handling thread records the thread number and exception information as follows:
[0073] The exception handling thread records the thread number and exception information as a log.
[0074] Specifically, the thread number and exception information are recorded as a log so that the staff can call it when needed.
[0075] Among them, the exception handling thread can call the log interface to record the thread number and exception information in the log file.
[0076] Of course, in addition to recording in the form of a log, it can also be recorded in other forms, which is not limited in the embodiment of the present invention.
[0077] As a preferred embodiment, the microkernel allocates corresponding memory space for each thread in the user space in its own memory in advance as follows:
[0078] Add a pointer field to the data structure of the microkernel thread in advance, so that when the microkernel creates a thread in the user space, it uses the pointer field to allocate the corresponding memory space for the created thread;
[0079] Among them, the pointer field is used to point to: a special memory allocated by the microkernel for the thread.
[0080] Specifically, this method of allocating memory space is relatively simple and efficient.
[0081] Specifically, the microkernel allocates corresponding memory space for each thread in the user space in its own memory in advance:
[0082] A field exceptionInfo is added to the thread data structure of the microkernel operating system. This field is a pointer to a special memory segment allocated by the microkernel for the thread. When the microkernel operating system creates a thread, it uses this field to allocate memory for the thread. The attributes of this memory segment are readable and writable in kernel space and read-only in user space, so it does not change the security of the microkernel operating system. The size of the allocated memory is an integer multiple of the operating system's pages. For example, if a page is 4K bytes, the size of the allocated memory is 4K, or 8K, or 16K, etc. The above units are bytes, and the allocated memory space is aligned according to the page size.
[0083] Among them, when the exception handling thread receives a message containing exception information that needs to be processed during its operation, it first parses the message to obtain the thread number of the thread where the exception occurred, and then obtains the first memory pointer pointed to by the exceptionInfo field of the thread's data structure from the thread number, and parses the content pointed to by the pointer to obtain the saved exception information.
[0084] As a preferred embodiment, after the microkernel sends the message to be sent to the exception handling thread in the user space through the inter-thread communication mechanism of the microkernel, the method for recording program exception information further includes:
[0085] In response to the exception information query instruction, the exception handling thread feeds back the thread number of the thread specified by the exception information query instruction and the exception information.
[0086] Specifically, considering that some upper-level users may query the exception information of the calling thread, the exception handling thread in the embodiment of the present invention also provides an interface function for upper-level users to call to obtain the exception information of the thread.
[0087] In order to facilitate upper-level user calls, the thread number and its corresponding exception information can be stored. The storage location can be a global variable, which improves work efficiency.
[0088] Please refer to Figure 2 , Figure 2 This is a flow chart of a device for recording program exception information provided by the present invention, the device for recording program exception information comprising:
[0089] A pre-allocation module 21 is used for the microkernel to allocate corresponding memory space for each thread in the user space in its own memory in advance;
[0090] An acquisition module 22 is configured to acquire exception information of a preset type of an abnormal thread when the microkernel detects an exception in a thread running in the user space of the CPU;
[0091] A writing module 23 is used for the microkernel to write the exception information into the memory space corresponding to the abnormal thread;
[0092] A sending module 24 is used for the microkernel to send an exception notification message including the thread number of the abnormal thread to the exception handling thread in the user space;
[0093] The recording module 25 is used for the exception handling thread to record the exception information and thread number in the memory space corresponding to the thread number in the exception notification message;
[0094] Among them, the exception handling thread only has the read permission of the memory space.
[0095] For an introduction to the apparatus for recording program exception information provided by an embodiment of the present invention, please refer to the embodiment of the method for recording program exception information described above, and the embodiment of the present invention will not be described in detail here.
[0096] Please refer to Figure 3 , Figure 3 This is a flow chart of a device for recording program exception information provided by the present invention, the device for recording program exception information comprising:
[0097] Memory 31, for storing computer programs;
[0098] The processor 32 is configured to implement the steps of the method for recording program exception information in the aforementioned embodiment when executing a computer program.
[0099] For an introduction to the device for recording program exception information provided by an embodiment of the present invention, please refer to the embodiment of the method for recording program exception information described above, and the embodiment of the present invention will not be described in detail here.
[0100] The present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for recording program exception information in the aforementioned embodiment are implemented.
[0101] For an introduction to the computer-readable storage medium provided by an embodiment of the present invention, please refer to the embodiment of the method for recording program exception information described above, and the embodiment of the present invention will not be described in detail here.
[0102] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should also be noted that in this specification, the term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of further restrictions, the elements defined by the sentence "comprise a..." do not exclude the presence of other identical elements in the process, method, article or equipment including the element.
[0103] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for recording program abnormality information, characterized in that: include: The microkernel allocates corresponding memory space for each thread in the user space in its own memory in advance; When the microkernel detects that an exception occurs in a thread running in the user space of the CPU, it obtains exception information of a preset type of the abnormal thread; The microkernel writes the exception information into the memory space corresponding to the exception thread; The microkernel sends an exception notification message including the thread number of the abnormal thread to the exception handling thread in the user space; The exception handling thread records the exception information and the thread number in the memory space corresponding to the thread number in the exception notification message; The exception handling thread only has read permission for the memory space.
2. The method for recording program abnormality information according to claim 1, characterized in that: When the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the specific method for obtaining the exception information of the preset type of the abnormal thread is as follows: When the microkernel detects an exception in a thread running in the user space of the CPU, it obtains the register values of all memories corresponding to the abnormal thread.
3. The method for recording program abnormality information according to claim 2, characterized in that: When the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the register values of all memories corresponding to the abnormal thread are obtained as follows: When the microkernel detects an exception in a thread running in the user space of the CPU, it uses assembly commands to obtain the register values of all memory devices corresponding to the abnormal thread.
4. The method for recording program abnormality information according to claim 3, characterized in that: The priority of the exception handling thread is second only to the system's clock interrupt thread.
5. The method for recording program abnormality information according to claim 1, characterized in that: The exception handling thread records the thread number and the exception information specifically as follows: The exception handling thread records the thread number and the exception information as a log.
6. The method for recording program abnormality information according to claim 1, characterized in that: The microkernel allocates corresponding memory space in its own memory in advance for each thread in the user space: Adding a pointer field in advance to the data structure of the microkernel thread, so that when the microkernel creates a thread in the user space, the pointer field is used to allocate corresponding memory space for the created thread; The pointer field is used to point to a special memory segment allocated by the microkernel for the thread.
7. The method for recording program abnormality information according to any one of claims 1 to 6, characterized in that: After the microkernel sends the message to be sent to the exception handling thread in the user space through the inter-thread communication mechanism of the microkernel, the method for recording program exception information further includes: In response to the exception information query instruction, the exception handling thread feeds back the thread number of the thread specified by the exception information query instruction and the exception information.
8. A method for recording program abnormality information, characterized in that: include: The pre-allocation module is used for the microkernel to allocate corresponding memory space for each thread in the user space in its own memory in advance; An acquisition module, used for the microkernel to acquire the abnormal information of a preset type of the abnormal thread when detecting that an abnormality occurs in a thread running in the user space of the CPU; A writing module, used for the microkernel to write the exception information into the memory space corresponding to the abnormal thread; A sending module, used for the microkernel to send an exception notification message including the thread number of the abnormal thread to the exception handling thread in the user space; A recording module, used for the exception handling thread to record the exception information and the thread number in the memory space corresponding to the thread number in the exception notification message; The exception handling thread only has read permission for the memory space.
9. A device for recording program abnormality information, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for recording program exception information as claimed in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for recording program abnormality information according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
A microkernel inter-process communication method and system
CN109933441A
System and method for interprocess communication
EP0695993A2