如何使用“*.stackdump"进行调试cygwin中的文件 [英] how to debug using "*.stackdump" file in cygwin

查看:46
本文介绍了如何使用“*.stackdump"进行调试cygwin中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 cygwin(和 linux)的新手.

I am newbie on cygwin(and linux).

当我尝试运行基于 C 语言的可执行文件时,发生分段错误,我获取了 stackdump 文件.但是,我不知道如何使用它进行调试.

When I tried to run my executable file based on C language, segmentation fault occured, and I take stackdump file. but, I don't know how to use it for debugging.

我一直在寻找如何使用 stackdump 文件进行调试的方法,但我找不到.任何小技巧对我来说都非常有用.感谢您阅读我蹩脚的英语(英语不是我的第一语言).

I have been searching for the way how to debug using stackdump file, but I cound't find it. Any small tips are very useful to me. thanks for reading my poor english (english is not my 1st language).

推荐答案

首先:你需要编译你的程序传递给 gcc 标志 -ggdb 否则 stackdump 信息没用.我建议也传递 -O0 标志,以便使用 gdb 进行调试会更容易,因为代码不会被优化.

First: you need to compile your program passing to gcc the flag -ggdb otherwise the stackdump info is useless. I suggest to pass also the -O0 flag so that debugging with gdb will be more easy as the code will not be optimized.

第二:stackdump 提供堆栈中存在的地址,在这个 32 位的例子中,我们有两个地址:

Second: the stackdump provide the addresses present in the stack, in this example on 32bit we have two addresses:

$ cat t-invmod.exe.stackdump
Stack trace:
Frame     Function  Args
0028C878  61032BCB (000000F4, 0000EA60, 000000A4, 0028C8D8)
0028C998  610E7A7A (00000001, 0028CA3F, 00000001, 611A2C80)

地址可以来自您的程序或加载的共享库.

The address can be coming from your programs or from loaded shared libs.

要将地址转换为代码位置,请使用 addr2line.示例:

To convert the address to code position, use addr2line. Example:

$ addr2line.exe -a 610E7A7A -a 61032BCB -e /usr/bin/cygwin1.dll 
0x610e7a7a
/usr/src/debug/cygwin-2.5.1-1/winsup/cygwin/cygerrno.h:36
0x61032bcb
/usr/src/debug/cygwin-2.5.1-1/winsup/cygwin/cygerrno.h:35

在这种情况下,高地址告诉我崩溃是在共享库中而不是在程序中.您可以使用 ldd 来识别地址属于什么:

In this case the high address told me that the crash was in a shared lib and not in the program. You can use ldd to identify to what the addresses belong:

$ ldd t-invmod.exe
        ntdll.dll => /cygdrive/c/Windows/SysWOW64/ntdll.dll (0x776d0000)
        kernel32.dll => /cygdrive/c/Windows/syswow64/kernel32.dll (0x75500000)
        KERNELBASE.dll => /cygdrive/c/Windows/syswow64/KERNELBASE.dll (0x75a10000)
        SYSFER.DLL => /cygdrive/c/Windows/SysWOW64/SYSFER.DLL (0x73480000)
        cygflint.dll => /usr/bin/cygflint.dll (0x5f390000)
        cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000)
        cyggmp-10.dll => /usr/bin/cyggmp-10.dll (0x589e0000)
        cygmpfr-4.dll => /usr/bin/cygmpfr-4.dll (0x51080000)
        cyggcc_s-1.dll => /usr/bin/cyggcc_s-1.dll (0x5ece0000)
        cygntl-9.dll => /usr/bin/cygntl-9.dll (0x50270000)
        cygstdc++-6.dll => /usr/bin/cygstdc++-6.dll (0x4b340000)

如果地址低于dll的地址,则属于你的程序;如果它属于共享库,则需要安装相关的 *debuginfo 包来恢复位置信息.

If the address is lower than dll's one, it belongs to your program; If it belongs to shared lib you need to installl the relative *debuginfo package for recovering the location information.

这篇关于如何使用“*.stackdump"进行调试cygwin中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆