Crash Reporting¶
Many software development teams strive to build defect-free software systems, spending vast amounts of resources in software quality assurance and code analysis tools to prevent software failure from occuring. In reality, however, faults will still occur in the software and ultimately, causing the application to crash.
To determine the cause of failure, a post-mortem analysis must be performed on the state of the application at the time of the crash. Such data includes stack traces, memory dumps and register contents at the point of failure, which can be used to identify the exact line in the source file where the crash occurred.
PSYGIG Mobility IoT SDK extends your application with crash reporting capabilties, collecting post-mortem data at the point of failure. The Crash Reporting API includes many features suitable for integration into embedded systems:
Works on existing applications; no need to recompile source code
Seamless integration with third party crash reporting platforms
Generate process snapshot dumps for the crash report, including:
Process environment - including command line and environment variables
Thread states - including register contents and stack memory
Loaded modules - such as shared libraries and memory-mapped files
Memory dump of sections in process memory space
Capture stack traces, including source file and line number
Small execution footprint to preserve program state
Append user-defined, application-specific metadata to the crash report
Export crash report to a variety of file formats (eg. JSON, CSV, HTML)
Using psymon
¶
Without modifying your existing source code, you can instantly enable crash reporting
to your application by using the psymon
script to run your program. For example:
psymon --crash "/path/to/your/app --arg1 --arg2 --arg3"
See psymon man page for a complete list of options.
Using C/C++ SDK API¶
The Crash Reporting API can be accessed by including a single header file
and linking the libpsyiage
shared library. See Advanced Setup - Building your application with libpsyiage for details.
Generate crash report on fatal signals (eg. SIGSEGV, SIGKILL)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <psyiage/psyiagesdk.h>
int main(int argc, char **argv)
{
psyiage_handle pah; // handle to psyiage instance
/* ... Initialize code omitted for simplicity ... */
// Install fatal signal handler
rc = psyiage_crash_enable_report_on_fatal_signal(pah, 1);
/* ... Cleanup code omitted for simplicity ... */
}
|
Generate crash report during core dump¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <psyiage/psyiagesdk.h>
int main(int argc, char **argv)
{
psyiage_handle pah; // handle to psyiage instance
/* ... Initialize code omitted for simplicity ... */
// Install binary that runs on core dump generation
rc = psyiage_crash_install_core_dump_handler(pah);
/* ... Cleanup code omitted for simplicity ... */
}
|
Generate crash report on demand¶
Note
Generate crash report on demand is a work-in-progress. Please contact us if you are interested in beta-testing this feature.
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <psyiage/psyiagesdk.h>
int main(int argc, char **argv)
{
psyiage_handle pah; // handle to psyiage instance
/* ... Initialize code omitted for simplicity ... */
// Install binary that runs on core dump generation
rc = psyiage_crash_capture_process_snapshot(pah);
/* ... Cleanup code omitted for simplicity ... */
}
|
Sample JSON crash report¶
{
"TaskInfo": {
"ProcID": 35392,
"UserID": 1000,
"GroupID": 1000,
"Cmdline": "./crash_report",
"Name": "crash_report",
"Signal": 11
},
"CrashInfo": {
"ThreadId": 35392,
"Exception": "Segmentation fault",
"StackTrace": {
"Frames": [
{
"FrameNum": 0,
"InstrAddr": "0x00000000004008d6",
"FilePath": "./crash_report",
"Function": "crash",
"Offset": "0x10",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x00007ffcafcc0b90",
"rsp": "0x00007ffcafcc0b90",
"rip": "0x00000000004008d6",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
{
"FrameNum": 1,
"InstrAddr": "0x00000000004008ee",
"FilePath": "./crash_report",
"Function": "foo4",
"Offset": "0xe",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x00007ffcafcc0ba0",
"rsp": "0x00007ffcafcc0ba0",
"rip": "0x00000000004008ee",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
{
"FrameNum": 2,
"InstrAddr": "0x0000000000400903",
"FilePath": "./crash_report",
"Function": "foo3",
"Offset": "0xe",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x00007ffcafcc0bb0",
"rsp": "0x00007ffcafcc0bb0",
"rip": "0x0000000000400903",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
{
"FrameNum": 3,
"InstrAddr": "0x0000000000400918",
"FilePath": "./crash_report",
"Function": "foo2",
"Offset": "0xe",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x00007ffcafcc0bc0",
"rsp": "0x00007ffcafcc0bc0",
"rip": "0x0000000000400918",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
{
"FrameNum": 4,
"InstrAddr": "0x000000000040092d",
"FilePath": "./crash_report",
"Function": "induce_segfault",
"Offset": "0xe",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x00007ffcafcc0bd0",
"rsp": "0x00007ffcafcc0bd0",
"rip": "0x000000000040092d",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
{
"FrameNum": 5,
"InstrAddr": "0x0000000000400a01",
"FilePath": "./crash_report",
"Function": "main",
"Offset": "0xcd",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x00007ffcafcc0c10",
"rsp": "0x00007ffcafcc0be0",
"rip": "0x0000000000400a01",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
{
"FrameNum": 6,
"InstrAddr": "0x00007f698cda7830",
"FilePath": "/lib/x86_64-linux-gnu/libc.so.6",
"Function": "__libc_start_main",
"Offset": "0xf0",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x0000000000400a60",
"rsp": "0x00007ffcafcc0c20",
"rip": "0x00007f698cda7830",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
{
"FrameNum": 7,
"InstrAddr": "0x00000000004007f9",
"FilePath": "./crash_report",
"Function": "_start",
"Offset": "0x29",
"Registers": {
"rax": "0x0000000000000000",
"rbx": "0x0000000000000000",
"rcx": "0x00007f698ce7e2c0",
"rdx": "0x00007f698d14d780",
"rsi": "0x0000000002229010",
"rdi": "0x0000000000000001",
"rbp": "0x0000000000000000",
"rsp": "0x00007ffcafcc0ce0",
"rip": "0x00000000004007f9",
"r8": "0x2e2e2e676e697473",
"r9": "0x6166206e6f697461",
"r10": "0x20726f6620746c75",
"r11": "0x0000000000000246",
"r12": "0x00000000004007d0",
"r13": "0x00007ffcafcc0cf0",
"r14": "0x0000000000000000",
"r15": "0x0000000000000000"
},
},
]
},
},
"MemoryMap": [
{
"StartAddr": "0x400000",
"EndAddr": "0x401000",
"Permissions": "r-xp",
"FileOffset": "0x0",
"Device": "00:32",
"Inode": 2087277,
"FilePath": "/home/psygig/psygig-sdk-c/build/crash_report"
},
{
"StartAddr": "0x600000",
"EndAddr": "0x601000",
"Permissions": "r--p",
"FileOffset": "0x0",
"Device": "00:32",
"Inode": 2087277,
"FilePath": "/home/psygig/psygig-sdk-c/build/crash_report"
},
{
"StartAddr": "0x601000",
"EndAddr": "0x602000",
"Permissions": "rw-p",
"FileOffset": "0x1000",
"Device": "00:32",
"Inode": 2087277,
"FilePath": "/home/psygig/psygig-sdk-c/build/crash_report"
},
{
"StartAddr": "0x2229000",
"EndAddr": "0x224a000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": "[heap]"
},
{
"StartAddr": "0x7f698c966000",
"EndAddr": "0x7f698c969000",
"Permissions": "r-xp",
"FileOffset": "0x0",
"Device": "08:01",
"Inode": 1972536,
"FilePath": "/lib/x86_64-linux-gnu/libdl-2.23.so"
},
{
"StartAddr": "0x7f698c969000",
"EndAddr": "0x7f698cb68000",
"Permissions": "---p",
"FileOffset": "0x3000",
"Device": "08:01",
"Inode": 1972536,
"FilePath": "/lib/x86_64-linux-gnu/libdl-2.23.so"
},
{
"StartAddr": "0x7f698cb68000",
"EndAddr": "0x7f698cb69000",
"Permissions": "r--p",
"FileOffset": "0x2000",
"Device": "08:01",
"Inode": 1972536,
"FilePath": "/lib/x86_64-linux-gnu/libdl-2.23.so"
},
{
"StartAddr": "0x7f698cb69000",
"EndAddr": "0x7f698cb6a000",
"Permissions": "rw-p",
"FileOffset": "0x3000",
"Device": "08:01",
"Inode": 1972536,
"FilePath": "/lib/x86_64-linux-gnu/libdl-2.23.so"
},
{
"StartAddr": "0x7f698cb6a000",
"EndAddr": "0x7f698cb82000",
"Permissions": "r-xp",
"FileOffset": "0x0",
"Device": "08:01",
"Inode": 1972533,
"FilePath": "/lib/x86_64-linux-gnu/libpthread-2.23.so"
},
{
"StartAddr": "0x7f698cb82000",
"EndAddr": "0x7f698cd81000",
"Permissions": "---p",
"FileOffset": "0x18000",
"Device": "08:01",
"Inode": 1972533,
"FilePath": "/lib/x86_64-linux-gnu/libpthread-2.23.so"
},
{
"StartAddr": "0x7f698cd81000",
"EndAddr": "0x7f698cd82000",
"Permissions": "r--p",
"FileOffset": "0x17000",
"Device": "08:01",
"Inode": 1972533,
"FilePath": "/lib/x86_64-linux-gnu/libpthread-2.23.so"
},
{
"StartAddr": "0x7f698cd82000",
"EndAddr": "0x7f698cd83000",
"Permissions": "rw-p",
"FileOffset": "0x18000",
"Device": "08:01",
"Inode": 1972533,
"FilePath": "/lib/x86_64-linux-gnu/libpthread-2.23.so"
},
{
"StartAddr": "0x7f698cd83000",
"EndAddr": "0x7f698cd87000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": ""
},
{
"StartAddr": "0x7f698cd87000",
"EndAddr": "0x7f698cf47000",
"Permissions": "r-xp",
"FileOffset": "0x0",
"Device": "08:01",
"Inode": 1972534,
"FilePath": "/lib/x86_64-linux-gnu/libc-2.23.so"
},
{
"StartAddr": "0x7f698cf47000",
"EndAddr": "0x7f698d147000",
"Permissions": "---p",
"FileOffset": "0x1c0000",
"Device": "08:01",
"Inode": 1972534,
"FilePath": "/lib/x86_64-linux-gnu/libc-2.23.so"
},
{
"StartAddr": "0x7f698d147000",
"EndAddr": "0x7f698d14b000",
"Permissions": "r--p",
"FileOffset": "0x1c0000",
"Device": "08:01",
"Inode": 1972534,
"FilePath": "/lib/x86_64-linux-gnu/libc-2.23.so"
},
{
"StartAddr": "0x7f698d14b000",
"EndAddr": "0x7f698d14d000",
"Permissions": "rw-p",
"FileOffset": "0x1c4000",
"Device": "08:01",
"Inode": 1972534,
"FilePath": "/lib/x86_64-linux-gnu/libc-2.23.so"
},
{
"StartAddr": "0x7f698d14d000",
"EndAddr": "0x7f698d151000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": ""
},
{
"StartAddr": "0x7f698d151000",
"EndAddr": "0x7f698d535000",
"Permissions": "r-xp",
"FileOffset": "0x0",
"Device": "00:32",
"Inode": 2057000,
"FilePath": "/home/psygig/psygig-sdk-c/build/libpsyiage.so.0.3.0"
},
{
"StartAddr": "0x7f698d535000",
"EndAddr": "0x7f698d734000",
"Permissions": "---p",
"FileOffset": "0x3e4000",
"Device": "00:32",
"Inode": 2057000,
"FilePath": "/home/psygig/psygig-sdk-c/build/libpsyiage.so.0.3.0"
},
{
"StartAddr": "0x7f698d734000",
"EndAddr": "0x7f698d767000",
"Permissions": "r--p",
"FileOffset": "0x3e3000",
"Device": "00:32",
"Inode": 2057000,
"FilePath": "/home/psygig/psygig-sdk-c/build/libpsyiage.so.0.3.0"
},
{
"StartAddr": "0x7f698d767000",
"EndAddr": "0x7f698d774000",
"Permissions": "rw-p",
"FileOffset": "0x416000",
"Device": "00:32",
"Inode": 2057000,
"FilePath": "/home/psygig/psygig-sdk-c/build/libpsyiage.so.0.3.0"
},
{
"StartAddr": "0x7f698d774000",
"EndAddr": "0x7f698d829000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": ""
},
{
"StartAddr": "0x7f698d829000",
"EndAddr": "0x7f698d84f000",
"Permissions": "r-xp",
"FileOffset": "0x0",
"Device": "08:01",
"Inode": 1972305,
"FilePath": "/lib/x86_64-linux-gnu/ld-2.23.so"
},
{
"StartAddr": "0x7f698da28000",
"EndAddr": "0x7f698da2c000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": ""
},
{
"StartAddr": "0x7f698da4b000",
"EndAddr": "0x7f698da4e000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": ""
},
{
"StartAddr": "0x7f698da4e000",
"EndAddr": "0x7f698da4f000",
"Permissions": "r--p",
"FileOffset": "0x25000",
"Device": "08:01",
"Inode": 1972305,
"FilePath": "/lib/x86_64-linux-gnu/ld-2.23.so"
},
{
"StartAddr": "0x7f698da4f000",
"EndAddr": "0x7f698da50000",
"Permissions": "rw-p",
"FileOffset": "0x26000",
"Device": "08:01",
"Inode": 1972305,
"FilePath": "/lib/x86_64-linux-gnu/ld-2.23.so"
},
{
"StartAddr": "0x7f698da50000",
"EndAddr": "0x7f698da51000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": ""
},
{
"StartAddr": "0x7ffcafca1000",
"EndAddr": "0x7ffcafcc2000",
"Permissions": "rw-p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": "[stack]"
},
{
"StartAddr": "0x7ffcafd1c000",
"EndAddr": "0x7ffcafd1f000",
"Permissions": "r--p",
"FileOffset": "0x0",
"Device": "00:00",
"Inode": 0,
"FilePath": "[vvar]"
},
],
}