I'm building statically linked binary using stack and I try to add debug symbols to it (following: https://downloads.haskell.org/~ghc/master/users-guide/debug-info.html). However GDB reports: no debugging symbols found
.
What am I missing?
I've added to the ghc-options
in the .cabal
file: -g -rtsopts
and to the ld-options
: -static
. I am building using stack with the following command:
stack install \
--install-ghc \
--split-objs \
--ghc-options="-fPIC -fllvm -pgmlo opt -pgmlc llc"
GDB is invoked as follows: gdb --args nodebug-exe +RTS -V0
GHC 8.2.1
Whole source code is here: https://github.com/carbolymer/haskell-missing-debug-symbols
The most frequent cause of "no debugging symbols found" when -g is present is that there is some "stray" -s or -S argument somewhere on the link line. From man ld : -s --strip-all Omit all symbol information from the output file.
A debug symbol is a special kind of symbol that attaches additional information to the symbol table of an object file, such as a shared library or an executable.
It allows you to symbolicate your crash log, else it's just meaningless memory adress. It's kind of a link between the builded code and the source code.
To remove debugging symbols from a binary (which must be an a. out or ELF binary), run strip --strip-debug filename. Wildcards can be used to treat multiple files (use something like strip --strip-debug $LFS/tools/bin/*).
--no-strip
prevents debugging information being removed in the stack build.
From the documentation:
stack now supports debugging and profiling with DWARF information, using the --no-strip, --no-library-stripping, and --no-executable-stripping flags to disable the default behavior of removing such information from compiled libraries and executables.
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