Method for realizing exception protection based on signal processing mechanism, medium and electronic equipment
By registering signal handlers in the program, capturing and processing predetermined error type information, encapsulating exception logs, and performing exception protection operations, the program crash problem was solved, and the program's stability and problem location efficiency were improved.
Patent Information
- Application Number
- CN202510813282.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-17
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2045-06-17
AI Technical Summary
The program crashes during operation due to memory access errors or other issues, affecting the program's stability and making it difficult to quickly locate the problem.
By registering signal handlers in the program, predefined error type information is captured, exception log information is encapsulated, and exception protection operations are performed according to preset processing rules, such as returning to a save point or exiting the program, to avoid crashes.
It improves the stability and robustness of the program, enabling it to quickly and accurately locate and resolve problems within the program.
Smart Images

Figure CN120973561A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computers, and in particular to a method, storage medium, and electronic device for anomaly protection based on a signal processing mechanism. Background Technology
[0002] During program execution, some errors can sometimes cause the program to crash. For example, when using pointers, it is usually necessary to perform a null check beforehand. If a null pointer is used, it will lead to a memory access error, which in turn will cause the program to crash and seriously affect the stability of the program.
[0003] How to prevent program crashes when errors such as memory access exceptions occur during program execution, and how to facilitate troubleshooting of problems in the program, thereby improving the robustness and stability of the program, is a technical issue worthy of attention. Summary of the Invention
[0004] To address the aforementioned technical problems, this disclosure is proposed. Embodiments of this disclosure provide a method, apparatus, storage medium, and electronic device for anomaly protection based on a signal processing mechanism.
[0005] According to one aspect of the present disclosure, a method for implementing anomaly protection based on a signal processing mechanism is provided. The method includes: during program execution, when predetermined error type information is generated, a signal processor registered for the predetermined error type information receives the predetermined error type information; the signal processor acquires current running information and encapsulates the current running information into anomaly log information; the signal processor determines a processing rule corresponding to the predetermined error type information; if the processing rule corresponding to the predetermined error type information is determined to be returning to a save point, the signal processor acquires information about the save point that needs to be returned to; the signal processor loads the save point information and performs corresponding anomaly protection operations according to the anomaly protection behavior corresponding to the save point.
[0006] According to another aspect of the present disclosure, a computer-readable storage medium is provided, the storage medium storing a computer program for implementing the above-described method.
[0007] According to another aspect of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; the processor being configured to read the executable instructions from the memory and execute the instructions to implement the method described above.
[0008] Based on the above embodiments of this disclosure, a method, medium, and electronic device for anomaly protection based on a signal processing mechanism are provided. By registering a signal processor for predetermined error type information, the signal processor can successfully capture the predetermined error type information once it occurs during program execution. By encapsulating and processing the current running information using the signal processor, the problem of not being able to provide anomaly log information using the anomaly handling mechanism when certain errors occur can be compensated for. The anomaly log information for predetermined error type information provided by the signal processor helps users analyze and locate program problems. Since the signal processor pre-sets processing rules for predetermined error type information, especially the processing rules for returning to a preset save point, the signal processing mechanism is combined with the save point mechanism to form a remedial measure after an anomaly occurs. This remedial measure can successfully prevent the existing signal processing mechanism from crashing when certain errors occur due to the inability to jump. Therefore, the technical solution provided by this disclosure is beneficial for quickly and accurately troubleshooting problems in programs, thereby improving program stability and robustness.
[0009] The technical solutions of this disclosure will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0010] The above and other objects, features, and advantages of this disclosure will become more apparent from the more detailed description of the embodiments thereof in conjunction with the accompanying drawings. The drawings are provided to offer a further understanding of the embodiments of this disclosure and form part of the specification. They are used together with the embodiments of this disclosure to explain the disclosure and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same components or steps.
[0011] Figure 1 This is a flowchart of an embodiment of the method for anomaly protection based on signal processing mechanism disclosed herein;
[0012] Figure 2 This is a flowchart of another embodiment of the method for anomaly protection based on signal processing mechanism disclosed herein;
[0013] Figure 3 This is a schematic diagram of an embodiment of the device for anomaly protection based on signal processing mechanism disclosed herein;
[0014] Figure 4 This is a structural diagram of an electronic device provided in an exemplary embodiment of this disclosure. Detailed Implementation
[0015] Example embodiments according to this disclosure will now be described in detail with reference to the accompanying drawings. It is obvious that the described embodiments are merely some embodiments of this disclosure, and not all embodiments of this disclosure, and it should be understood that this disclosure is not limited to the example embodiments described herein.
[0016] It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of this disclosure.
[0017] Those skilled in the art will understand that the terms "first," "second," etc., in the embodiments of this disclosure are only used to distinguish different steps, devices, or modules, and do not represent any specific technical meaning, nor do they indicate a necessary logical order between them.
[0018] It should also be understood that in the embodiments disclosed herein, "multiple" can refer to two or more, and "at least one" can refer to one, two or more.
[0019] It should also be understood that any component, data or structure mentioned in the embodiments of this disclosure can generally be understood as one or more unless expressly defined or given to the contrary in the context.
[0020] Furthermore, the term "and / or" in this disclosure is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this disclosure generally indicates that the preceding and following related objects have an "or" relationship.
[0021] It should also be understood that the description of the various embodiments in this disclosure emphasizes the differences between the various embodiments, and the similarities or similarities can be referred to each other. For the sake of brevity, they will not be described in detail.
[0022] At the same time, it should be understood that, for ease of description, the dimensions of the various parts shown in the accompanying drawings are not drawn according to actual scale.
[0023] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit this disclosure or its application or use.
[0024] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.
[0025] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.
[0026] The embodiments of this disclosure can be applied to electronic devices such as terminal devices, computer systems, and servers, and can operate with a wide range of other general-purpose or special-purpose computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments, and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, or servers include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputer systems, mainframe computer systems, and distributed cloud computing environments that include any of the above systems, etc.
[0027] Electronic devices such as terminal devices, computer systems, and servers can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment. In a distributed cloud computing environment, tasks can be executed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can reside on local or remote computing system storage media, including storage devices.
[0028] Exemplary methods
[0029] Figure 1 This is a flowchart of one embodiment of the anomaly protection method based on signal processing mechanism disclosed herein. Figure 1 The methods shown include: S100, S101, S102, S103, and S104. The following describes... Figure 1 Each step in the process will be explained separately.
[0030] S100. During program execution, when a predetermined error type information is generated, the signal processor registered for the predetermined error type information receives the predetermined error type information.
[0031] The program in this disclosure can be a test program. The predetermined error type information in this disclosure refers to the operating system error signals involved when registering a signal handler (such as the SignalHandler function). That is, this disclosure sets up signal handlers for some error signals in the operating system. During program execution (such as when a process executes corresponding commands in the program), if the execution of some commands causes a specific error, the operating system will generate predetermined error type information (such as the corresponding process outputting predetermined error type information). Since this predetermined error type information belongs to the operating system error signals involved when the signal handler is registered, the signal handler will successfully capture this predetermined error type information, thereby causing the signal handler to be called, that is, the method within the signal handler will be executed. In other words, when a predetermined error occurs during program execution, the handling method defined by the user for that predetermined error will be executed, preventing the program from crashing.
[0032] The predetermined error type information in this disclosure may include error signals that directly cause / may cause program crashes (such as program interruption). For example, the predetermined error type information may be memory access exception errors (such as SIGSEGV, i.e., Segmentation Fault), arithmetic exception error types (such as SIGFPE, i.e., Arithmetic Exception), illegal instruction execution error types (such as SIGILL), or bus error types (such as SIGBUS, i.e., Bus Error), etc. The predetermined error type information can be set according to user needs and application scenarios such as the operating system on which the program runs, and this disclosure does not limit it.
[0033] Registering signal handlers for memory access exceptions helps prevent program crashes caused by attempts to access unauthorized memory regions (e.g., illegal memory access, array out-of-bounds errors, null pointer dereferences, stack overflows, read-only memory access, dynamic link library problems, or insufficient system resources). Registering signal handlers for arithmetic exceptions helps prevent crashes caused by attempts to perform calculations using invalid data (e.g., division by zero, integer overflow, or floating-point exceptions). Registering signal handlers for illegal instruction execution errors helps prevent crashes caused by the use of illegal instructions that the CPU cannot recognize (e.g., incorrect code segment modifications, instruction set evolution, toolchain bugs, memory access alignment or floating-point format problems, or memory corruption). Registering signal handlers for bus errors helps prevent crashes caused by data access address misalignment (e.g., memory alignment errors, insufficient memory, or illegal memory access).
[0034] The signal handler in this disclosure can correspond to one predetermined error type (i.e., only one predetermined error type can be captured by the signal handler) or multiple different predetermined error types (i.e., multiple predetermined error types can be captured by the signal handler). For example, this disclosure can perform signal handler registration operations for SIGSEGV, SIGFPE, SIGILL, and SIGBUS respectively, so that the signal handler can simultaneously implement exception protection for multiple predetermined error types such as SIGSEGV, SIGFPE, SIGILL, and SIGBUS; that is, when any of the error signals listed above occur in the operating system, the signal handler will be called, so that the method within the signal handler will be executed to avoid program crashes.
[0035] In one embodiment, this disclosure allows the signal processor registration operation to be performed during program startup. This disclosure can utilize a preset file (i.e., a rules file) to complete the signal processor registration process. This preset file is primarily used to display the processing rules declared for each predetermined error type information. For example, the preset file stores the correspondence information between each predetermined error type information and its corresponding processing rule. During the registration process, records containing predetermined error type information and their corresponding processing rules can be read sequentially from the preset file according to the order of the predetermined error type information. Then, for each read record containing predetermined error type information and its corresponding processing rule, a signal processor registration operation is performed, thereby forming key-value pairs based on the predetermined error type information and processing rules in the operating system—that is, key-value pairs with the predetermined error type information as the key and the processing rule as the value.
[0036] An example of the processing rules set for each predetermined error type information as declared in the above preset file can be represented in the following form:
[0037] "SIGSEGV" = "TO_SAVE_POINT" / / Return to the save point and continue execution
[0038] "SIGFPE" = "EXIT_PROGRAM" / / Exit the program directly
[0039] "SIGILL" = "EXIT_PROGRAM" / / Exit the program directly
[0040] "SIGBUS" = "RESTART_PROGRAM" / / Rerun the program
[0041] By displaying the processing rules for each predefined error type information in a preset file during program startup, users can easily and flexibly adjust the preset error signals and their corresponding processing rules according to actual needs. Since the predefined error type information and its corresponding processing rules are formed in the form of key-value pairs during registration, if a predefined error type information is generated during subsequent program operation, the corresponding processing rules can be quickly obtained using the captured predefined error type information.
[0042] An example of the signal handler registration process during program startup can be represented in the form of the following pseudocode:
[0043] / / Read the preset file signal_rule.txt to obtain the preset error type information and processing rules.
[0044] signalRule=readRuleFromFile(“. / signal_rule.txt”);
[0045] / / Register signal processors sequentially. signalRule.length represents the number of records for the predefined error type information and processing rules, i.e., the number of predefined error type information records in the preset file. name represents the name of the predefined error type information, and rule represents the processing rule corresponding to the predefined error type information.
[0046] For i = 0; i <signalRule.length;i++
[0047] SignalHandler[name] = rule;
[0048] End For
[0049] S101, The signal processor obtains the current running information and encapsulates the obtained current running information into an exception log information.
[0050] The current runtime information in this disclosure refers to information used to describe the current running status of a program. Current runtime information typically includes several key elements and can be set according to actual needs. For example, current runtime information may include: the time when a predetermined error type information was generated, the predetermined error type information, and the stack information at the time the predetermined error type information was generated. Specifically, when the signal processor receives the predetermined error type information, it can obtain the current time and the current stack information. Then, it formats the obtained current stack information to convert it into an easily readable and understandable form; that is, the signal processor can organize the current stack information according to a certain format. Afterward, the signal processor writes the obtained current time, predetermined error type information, and formatted stack information to an exception log file, which is the encapsulated exception log information.
[0051] Since stack traces can be considered a record of the function call sequence in a program, and when an exception occurs during program execution, the stack traces and records not only the method call sequence at the time of the exception, but also provides a brief description of the exception, records context information, and the state of each thread at the time of the exception, stack traces are crucial for analyzing logical errors and locating problems in a program. This disclosure, by storing the current time, the predetermined error type information, and formatted stack traces in an exception log file when an exception occurs (a predetermined error type information is received), provides users with as much information as possible related to the predetermined error type information. This facilitates the analysis of the specific location and cause of the predetermined error type information, thereby enabling quick and accurate location of problems in the program.
[0052] In one embodiment, an example of the signal processor in this disclosure writing the current time, predetermined error type information, and formatted stack information to an exception log file can be represented in the form of the following pseudocode:
[0053]
[0054]
[0055] S102, The signal processor determines the processing rules corresponding to the predetermined error type information.
[0056] Each predetermined error type in this disclosure corresponds to a processing rule. In one example, the processing rules for different predetermined error types may be different; in another example, the processing rules for two different predetermined error types may be the same. The processing rules in this disclosure can be considered as processing methods or processing types, etc. Each processing rule corresponds to a corresponding processing operation. Thus, when the signal processor captures a predetermined error type, the signal processor can execute the corresponding processing operation based on the processing rule corresponding to the predetermined error type, thereby avoiding program crashes due to the occurrence of the predetermined error type.
[0057] This disclosure utilizes key-value pairs formed during the signal processor registration process to obtain the processing rules corresponding to the currently captured predetermined error type information. For example, the signal processor uses the currently captured predetermined error type information as a key to search through the key-value pairs formed during the registration process. If a matching key-value pair is found, the signal processor uses the value in the matching key-value pair as the processing rule corresponding to the predetermined error type information. By using the predetermined error type information as a key to search for the corresponding value in the key-value pairs, it is beneficial to quickly and accurately obtain the processing rules corresponding to the currently captured predetermined error type information.
[0058] In one embodiment, the processing rules in this disclosure can be not only returning to a save point, but also exiting or restarting the program. If the processing rule corresponding to the predetermined error type information is to exit the program, the signal handler can execute a program exit operation (such as releasing all resources currently occupied by the program and jumping to the program's end statement) to terminate the current program's execution. If the processing rule corresponding to the predetermined error type information is to restart the program, the signal handler can execute a restart operation (such as releasing all resources currently occupied by the program, jumping to the program's end statement, and then triggering the program to execute the corresponding operation again from the start statement) to restart the current program's execution. By setting processing rules such as exiting and restarting the program for predetermined error type information, it is beneficial to enrich the ways of implementing exception protection based on signal processing mechanisms, thereby improving both program stability and the flexibility of program testing.
[0059] In one embodiment, an example of the signal processor in this disclosure determining and executing the processing rule corresponding to the predetermined error type information can be represented in the form of the following pseudocode:
[0060]
[0061]
[0062] S103. If the processing rule is determined to be to return to the save point, the signal processor obtains the information of the save point that needs to be returned to.
[0063] In this disclosure, a savepoint is a logical point (i.e., a marker within a transaction) set during transaction processing. Savepoints are primarily used to roll back a transaction to that point when needed, rather than rolling back the entire transaction. Because savepoints allow for partial rollback of transactions, if an error occurs during program execution, the program can roll back only to the nearest savepoint, thereby improving the flexibility and efficiency of transaction processing.
[0064] In this disclosure, returning to a savepoint means ceasing further execution of subsequent program operations and instead performing the operations corresponding to the specified savepoint. The signal processor in this disclosure can obtain information about the savepoint to which the program needs to return through a savepoint manager. The savepoint manager is primarily used to execute savepoint-related operations; it can be considered a collection of related operations that need to be performed to achieve a return to a savepoint.
[0065] In one embodiment, the savepoint manager of this disclosure can be a stack-based savepoint manager, meaning the savepoint manager uses a stack to manage each savepoint. For example, during program execution, savepoints pre-added to the program are added to the stack sequentially by the savepoint manager as the program runs. If a predetermined error type occurs during program execution, and the corresponding processing rule for this error type is to return to a savepoint, the signal processor can obtain the information of the savepoint that needs to be returned to by popping from the stack using the savepoint manager. For example, the savepoint manager can perform a pop operation from the savepoint currently at the top of the stack, thereby allowing the signal processor to obtain the information of the savepoint at the top of the stack. Furthermore, during the savepoint push process, information related to the savepoint can be pushed onto the stack along with the savepoint, and during the savepoint pop process, information related to the savepoint will be popped from the stack along with the savepoint. For example, during the process of pushing a savepoint onto the stack, the savepoint manager adds the savepoint's name, creation time (i.e., the time the savepoint was pushed onto the stack), and context information to the top of the stack. During the process of popping a savepoint from the stack, if the stack is not empty, the savepoint manager removes the savepoint's name, creation time, and context information from the top of the stack.
[0066] By using a stack to manage savepoints through push and pop operations, the process of rolling back to a savepoint can be implemented in an orderly manner. Moreover, it is beneficial to control the lifecycle of each savepoint within the scope of the program level, and to easily reclaim the resources used by the savepoints when the program ends.
[0067] In one embodiment, an example of the savepoint manager in this disclosure can be represented in the form of the following pseudocode:
[0068] / / Create a class named SavePoint
[0069] Class SavePoint
[0070] / / Savepoint construction method
[0071] SavePoint()
[0072] {
[0073] / / Push the savepoint onto the stack, that is, perform the savepoint push operation based on the this pointer.
[0074] SavePointStack.push(this);
[0075] }
[0076] / / Save point destruct method
[0077] ~SavePoint()
[0078] {
[0079] / / Pop the savepoint from the stack, that is, perform the savepoint pop operation based on the this pointer.
[0080] SavePointStack.pop(this);
[0081] }
[0082] / / Save point creation time
[0083] Private DateTimecreateTime;
[0084] / / Save the context information of the point cache
[0085] Private jmp_bufferevn;
[0086] End class
[0087] S104. The signal processor loads the information of the save point and performs the corresponding abnormal protection operation according to the abnormal protection behavior corresponding to the save point.
[0088] Each savepoint in this disclosure corresponds to a specific exception protection behavior, which is typically set for each savepoint during the savepoint addition process. Here, exception protection behavior refers to the operations performed to prevent a chain reaction (e.g., program crash or error propagation) that may be caused by an exception encountered during program execution.
[0089] During the savepoint popping process, if the stack is empty, the signal processor will not perform the savepoint information loading operation and can terminate the current program execution.
[0090] In one embodiment, the exception protection behavior in this disclosure can be outputting exception information, ignoring the exception, and jumping to a target location. For example, when the savepoint manager determines that the exception protection behavior corresponding to the currently popped savepoint is to output exception information, it can execute the operation of outputting exception information according to pre-set exception information, and terminate the execution of the savepoint manager. Alternatively, it can terminate the program's execution after releasing resources. The exception information in this disclosure can be set during the savepoint registration process, and this disclosure does not limit the specific content of the exception information to be output. Another specific example is that when the savepoint manager determines that the exception protection behavior corresponding to the currently popped savepoint is to ignore the exception and jump to a target location, it can execute the corresponding operation based on the program code at the target location, i.e., the program code at the target location is executed. The target location can be represented by a corresponding label. By utilizing the savepoint manager to output exception information, users can better understand the exceptions that occur during program execution and their locations, thereby helping users accurately locate problems in the program. By using a savepoint manager to ignore exceptions and jump to the target location, the program's execution can be redirected in the expected direction, thus helping to prevent the spread of program errors and program crashes, and facilitating the normal termination of the program.
[0091] In one embodiment, the target location in this disclosure can be specifically the location of the exit label or the location of a non-exit specified label. Here, the exit label refers to a label used to enable the program to exit normally; that is, the program code at the location of the exit label can enable the program to exit normally. For example, the savepoint manager can release the resources occupied by various savepoints and processes by executing the program code at this location, terminate the execution of the savepoint manager, and terminate the program's execution. The location of a non-exit specified label refers to a label used to enable the program to continue execution; that is, the savepoint manager can enable the program to continue running normally by enabling the program to continue executing the program code at the location of the non-exit specified label. For example, the savepoint manager triggers the program to continue execution from the location of the non-exit specified label based on the context information of the currently popped savepoint, so that the program can terminate normally. By setting exit labels and non-exit specified labels, program crashes can be effectively avoided while providing users with more options, allowing users to decide how to handle exceptions according to their actual needs.
[0092] In one embodiment, an example of a savepoint macro definition in this disclosure can be represented in the form of the following pseudocode:
[0093]
[0094]
[0095] In one example, the flow of an embodiment of the anomaly protection method based on signal processing mechanism disclosed herein is as follows: Figure 2 As shown.
[0096] Figure 2 In step S200, the program starts, initiating the abnormal protection process based on the signal processing mechanism disclosed herein.
[0097] S201. During program startup, register signal processors. For example, use all error signals and their corresponding processing rules in a preset file to perform signal processor registration.
[0098] S202. During program execution, the savepoint manager adds the corresponding savepoints and their related information to the stack.
[0099] S203. During program execution, a predetermined error type message appears.
[0100] S204. Since a signal handler has been registered for the predetermined error type information during program startup, the signal handler successfully captures the predetermined error type information.
[0101] S205. The signal processor performs an exception log information encapsulation operation, such as writing the predetermined error type information, the current time, and the current program running information (such as formatted stack information) into the exception log file to form exception log information.
[0102] S206. The signal processor determines the processing rule corresponding to the predetermined error type information. For example, it searches in the key-value pairs formed in the registration with the name of the predetermined error type information as the key, and uses the value in the matching key-value pair as the processing rule corresponding to the predetermined error type information.
[0103] If the processing rule corresponding to the currently obtained predetermined error type information is to exit the program, proceed to S207; if the processing rule corresponding to the currently obtained predetermined error type information is to restart the program, proceed to S208; if the processing rule corresponding to the currently obtained predetermined error type information is to return to the save point, proceed to S209.
[0104] S207. The signal handler executes the exit procedure, and before exiting the procedure, it should release the savepoints and resources occupied by the process. This program execution process ends.
[0105] S208. The signal processor performs a restart operation, such as executing the restartProcess() command, and should release the resources occupied by the savepoint before restarting the program. Proceed to S210.
[0106] S209, The signal processor obtains information about the save point that needs to be returned to.
[0107] S210, the program restarts, for example, it can return to S201.
[0108] S211. The signal processor loads the information of the savepoints it has acquired, and then performs the corresponding exception protection operation. This exception protection operation can be S212, S213, or S214. S212. The signal processor outputs exception information. Additionally, the savepoint manager can release resources occupied by savepoints and processes, and terminate the program's execution.
[0109] S213, the signal processor executes the program code at the location of the exit label to terminate the program's execution, proceeding to S215. Additionally, the savepoint manager should release resources occupied by savepoints and processes.
[0110] S214. The signal processor triggers the program to continue execution from the program code at the location of the specified label that is not exiting, based on the context information of the current popped save point, until S215.
[0111] S215. This program has finished running.
[0112] Exemplary device
[0113] Figure 3 This is a schematic diagram of a specific embodiment of the anomaly protection device based on a signal processing mechanism disclosed herein. The device in this embodiment can be used to implement this disclosure. Figure 1 The method embodiment shown.
[0114] like Figure 3 The apparatus shown includes a signal processor 300 and a savepoint manager 301. The signal processor 300 and the savepoint manager 301 will be described below.
[0115] The signal processor 300 is a signal processor registered with predetermined error type information. This predetermined error type information can be memory access exception error type information, arithmetic exception error type information, illegal instruction execution error type information, or bus error type information, etc.
[0116] The signal processor 300 is primarily used to capture predetermined error type information during program execution. When such information is generated, the signal processor 300 captures it, then obtains the current runtime information and encapsulates it into exception log information. For example, the signal processor 300 obtains the current time and the stack information at the time the predetermined error type information was generated, formats the obtained stack information, and writes the current time, the predetermined error type information, and the formatted stack information into an exception log file, thus forming exception log information. Furthermore, the signal processor 300 should determine the processing rule corresponding to the predetermined error type information. If the processing rule is to return to a savepoint, the signal processor 300 obtains the information of the savepoint to be returned to (for example, through the savepoint manager 301; the information of the savepoint to be returned to could be the savepoint at the top of the stack). If the currently popped savepoint is not empty, the signal processor 300 can load the savepoint information, thereby performing the corresponding exception protection operation according to the exception protection behavior corresponding to the savepoint.
[0117] In one example, upon program startup, the signal processor 300 can sequentially read error type information and its corresponding processing rules from a preset file. For each read error type information and its corresponding processing rule, the signal processor 300 performs a signal processor registration operation, thereby forming key-value pairs based on the error type information and processing rules. Subsequently, when the signal processor 300 captures predetermined error type information, it can use the received predetermined error type information as a key to search for a matching value in the previously formed key-value pairs, and use the matching value as the processing rule corresponding to the predetermined error type information.
[0118] In one example, if the signal processor 300 determines that the processing rule corresponding to the predetermined error type information is to exit the program, it can terminate the program's execution. If the signal processor 300 determines that the processing rule corresponding to the predetermined error type information is to restart the program, it can restart the program's execution.
[0119] In one example, when the exception protection behavior corresponding to the currently popped savepoint in savepoint manager 301 is to output exception information, signal processor 300 executes the operation of outputting exception information and terminates the savepoint's operation. When the exception protection behavior corresponding to the currently popped savepoint is to ignore the exception and jump to the target location, signal processor 300 jumps to the target location and executes the operation at the target location.
[0120] For example, if the exception protection behavior corresponding to the current popped savepoint is to ignore the exception and jump to the exit label, the signal processor 300 terminates its execution. As another example, if the exception protection behavior corresponding to the current popped savepoint is to ignore the exception and jump to a non-exit specified label, the signal processor 300 triggers the program to continue execution from the location of the non-exit specified label based on the context information of the current popped savepoint.
[0121] Exemplary electronic devices
[0122] The following is for reference. Figure 4 To describe an electronic device according to embodiments of the present disclosure. Figure 4 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. Figure 4 As shown, the electronic device 41 includes one or more processors 411 and memory 412.
[0123] The processor 411 may be a central processing unit (CPU) or other form of processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 41 to perform desired functions.
[0124] The memory 412 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory. The non-volatile memory may, for example, include read-only memory (ROM), hard disk, and flash memory. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 411 may execute the program instructions to implement the signal processing mechanism-based anomaly protection methods and / or other desired functions described in the various embodiments of this disclosure above.
[0125] In one example, electronic device 41 may further include input device 413 and output device 414, etc., these components being interconnected via a bus system and / or other forms of connection mechanism (not shown). Furthermore, the input device 413 may also include, for example, a keyboard, mouse, etc. The output device 414 can output various information to the outside. The output device 414 may include, for example, a display, speaker, printer, and communication networks and their connected remote output devices, etc.
[0126] Of course, for the sake of simplicity, Figure 4Only some of the components of the electronic device 41 relevant to this disclosure are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device 41 may include any other suitable components depending on the specific application.
[0127] Exemplary computer program products and computer-readable storage media
[0128] In addition to the methods and apparatus described above, embodiments of this disclosure may also be computer program products comprising computer program instructions that, when executed by a processor, cause the processor to perform the steps of the methods for implementing anomaly protection based on signal processing mechanisms according to various embodiments of this disclosure as described in the "Exemplary Methods" section above.
[0129] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of this disclosure. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on a user's computing device, partially on a user's computing device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0130] Furthermore, embodiments of this disclosure may also be computer-readable storage media storing computer program instructions that, when executed by a processor, cause the processor to perform the steps of the method for implementing anomaly protection based on a signal processing mechanism according to various embodiments of this disclosure as described in the "Exemplary Methods" section above.
[0131] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples (not an exhaustive list) of a readable storage medium may include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0132] The basic principles of this disclosure have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the aforementioned specific details for implementation.
[0133] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments, since they largely correspond to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0134] The methods and apparatus of this disclosure may be implemented in many ways. For example, they may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above-described order of steps for the methods is for illustrative purposes only, and the steps of the methods of this disclosure are not limited to the order specifically described above unless otherwise specifically stated. Furthermore, in some embodiments, this disclosure may also be implemented as a program recorded on a recording medium, the program including machine-readable instructions for implementing the methods according to this disclosure. Thus, this disclosure also covers recording media storing programs for performing the methods according to this disclosure.
[0135] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.
Claims
1. A method for anomaly protection based on signal processing mechanisms, characterized in that, include: During program execution, when a predetermined error type information is generated, the signal processor registered for the predetermined error type information receives the predetermined error type information; The signal processor acquires the current operating information and encapsulates the current operating information into an exception log information. The signal processor determines the processing rule corresponding to the predetermined error type information based on the pre-set correspondence between error type information and processing rules; If the processing rule corresponding to the predetermined error type information is to return to the save point, the signal processor obtains the information of the save point that needs to be returned to. The signal processor loads the information of the saved point and performs corresponding abnormal protection operations according to the abnormal protection behavior corresponding to the saved point.
2. The method according to claim 1, characterized in that, The predetermined error type information includes: memory access exception error type information, arithmetic exception error type information, illegal instruction execution error type information, or bus error type information.
3. The method according to claim 1, characterized in that, The signal processor acquires current operating information and encapsulates the current operating information into exception log information, including: The signal processor acquires the current time and the stack information when a predetermined error type is generated. The signal processor formats the stack information and writes the current time, the predetermined error type information, and the formatted stack information into the exception log file.
4. The method according to claim 1, characterized in that, The method further includes: When the program starts, it reads the error type information and its corresponding processing rules from the preset file in sequence. For each error type information and its corresponding processing rule read out, a signal processor registration operation is performed, and a key-value pair based on the error type information and processing rule is formed. The signal processor determines the processing rules corresponding to the predetermined error type information, including: The signal processor uses the received predetermined error type information as a key, searches for a value that matches the predetermined error type information in the key-value pair, and uses the matching value as the processing rule corresponding to the predetermined error type information.
5. The method according to claim 1, characterized in that, The method further includes: If the signal processor determines that the processing rule is to exit the program, it will terminate the program execution; or If the signal processor determines that the processing rule is to restart the program, it will perform the operation of restarting the program.
6. The method according to any one of claims 1 to 5, characterized in that, The signal processor acquires information about the save point that needs to be returned to, and loads the save point information, including: The signal processor obtains information about the savepoint located at the top of the stack by performing a savepoint pop operation through the savepoint manager; When the current popped savepoint is not empty, the signal processor loads the information of the savepoint.
7. The method according to claim 6, characterized in that, The step of performing corresponding anomaly protection operations based on the anomaly protection behavior corresponding to the save point includes: If the exception protection behavior corresponding to the current popped save point is to output an exception message, execute the operation of outputting the exception message and terminate the program; or If the exception protection behavior corresponding to the current popped save point is to ignore the exception and jump to the target location, then the operation at the target location is executed.
8. The method according to claim 7, characterized in that, The step of ignoring the exception and jumping to the target location includes: ignoring the exception and jumping to the exit label, or ignoring the exception and jumping to a specified label that is not an exit label; Furthermore, when the exception protection behavior corresponding to the current popped save point is to ignore the exception and jump to the target location, the operation at the target location is executed, including: If the exception protection behavior corresponding to the current popped save point is to ignore the exception and jump to the exit label, then the program execution ends; or When the exception protection behavior corresponding to the current popped save point is to ignore the exception and jump to the specified non-exit label, the program is triggered to continue execution from the location of the specified non-exit label according to the context information of the current popped save point.
9. A computer-readable storage medium storing a computer program for performing the method according to any one of claims 1-8.
10. An electronic device, the electronic device comprising: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the method of any one of claims 1-8.
