Debugging¶
To profile a component of the current project, simply pass the --profile
flag to stack. The --profile flag turns on the --enable-library-profiling
and --enable-executable-profiling Cabal options and passes the +RTS -p
runtime options to any testsuites and benchmarks.
For example the following command will build the my-tests testsuite with
profiling options and create a my-tests.prof file in the current directory
as a result of the test run.
The my-tests.prof file now contains time and allocation info for the test run.
To create a profiling report for an executable, e.g. my-exe, you can command:
For more fine-grained control of compilation options there are the
--library-profiling and --executable-profiling flags which will turn on the
--enable-library-profiling and --enable-executable-profiling Cabal
options respectively. Custom GHC options can be passed in with
--ghc-options "more options here".
To enable compilation with profiling options by default you can add the
following snippet to your stack.yaml or ~/.stack/config.yaml:
Further reading¶
For more commands and uses, see the official GHC chapter on profiling, the Haskell wiki, and the chapter on profiling in Real World Haskell.
Tracing¶
To generate a backtrace in case of exceptions during a test or benchmarks run,
use the --trace flag. Like --profile this compiles with profiling options,
but adds the +RTS -xc runtime option.
Debugging symbols¶
Building with debugging symbols in the
DWARF information is supported by
Stack. This can be done by passing the flag --ghc-options="-g" and also to
override the default behaviour of stripping executables of debugging symbols by
passing either one of the following flags: --no-strip,
--no-library-stripping or --no-executable-stripping.
In Windows, GDB can be installed to debug an executable with
stack exec -- pacman -S gdb. Windows' Visual Studio compiler's debugging
format PDB is not supported at the moment. This might be possible by
separating
debugging symbols and
converting their format. Or as an option
when
using the LLVM backend.