Data processing method and device for program fleeting, equipment and medium
By detecting and recording the code running status and register information of the program run-fly event in the MCU chip, and generating abnormal status information, it solves the difficulty of reproducing and debugging of the program run-fly problem, and realizes efficient fault analysis and resolution, improving the System stability and security.
Patent Information
- Application Number
- CN202411034182.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-11-08
AI Technical Summary
In smart cockpit systems, it is difficult to reproduce, locate and debug the program run-off problem of MCU chips, resulting in system failure and safety risks, and the existing technology is difficult to effectively solve these problems.
When the target program triggers a preset run-off event, the code is interrupted, and the current code running is obtained, the current code running status, the register internal state information and the program execution status information are generated, and the abnormal state information is saved or uploaded for subsequent analysis.
By retaining relevant information on the problem site, the accurate and efficient analysis and solution of program run-off problems are achieved, reducing debugging time and energy, and improving the reliability and safety of the system.
Smart Images

Figure CN118916202A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of anomaly detection, and in particular to a data processing method for program runaway, a data processing device for program runaway, an electronic device and a computer-readable storage medium. Background Art
[0002] In modern smart cockpit systems, MCU (Microcontroller Unit) chips play a vital role, responsible for controlling and managing various in-vehicle functions. In-car entertainment, navigation systems, autonomous driving, etc. are all inseparable from MCU. When the MCU chip program runs out of control, it may cause system failure or even safety risks.
[0003] In the actual application of MCU chips, program runaway is a common problem. The causes of program runaway are complicated and may be hardware failure, electromagnetic interference, software error and many other factors. Once the program runaway problem occurs, it will cause a lot of troubles to programmers, mainly including the following points:
[0004] 1. Difficult to reproduce the problem:
[0005] Runaway issues may only occur in specific hardware environments, operating system versions, or user input conditions, which makes it difficult to reproduce the problem in a development environment; the problem may be intermittent and only occur in certain rare circumstances, increasing the difficulty of reproducing the problem; it may be necessary to simulate real user scenarios, network conditions, or interactions with external devices, which requires more time and resources.
[0006] 2. The location of the error is unclear:
[0007] Runaway problems may be caused by any part of the code, from the underlying driver to the high-level business logic; the error may be caused by the interaction of multiple factors, and each link needs to be checked step by step; the problem may be hidden in complex system calls, asynchronous operations or multi-threaded environments, which increases the difficulty of locating the error.
[0008] 3. Difficult to debug:
[0009] Runaway problems may cause the program to crash or produce unpredictable behavior. Debugging tools may not provide enough information to determine the root cause of the problem. The debugging process may require rerunning the program multiple times and testing under different conditions, which consumes a lot of time and energy. Locating and solving runaway problems usually requires a deep understanding of the system architecture, code logic, and underlying mechanisms. It may require reading a lot of documents, researching related technical knowledge, and searching for solutions to similar problems. The debugging process may require repeated code modifications, testing, and verification until the problem is solved. Summary of the invention
[0010] In view of the above problems, a data processing method for program runaway, a data processing device for program runaway, an electronic device and a computer-readable storage medium are proposed to overcome the above problems or at least partially solve the above problems, including:
[0011] A data processing method for program runaway, the method comprising:
[0012] When it is detected that the target program triggers a preset runaway event, interrupting the code execution of the target program;
[0013] Obtaining the current code running status, register internal status information and program execution status information of the target program;
[0014] Exception status information is generated according to the current code running status, the register internal status information and the program execution status information, and the exception status information is saved.
[0015] Optionally, the saving the abnormal state information includes:
[0016] The abnormal state information is stored in a hardware storage unit.
[0017] Optionally, the saving the abnormal state information includes:
[0018] The abnormal status information is uploaded to a preset remote device for storage.
[0019] Optionally, uploading the abnormal status information to a preset remote device for storage includes:
[0020] Uploading the abnormal status information to a preset remote device and storing it in the remote device;
[0021] And / or, the abnormal status information is uploaded to a preset remote device, and the remote device transmits the abnormal status information to a preset log system for storage.
[0022] Optionally, the method further comprises:
[0023] When a memory access violation is detected, determining to trigger the runaway event;
[0024] and / or, when a bus error is detected, determining to trigger the runaway event;
[0025] and / or, when an execution error is detected, determining that the runaway event is triggered;
[0026] and / or, when a mathematical operation error is detected, determining that the runaway event is triggered;
[0027] and / or, when a stack error is detected, determining to trigger the runaway event;
[0028] and / or, when a power management error is detected, determining to trigger the runaway event;
[0029] and / or, when a clock management error is detected, determining to trigger the runaway event;
[0030] And / or, when a peripheral error is detected, determining to trigger the runaway event.
[0031] Optionally, interrupting the code execution of the target program includes:
[0032] Interrupt driven to interrupt the code execution of the target program.
[0033] Optionally, the obtaining of the current code running state, register internal state information, and program execution state information of the target program includes:
[0034] The preset interrupt processing function is called to collect and record the current code running status of the target program, the internal status information of the register, and the program execution status information.
[0035] Optionally, the method further comprises:
[0036] Add a software tracking point, and the software tracking point is used to detect whether the target program triggers a preset runaway event.
[0037] Optionally, the method further comprises:
[0038] An abnormality analysis is performed based on the abnormal status information.
[0039] The present invention also provides a data processing device for program runaway, the device comprising:
[0040] An interrupt module, used for interrupting the code running of the target program when detecting that the target program triggers a preset runaway event;
[0041] An acquisition module, used to acquire the current code running status, register internal status information and program execution status information of the target program;
[0042] The storage module is used to generate abnormal state information according to the current code running state, the register internal state information and the program execution state information, and save the abnormal state information.
[0043] Optionally, the storage module is used to save the abnormal status information in a hardware storage unit.
[0044] Optionally, the storage module is used to upload the abnormal status information to a preset remote device for storage.
[0045] Optionally, the storage module is used to upload the abnormal status information to a preset remote device and store it in the remote device; and / or upload the abnormal status information to a preset remote device and transmit it from the remote device to a preset log system for storage.
[0046] Optionally, the device further comprises:
[0047] A determination module is used to determine whether the runaway event is triggered when a memory access violation is detected; and / or, when a bus error is detected, to determine whether the runaway event is triggered; and / or, when an execution error is detected, to determine whether the runaway event is triggered; and / or, when a mathematical operation error is detected, to determine whether the runaway event is triggered; and / or, when a stack error is detected, to determine whether the runaway event is triggered; and / or, when a power management error is detected, to determine whether the runaway event is triggered; and / or, when a clock management error is detected, to determine whether the runaway event is triggered; and / or, when a peripheral error is detected, to determine whether the runaway event is triggered.
[0048] Optionally, the interrupt module is used for interrupt driving to interrupt the code execution of the target program.
[0049] Optionally, the acquisition module is used to call a preset interrupt processing function to collect and record the current code running status of the target program, the register internal status information, and the program execution status information.
[0050] Optionally, the device further comprises:
[0051] The tracking point module is used to add software tracking points, and the software tracking points are used to detect whether the target program triggers a preset runaway event.
[0052] Optionally, the device further comprises:
[0053] The analysis module is used to perform abnormality analysis based on the abnormal state information.
[0054] The present invention also provides an electronic device, characterized in that it includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, and when the computer program is executed by the processor, it implements the above-mentioned data processing method for program running away.
[0055] The present invention also provides a computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the data processing method for program running away as described above is implemented.
[0056] Beneficial effects of the present invention:
[0057] In the present invention, when it is detected that the target program triggers a preset runaway event, the code running of the target program is interrupted; the current code running state, register internal state information and program execution state information of the target program are obtained; according to the current code running state, register internal state information and program execution state information, abnormal state information is generated and saved. Through the embodiment of the present invention, relevant information of the problem site can be retained, so as to accurately and efficiently analyze and solve the program runaway problem. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 This is a flowchart of a data processing method for program runaway according to an embodiment of the present invention;
[0059] Figure 2 is a flowchart of another method for processing data for program runaway according to an embodiment of the present invention;
[0060] Figure 3 This is a flowchart of another method for processing data for program runaway according to an embodiment of the present invention;
[0061] Figure 4 is a flowchart of steps for determining an abnormality according to an embodiment of the present invention;
[0062] Figure 5 is a flowchart of steps for storing abnormal state information according to an embodiment of the present invention;
[0063] Figure 6 is another flow chart of steps for storing abnormal status information according to an embodiment of the present invention;
[0064] Figure 7 is another flow chart of steps for storing abnormal status information according to an embodiment of the present invention;
[0065] Figure 8 is a flowchart of another step of storing abnormal state information according to an embodiment of the present invention;
[0066] Fig. 9 is another step flow chart of storing abnormal state information according to an embodiment of the present invention;
[0067] Fig.10 is a schematic diagram of a scenario in an embodiment of the present invention;
[0068] Fig.11 The present invention is a schematic diagram of the structure of a data processing device for program runaway according to an embodiment of the present invention. DETAILED DESCRIPTION
[0069] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all 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.
[0070] Reference Figure 1 , shows a flowchart of a data processing method for program runaway according to an embodiment of the present invention, which may include the following steps:
[0071] Step 101: When it is detected that the target program triggers a preset runaway event, the code execution of the target program is interrupted.
[0072] In actual applications, when a target program is detected to trigger a preset runaway event, the code execution of the target program may be interrupted first in order to save on-site information.
[0073] For example, during the process of debugging a vehicle or a test bench, it may be detected whether a target program triggers a preset runaway event, which is not limited in this embodiment of the present invention.
[0074] Step 102: Obtain the current code running status, register internal status information and program execution status information of the target program.
[0075] After interrupting the code execution of the target program, on-site information may be collected; specifically, register internal status information, program execution status information, and the current code execution status of the target program may be collected and recorded.
[0076] The current code running status may include the current instruction address, specific information of which step is executed, and the next operation to be executed.
[0077] The register internal state information may include the internal state of various registers, such as the values of general-purpose registers (such as R0 to R12), which are usually used to store variables and intermediate calculation results. At the same time, it also includes program status registers (such as xPSR), which provide CPU (Central Processing Unit) status flags and execution status information.
[0078] Program execution status information can include the current value of the stack pointer, which points to the memory location at the top of the stack when the program is running. The stack may contain key information such as local variables, backup values of registers, and return addresses of function calls.
[0079] Step 103: Generate abnormal status information according to the current code running status, register internal status information and program execution status information, and save the abnormal status information.
[0080] After obtaining the current code running status, register internal status information and program execution status information, exception status information can be generated based on this information and saved to save the on-site information, so that the on-site situation can be successfully reproduced after the exception analysis, and then the exception analysis can be carried out in a targeted manner.
[0081] In some feasible embodiments, the abnormal status information may also include, but is not limited to, information such as voltage, current, power status, pin status, etc., which is not limited in the embodiments of the present invention.
[0082] In the embodiment of the present invention, when it is detected that the target program triggers a preset runaway event, the code running of the target program is interrupted; the current code running state, register internal state information and program execution state information of the target program are obtained; according to the current code running state, register internal state information and program execution state information, abnormal state information is generated and saved. Through the embodiment of the present invention, relevant information at the problem site can be retained, so as to accurately and efficiently analyze and solve the program runaway problem.
[0083] Reference Figure 2 , shows a flowchart of another data processing method for program runaway according to an embodiment of the present invention, which may include the following steps:
[0084] Step 201: When it is detected that the target program triggers a preset runaway event, interrupt driving is performed to interrupt the code execution of the target program.
[0085] In actual applications, when a target program is detected to trigger a preset runaway event, in order to save the on-site information, the interrupt driver can be used to interrupt the code execution of the target program. Interrupt driver means that the processor will immediately interrupt the current task (i.e., the target program) and jump to the exception handling routine to respond to the runaway event.
[0086] In an embodiment of the present invention, the above method may further include the following steps:
[0087] When a memory access violation is detected, it is determined that a runaway event is triggered; and / or, when a bus error is detected, it is determined that a runaway event is triggered; and / or, when an execution error is detected, it is determined that a runaway event is triggered; and / or, when a mathematical operation error is detected, it is determined that a runaway event is triggered; and / or, when a stack error is detected, it is determined that a runaway event is triggered; and / or, when a power management error is detected, it is determined that a runaway event is triggered; and / or, when a clock management error is detected, it is determined that a runaway event is triggered; and / or, when a peripheral error is detected, it is determined that a runaway event is triggered.
[0088] In some feasible embodiments, when a memory access violation is detected, it can be determined that the target program triggers a preset runaway event; wherein, the memory access violation can refer to: attempting to access an undefined or protected memory area, accessing a memory address that violates alignment requirements, that is, unaligned access, attempting to execute unauthorized code, such as executing code loaded from a non-executable memory area, etc.
[0089] In some feasible embodiments, when a bus error is detected, it can also be determined that the target program triggers a preset runaway event; wherein, a bus error can refer to when the CPU cannot normally complete read and write operations on peripherals or memory, or it can refer to an error on the data bus, address bus or control bus (which may be caused by hardware failure or external interference).
[0090] In some feasible embodiments, when an execution error is detected, it can also be determined that the target program triggers a preset runaway event; wherein the execution error can refer to an invalid or undefined instruction, or an attempt to execute a privileged operation without sufficient authority.
[0091] In some feasible embodiments, when a mathematical operation error is detected, it can also be determined that the target program triggers a preset run-away event; wherein the mathematical operation error can refer to a floating-point operation exception (such as division by zero or overflow), or it can refer to the execution of an incorrect type conversion or an illegal bit operation.
[0092] In some feasible embodiments, when a stack error is detected, it can also be determined that the target program triggers a preset runaway event; wherein, a stack error can refer to a stack overflow or underflow, an attempt to use memory beyond the allocated stack boundary, incorrect stack pointer operation, which may lead to illegal memory access, etc.
[0093] In some feasible embodiments, when a power management error is detected, it can also be determined that the target program triggers a preset runaway event; wherein the power management error can refer to voltage instability causing the system to be unable to maintain stable operation.
[0094] In some feasible embodiments, when a clock management error is detected, it can also be determined that the target program triggers a preset runaway event; wherein the clock management error can refer to a clock configuration error that causes the system to be unable to maintain stable operation.
[0095] In some feasible embodiments, when a peripheral error is detected, it can also be determined that the target program triggers a preset runaway event; wherein, the peripheral error can refer to a parameter error when configuring the peripheral or a logical error when using the peripheral, or it can refer to an abnormal state returned by the peripheral or an interrupt that is not properly processed, and the embodiments of the present invention are not limited to this.
[0096] Step 202: Call a preset interrupt processing function to collect and record the current code running status of the target program, register internal status information, and program execution status information.
[0097] After interrupting the code execution of the target program, on-site information can be collected; specifically, a preset interrupt processing function can be called to collect and record the current code execution status, register internal status information and program execution status information of the target program.
[0098] Step 203: Generate abnormal status information according to the current code running status, register internal status information and program execution status information.
[0099] After obtaining the current code running status, register internal status information and program execution status information, abnormal status information can be generated based on the information.
[0100] Step 204: Save the abnormal status information to the hardware storage unit.
[0101] After the abnormal state information is obtained, the abnormal state information can be stored in a hardware storage unit for preservation, so as to avoid the abnormal state information being deleted due to a runaway event, resulting in no on-site information for abnormal analysis.
[0102] In an embodiment of the present invention, the above method may further include the following steps:
[0103] Add software tracking points, which are used to detect whether the target program triggers the preset runaway event.
[0104] In some feasible embodiments, software tracking can be added. When the system is running, the software tracking will monitor key operations and state changes to detect whether the target program triggers a preset runaway event. When it is detected that the target program triggers a preset runaway event, the system immediately stops the code execution of the target program and enters the error handling mode to retain the on-site information.
[0105] In an embodiment of the present invention, the above method may further include the following steps:
[0106] Perform abnormal analysis based on abnormal status information.
[0107] In some feasible embodiments, after obtaining the exception status information, an exception analysis can be performed on the run-away event of the target program based on the exception status information, so as to optimize the code in a targeted manner, fix the problem that caused the run-away, and add more boundary checks and exception handling mechanisms to the code to prevent similar problems from occurring again.
[0108] In the embodiment of the present invention, when it is detected that the target program triggers a preset runaway event, an interrupt driver is used to interrupt the code running of the target program; a preset interrupt processing function is called to collect and record the current code running state, register internal state information, and program execution state information of the target program; abnormal state information is generated according to the current code running state, register internal state information, and program execution state information; and the abnormal state information is saved in a hardware storage unit. Through the embodiment of the present invention, by combining software and hardware, it helps R&D personnel to collect relevant information of the problem, thereby retaining relevant information of the problem site, and thus enabling R&D personnel to accurately and efficiently analyze and solve the program runaway problem.
[0109] Reference Figure 3 , shows a flowchart of another method for processing data for program runaway according to an embodiment of the present invention, which may include the following steps:
[0110] Step 301: When it is detected that the target program triggers a preset runaway event, interrupt driving is performed to interrupt the code execution of the target program.
[0111] In actual applications, when a target program is detected to trigger a preset runaway event, in order to save the on-site information, the interrupt driver can be used to interrupt the code execution of the target program. Interrupt driver means that the processor will immediately interrupt the current task (i.e., the target program) and jump to the exception handling routine to respond to the runaway event.
[0112] Step 302: Call a preset interrupt processing function to collect and record the current code running status of the target program, register internal status information, and program execution status information.
[0113] After interrupting the code execution of the target program, on-site information can be collected; specifically, a preset interrupt processing function can be called to collect and record the current code execution status, register internal status information and program execution status information of the target program.
[0114] Step 303: Generate abnormal status information according to the current code running status, register internal status information and program execution status information.
[0115] After obtaining the current code running state, register internal state information and program execution state information, the abnormal state information can be generated according to the information. Specifically, the current code running state, register internal state information and program execution state information can be combined to obtain the abnormal state information.
[0116] Step 304: Upload the abnormal status information to a preset remote device for storage.
[0117] In some feasible embodiments, the abnormal state information may also be uploaded to a preset remote device for storage. Specifically, step 304 may be implemented by the following sub-steps:
[0118] Sub-step 11: Upload the abnormal status information to a preset remote device and store it in the remote device.
[0119] In some feasible embodiments, the abnormal status information may be directly uploaded to a preset remote device and stored in the preset remote device.
[0120] Sub-step 12: Upload the abnormal status information to a preset remote device, and the remote device transmits the abnormal status information to a preset log system for storage.
[0121] In other feasible embodiments, the abnormal state information may be first uploaded to a preset remote device, and then transmitted to a preset log system by the remote device for storage. The remote device may be a host computer, which is not limited in the embodiment of the present invention.
[0122] In an embodiment of the present invention, when it is detected that the target program triggers a preset runaway event, an interrupt is driven to interrupt the code running of the target program; a preset interrupt processing function is called to collect and record the current code running status, register internal status information, and program execution status information of the target program; abnormal status information is generated according to the current code running status, register internal status information, and program execution status information; and the abnormal status information is uploaded to a preset remote device for storage. Through the embodiment of the present invention, through a combination of software and hardware, it helps R&D personnel to collect relevant information of the problem, thereby retaining relevant information at the problem site, and thus enabling R&D personnel to accurately and efficiently analyze and solve the program runaway problem.
[0123] The following, combined Figure 4 - Fig.11 , further explain the above data processing method for program runaway:
[0124] When the MCU core detects an exception, an exception interrupt will be triggered, which will jump to the corresponding exception interrupt processing function for execution. HardFault is the most common error type, and, if no other exception processing is enabled, the HardFault exception interrupt processing function is entered by default. From a software perspective, the possible causes of HardFault are:
[0125] (1) Array out of bounds
[0126] (2) Wild pointer
[0127] (3) Operation starts without initializing the hardware, or without an interrupt service function, etc.
[0128] (4) Task stack overflow, etc.
[0129] In the ARM (Advanced RISC Machines) architecture processor, the registers related to the HardFault exception are the core part of the exception and fault handling. These registers provide developers with key information for fault cause analysis:
[0130] 1.1. Exception handling register:
[0131] Program Status Register (xPSR, eXecutable Program Status Register): includes the Application Program Status Register (APSR, Application Program Status Register), the Interrupt Program Status Register (IPSR, Interrupt Program Status Register) and the Execution Program Status Register (EPSR, Execution Program Status Register). These registers provide information about the current status of the program, including whether there is a fault (such as HardFault).
[0132] Control register (CONTROL): This register contains control bits used to switch processor states, such as switching from the main stack pointer (MSP) to the process stack pointer (PSP), or switching between different privilege levels.
[0133] 1.2. System Control Block (SCB) Registers:
[0134] System Control Block (SCB): The ARM processor contains an SCB module, which provides system configuration and status information.
[0135] Configuration and Control Register (SCB->CCR, System Control Block->Configuration and Control Register): Provides control options for configuring processor behavior, such as stack alignment requirements and exception handling settings.
[0136] 1.3. Hardware fault related registers:
[0137] Hardware Fault Status Register (HFSR): When a hardware fault occurs, this register records the cause of the fault. For example, when an attempt is made to execute an invalid instruction or to access an incorrect memory address, a hardware fault is triggered and the corresponding bit is set in this register.
[0138] Configurable Fault Status Register (CFSR): It is subdivided into Bus Fault Status Register (BFSR), Memory Management Fault Status Register (MMFSR) and Usage Fault Status Register (UFSR). These registers provide a more detailed description of the specific cause of the fault.
[0139] Bus Fault Status Register (BFSR): records fault information related to data bus operations, such as illegal data access.
[0140] Memory Management Fault Status Register (MMFSR): Records fault information related to the memory protection unit (MPU) settings, such as access to protected memory areas.
[0141] Usage Fault Status Register (UFSR): Records faults due to incorrect instruction usage, such as unaligned memory access or illegal instruction set usage.
[0142] 1.4. Fault address register:
[0143] Fault Address Register (FaultAddr): When a memory access fault occurs, this register records the address at which the fault occurred. This is very useful for debugging illegal memory access.
[0144] 1.5. Stack related registers:
[0145] Main Stack Pointer (MSP): The current top-of-stack pointer of the processor when the main stack is in use. The processor automatically uses this pointer when an exception occurs.
[0146] Process Stack Pointer (PSP): The current top-of-stack pointer of the processor, when a process stack is used.
[0147] When a HardFault exception occurs, the processor automatically pushes part of the context onto the stack, including key information such as the program counter (PC) and program status register (xPSR).
[0148] 1.6. Stack frames and automatically saved registers:
[0149] When an exception occurs, the processor automatically saves the values of some key registers on the currently used stack. These registers include:
[0150] General registers (R0-R3): used to store and pass function parameters.
[0151] Return address register (LR, R14): stores the return address of the function call.
[0152] Program Counter (PC, R15): Stores the instruction address when an exception occurs.
[0153] Program Status Register (xPSR): Contains the status flags of the processor.
[0154] The values of these registers are saved on the stack so that they can be restored to the state before the exception occurs after the exception handling is completed. The exception handler can analyze the context of the fault by checking these values.
[0155] When the MCU chip software is abnormal, the memory information of the related software abnormal fault can be obtained (the memory information includes the abnormal status information), and the fault information can be finally transmitted to the R&D personnel through the medium, which can help engineers locate the cause of the abnormality more quickly and solve the problem more quickly.
[0156] For example, tools, including but not limited to serial ports, logs, CAN buses and other communication methods, can be used to help R&D personnel diagnose and analyze relevant information of the problem, including but not limited to type, time, chip status, register status, function call status, etc. This information can help understand the system status and environment when the problem occurred, and then more accurately locate and solve the problem, and ultimately correct code defects.
[0157] During the operation of the MCU system, there is an interrupt controller called Nested Vectored Interrupt Controller (NVIC) in the Cortex processor, which is programmable and its registers are memory mapped.
[0158] The address of the NVIC is fixed, and the programming model of the NVIC is consistent for all Cortex processors.
[0159] An exception is an event that changes the program flow. When an exception occurs, the processor will suspend the currently executing task and execute a procedure called exception handling. After the exception handling is executed, the processor will continue to execute the program normally. For the ARM architecture, an interrupt is a type of exception. It is generally generated by hardware (such as peripherals and external input pins), and sometimes it can be triggered by software. The exception handling of the interrupt is also called the interrupt service routine (ISR). All error events will trigger HardFault by default.
[0160] There are several exceptions in the Cortex processor that are error handling exceptions. When the processor detects an error, it triggers an error handling exception. The detected errors include errors in executing undefined instructions, bus errors, register access errors, etc. This mechanism allows errors to be discovered quickly, so the software can take corresponding actions for the exceptions:
[0161] 2.1. During the operation of the microcontroller (MCU), the processor may encounter various exceptions that trigger the exception interrupt mechanism, usually a HardFault. HardFault is an exception that captures serious errors. It is part of the ARM architecture processor. Once the processor detects something abnormal or unhandled, it triggers a HardFault. The following are some common scenarios that may cause HardFault exceptions. Here are some common exceptions:
[0162] 1) Memory access violation:
[0163] Attempt to access undefined or protected memory area;
[0164] Accessing a memory address that violates alignment requirements, i.e., unaligned access;
[0165] Attempt to execute unauthorized code, such as executing code loaded from non-executable memory areas;
[0166] 2) Bus error:
[0167] When the CPU cannot normally complete the read and write operations to the peripherals or memory;
[0168] Errors on the data bus, address bus, or control bus may be caused by hardware failure or external interference;
[0169] 3) Execution error:
[0170] Invalid or undefined instruction;
[0171] Attempting to perform a privileged operation without sufficient permissions;
[0172] The software attempted an illegal instruction set state switch;
[0173] 4) Mathematical errors:
[0174] Floating point arithmetic exceptions, such as division by zero or overflow;
[0175] Performing incorrect type conversion or illegal bit operations;
[0176] 5) Stack Error:
[0177] A stack overflow or underflow, attempting to use memory beyond the bounds of the allocated stack;
[0178] Incorrect stack pointer operation may lead to illegal memory access;
[0179] 6) Power and clock management errors:
[0180] Unstable voltage or incorrect clock configuration causes the system to be unable to maintain stable operation;
[0181] 7) Peripheral error:
[0182] Parameter errors when configuring peripherals or logic errors when using peripherals;
[0183] The exception status or interrupt returned by the peripheral is not handled correctly;
[0184] When the MCU processor detects an exception during operation, it triggers the response exception mechanism. The exception includes but is not limited to various execution errors, bus errors, access errors, etc. All exceptions will trigger HardFault by default, such as Figure 4 shown.
[0185] 2.2. When an exception is encountered during the execution of the microcontroller (MCU) code, HardFault is triggered by default; at this time, the processor will quickly trigger a special exception handling interrupt process. This process is interrupt-driven, which means that the processor will immediately interrupt the current task and jump to the exception handling routine to respond to this situation. In this routine, the processor will first detect and collect the exception status information, which is crucial because it can provide detailed context when the exception occurs.
[0186] The exception status information covers the running status of the code extensively, including the current instruction address, the specific information of which step is executed, and the next operation to be performed. In addition, there are the internal states of various registers, such as the values of general-purpose registers (such as R0 to R11), which are usually used to store variables and intermediate calculation results. At the same time, it also includes program status registers (such as xPSR), which provide CPU status flags and execution status information.
[0187] The processor's program execution state is also part of the exception status information, including the current value of the stack pointer (SP), which points to the memory location at the top of the stack when the program is running. The stack may contain key information such as local variables, backup values of registers, and return addresses of function calls.
[0188] In exception handling, these are key clues to locate problems and understand the cause of program crashes. Once these exception status information is collected, the exception handler will immediately save them to the hardware storage unit for subsequent analysis and problem solving. The hardware storage unit includes not only EEPROM, but also other forms of non-volatile memory, such as Flash memory or special RAM areas, which are used to save emergency data.
[0189] On the contrary, if no abnormality occurs, continue monitoring, such as Figure 5 .
[0190] 2.3. When the microcontroller (MCU) code is running, when an exception is detected, HardFault is triggered by default; the exception handling interrupt is immediately entered to detect the abnormal status information. After the exception occurs, the abnormal status information is transmitted to the upper-level log system through the internal communication protocol. This can be integrated in the SOC (System on Chip) or a distributed log system for centralized storage, management and analysis of abnormal status information from the MCU. In this way, through effective log management and exception handling, the development team can remotely diagnose and analyze to quickly locate and solve problems, reduce system downtime, and improve product reliability. On the contrary, if no abnormality occurs, continuous monitoring, such as Figure 6 .
[0191] 2.4. When the microcontroller (MCU) code is running, when an exception is detected, HardFault is triggered by default; the exception handling interrupt is immediately entered. After detecting the exception, the exception handler will automatically start to collect detailed information about the exception status. This information usually includes: code running status, register internal status, program execution status, stack information and other related information. After the exception status information is sorted, it is output to the host device through the communication protocol after the exception occurs. The host device includes PC and professional debugging equipment. Developers can use the debugging and analysis tools of the host computer to conduct in-depth analysis of the exception status information. By comparing the code, viewing the function call stack, and checking the values of variables and registers, developers can determine the cause of the exception and proceed to fix defects in the code or enhance the system's fault tolerance for specific errors. Conversely, if no exception occurs, continue monitoring, such as Figure 7 .
[0192] 2.5. After the abnormal status information is collected, the code is stopped and the abnormal status information is retained. The code enters the pause state and all kinds of information at the abnormal scene are retained. In this way, the system can ensure that even in the event of an exception, the information that helps analyze and repair the error can be retained to the maximum extent. Once the field information is successfully saved, the exception handler can handle the exception according to the predefined strategy. This step of retaining the scene is the key to ensuring the reliability and maintainability of the system. It allows developers to accurately locate the cause of the problem by analyzing the saved status information and take corresponding measures, which is crucial for the stable operation and timely fault response of the embedded system.
[0193] During the operation of the microcontroller (MCU), the processor may encounter various exceptions, such as: memory access violation, bus error, execution error, mathematical operation error, stack error, power and clock management error, peripheral error, etc. All exceptions will trigger HardFault by default; when HardFault is triggered, the scene is retained; specifically, the program can be paused, the host device output, the hardware storage unit storage, and uploaded to the log system, etc. Figure 8 .
[0194] 2.6. Add software tracking points. When the system is running, the tracking points will monitor key operations and status changes. When abnormal status information is detected (such as assertion errors, memory leaks, illegal operations, etc.), HardFault is triggered by default; the system immediately stops code execution and enters error handling mode. The abnormal status information on the scene is retained, and the code execution enters a paused state (that is, the program is paused). The current erroneous thread is located, and the code defect is directly located. When an exception is detected, the exception handling interrupt is immediately entered, the abnormal status information on the scene is retained, the code execution enters a paused state, the code defect is directly located, the scene is retained, and when HardFault is triggered, the scene is retained; specifically, the program can be paused, the host computer device output, the hardware storage unit can be stored, and it can be uploaded to the log system, etc. Fig. 9 .
[0195] like Fig.10 As shown, in the MCU, an NVIC is provided; the NVIC can send out IRQs (Interrupt Request Signals) when other peripherals are abnormal or the processor core system is abnormal; based on the interrupt vector table, after determining that the HardFault is triggered, the abnormal status information can be uploaded to the SOC to upload to the log system; the abnormal status information can also be output through the host computer; the abnormal status information can also be stored in the EEPROM or Flash.
[0196] This solution is mainly used in the early R&D stage of the project, aiming to help engineers retain on-site information of crashes (program crashes or exceptions) caused by code defects during the development process. The solution is divided into two parts: the bench development stage and the test vehicle stage, which respectively introduce how to effectively monitor and analyze the code operation in these two stages:
[0197] 3.1. During the bench development stage, engineers can monitor the program running status in real time by connecting to the host computer. The goal of this stage is to promptly discover and resolve code defects to ensure the stability and correctness of the program.
[0198] The exception capture mechanism of this solution automatically triggers exception capture and on-site information recording when the program crashes or runs away. Engineers view the stack information when the exception occurs through stack backtracing, use debugging tools to perform stack backtracing, view the function call chain when the exception occurs, locate the code position that caused the runaway, analyze the parameters and local variables in the stack, find abnormal values or illegal operations, and find memory read and write problems that may cause the runaway by analyzing the memory snapshot of the exception site. Memory checking tools are used to detect memory leaks and illegal memory accesses.
[0199] 3.2. During the test vehicle phase, the code monitoring during this period is mainly done by uploading the code to the Android log system after the code runs out of control. When a code runs out of control, the on-site information at the time of the exception is recorded, including the program counter, stack pointer, register status, memory snapshot, and peripheral status. An automatic logging mechanism is set up to ensure that each running monitoring data and on-site information of the exception are retained in the local log system or remote server. At the same time, the on-site information is processed in the same way as above. According to the results of the exception analysis, the code is optimized in a targeted manner to fix the problem that caused the code to run out of control, and more boundary checks and exception handling mechanisms are added to the code to prevent similar problems from happening again.
[0200] Application examples:
[0201] When an assertion error occurs in a thread during execution, such as a precondition no longer being met, the system will immediately call the defined error handling mechanism. This mechanism will immediately record the location where the error occurred, including the file name, line number, and function name, to ensure that the error information is not lost and provide a key reference for subsequent debugging. Once an assertion error is detected, the system will trigger a hard error interrupt, which is an advanced interrupt mechanism designed to immediately stop the normal operation of the system and enter error handling mode, thereby preventing the error from spreading and ensuring the stability of other parts of the system.
[0202] When an error interrupt occurs, the system will enter a special interrupt processing function. The main function of this function is to record the current code execution status and the values of all key registers. This information is crucial for debugging and error analysis, and can help developers restore the scene when the error occurred. In order to further improve the accuracy of error analysis, the system will notify the error thread to retain the current scene information, and save the thread context by obtaining relevant information of the current thread and calling related functions.
[0203] Through this series of steps, the system can quickly enter the hard error interrupt state when an assertion error occurs, record the error information, and notify the error thread to retain the scene information, thereby improving the efficiency of error location and processing. This mechanism can not only respond to errors quickly, but also provide detailed reference materials for subsequent debugging and repair, effectively improving the stability and reliability of the system.
[0204] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0205] Reference Fig.11 , shows a schematic diagram of the structure of a data processing device for program runaway according to an embodiment of the present invention, which may include the following modules:
[0206] The interrupt module 1101 is used to interrupt the code execution of the target program when it is detected that the target program triggers a preset runaway event;
[0207] The acquisition module 1102 is used to acquire the current code running status, register internal status information and program execution status information of the target program;
[0208] The storage module 1103 is used to generate abnormal state information according to the current code running state, register internal state information and program execution state information, and save the abnormal state information.
[0209] In one embodiment of the present invention, the storage module 1103 is used to save the abnormal state information in a hardware storage unit.
[0210] In one embodiment of the present invention, the storage module 1103 is used to upload the abnormal status information to a preset remote device for storage.
[0211] In one embodiment of the present invention, the storage module 1103 is used to upload the abnormal status information to a preset remote device and store it in the remote device; and / or upload the abnormal status information to a preset remote device, and the remote device transmits the abnormal status information to a preset log system for storage.
[0212] In one embodiment of the present invention, the device further includes:
[0213] A determination module is used to determine whether a runaway event is triggered when a memory access violation is detected; and / or, when a bus error is detected, to determine whether a runaway event is triggered; and / or, when an execution error is detected, to determine whether a runaway event is triggered; and / or, when a mathematical operation error is detected, to determine whether a runaway event is triggered; and / or, when a stack error is detected, to determine whether a runaway event is triggered; and / or, when a power management error is detected, to determine whether a runaway event is triggered; and / or, when a clock management error is detected, to determine whether a runaway event is triggered; and / or, when a peripheral error is detected, to determine whether a runaway event is triggered.
[0214] In one embodiment of the present invention, the interrupt module 1101 is used for interrupt driving to interrupt the code execution of the target program.
[0215] In one embodiment of the present invention, the acquisition module 1102 is used to call a preset interrupt processing function to collect and record the current code running state of the target program, register internal state information, and program execution state information.
[0216] In one embodiment of the present invention, the device further includes:
[0217] The tracking point module is used to add software tracking points. Software tracking points are used to detect whether the target program triggers the preset runaway event.
[0218] In one embodiment of the present invention, the device further includes:
[0219] The analysis module is used to perform abnormal analysis based on abnormal status information.
[0220] In the embodiment of the present invention, when it is detected that the target program triggers a preset runaway event, the code running of the target program is interrupted; the current code running state, register internal state information and program execution state information of the target program are obtained; according to the current code running state, register internal state information and program execution state information, abnormal state information is generated and saved. Through the embodiment of the present invention, relevant information at the problem site can be retained, so as to accurately and efficiently analyze and solve the program runaway problem.
[0221] An embodiment of the present invention further provides an electronic device, which may include a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the above-mentioned data processing method for program running away is implemented.
[0222] An embodiment of 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 above-mentioned data processing method for program runaway is implemented.
[0223] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0224] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0225] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0226] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0227] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1A function specified in one or more boxes.
[0228] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0229] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0230] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0231] The data processing method for program runaway, the data processing device for program runaway, the electronic device and the computer-readable storage medium provided are introduced in detail above. The principle and implementation mode of the present invention are explained in this article by using specific examples. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for the general technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation mode and the scope of application. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A data processing method for program runaway, characterized in that: The method comprises: When it is detected that the target program triggers a preset runaway event, interrupting the code execution of the target program; Obtaining the current code running status, register internal status information and program execution status information of the target program; Exception status information is generated according to the current code running status, the register internal status information and the program execution status information, and the exception status information is saved.
2. The method according to claim 1, characterized in that: The storing of the abnormal state information comprises: The abnormal state information is stored in a hardware storage unit.
3. The method according to claim 1, characterized in that The storing of the abnormal state information comprises: The abnormal status information is uploaded to a preset remote device for storage.
4. The method according to claim 3, characterized in that The uploading of the abnormal status information to a preset remote device for storage includes: Uploading the abnormal status information to a preset remote device and storing it in the remote device; And / or, the abnormal status information is uploaded to a preset remote device, and the remote device transmits the abnormal status information to a preset log system for storage.
5. The method according to claim 1, characterized in that: The method further comprises: When a memory access violation is detected, determining to trigger the runaway event; and / or, when a bus error is detected, determining to trigger the runaway event; and / or, when an execution error is detected, determining that the runaway event is triggered; and / or, when a mathematical operation error is detected, determining that the runaway event is triggered; and / or, when a stack error is detected, determining to trigger the runaway event; and / or, when a power management error is detected, determining to trigger the runaway event; and / or, when a clock management error is detected, determining to trigger the runaway event; And / or, when a peripheral error is detected, determining to trigger the runaway event.
6. The method according to claim 1, characterized in that The interrupting the code execution of the target program includes: Interrupt driven to interrupt the code execution of the target program.
7. The method according to claim 1, characterized in that The obtaining of the current code running state, register internal state information and program execution state information of the target program includes: The preset interrupt processing function is called to collect and record the current code running status of the target program, the internal status information of the register, and the program execution status information.
8. The method according to claim 1, characterized in that The method comprises: Add a software tracking point, and the software tracking point is used to detect whether the target program triggers a preset runaway event.
9. The method according to claim 1, characterized in that: The method further comprises: An abnormality analysis is performed based on the abnormal status information.
10. A data processing device for program runaway, characterized in that: The device comprises: An interrupt module, used for interrupting the code running of the target program when detecting that the target program triggers a preset runaway event; An acquisition module, used to acquire the current code running status, register internal status information and program execution status information of the target program; The storage module is used to generate abnormal state information according to the current code running state, the register internal state information and the program execution state information, and save the abnormal state information.
11. An electronic device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the data processing method for program runaway as claimed in any one of claims 1 to 9 is implemented.
12. 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 data processing method for program runaway as claimed in any one of claims 1 to 9 is implemented.
Citation Information
Cited By
Processor fault identification method and device, electronic equipment and readable storage medium
CN120909880A
