How to get debugging symbols (e.g., DWARF)

Hi all, I have a question about DWARF of GHC debugging.

Given simple C code, a command gcc -g example.c -o example outputs example with built DWARF.

#include <stdio.h>

int main()
{
    int x = 42;
    printf("The answer is %d\n", x);
    return 0;
}

Now I run dwarfdump example shows useful DWARF values like follows:

< 2><0x0000034b>      DW_TAG_variable
                        DW_AT_name                  x
                        DW_AT_decl_file             0x00000001 ~/example.c
                        DW_AT_decl_line             0x00000005
                        DW_AT_decl_column           0x00000009
                        DW_AT_type                  <0x00000063>
                        DW_AT_location              len 0x0002: 916c: DW_OP_fbreg -20

The output description says a variable x is declared at line number 5.

When the similar haskell code comes to compile with -g flag (i.e., ghc -g Main.hs -o Main):

main :: IO ()
main = do
  let x12345 = 1
      x6789 = 2
  putStrLn $ show (x12345 + x6789)

The output of dwarfdump does not show similar information as shown in the C example. I guess the representation seems different and I have no idea how to find the same information from.

Any comment on how can I find debugging symbols?

Thank you

1 Like

You should be using one of the -dwarf flavours of GHC bindists: Index of /ghc/9.4.4/

2 Likes

Thank you. I’ll give it a try. If it’s within the scope of this question, has the official GHC recently considered adopting DWARF?

1 Like