Program crash processing method and device, equipment and medium
By calling the protection engine to initialize and listening to crash information in the application, the problem of poor user experience when the program crashes is solved, and the application stability and crash information processing efficiency are improved.
Patent Information
- Application Number
- CN202411655229.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-03-07
AI Technical Summary
In the prior art, when a program crashes, it is impossible to process the crash information without interrupting the user's use, resulting in poor user experience and failure to deal with the crash cause in time.
By calling the guard engine, the guard engine is initialized when the application starts, the crash information is listened to and captured, and interrupt processing is performed according to the type of exception stack information to make the application run normally, and the crash information is collected to generate a crash log and upload it to the server.
It realizes that users will not interrupt their use when the program crashes, enhances the stability and reliability of the application, reduces crash problems, and improves the processing efficiency of crash information and business recovery capabilities.
Smart Images

Figure CN119576623A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of software technology, and in particular, relates to a program crash processing method, device, equipment and medium. Background Art
[0002] With the rapid development of integrated circuit technology and communication network technology, terminals (tablets, mobile phones, TVs or computers, etc.) have gradually acquired powerful processing capabilities and communication functions. In the process of using the terminal, in some cases, the application may crash due to the application's own code or operating system, and thus cannot be used any further; for example, runtime exceptions, execution errors (such as memory overflow, etc.) and exceptions thrown by child threads may all cause the application to crash or the APP program to crash.
[0003] In the related art, when an application in a terminal crashes, the system will capture the crash and submit the crash information to the server and perform crash processing; by globally capturing the exception stack information when the APP crashes, and storing the exception stack information locally, the next time the APP is started, the exception stack information will be reported to the background monitoring platform, allowing developers to check and repair it. However, this technical solution cannot allow users to continue using the APP when the APP crashes. Due to the sudden exit of the APP, users can only reopen the APP to continue using it. In this way, on the one hand, it is difficult to solve the crash problem, resulting in a poor user experience; on the other hand, the cause of the crash is not dealt with in a timely manner, which also reduces the user experience. Summary of the invention
[0004] In view of the shortcomings of the prior art described above, the purpose of the present application is to provide a program crash processing method, device, equipment and medium, which are used to solve the problem in the prior art that when a program crashes, the normal use of the program is affected and the user experience is reduced.
[0005] To achieve the above-mentioned purpose and other related purposes, the first aspect of the present application provides a program crash processing method, including: calling a protection engine; when the application is started, initializing the protection engine to monitor and capture crash information in the application, the crash information including exception stack information when the application crashes; if the crash information of any of the applications is captured, interrupting the processing of the crash information according to the type of the exception stack information to enable the application to run normally; collecting the crash information of the application to generate a crash log, and uploading the crash log to a server.
[0006] In some embodiments of the first aspect, before monitoring and capturing the crash information in the application, it also includes: calling the basic object class, writing the protection engine initialization code in the loading method of the basic object class, and executing the loading method to initialize the protection engine; traversing the method names in the array class where the application is located, and generating a calling method for replacing the method name through the method exchange application programming interface; calling the exception capture module for capturing the exception method, adding the exception capture module to the calling method, and completing the initialization of the protection engine.
[0007] In some embodiments of the first aspect, if crash information of any of the applications is captured, the crash information is interrupted and processed according to the type of the exception stack information so that the application can run normally, including: capturing the crash information of the application to obtain the exception stack information including the exception type, exception description and stack frame; determining the exception code corresponding to the method call exception of the application according to the exception type, the exception description and the stack frame; extracting the first function pointer and the first method name of the original calling method in the exception code; searching for a method name that is identical, similar or unrelated to the function to which the first method name belongs as the target calling method according to the function to which the first method name belongs; replacing the first function pointer with the second function pointer of the target calling method to replace the original calling method, so that the application can run normally.
[0008] In some embodiments of the first aspect, replacing the first function pointer with the second function pointer of the target calling method to replace the original calling method so that the application can run normally also includes: using the second function pointer of the target calling method to replace the first function pointer of the original calling method; if it is detected that the original calling method is not executed, executing the target calling method to interrupt the transmission of the crash information caused by the original calling method so that the application can run normally; if it is detected that the original calling method is being executed, interrupting the original calling method and executing the target calling method to interrupt the transmission of the crash information so that the application can run normally.
[0009] In some embodiments of the first aspect, crash information of the application is collected to generate a crash log, and the crash log is uploaded to a server, including: receiving crash information of the application in an array class; determining a callback variable in the crash information, and if exception stack information exists in the captured callback variable, disassembling the exception stack information, and encapsulating the disassembled exception type, exception description and stack frame into stack log information; extracting the stack log information to generate a crash log, and encrypting and uploading the crash log to the server.
[0010] In some embodiments of the first aspect, after the crash log is encrypted and uploaded to the server, the method includes: receiving and parsing the crash log, identifying the parsed crash log, and generating a graphic representation of the exception type, the exception description, and prompt information for maintenance personnel; generating a QR code image, and saving the prompt information to a link corresponding to the QR code image; displaying the prompt information and the QR code image in a pop-up window, and displaying different colors for warning according to the urgency of the crash information.
[0011] In some embodiments of the first aspect, after uploading the crash log to the server, it also includes: receiving and parsing the crash log to determine the source of the failure of the application; generating a repair program in response to the source of the failure, and sending it to the terminal; if it is monitored that the target application that crashed in the terminal is in an idle or closed state, executing the repair program to repair the target application.
[0012] The second aspect of the present application provides a program crash processing device, including: an engine module, used to call a protection engine; a crash monitoring module, used to initialize the protection engine when the application is started, so as to monitor and capture crash information in the application, wherein the crash information includes exception stack information of the application crash; a crash protection module, used to interrupt the processing of the crash information according to the type of the exception stack information if the crash information of any of the applications is captured, so as to enable the application to run normally; a crash response module, used to collect the crash information of the application to generate a crash log, and upload the crash log to a server.
[0013] The third aspect of the present application provides a program crash processing device, comprising: one or more processing devices; a memory for storing one or more programs; when the one or more programs are executed by the one or more processing devices, the one or more processing devices implement the above-mentioned program crash processing method.
[0014] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is used to cause the computer to execute the above-mentioned program crash processing method.
[0015] As described above, a technical solution of the program crash processing method, device, equipment and medium described in the present application has the following beneficial effects:
[0016] This application calls a protection engine specifically used for handling crashes. After the protection engine is initialized when the application starts, continuous monitoring can effectively capture crash information in the application. When the crash information of the application is captured, interrupt processing is performed according to the type of exception stack information, so as to quickly restore the normal operation of the application, enhance the stability and reliability of the application, and reduce the problem of crashes caused by improper array operations; by collecting the crash information of the application and generating a detailed crash log, it is convenient for developers to perform remote analysis and repair, and also improves the efficiency of debugging and repair; it not only avoids application crashes, but also improves business recovery capabilities. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A diagram showing an implementation environment of a program crash handling method provided by the present application;
[0018] Figure 2 Shown is a flow chart of a program crash processing method provided by the present application;
[0019] Figure 3 Shows a complete flow chart of a program crash processing method provided by the present application;
[0020] Figure 4 Shown is a structural block diagram of a program crash processing device provided by the present application;
[0021] Figure 5 Shown is a schematic diagram of the structure of an electronic device provided by the present application and suitable for implementing an embodiment of the present application. DETAILED DESCRIPTION
[0022] The following describes the embodiments of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0023] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application, and thus the drawings only show components related to the present application rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed at will, and the component layout may also be more complicated.
[0024] The embodiment of the present application provides a method for handling program crashes, which can be applied to a terminal or a server, or can be software running in a terminal or a server. In some embodiments, the terminal can be an electronic device such as a smart phone, a tablet computer, a vehicle terminal, a laptop computer, or a desktop computer; the server can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers, or as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and big data and artificial intelligence platforms; the software can be an application for program crash handling, etc., but is not limited to the above forms.
[0025] For example, see Figure 1 Taking the program crash processing method executed by a terminal as an example, the terminal can call a protection engine; when the application is started, the protection engine is initialized to monitor and capture crash information in the application, and the crash information includes exception stack information when the application crashes; if the crash information of any of the applications is captured, the crash information is interrupted and processed according to the type of the exception stack information to enable the application to run normally; the crash information of the application is collected to generate a crash log, and the crash log is uploaded to a server.
[0026] The present application is described in detail below through specific embodiments. Figure 2 As shown, Figure 2 The program crash processing method provided in the embodiment of the present application includes the following steps:
[0027] Step S210, calling the protection engine;
[0028] Among them, APP, or application program, refers to a computer program that is used to complete one or more specific tasks. It has a visual user interface and can interact with users.
[0029] By calling the protection engine for processing application crashes, it should be noted that the crash information processed, that is, the Crash data includes but is not limited to the improper use of the NSArray class, that is, the developer uses the NSArray class incorrectly, causing the APP to crash directly.
[0030] Exemplarily, the protection engine includes a Crash protection engine management of an NSArray class, and the NSArray class is an important class of the Foundation framework (which provides basic data structures and operation interfaces) in the development of IOS and MACOS (Apple system), which is used to store ordered collections of objects, including strings, numbers, and packaging classes.
[0031] Specifically, a protection engine class is designed and implemented, which contains methods for initializing, monitoring, capturing and processing crash information. In the protection engine class, a data structure for storing crash information is defined, such as a dictionary, array or custom class, and a crash information capture mechanism is implemented, such as by registering a global exception handling function or using the runtime features of Objective-C.
[0032] Step S220, when the application is started, the protection engine is initialized to monitor and capture crash information in the application, wherein the crash information includes exception stack information when the application crashes;
[0033] Initializing the protection engine means initializing related components and variables, and the protection engine refers to a module or system used for application security protection.
[0034] Exemplarily, the runtime features of Objective-C or the API (Application Programming Interface) provided by a third-party library are used to register a global exception handling function. In the exception handling function, crash information, including exception stack, error code, etc., is captured, and the captured crash information is passed to the protection engine for processing.
[0035] Optionally, in some embodiments, before monitoring and capturing the crash information in the application, the method further includes:
[0036] Calling a base object class (ie, NSObject), writing the protection engine initialization code in a loading method of the base object class, and executing the loading method to initialize the protection engine;
[0037] Traversing the method names in the array class where the application is located, and generating a calling method (ie, API method) for replacing the method name through a method exchange application programming interface;
[0038] An exception capture module for capturing an exception method is called, and the exception capture module is added to the calling method to complete the initialization of the protection engine.
[0039] NSObject is the root class of all classes in Objective-C (i.e., the base object class). The Load class method, i.e., +(void)load, is a special class method that is automatically called when a class is loaded into the runtime, and is usually used for class initialization settings.
[0040] Exemplarily, utilizing the runtime features of Objective-C, the +(void)load method is automatically called when a class is loaded for the first time, and is used to initialize global resources or perform class-level settings. The Objective-C runtime allows the behavior of a class to be dynamically modified at runtime, including method implementations. Method exchange is used to intercept and modify method calls without modifying the source code. An exception capture module is called, which is usually implemented using a @try...@catch block. Objective-C provides an exception handling mechanism that allows developers to use @try...@catch blocks in their code to capture and handle exceptions. By adding these blocks to key methods, the robustness and error handling capabilities of the program can be enhanced.
[0041] Specifically, configure a new subclass inherited from NSObject, implement the +(void)load method in the new subclass (ie, the base object class), and write the initialization code of the protection engine in the +(void)load method, such as creating a protection engine instance, configuring parameters, etc.
[0042] Traverse the classes and methods in the application, find the specific method name in the target NSArray class (i.e., array class), and use the Objective-C runtime function method_exchangeImplementations to exchange the found method with the custom calling method. Create an exception capture module, usually using @try...@catch as an exception capture module, and add the exception capture module to the custom calling method to capture and handle exceptions during method execution.
[0043] In this embodiment, by creating an NSObject subclass and initializing the protection engine in the +(void)load method, it is possible to ensure that the protection engine is loaded and configured immediately when the application starts; by finding and replacing the method name in the NSArray class, specific method calls can be intercepted and processed, thereby enabling monitoring and modification of the application behavior; by calling the exception capture module and adding it to the calling method, the program's exception handling capability can be enhanced, thereby improving the program's stability and reliability.
[0044] Step S230, if the crash information of any of the application programs is captured, interrupting the processing of the crash information according to the type of the exception stack information to enable the application program to run normally;
[0045] Among them, by analyzing the exception stack information, the specific type and cause of the crash can be determined. The protection engine executes the corresponding interrupt processing logic according to the crash type to try to restore the normal operation of the application or perform other remedial measures.
[0046] Specifically, in the protection engine, a method for processing crash information is implemented. This method executes corresponding interrupt processing logic according to the type of exception stack information (such as null pointer exception, array out of bounds exception, etc.). The interrupt processing logic may include attempting to restore the normal operation of the application, recording error logs, displaying error prompts, etc.
[0047] Optionally, in some embodiments, if the crash information of any of the applications is captured, interrupting the processing of the crash information according to the type of the exception stack information to enable the application to run normally includes:
[0048] Capturing crash information of the application program, and obtaining the exception stack information including the exception type, exception description and stack frame;
[0049] Determine, according to the exception type, the exception description and the stack frame, the exception code corresponding to the method call exception of the application program;
[0050] Extracting the first function pointer and the first method name of the original calling method in the exception code;
[0051] According to the function to which the first method name belongs, search for a method name that is the same as, similar to, or unrelated to the function, and use it as the target calling method;
[0052] The first function pointer is replaced with the second function pointer of the target calling method to replace the original calling method, so that the application can run normally.
[0053] Exemplarily, the crash capture mechanism obtains exception stack information by intercepting unhandled exceptions or errors, and the stack frame records the function call sequence when the exception occurs, which helps to locate the cause of the crash. Each stack frame in the exception stack information contains method call information, including method name, class name, source file name and line number, etc. By analyzing this information, the exception code that caused the crash can be determined.
[0054] After determining the exception code, extract the function pointer and method name of the calling method involved. The function pointer can usually be obtained through symbol resolution or memory address conversion. The calling methods in the application are usually organized according to functional modules or business logic. By analyzing the naming and documentation of the calling method, its function can be determined and the corresponding candidate method can be found. When the application is running, the function pointer is used to call the corresponding method. By modifying the pointing of the function pointer, the behavior of the method call can be changed.
[0055] Specifically, a crash capture mechanism is integrated into the application by registering a global exception handling function or using a specific crash capture library. When the application crashes, the capture mechanism records the exception stack information at the time of the crash, including the exception type, exception description, and stack frame, analyzes the captured exception stack information, finds the exception type and exception description that caused the crash, and locates the specific method call that caused the crash, i.e., the exception code, in the exception stack based on the exception type and exception description.
[0056] After determining the exception code, extract the function pointer and method name of the calling method involved. The function pointer can usually be obtained through symbol resolution or memory address conversion. According to the extracted first method name, determine the functional module or business logic to which it belongs, and search the API list of the application for method names that are the same, similar, or unrelated to the function as candidate target calling methods. Select the most appropriate target calling method according to specific needs, find the storage location of the first function pointer in the memory of the application, replace the first function pointer with the second function pointer of the target calling method, and verify whether the replaced application can run normally.
[0057] In this embodiment, first, by capturing the crash information of the application and extracting the exception type, exception description and stack frame information in the exception stack, the exception code that caused the crash can be determined, and then, according to the calling method name in the exception code, a method that is the same, similar or unrelated to the target function is found and selected as the target calling method. Finally, by replacing the function pointer of the original calling method with the function pointer of the target calling method, the application can be automatically repaired so that it can run normally and effectively, thus improving the stability and user experience of the application and reducing the losses caused by the crash.
[0058] Optionally, in some embodiments, replacing the first function pointer with the second function pointer of the target calling method to replace the original calling method so that the application can run normally further includes:
[0059] Replacing the first function pointer of the original calling method with the second function pointer of the target calling method;
[0060] If it is detected that the original calling method is not executed, executing the target calling method to interrupt the transmission of the crash information caused by the original calling method, so as to enable the application to run normally;
[0061] If it is detected that the original calling method is being executed, the original calling method is interrupted and the target calling method is executed to interrupt the transmission of the crash information so that the application can run normally.
[0062] Exemplarily, a function pointer is a pointer variable used to call a function in an application. By modifying the pointing of the function pointer, the target of the method call can be changed, thereby achieving replacement of the calling method; by monitoring the execution of the original calling method, alternative measures can be taken in time when it is not executed. The execution of the target calling method can interrupt the transmission chain of crash information that may be caused by the original calling method, thereby avoiding application crashes. The interruption mechanism can be implemented by modifying the execution flow of the application or utilizing the signal mechanism of the operating system; by interrupting the execution of the original calling method and replacing it with the target calling method, the transmission chain of crash information can be interrupted, thereby avoiding application crashes.
[0063] Specifically, the location where the first function pointer of the original calling method is stored is located in the memory of the application, and the first function pointer at this location is replaced with the second function pointer of the target calling method, so as to ensure the safety of the replacement operation and avoid affecting the normal operation of other parts of the application. A monitoring point is set in the application to monitor the execution of the original calling method; when it is detected that the original calling method is not executed (for example, it is skipped because the condition judgment is not met), the target calling method is executed immediately to ensure that the execution of the target calling method can replace the function of the original calling method and avoid the transmission of crash information; an interruption mechanism is set in the application to interrupt the execution of the original calling method when the execution of the original calling method is detected, and after the original calling method is interrupted, the target calling method is executed immediately to ensure the timeliness and accuracy of the interruption and replacement operations to avoid unpredictable effects on the application.
[0064] In this embodiment, by replacing the first function pointer of the original calling method with the second function pointer of the target calling method, and taking corresponding measures (executing the target calling method or interrupting the original calling method and executing the target calling method) when it is detected that the original calling method is not executed or is being executed, the transmission chain of the crash information can be effectively interrupted or interrupted, thereby avoiding the crash of the application caused by the original calling method. This technology can significantly improve the stability and reliability of the application and reduce the loss of users and losses caused by crashes.
[0065] Step S240: Collect the crash information of the application to generate a crash log, and upload the crash log to a server.
[0066] Among them, crash logs are an important basis for analyzing and debugging application crash problems. By combining the captured crash information into a complete crash log, subsequent analysis and processing can be more convenient. Uploading crash logs to the server can ensure that the development team can obtain crash information in a timely manner and take corresponding repair measures.
[0067] Specifically, in the protection engine, a method for collecting crash information and generating crash logs is implemented. This method combines the captured crash information (such as exception stack, error code, user behavior data, etc.) into a complete crash log, and uses the network request library (such as AFNetworking, NSURLSession, etc.) to upload the crash log to the specified server address.
[0068] Optionally, in some embodiments, collecting the crash information of the application to generate a crash log, and uploading the crash log to a server includes:
[0069] Receive crash information of the application in an array class;
[0070] Determine the callback variable in the crash information, and if the callback variable contains exception stack information, disassemble the exception stack information, and encapsulate the exception type, exception description and stack frame obtained by disassembly into stack log information;
[0071] The stack log information is extracted to generate a crash log, and the crash log is encrypted and uploaded to a server.
[0072] Exemplarily, the crash capture mechanism obtains crash information by intercepting unhandled exceptions or errors.
[0073] The crash handling module identifies crashes related to specific classes (such as NSArray) by parsing crash information. Crash information usually contains multiple stack frames, each of which records the function call information when the exception occurs. By analyzing this information, the callback variable and exception stack information that caused the crash can be determined. By encapsulating the disassembled information, the crash information can be easily stored, transmitted, and analyzed.
[0074] By extracting key information and generating crash logs, you can easily understand the crash of the application. Encryption processing can protect sensitive information in the crash log from being leaked. Uploading the crash log to the server can achieve remote monitoring and analysis.
[0075] Specifically, when an application crashes, it generates crash information, which usually includes the crash stack trace, exception type, and exception description. The crash capture mechanism (such as PLCrashReporter, Breakpad, etc.) captures the crash information and passes it to a dedicated crash handling module, which receives the crash information and identifies the crash information related to the NSArray array class.
[0076] In the crash information, identify the part related to the callback variable, check whether the callback variable contains exception stack information, and if so, disassemble the exception stack information to extract the exception type, exception description, and stack frame; organize and encapsulate the disassembled exception type, exception description, and stack frame information to form stack log information, which contains the complete exception information that caused the crash. Extract key information from the encapsulated stack log information to generate a crash log. Encrypt the crash log to ensure security during transmission, and upload the encrypted crash log to the server for subsequent analysis and processing.
[0077] In this embodiment, by receiving the crash information of the application in the NSArray array class, determining the callback variable in the crash information, capturing the exception stack information in the callback variable and disassembling it, encapsulating the exception type, exception description and stack frame obtained by disassembly into stack log information, extracting the stack log information to generate a crash log, and encrypting and uploading the crash log to the server, the crash situation of the application on a specific class (such as NSArray) can be effectively collected and analyzed. This technology can help developers quickly locate and solve crash problems, improve the stability of the application and user experience; at the same time, by encrypting and uploading crash logs, it can also protect the user's privacy and sensitive information from being leaked.
[0078] Optionally, in some embodiments, after uploading the crash log to the server through encryption, the following steps are performed:
[0079] Receive and parse the crash log, identify the parsed crash log, and generate a graphic and textual representation of the exception type, the exception description, and prompt information for maintenance personnel;
[0080] Generate a two-dimensional code image, and save the prompt information into a link corresponding to the two-dimensional code image;
[0081] The prompt information and the QR code image are displayed in a pop-up window, and different colors are displayed for early warning according to the urgency of the crash information.
[0082] For example, crash logs usually contain specific formats and tags. The parser extracts key information by identifying these formats and tags. The parsing process needs to ensure the accuracy and completeness of the information so that subsequent steps can be executed correctly.
[0083] The recognition module generates corresponding graphic content by matching the preset abnormal type and description template. The generation of prompt information needs to be based on the experience and knowledge of the maintenance personnel to ensure its accuracy and practicality. The QR code generator converts the information into graphic elements in the QR code image through a specific encoding algorithm. The scanning device reads the graphic elements in the QR code image through a decoding algorithm and restores the original information.
[0084] The pop-up display module implements the display and color adjustment of the pop-up window by calling the UI framework or library of the operating system. The choice of color needs to be based on the user's perception and psychological reaction to color to ensure the effectiveness of the warning effect.
[0085] Specifically, crash logs are usually generated by the crash capture mechanism of the application and stored in a specified location. The receiving module reads the crash log from the specified location and uses a parser to parse it line by line. The parser extracts key information such as exception type and exception description based on the format and content of the log. The parsed crash log contains key information such as exception type and exception description. The recognition module generates corresponding graphic content based on this information.
[0086] The graphic content includes an icon or picture of the exception type, text describing the exception, and prompt information for maintenance personnel (such as solutions, recommended operating procedures, etc.). Use a QR code generator to generate a blank QR code image, encode the prompt information into a URL (Uniform Resource Locator) link, and save it in the QR code image.
[0087] Ensure that the QR code image can be correctly read and parsed by the scanning device. Select the corresponding color (such as red, yellow, green, etc.) according to the urgency of the crash information (such as severe, general, minor, etc.). Use the pop-up display module to display the prompt information and the QR code image to the user in the form of a pop-up window. The color of the pop-up window is dynamically adjusted according to the urgency of the crash information to achieve an early warning effect.
[0088] In this embodiment, by receiving and parsing the crash log, generating the exception type, exception description and maintenance personnel prompt information in the form of pictures and texts, and saving this information in a QR code image, and then displaying it to the user in a pop-up window, and displaying different colors for early warning according to the urgency of the crash information, it can effectively improve the application's fault handling efficiency and user experience, and can also help developers and maintenance personnel quickly locate and solve crash problems, while providing users with clear and intuitive fault information and solutions. In addition, through the sharing and dissemination of QR code images, it is also possible to achieve rapid sharing and collaborative processing of fault information.
[0089] Optionally, in some embodiments, after uploading the crash log to the server, the method further includes:
[0090] Receiving and analyzing the crash log to determine the source of the failure of the application;
[0091] In response to the fault source, a repair program is generated and sent to the terminal;
[0092] If it is monitored that the target application program that crashed in the terminal is in a dormant or closed state, the repair program is executed to repair the target application program.
[0093] For example, crash logs usually contain specific formats and tags, and the parser extracts key information by identifying these formats and tags. The fault location algorithm or tool analyzes the stack trace, exception type and other information in the crash log to infer the source of the fault that caused the crash. The accuracy of fault location depends on the intelligence of the algorithm or tool and the integrity of the log information. The generation of the repair program needs to be based on the specific situation of the fault source and the repair strategy (such as repairing known vulnerabilities, updating code logic, etc.).
[0094] The issuance of the patch program needs to ensure the security and reliability of the transmission to prevent malicious tampering or loss. The monitoring module checks the status of the application by calling the operating system API or using other monitoring tools. The execution of the patch program needs to ensure compatibility and security with the application to avoid introducing new faults or vulnerabilities.
[0095] Specifically, the crash log is usually generated by the crash capture mechanism of the application and stored in a specified location or sent to a log server through the network. The receiving module reads the crash log from the specified location or receives it through the network, and uses a parser to parse it line by line. The parser extracts the key information that causes the crash, such as error code, stack trace, exception type, etc., based on the format and content of the log. According to the key information in the parsed crash log, the fault location algorithm or tool is used to determine the source of the fault. The source of the fault may be a specific code segment, a function call, a resource access, etc. After determining the source of the fault, it is recorded and prepared to generate a repair program. According to the determined source of the fault, the corresponding repair program is generated. The repair program may be a patch, an update package, a configuration file, etc. After the repair program is generated, it is sent to the terminal (such as the user's mobile phone, computer, etc.) through the network or other means.
[0096] The terminal receives and stores the repair program and prepares for execution. The monitoring module continuously monitors the status of the target application in the terminal. When it is detected that the target application is in an idle or closed state, the repair program execution module is triggered. The repair program execution module loads and executes the previously issued repair program to repair the target application. After the repair is completed, the repair result is recorded and the user or administrator may be notified.
[0097] In this embodiment, by receiving and parsing the crash log, determining the source of the application's failure, generating and issuing a repair program, and executing the repair program to repair the target application when it is detected that the target application is in an idle or closed state, the application's fault handling efficiency and user experience can be effectively improved. This technology can help developers and maintenance personnel quickly locate and solve crash problems, while reducing the impact on users caused by application crashes. In addition, through automated and integrated processing methods, the cost and time of manual intervention can be reduced, and the overall operation and maintenance efficiency can be improved.
[0098] See also Figure 3 , which is a complete flow chart of a program crash handling method provided by this application, including:
[0099] 1. Crash protection engine initialization
[0100] In order to load the Crash protection engine as soon as the APP is started, you need to rewrite the +(void)load{} method of NSObject. In the load implementation method, initialize the Crash protection engine and enable the engine log output:
[0101] [HLLUSafeCrashManager.sharedInstanceInitWithAppId:@"com.xxx.user"enableLog:YES];
[0102] 2. Hook NSArray API method (call method)
[0103] Through the method exchange API provided by Apple: class_replaceMethod(Class_Nullablecls,SEL_Nonnull name,IMP_Nonnull imp,const char*_Nullable types), this solution replaces the @selector(objectAtIndex:@selector(objectAtIndexedSubscript:) methods in the NSArray class. The replaced method names are @selector(hllu_objectAtIndex:) and @selector(hllu_objectAtIndexedSubscript:).
[0104] 3. Add @try-catch module to protect the necessary NSArray hook methods
[0105] In the hooked @selector(hllu_objectAtIndex:) method, add try-catch implementation logic:
[0106] @try{object=[self hllu_objectAtIndex:index];}
[0107] @catch(NSException*exception){}
[0108] @finally{return object;}
[0109] In this way, the operation of adding protection exceptions to this hook method is completed.
[0110] 4. Output the abnormal information
[0111] The callback variable in @catch(NSException*exception){} can be used to know the exception stack information of the current error. We disassemble its object and encapsulate it into detailed stack log information. The operation code is as follows:
[0112] NSString*crashType=[NSStringstringWithFormat:@">>>[CrashType]:%@",exception.name];
[0113] NSString*errorReason=[NSStringstringWithFormat:@">>>[CrashReason]:%@",exception.reason];;
[0114] NSString*errorPlace=[NSStringstringWithFormat:@">>>[CrashName]:%@",c rashName];
[0115] NSString*crashProtector=[NSStringstringWithFormat:@">>>[AttachedTODO]:%@",todo];
[0116] NSString*logErrorMessage=[NSStringstringWithFormat:@"\n\n%@\n%@\n%@\n%@\n",crashType,errorReason,errorPlace,crashProtector];
[0117] After data extraction is completed, the data is stored locally to provide a data source for subsequent processes.
[0118] 5. Data encryption and reporting
[0119] After collecting the current abnormal information, the data is encrypted (it can also be not encrypted to ensure data security) and uploaded to the server.
[0120] [HLLBugly reportException:exception]
[0121] In this embodiment, a crash protection engine management class of the NSArray class is implemented. The engine management class uses the Method Swizzling technology to hook the calling methods in the NSArray class in the iOS system framework that are prone to crashes, and non-invasively adds @try-catch exception capture modules to these calling methods.
[0122] When a Crash exception occurs in the hooked system call method, the exception will be caught to handle the problem that caused the exception and interrupt the upward transmission of the Crash exception. The protection engine management class stores the exception information locally and reports the exception information to the background service, making it easier for developers to view and locate the current exception problem.
[0123] In this application, on the one hand, protection is provided for APP anomalies to ensure the normal operation of APP; on the other hand, the crash of APP is reduced to provide business stability; on the other hand, Crash protection anomaly information is reported to facilitate development and troubleshooting.
[0124] See also Figure 4 , is a structural block diagram of a program crash processing device 400 provided by the present application, including:
[0125] Engine module 401, used to call the protection engine;
[0126] A crash monitoring module 402 is used to initialize the protection engine when the application is started, so as to monitor and capture crash information in the application, wherein the crash information includes abnormal stack information of the crash of the application;
[0127] The crash protection module 403 is used to interrupt the processing of the crash information according to the type of the exception stack information if the crash information of any of the applications is captured, so as to enable the application to run normally; the crash response module 404 is used to collect the crash information of the application to generate a crash log, and upload the crash log to the server.
[0128] It should also be noted that there is a one-to-one correspondence between the program crash handling method and the program crash handling device. Here, the technical details and technical effects involved in the program crash handling device are the same as the above-mentioned identification method, which will not be repeated here. Please refer to the above-mentioned program crash handling method.
[0129] Through the above method, by calling the protection engine specifically used for handling crashes, after the protection engine is initialized when the application starts, continuous monitoring can effectively capture the crash information in the application. When the crash information of the application is captured, interrupt processing is performed according to the type of exception stack information, so as to quickly restore the normal operation of the application, enhance the stability and reliability of the application, and reduce the flash back problem caused by improper array operation; by collecting the crash information of the application and generating a detailed crash log, it is convenient for developers to perform remote analysis and repair, and also improves the efficiency of debugging and repair; not only avoids the flash back of the application, but also improves the business recovery capability.
[0130] Reference below Figure 5 , see Figure 5 , Figure 5 It is a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. It should be noted that: Figure 5 The electronic device 500 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0131] like Figure 5 As shown, the electronic device 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage part 508 to the random access memory (RAM) 503, such as executing the method in the above embodiment. In the RAM 503, various programs and data required for system operation are also stored. The CPU 501, ROM 502 and RAM 503 are connected to each other through a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0132] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed so that a computer program read therefrom is installed into the storage section 508 as needed.
[0133] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 509, and / or installed from a removable medium 511. When the computer program is executed by a central processing unit (CPU) 501, various functions defined in the device of the present application are executed.
[0134] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above.
[0135] A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0136] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the apparatus, method and computer program product according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the above-mentioned module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based device that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0137] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not constitute limitations on the units themselves in some cases.
[0138] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor of a computer, the computer executes the program crash processing method as described above. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0139] The above embodiments are merely illustrative of the principles and effects of the present application and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.
Claims
1. A method for processing a program crash, characterized in that: include: Call the protection engine; Initialize the protection engine when the application is started to monitor and capture crash information in the application, wherein the crash information includes exception stack information when the application crashes; If crash information of any of the applications is captured, interrupting the processing of the crash information according to the type of the exception stack information to enable the application to run normally; The crash information of the application is collected to generate a crash log, and the crash log is uploaded to a server.
2. The program crash processing method according to claim 1, characterized in that: Before listening to capture the crash information in the application, also include: Calling a basic object class, writing the protection engine initialization code in a loading method of the basic object class, and executing the loading method to initialize the protection engine; Traversing the method names of the array class corresponding to the application program call, and generating a calling method for replacing the method name through a method exchange application programming interface; An exception capture module for capturing an exception method is called, and the exception capture module is added to the calling method to complete the initialization of the protection engine.
3. The program crash processing method according to claim 1, characterized in that: If the crash information of any of the applications is captured, interrupting and processing the crash information according to the type of the exception stack information to enable the application to run normally includes: Capturing crash information of the application program, and obtaining the exception stack information including the exception type, exception description and stack frame; Determine, according to the exception type, the exception description and the stack frame, the exception code corresponding to the method call exception of the application program; Extracting the first function pointer and the first method name of the original calling method in the exception code; According to the function to which the first method name belongs, search for a method name that is the same as, similar to, or unrelated to the function, and use it as the target calling method; The first function pointer is replaced with the second function pointer of the target calling method to replace the original calling method, so that the application can run normally.
4. The program crash processing method according to claim 3, characterized in that: Replacing the first function pointer with the second function pointer of the target calling method to replace the original calling method so that the application can run normally, further comprising: Replacing the first function pointer of the original calling method with the second function pointer of the target calling method; If it is detected that the original calling method is not executed, executing the target calling method to interrupt the transmission of the crash information caused by the original calling method, so as to enable the application to run normally; If it is detected that the original calling method is being executed, the original calling method is interrupted and the target calling method is executed to interrupt the transmission of the crash information so that the application can run normally.
5. The program crash processing method according to claim 1, characterized in that: Collecting the crash information of the application to generate a crash log, and uploading the crash log to a server, including: Receive crash information of the application in an array class; Determine the callback variable in the crash information, and if the callback variable contains exception stack information, disassemble the exception stack information, and encapsulate the exception type, exception description and stack frame obtained by disassembly into stack log information; The stack log information is extracted to generate a crash log, and the crash log is encrypted and uploaded to a server.
6. The program crash processing method according to claim 5, characterized in that: After uploading the crash log to the server through encryption, it includes: Receive and parse the crash log, identify the parsed crash log, and generate a graphic and textual representation of the exception type, the exception description, and prompt information for maintenance personnel; Generate a two-dimensional code image, and save the prompt information into a link corresponding to the two-dimensional code image; The prompt information and the QR code image are displayed in a pop-up window, and different colors are displayed for early warning according to the urgency of the crash information.
7. The method for processing a program crash according to any one of claims 1 to 5, characterized in that: After uploading the crash log to the server, it also includes: Receiving and analyzing the crash log to determine the source of the failure of the application; In response to the fault source, a repair program is generated and sent to the terminal; If it is monitored that the target application program that crashed in the terminal is in a dormant or closed state, the repair program is executed to repair the target application program.
8. A program crash processing device, characterized in that: include: The engine module is used to call the protection engine; A crash monitoring module, used to initialize the protection engine when the application is started, so as to monitor and capture crash information in the application, wherein the crash information includes exception stack information of the crash of the application; A crash protection module, for, if crash information of any of the application programs is captured, interrupting the processing of the crash information according to the type of the exception stack information, so as to enable the application program to run normally; The crash response module is used to collect the crash information of the application to generate a crash log, and upload the crash log to the server.
9. An electronic device, characterized in that: include: one or more processing devices; A memory for storing one or more programs; When the one or more programs are executed by the one or more processing devices, the one or more processing devices implement the program crash processing method described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is used to enable a computer to execute the program crash processing method according to any one of claims 1 to 7.
Citation Information
Cited By
Data processing method, system and device for iOS application crash log and medium
CN121501606A
Data processing method, system and device of iOS application crash log and medium
CN121501606B