本文主要是介绍再聊用strace来定位没有core文件的core dump,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我把ulimit -c 给关掉, 如下程序虽然core dump了, 但并不会产生core文件, 看看:
#include <stdio.h>
#include <unistd.h>int main()
{for(int i = 0; i < 60; i++){printf("aa [%d]\n", i);if(10 == i){int *p = NULL;*p = 0;}sleep(1);}return 0;
}
结果:
taoge@localhost Desktop> ulimit -c
0
taoge@localhost Desktop> g++ main.cpp
taoge@localhost Desktop> strace -i ./a.out
[00374424] execve("./a.out", ["./a.out"], [/* 38 vars */]) = 0
[0086e2fd] brk(0) = 0x8634000
[0086f6d3] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb78ce000
[0086f5d1] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[0086f494] open("/etc/ld.so.cache", O_RDONLY) = 3
[0086f45e] fstat64(3, {st_mode=S_IFREG|0644, st_size=49072, ...}) = 0
[0086f6d3] mmap2(NULL, 49072, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb78c2000
[0086f4cd] close(3) = 0
[0086f494] open("/usr/lib/libstdc++.so.6", O_RDONLY) = 3
[0086f514] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20F\254\0044\0\0\0"..., 512) = 512
[0086f45e] fstat64(3, {st_mode=S_IFREG|0755, st_size=942040, ...}) = 0
[0086f6d3] mmap2(0x4a7f000, 969644, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x4a7f000
[0086f6d3] mmap2(0x4b60000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe0) = 0x4b60000
[0086f6d3] mmap2(0x4b66000, 23468, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4b66000
[0086f4cd] close(3) = 0
[0086f494] open("/lib/libm.so.6", O_RDONLY) = 3
[0086f514] read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0p4\243\0004\0\0\0"..., 512) = 512
[0086f45e] fstat64(3, {st_mode=S_IFREG|0755, st_size=202040, ...}) = 0
[0086f6d3] mmap2(0xa30000, 168064, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xa30000
[0086f6d3] mmap2(0xa58000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x27) = 0xa58000
[0086f4cd] close(3) = 0
[0086f494] open("/lib/libgcc_s.so.1", O_RDONLY) = 3
[0086f514] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\240\257\212\0044\0\0\0"..., 512) = 512
[0086f45e] fstat64(3, {st_mode=S_IFREG|0755, st_size=122232, ...}) = 0
[0086f6d3] mmap2(0x48a9000, 119592, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x48a9000
[0086f6d3] mmap2(0x48c6000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1d) = 0x48c6000
[0086f4cd] close(3) = 0
[0086f494] open("/lib/libc.so.6", O_RDONLY) = 3
[0086f514] read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 N\211\0004\0\0\0"..., 512) = 512
[0086f45e] fstat64(3, {st_mode=S_IFREG|0755, st_size=1855584, ...}) = 0
[0086f6d3] mmap2(0x87e000, 1620360, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x87e000
[0086f754] mprotect(0xa03000, 4096, PROT_NONE) = 0
[0086f6d3] mmap2(0xa04000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x185) = 0xa04000
[0086f6d3] mmap2(0xa07000, 10632, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xa07000
[0086f4cd] close(3) = 0
[0086f6d3] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb78c1000
[0086f6d3] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb78c0000
[0085a552] set_thread_area({entry_number:-1 -> 6, base_addr:0xb78c06d0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
[0086f754] mprotect(0xa04000, 8192, PROT_READ) = 0
[0086f754] mprotect(0xa58000, 4096, PROT_READ) = 0
[0086f6d3] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb78bf000
[0086f754] mprotect(0x4b60000, 16384, PROT_READ) = 0
[0086f754] mprotect(0x876000, 4096, PROT_READ) = 0
[0086f711] munmap(0xb78c2000, 49072) = 0
[00d80424] fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
[00d80424] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb78cd000
[00d80424] write(1, "aa [0]\n", 7aa [0]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [1]\n", 7aa [1]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [2]\n", 7aa [2]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [3]\n", 7aa [3]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [4]\n", 7aa [4]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [5]\n", 7aa [5]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [6]\n", 7aa [6]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [7]\n", 7aa [7]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [8]\n", 7aa [8]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [9]\n", 7aa [9]
) = 7
[00d80424] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[00d80424] rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
[00d80424] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[00d80424] nanosleep({1, 0}, 0xbfe789e4) = 0
[00d80424] write(1, "aa [10]\n", 8aa [10]
) = 8
[080484de] --- SIGSEGV (Segmentation fault) @ 0 (0) ---
[????????] +++ killed by SIGSEGV (core dumped) +++
Segmentation fault (core dumped)
taoge@localhost Desktop> ll | grep core
taoge@localhost Desktop>
可见, 没有core文件, 也能定位出core, 当然, 我们也可以用strace -p哈。
夜深人静, 玩玩core, 就这样。
这篇关于再聊用strace来定位没有core文件的core dump的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!