I am newbie on cygwin(and linux).
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.
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).
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.
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.
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
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With