c - GDB在特定情况下如何处理段错误?

标签 c linux debugging gdb

我在 linux 上写了一个 C 程序来处理大量数据。大多数时候它似乎工作正常,但我在做作业时遇到了段错误。因为该程序可以与其他数据一起使用,所以我不知道如何处理这个问题。顺便说一句,发生段错误时如何检索变量值?

这是 gdb 输出:

Program received signal SIGSEGV, Segmentation fault.
tyn_p4d_encode32 (in=0x10000000c01, cnt_in=118248, out=0x10000000101 <Address 0x10000000101 out of bounds>, add_termination=1) at tyn_coder.c:645
645                         length_stat[count_bits32(*(in + i)) - 1]++;     
Missing separate debuginfos, use: debuginfo-install glibc-2.14.90-24.fc16.6.x86_64 zlib-1.2.5-5.fc16.x86_64
(gdb) bt
#0  tyn_p4d_encode32 (in=0x10000000c01, cnt_in=118248, out=0x10000000101 <Address 0x10000000101 out of bounds>, add_termination=1) at tyn_coder.c:645
#1  0x0000000000404582 in nodes_term32_flush (array=<optimized out>, size=<optimized out>, nodes_context=0x2ded020, is_last=0) at tyn_indexer.c:116
#2  0x0000000000407b78 in tyn_exsorter_sort (exsorter=0x64c4a0, context=0x2ded020, nodes_flush=0x404320 <nodes_term32_flush>, progress_callback=0x404190 <progress_callback>) at tyn_exsorter.c:131
#3  0x0000000000406ddf in tyn_build_index (tyn_config=0x61a060, index_name=0x4138d1 "mysql_index") at tyn_indexer.c:731
#4  0x0000000000403850 in main (argc=<optimized out>, argv=<optimized out>) at tyn_indexer.c:943

最佳答案

您需要使用-g 标记进行编译和链接才能使用调试器;但你似乎已经在这样做了。 print(缩写为p)打印变量值; btupdownframe 是其他有用的命令。否则,help 在 gdb 或 info gdb 中。

关于c - GDB在特定情况下如何处理段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9825975/

相关文章:

c - 哈希表打印有点乱

c - 在 C 中将 var 赋值给 var

c - 为什么 fork() 之前的 printf() 甚至在 fork() 之后执行?

linux - BASH:[](测试)行为不一致

python - 有没有办法调试在 `multiprocessing.Process` 上运行的 Python 代码?

c++ - 文件是否需要扩展名才能在 C/C++ 中使用 open() 打开?

c++ - netlink 接口(interface) stat goto 交叉初始化错误

linux - 如何将文件的行分成其他文件

c - 没有为指针分配内存,这会导致我在 C 中出现段错误(核心转储)吗?

actionscript-3 - 闪光错误as3