Method, device, equipment and readable storage medium for recording program abnormal information

Through the microkernel monitoring of exception threads and using inter-thread communication mechanisms to send information to user space, the problem of difficulty in recording and analyzing user space thread exceptions in the prior art is solved, and the work efficiency and user experience are improved.

CN114328125BActive Publication Date: 2025-01-14BEIJING HOLLYSYS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111682334.8
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

Technical Problem

The existing technology lacks mature methods to record and analyze abnormal information of user space thread operation, which makes it difficult to locate and eliminate problems, reducing work efficiency and user experience.

Method used

The exception thread is monitored through the microkernel, obtain exception information and send it to the exception processing thread in the user space through the inter-thread communication mechanism for recording, and analyze and locate using thread number and exception information.

Benefits of technology

Improve work efficiency and user experience. By recording thread numbers and exception information, it can effectively analyze and eliminate thread operation problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114328125B_ABST
    Figure CN114328125B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for recording program exception information. Considering that the microkernel cannot directly write data to the user space, it can send messages through the inter-thread communication mechanism, and the message can carry a small amount of data. Therefore, the present application can package the thread number and exception information of the abnormal thread to generate a message to be sent, and send it to the exception handling process of the user space through the inter-thread communication mechanism, so that it can record the thread number and exception information. In this way, 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. The present invention also discloses a recording device, equipment and computer-readable storage medium for program exception information, which has the same beneficial effects as the above method for recording program exception information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of controllers, and in particular to a method for recording program abnormality information. The present invention also relates to a device, equipment and computer-readable storage medium for recording program abnormality 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 (microkernel for short, 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 of abnormal operation of threads in user space. When threads in user space run abnormally, it will cause certain work to stagnate. The prior art lacks a mature recording method to record relevant abnormal information when threads in user space run abnormally, which makes it difficult to analyze and locate the problem of thread operation abnormality, resulting in the problem being difficult to eliminate, 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, 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, thereby improving work efficiency and user experience.

[0006] In order to solve the above technical problems, the present invention provides a method for recording program abnormality information, comprising:

[0007] When the microkernel detects an exception in a thread running in the user space of the CPU, it obtains the exception information of the preset type of the abnormal thread;

[0008] The microkernel packages the thread number of the abnormal thread and the abnormal information to generate a message to be sent;

[0009] 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;

[0010] The exception handling thread records the thread number and the exception information.

[0011] Preferably, when the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the abnormal information of a preset type of the abnormal thread is obtained specifically as follows:

[0012] When the microkernel detects that an exception occurs in a thread running in the user space of the CPU, it obtains the register values ​​of all registers corresponding to the abnormal thread.

[0013] 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 registers corresponding to the abnormal thread are obtained as follows:

[0014] When the microkernel detects an exception in a thread running in the user space of the CPU, it uses assembly commands to obtain register values ​​of all registers corresponding to the abnormal thread.

[0015] Preferably, the priority of the exception handling thread is second only to the system's clock interrupt thread.

[0016] Preferably, the exception handling thread records the thread number and the exception information specifically as follows:

[0017] The exception handling thread records the thread number and the exception information as a log.

[0018] Preferably, the creation process of the exception handling thread is:

[0019] The user space sends an instruction to the microkernel requesting to establish an exception handling thread;

[0020] The microkernel creates an exception handling thread in the user space;

[0021] The microkernel records the thread number of the exception handling thread in all variables so as to communicate with the exception handling thread through the thread number of the exception handling thread.

[0022] 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:

[0023] 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.

[0024] In order to solve the above technical problems, the present invention further provides a device for recording program abnormality information, comprising:

[0025] An acquisition module is used for the microkernel to acquire the abnormal information of a preset type of the abnormal thread when the microkernel detects that an abnormality occurs in a thread running in the user space of the CPU;

[0026] A packing module, used for the microkernel to pack the thread number of the abnormal thread and the abnormal information to generate a message to be sent;

[0027] A sending module, used for the microkernel to send the message to be sent to the exception handling thread in the user space through the inter-thread communication mechanism of the microkernel;

[0028] The recording module is used for the exception handling thread to record the thread number and the exception information.

[0029] In order to solve the above technical problems, the present invention further provides a device for recording program abnormality information, comprising:

[0030] Memory for storing computer programs;

[0031] A processor is used to implement the steps of the method for recording program exception information as described above when executing the computer program.

[0032] To solve the above technical problem, 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.

[0033] The present invention provides a method for recording program exception information. Considering that the microkernel cannot directly write data to the user space, it can send messages through the inter-thread communication mechanism, and the messages can carry a small amount of data. Therefore, the present application can package the thread number and exception information of the abnormal thread to generate a message to be sent, and send it to the exception handling process of the user space through the inter-thread communication mechanism, so that it can record the thread number and exception information. In this way, the problem of thread operation abnormality can be analyzed and located according to the recorded thread number and exception information to eliminate the problem, thereby improving work efficiency and user experience.

[0034] 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

[0035] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the prior art and the drawings required for use in the embodiments are briefly introduced below. 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 creative work.

[0036] Figure 1 A flowchart of a method for recording program abnormality information provided by the present invention;

[0037] Figure 2 A schematic diagram of the structure of a device for recording program abnormality information provided by the present invention;

[0038] Figure 3 A schematic diagram of the structure of a device for recording program exception information provided by the present invention. DETAILED DESCRIPTION

[0039] The core of the present invention is to provide a method for recording program exception information, and according to the recorded thread number and exception information, the problem of thread operation exception can be analyzed and located 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, and according to the recorded thread number and exception information, the problem of thread operation exception can be analyzed and located to eliminate the problem, thereby improving work efficiency and user experience.

[0040] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are 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 creative work are within the scope of protection of the present invention.

[0041] Please refer to Figure 1 , Figure 1 A flowchart of a method for recording program exception information provided by the present invention is provided, and the method for recording program exception information includes:

[0042] S101: 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;

[0043] Specifically, taking into account the technical problems in the above background technology, and taking into account that the microkernel can monitor the abnormally running thread 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 directly pass the information to the user space where the controller software is located through the memory. Therefore, the present application intends to use the inter-thread communication mechanism, and the microkernel passes the relevant exception information to the specified thread in the user space, thereby completing the recording of the exception information. Therefore, in this step, when the microkernel detects that an exception has occurred in the thread running in the user space of the CPU, it obtains the preset type of exception information of the abnormal thread, and uses it as the data basis for the subsequent steps.

[0044] Among them, the preset type can be set independently, and the embodiment of the present invention does not limit it here.

[0045] S102: The microkernel packages the thread number and exception information of the abnormal thread to generate a message to be sent;

[0046] Specifically, after obtaining the exception information, in order to identify which thread the exception information belongs to, the thread number and the exception information can be packaged together to generate a message to be sent. The reason for packaging it into the form of a message to be sent is that the message can be directly transmitted through the inter-thread communication mechanism, and the data volume of the exception information is small and can be directly put into the message.

[0047] S103: 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;

[0048] Specifically, after generating the message to be sent, the microkernel can send the message to be sent to the exception handling thread in the user space through the inter-thread communication mechanism of the microkernel, so that the exception handling thread can record it.

[0049] S104: The exception processing thread records the thread number and exception information.

[0050] Specifically, after the exception handling thread in the user space receives the message to be sent, it can obtain the thread number and the exception information therefrom, and then record both of them, thereby realizing the recording of the exception information of the abnormal thread.

[0051] The present invention provides a method for recording program exception information. Considering that the microkernel cannot directly write data to the user space, it can send messages through the inter-thread communication mechanism, and the messages can carry a small amount of data. Therefore, the present application can package the thread number and exception information of the abnormal thread to generate a message to be sent, and send it to the exception handling process of the user space through the inter-thread communication mechanism, so that it can record the thread number and exception information. In this way, the problem of thread operation abnormality can be analyzed and located according to the recorded thread number and exception information to eliminate the problem, thereby improving work efficiency and user experience.

[0052] Based on the above embodiments:

[0053] As a preferred embodiment, when the microkernel detects that an exception occurs in a thread running in the user space of the CPU, the abnormal information of the preset type of the abnormal thread is obtained as follows:

[0054] When the microkernel detects that an exception occurs in a thread running in the user space of the CPU, it obtains the register values ​​of all registers corresponding to the abnormal thread.

[0055] Specifically, each thread has a corresponding register used when an exception occurs, and the register values ​​in these registers can reflect a lot of information related to the exception, so the embodiment of the present invention uses it as a preset type of exception information.

[0056] 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.

[0057] 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 registers corresponding to the abnormal thread are obtained as follows:

[0058] When the microkernel detects an exception in a thread running in the user space of the CPU, it uses assembly commands to obtain register values ​​of all registers corresponding to the abnormal thread.

[0059] Specifically, the register values ​​of all registers corresponding to the abnormal thread can be obtained accurately and quickly using the assembly command.

[0060] 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 the embodiment of the present invention.

[0061] As a preferred embodiment, the priority of the exception handling thread is second only to the system clock interrupt thread.

[0062] 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 failure to be processed in time.

[0063] Of course, in addition to this, the priority of the exception handling thread may also be other specific situations, which are not limited in the embodiment of the present invention.

[0064] As a preferred embodiment, the exception handling thread records the thread number and exception information specifically as follows:

[0065] The exception handling thread records the thread number and exception information as a log.

[0066] Specifically, the thread number and exception information are recorded as logs so that the staff can call them when they need to use them.

[0067] Among them, the exception handling thread can call the log interface to record the thread number and exception information into the log file.

[0068] 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.

[0069] As a preferred embodiment, the process of creating an exception handling thread is as follows:

[0070] The user space sends an instruction to the microkernel requesting the establishment of an exception handling thread;

[0071] The microkernel creates an exception handling thread in user space;

[0072] The microkernel records the thread number of the exception handling thread in all variables so as to communicate with the exception handling thread through the thread number of the exception handling thread.

[0073] Specifically, the process of creating an exception handling thread can be as follows:

[0074] During the system startup phase, an exception handling thread needs to be created. This thread has a special parameter identifier EXCEPTION_THTREAD when it is created. Therefore, when the microkernel creates the thread, it will know that the thread is an exception handling thread and record the thread number of the thread in a global variable. The thread number identifies the target thread to which the message is to be sent. The kernel uses the thread number as the parameter of the target thread when sending a message to the exception handling thread.

[0075] Specifically, the above creation process is relatively simple and fast, and the microkernel can quickly find the exception handling thread from the thread numbers recorded in all variables and communicate with it.

[0076] Of course, in addition to the above process, the creation process of the exception handling thread may also be of other types, which are not limited in the embodiment of the present invention.

[0077] 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:

[0078] 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.

[0079] 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.

[0080] In order to facilitate the upper-level user to call, the thread number and its corresponding exception information can be stored, and the storage location can be a global variable, which is more efficient.

[0081] Please refer to Figure 2 , Figure 2 A schematic diagram of the structure of a device for recording program abnormality information provided by the present invention, wherein the device for recording program abnormality information comprises:

[0082] An acquisition module 21 is used for the microkernel to acquire the abnormal information of a preset type of the abnormal thread when the microkernel detects that an abnormality occurs in a thread running in the user space of the CPU;

[0083] Packaging module 22, used for the microkernel to pack the thread number and abnormal information of the abnormal thread to generate a message to be sent;

[0084] A sending module 23, used for the microkernel to send the message to be sent to the exception handling thread in the user space through the inter-thread communication mechanism of the microkernel;

[0085] The recording module 24 is used for the exception handling thread to record the thread number and exception information.

[0086] 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.

[0087] Please refer to Figure 3 , Figure 3 A schematic diagram of the structure of a device for recording program abnormality information provided by the present invention, wherein the device for recording program abnormality information comprises:

[0088] A memory 31, used for storing computer programs;

[0089] The processor 32 is used to implement the steps of the method for recording program exception information in the above-mentioned embodiment when executing a computer program.

[0090] 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.

[0091] The present invention also 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 abnormality information in the aforementioned embodiment are implemented.

[0092] For an introduction to the computer-readable storage medium provided in an embodiment of the present invention, please refer to the aforementioned embodiment of the method for recording program exception information, and the embodiment of the present invention will not be described in detail here.

[0093] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and 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 refer to the method part description. It should also be noted that in this specification, the term "includes", "comprising" 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 more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or equipment including the element.

[0094] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be 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 will not be limited to the embodiments shown herein, but rather 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: When the microkernel detects an exception in a thread running in the user space of the CPU, it obtains the exception information of the preset type of the abnormal thread; The microkernel packages the thread number of the abnormal thread and the abnormal information to generate a message to be sent; 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 exception handling thread records the thread number and the exception information.

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 that an exception occurs in a thread running in the user space of the CPU, it obtains the register values ​​of all registers 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 registers 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 registers 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 creation process of the exception handling thread is: The user space sends an instruction to the microkernel requesting to establish an exception handling thread; The microkernel creates an exception handling thread in the user space; The microkernel records the thread number of the exception handling thread in all variables so as to communicate with the exception handling thread through the thread number of the exception handling 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: An acquisition module is used for the microkernel to acquire the abnormal information of a preset type of the abnormal thread when the microkernel detects that an abnormality occurs in a thread running in the user space of the CPU; A packing module, used for the microkernel to pack the thread number of the abnormal thread and the abnormal information to generate a message to be sent; A sending module, used for the microkernel to send the message to be sent to the exception handling thread in the user space through the inter-thread communication mechanism of the microkernel; The recording module is used for the exception handling thread to record the thread number and the exception information.

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

  • Mobile phone device abnormity monitoring method and device

    CN109951591A

  • Object-oriented operating system

    US6275983B1