Hi
I'm investigating why gdb returns so unreliable backtraces for mingw
binaries without debuginfos, and noticed a big improvement if I change
strip-unneeded to strip-debug in mingw-find-debuginfo.sh. Currently,
mingw-find-debuginfo.sh does the following:
mingw-objcopy --only-keep-debug "$binary" "$binary.debug"
mingw-objcopy --add-gnu-debuglink=$(basename "$binary.debug")
--strip-unneeded "$binary"
For a trivial test application (see bottom of email), with
strip-unneeded and no debug symbols, gdb reports:
#0 0x000000000040157d in ?? ()
#1 0x00000000004015b5 in ?? ()
#2 0x00000000004013f7 in ?? ()
#3 0x000000000040152b in ?? ()
#4 0x0000000076af652d in KERNEL32!BaseThreadInitThunk ()
from C:\Windows\system32\kernel32.dll
#5 0x0000000076d2c521 in ntdll!RtlUserThreadStart ()
from C:\Windows\SYSTEM32\ntdll.dll
#6 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
With strip-debug, gdb reports:
#0 0x000000000040157d in foo() ()
#1 0x00000000004015b5 in main ()
which is what I'd expect. Downside is the binary size:
strip-debug: 46k
strip-unneeded: 21k
Looking at the native find-debuginfo.sh, I see that some symbols are kept:
nm "$debuginfo" --format=sysv --defined-only | awk -F \| '{ if ($4 ~
"FUNC") print $1 }' | sort > "$funcsyms"
I tried replicating something similar for mingw, using strip-unneeded
but keeping these FUNC symbols:
mingw-objcopy --only-keep-debug "$binary" "$binary.debug"
x86_64-w64-mingw32-nm "$binary.debug" --format=sysv --defined-only | awk
-F \| '{ if ($4 ~ "Function") print $1 }' | sort > "$keep_symbols"
mingw-objcopy --add-gnu-debuglink=$(basename "$binary.debug")
--strip-unneeded "$binary" --keep-symbols="$keep_symbols"
and it seems to work great, the binary size is 24k, and the stack trace
#0 0x000000000040157d in foo() ()
#1 0x00000000004015b5 in main ()
is also good.
The thing is however that I'm not really too sure of what I'm doing.
Does this make any sense? Should/could mingw-find-debuginfo.sh be
enhanced this way?
Thanks
Sandro
--------
#include <iostream>
void foo() {
std::cout << (*((int*)0)) << std::endl;
}
int main() {
foo();
return 0;
}
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx