• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Crash Event Overview
2<!--Kit: Performance Analysis Kit-->
3<!--Subsystem: HiviewDFX-->
4<!--Owner: @chenshi51-->
5<!--Designer: @Maplestory-->
6<!--Tester: @yufeifei-->
7<!--Adviser: @foryourself-->
8
9## Overview
10
11A crash is an unexpected exit of an application process. Specifically, crash events occur in the following scenarios:
12
131. **NativeCrash** events are generated when the native code does not process [crash signals](cppcrash-guidelines.md#crash-signals).
14
152. **JsError** events are generated when ArkTS/JS code does not process exceptions.
16
17This topic describes the crash event detection principles, field meanings, and specifications. For details about how to use the ArkTs and C/C++ APIs provided by HiAppEvent to subscribe to system crash events, see the following documents: Currently, ArkTS and C/C++ APIs are provided. You can select the APIs as required.
18
19- [Subscribing to Crash Events (ArkTS)](hiappevent-watcher-crash-events-arkts.md)
20
21- [Subscribing to Crash Events (C/C++)](hiappevent-watcher-crash-events-ndk.md)
22
23## Detection Principles
24
25### NativeCrash
26
27Based on the POSIX signal mechanism, the process crash detection capability of the system is implemented as follows: When a process crashes, it receives a crash signal, enters the system signal registration handling process, collects crash information, generates an event, and reports the event to the crash event subscriber of the application process.
28
29The system detects a process crash as follows:
30
311. After a process crashes, it receives a crash signal from the kernel, which is processed by the signal processing module registered by the process during startup.
32
332. After receiving the crash signal, the process saves the current process context and forks a child process to execute the ProcessDump command to capture crash information.
34
353. After collecting crash information, the ProcessDump process reports it to the HiView process. The HiView process stores the event information in the [application sandbox](../file-management/app-sandbox-directory.md).
36
374. The crash event watcher registered by HiAppEvent listens for the file changes in the application sandbox directory and delivers the event callback to the application process.
38
39### JsError
40
41In ArkTS, the JsError crash detection detects global exceptions, collects the error object types (such as **Error**, **TypeError**, and **ReferenceError**), and reports them to the HiView process. The HiView process stores the event information in the [application sandbox](../file-management/app-sandbox-directory.md). The crash event watcher registered by HiAppEvent listens for the file changes in the application sandbox directory and delivers the event callback to the application process, helping you quickly locate and rectify faults.
42
43## Customizing Crash Log Specifications
44
45Since API version 20, crash log specifications can be customized.
46
47The system provides the common **NativeCrash** log generation functionality. However, some applications have specific requirements on the **NativeCrash** log content. Therefore, you need to set crash log parameters.
48
49### **Available APIs**
50
51| Name| Description|
52| -------- | -------- |
53| setEventConfig(name: string, config: Record&lt;string, ParamType>): Promise&lt;void> | Sets crash log parameters. The **name** parameter must be set to the crash event name constant **hiappevent.event.APP_CRASH**. This API supports only **NativeCrash**.|
54
55### **Parameters**
56
57You can set the crash log printing specifications in **Record <string, ParamType>** by using the API provided by HiAppEvent. The specific parameter descriptions are as follows.
58
59| Name| Type| Mandatory| Description|
60| -------- | -------- | -------- | -------- |
61| extend_pc_lr_printing | boolean | No| The value **true** means to print the memory values of 248 bytes before and 256 bytes after the PC and LR on 64-bit system, or 124 bytes before and 128 bytes after on 32-bit systems.<br>The value **false** means to print the memory values of 16 bytes before and 232 bytes after the PC and LR on 64-bit system, or 8 bytes before and 116 bytes after on 32-bit systems.<br>Default value: **false**.|
62| log_file_cutoff_sz_bytes | number | No| The value ranges from 0 to 5242880, in bytes.<br>The crash log is truncated to the specified size when this parameter is set.<br>Otherwise, the default value **0** is used, which means no truncation.|
63| simplify_vma_printing | boolean | No| The value **true** means to print only the Virtual Memory Area (VMA) mapping information of the addresses in the crash log, that is, **Maps** in the crash log, to reduce the log size.<br>The value **false** means to print all VMA mapping information.<br>Default value: **false**.|
64
65The following is an example of parameter settings:
66
67```text
68let configParams: Record<string, hiAppEvent.ParamType> = {
69    "extend_pc_lr_printing": true, // Enable the functionality of printing the memory values near the PC and LR.
70    "log_file_cutoff_sz_bytes": 102400, // Truncate the crash log to 100 KB.
71    "simplify_vma_printing": true // Enable simplified printing of maps.
72};
73```
74
75For example, on the 32-bit system, subscribe to crash events and set log configuration parameters by referring to [Subscribing to Crash Events (ArkTS)](hiappevent-watcher-crash-events-arkts.md#how-to-develop) and obtain the **NativeCrash** log content through the [external_log](#params) field. The following enabled configuration parameters are printed in the log:
76
77```text
78...
79Build info:OpenHarmony 6.0.0.33
80Enabled app log configs:    <- List of enabled configuration parameters. Only the configuration parameters that are not set to the default values are printed.
81Extend pc lr printing:true  <- Set extend_pc_lr_printing to true.
82Log cut off size:102400B    <- Truncate the crash log to 100 KB.
83Simplify maps printing:true <- Set simplify vma_printing to true.
84Timestamp:2025-05-17 19:17:07.000
85...
86```
87
88For details about the crash log, see [Application Crash Log Configured by HiAppEvent](cppcrash-guidelines.md#application-crash-log-configured-by-hiappevent).
89
90## Fields
91
92### params
93
94The **params** parameter in the event information is described as follows.
95
96| Name| Type| Description|
97| -------- | -------- | -------- |
98| time | number | Event triggering time, in ms.|
99| crash_type | string | Crash type, which can be **NativeCrash** (native exception) or **JsError** (JS exception). For details about the detection method, see [C++ Crash (Process Crash) Detection](cppcrash-guidelines.md) and [JS Crash (Process Crash) Detection](jscrash-guidelines.md).|
100| foreground | boolean | Whether the application is running in the foreground. The value **true** indicates that the application is in the foreground, and the value **false** indicates the opposite.|
101| bundle_version | string | Application version.|
102| bundle_name | string | Application name.|
103| pid | number | Process ID of an application.|
104| uid | number | User ID of an application.|
105| uuid | string | Error ID, which is generated based on fault information and uniquely identifies crash faults of the same type.|
106| exception | object | Exception information in brief. For details, see [exception](#exception). For details about all fault information, see the **external_log** file.|
107| hilog | string[] | Log information, which displays a maximum of 100 lines of HiLog logs. For more logs, see the fault log file.|
108| threads | object[] | Full thread call stack. For details, see [thread](#thread). This field applies only to **NativeCrash** events.|
109| external_log<sup></sup> | string[] | [Application sandbox path](../file-management/app-sandbox-directory.md) of the fault log file. You can read the fault log file through the path. To avoid failed writing of new log files due to insufficient directory space, delete the log files after they are processed. For details about the threshold, see the **log_over_limit** field.|
110| log_over_limit | boolean | Whether the total size of the generated and existing fault log files exceeds the upper limit 5 MB. The value **true** indicates that the upper limit is exceeded and logs fail to be written. The value **false** indicates that the upper limit is not exceeded.|
111
112### exception
113
114**exception** of **JsError**
115
116| Name| Type| Description|
117| -------- | -------- | -------- |
118| name | string | Exception type.|
119| message | string | Exception cause.|
120| stack | string | Exception call stack.|
121
122**exception** of **NativeCrash**
123
124| Name| Type| Description|
125| -------- | -------- | -------- |
126| message | string | Exception cause.|
127| signal | object | Signal information. For details, see [signal](#signal).|
128| thread_name | string | Thread name.|
129| tid | number | Thread ID.|
130| frames | object[] | Thread call stack. For details, see [frame](#frame).|
131
132### signal
133
134For details, see [C++ Crash (Process Crash) Detection Implementation Principles](cppcrash-guidelines.md#implementation-principles).
135
136| Name| Type| Description|
137| -------- | -------- | -------- |
138| signo | number | Signal value.|
139| code | number | Level-2 signal category.|
140| address | string | Address where an access error occurs.|
141
142### thread
143
144| Name| Type| Description|
145| -------- | -------- | -------- |
146| thread_name | string | Thread name.|
147| tid | number | Thread ID.|
148| frames | object[] | Thread call stack. For details, see [frame](#frame).|
149
150### frame
151
152Native **frame**
153
154| Name| Type| Description|
155| -------- | -------- | -------- |
156| file | string | File name.|
157| symbol | string | Function name. The symbol may be empty due to the following reasons:<br>1. The function name is not saved in the binary file.<br>2. The function name is deleted because it contains more than 256 bytes.|
158| buildId | string | Unique file ID. The file may not contain **buildId**. For details, see [C++ Crash (Process Crash) Log Specifications](cppcrash-guidelines.md#common-faults).|
159| pc | string | Hexadecimal byte offset of the executed instruction within the file.|
160| offset | number | Byte offset of the executed instruction within the function.|
161
162Js **frame**
163
164| Name| Type| Description|
165| -------- | -------- | -------- |
166| file | string | File name.|
167| packageName | string | Package name of the module.|
168| symbol | string | Function name.|
169| line | number | Code line number.|
170| column | number | Code column number.|
171
172## Customizing Crash Event Parameters
173
174Currently, the crash event reports common system crash information, which may not meet your specific requirements. Therefore, the **setEventParam** method is provided to customize event reporting information.
175
176### APIs
177
178| Name| Description|
179| -------- | -------- |
180| setEventParam(params: Record&lt;string, ParamType>, domain: string, name?: string): Promise&lt;void> | Sets custom event parameters.|
181