Linux环境,当应用程序段错误宕机时,系统log(/var/log/messages*)会记录类似以下的错误日志:
segfault at 10 ip 00007f9bebcca90d sp 00007fffb62705f0 error 4 in demo[7f9beb83a000+f6f000]
这条log记录了与当启现场有关的信息。
/*
* Page fault error code bits:
*
* bit 0 == 0: no page found 1: protection fault
* bit 1 == 0: read access 1: write access
* bit 2 == 0: kernel-mode access 1: user-mode access
* bit 3 == 1: use of reserved bit detected
* bit 4 == 1: fault was an instruction fetch
* bit 5 == 1: protection keys block access
* bit 15 == 1: SGX MMU page-fault
*/
那么,可以通过ip寄存器信息获得宕机位置:
addr2line -e path_of_demo 00007f9bebcca90d
那就麻烦了。动态链接库结束后,不可能知道库在内存中的位置,只能在gdb下重现了。