Meet my
满足我的
$uname -a Linux hostmachine 4.1.2-2-ARCH #1 SMP PREEMPT Wed Jul 15 08:30:32 UTC 2015 x86_64 GNU/Linux
$uname - Linux主机4.1.2-2-ARCH #1 SMP抢占到7月15日08:30:32 UTC 2015 x86_64 GNU/Linux
I'm trying to learn how to use GDB for debugging C programs. I think it would be particularly excellent if I could use GDB to ferret out bugs that lead to segfaults. I have a small program that I've written as a solution to K&R's exercise 1-13, and given an input string of a certain size it will generate a segfault:
我正在学习如何使用GDB来调试C程序。我认为,如果我能使用GDB查找导致分段错误的错误,那将是非常棒的。我有一个小程序,作为K&R练习1-13的解决方案,给定一个特定大小的输入字符串,它将生成一个segfault:
$ ~/learning_c/KR_exercises/chapter_1/1.13.x
--I provide a string from stdin, and...-- Segmentation fault (core dumped)
$ ~ / learning_c / KR_exercises / chapter_1/1.13。x——我提供了来自stdin的字符串,而且……——分割故障(堆芯)
According to the Arch wiki, "Systemd's default behavior is to generate core dumps for all processes in /var/lib/systemd/coredump/
."
根据Arch wiki,“Systemd的默认行为是为/var/lib/systemd/coredump/中的所有进程生成核心转储。”
Okie doke:
农夫移民doke:
$ls /var/lib/systemd/coredump/ core.1\x2e13\x2ex.1000.0da6be3a2b4647c8befe14e0e73af848.1719.1438627150000000.lz4
$ ls /var/lib/systemd/coredump/ core.1 \ x2e13 \ x2ex.1000.0da6be3a2b4647c8befe14e0e73af848.1719.1438627150000000.lz4
But when I run:
但当我运行:
$ gdb -q ~/learning_c/KR_exercises/chapter_1/1.13.x /var/lib/systemd/coredump/core.1\\x2e13\\x2ex.1000.0da6be3a2b4647c8befe14e0e73af848.1719.1438627150000000.lz4
gdb - q ~ /美元learning_c / KR_exercises / chapter_1/1.13。x /var/lib/systemd/coredump/core.1 \ \ x2e13 \ \ x2ex.1000.0da6be3a2b4647c8befe14e0e73af848.1719.1438627150000000.lz4
I get:
我得到:
Reading symbols from /home/dean/learning_c/KR_exercises/chapter_1/1.13.x...done. "/var/lib/systemd/coredump/core.1\x2e13\x2ex.1000.0da6be3a2b4647c8befe14e0e73af848.1719.1438627150000000.lz4" is not a core dump: File format not recognized
从/home/dean/learning_c/KR_exercises读取符号/ chapter_1/1.13.x……。" / var / lib / systemd / coredump / core.1 \ x2e13 \ x2ex.1000.0da6be3a2b4647c8befe14e0e73af848.1719.1438627150000000。lz4"不是一个核心转储:文件格式不被识别
Trying to generate a core dump by attaching GDB to the process as detailed here only makes my terminal emulator start capturing control characters (^D
, ^C
, and ^Z
won't work in emulator after attaching GDB), and if a segfault is occuring after attaching GDB it isn't being reported in the shell.
试图产生一个附加GDB核心转储的过程详细这只会让我的终端模拟器启动捕获控制字符(C D ^,^,^ Z不会工作在模拟器附加GDB),如果一段错误发生后附加GDB外壳不被报告。
Help me to understand, oh merciful and beneficent lords of Stack Overflow!
请帮助我理解,哦,仁慈和仁慈的栈溢出的领主!
ADDENDUM:
附录:
I've solved this particular issue, thanks largely to WhozCraig, whom suggested that GDB was behaving as it should have when being force-fed an lz4 compressed corefile. If Craig would be so kind as to post a solution saying something similar, I'd be happy to give him that big 'ol check mark.
我已经解决了这个特殊的问题,这很大程度上要感谢WhozCraig,他认为GDB在强制输入lz4压缩的corefile时应该表现得很好。如果克雷格能好心地发布一个类似的解决方案,我很乐意给他那个大支票。
The easist solution is to start gdb via a subroutine named coredumpctl
along with the crashed program's PID, a la
最简单的解决方案是通过一个名为coredumpctl的子例程启动gdb,以及崩溃程序的PID
$coredumpctl gdb *PID HERE*
美元coredumpctl gdb * * PID
This vexes me, Arch, and I may migrate over to Gentoo because of it.
这让我很烦恼,我也可能会因为它而迁移到Gentoo。
2 个解决方案
#1
3
I've solved this particular issue, thanks largely to WhozCraig, whom suggested that GDB was behaving as it should have when being force-fed an LZ4 compressed corefile.
If Craig would be so kind as to post a solution saying something similar, I'd be happy to give him that big 'ol check mark
I'm taking all the credit, though. Bwahahaha!
我已经解决了这个特殊的问题,这很大程度上要感谢WhozCraig,他认为GDB在强制输入LZ4压缩的corefile时应该表现得很好。如果克雷格能好心地发布一个类似的解决方案,我很乐意给他那个大大的支票马克,我将会得到所有的荣誉。Bwahahaha !
The easiest solution is to start gdb via a subroutine named coredumpctl along with the crashed program's PID, a la
最简单的解决方案是通过一个名为coredumpctl的子例程启动gdb,以及崩溃程序的PID
$coredumpctl gdb PID HERE
美元coredumpctl gdb PID
This vexes me, Arch, and I may migrate over to Gentoo
because of it
.
这让我很恼火,阿奇,我可能会因此搬到吉诺图去。
#2
0
I have same purpose with you. Just uncompress lz4 file by lz4
command, then you can debug by gdb crashed_C_executable_file uncompressed_coredump_file
我和你有同样的目的。只需使用lz4命令解压lz4文件,然后就可以通过gdb crashed_C_executable_file uncompressed_coredump_file调试了
#1
3
I've solved this particular issue, thanks largely to WhozCraig, whom suggested that GDB was behaving as it should have when being force-fed an LZ4 compressed corefile.
If Craig would be so kind as to post a solution saying something similar, I'd be happy to give him that big 'ol check mark
I'm taking all the credit, though. Bwahahaha!
我已经解决了这个特殊的问题,这很大程度上要感谢WhozCraig,他认为GDB在强制输入LZ4压缩的corefile时应该表现得很好。如果克雷格能好心地发布一个类似的解决方案,我很乐意给他那个大大的支票马克,我将会得到所有的荣誉。Bwahahaha !
The easiest solution is to start gdb via a subroutine named coredumpctl along with the crashed program's PID, a la
最简单的解决方案是通过一个名为coredumpctl的子例程启动gdb,以及崩溃程序的PID
$coredumpctl gdb PID HERE
美元coredumpctl gdb PID
This vexes me, Arch, and I may migrate over to Gentoo
because of it
.
这让我很恼火,阿奇,我可能会因此搬到吉诺图去。
#2
0
I have same purpose with you. Just uncompress lz4 file by lz4
command, then you can debug by gdb crashed_C_executable_file uncompressed_coredump_file
我和你有同样的目的。只需使用lz4命令解压lz4文件,然后就可以通过gdb crashed_C_executable_file uncompressed_coredump_file调试了