In this little gist I will look at how it helps the debug data to use all the sections in the binary.
I will first compile the program with -g
(using Peter's patches). Then I'll
run it once and will get a quite nice stack trace. I will then succesively
strip out important debug information and rerun the binary (without recompiling
of course!). The result will be that the stack trace is degrading for each
stripping, and we can then get a sense for the usefulness of each DWARF section
in the binary.
You might also want to look at
https://github.com/scpmw/ghc/commit/bbf6f35d8c341c8aadca1a48657084c007837b21,
there you see also see how much space these sections take. Roughly it seems like
.debug_ghc
, .debug_info
and .text
all take a 1/4 each, then the 30 other
sections take the other 1/4th.
Arash, 24 March 2014
$ gorun Main -O2
[1 of 1] Compiling Main ( my/Main.hs, my/Main.o )
Linking my/Main ...
Compilation complete!
1
10
100
1000
Hi there! :)
Hi there! :)
Hi there! :)
Main: divide by zero
Loading debug data...
Stack trace:
0: divZeroError (at libraries/base/GHC/Real.lhs:55:1-55:39)
divZeroError (at libraries/base/GHC/Real.lhs:55:23-55:39)
1: crashSelf (at my/Main.hs:24:1-25:32)
crashSelf (at my/Main.hs:24:1-25:32)
crashSelf (at my/Main.hs:24:1-25:32)
2: c (at my/Main.hs:19:1-21:21)
3: showSignedInt (at libraries/base/GHC/Show.lhs:432:1-434:56)
4: print (at libraries/base/System/IO.hs:281:29-281:37)
putStrLn (at libraries/base/System/IO.hs:267:37-267:38)
print (at libraries/base/System/IO.hs:281:35-281:36)
5: writeBlocks (at libraries/base/GHC/IO/Handle/Text.hs:584:4-609:31)
6: stg_ap_v_ret (at rts/dist/build/AutoApply.cmm:8:1-92:2)
7: bindIO (at libraries/base/GHC/Base.lhs:609:72-609:77)
unIO (at libraries/base/GHC/Base.lhs:615:1-615:16)
bindIO (at libraries/base/GHC/Base.lhs:609:61-609:77)
bindIO (at libraries/base/GHC/Base.lhs:609:69-609:70)
8: bindIO (at libraries/base/GHC/Base.lhs:609:72-609:77)
unIO (at libraries/base/GHC/Base.lhs:615:1-615:16)
bindIO (at libraries/base/GHC/Base.lhs:609:61-609:77)
bindIO (at libraries/base/GHC/Base.lhs:609:69-609:70)
9: bindIO (at libraries/base/GHC/Base.lhs:609:72-609:77)
unIO (at libraries/base/GHC/Base.lhs:615:1-615:16)
bindIO (at libraries/base/GHC/Base.lhs:609:61-609:77)
bindIO (at libraries/base/GHC/Base.lhs:609:69-609:70)
10: bindIO (at libraries/base/GHC/Base.lhs:609:72-609:77)
unIO (at libraries/base/GHC/Base.lhs:615:1-615:16)
bindIO (at libraries/base/GHC/Base.lhs:609:61-609:77)
bindIO (at libraries/base/GHC/Base.lhs:609:69-609:70)
11: stg_catch_frame_ret (at rts/Exception.cmm:365:1-367:2)
~/repos/ghc dev*
❯ size --format=SysV my/Main
my/Main :
section size addr
.interp 28 4194872
.note.ABI-tag 32 4194900
.note.gnu.build-id 36 4194932
.gnu.hash 656 4194968
.dynsym 6000 4195624
.dynstr 2545 4201624
.gnu.version 500 4204170
.gnu.version_r 272 4204672
.rela.dyn 96 4204944
.rela.plt 5664 4205040
.init 26 4210704
.plt 3792 4210736
.text 3834576 4214528
.fini 9 8049104
.rodata 198168 8049120
.eh_frame_hdr 10572 8247288
.eh_frame 42644 8257864
.gcc_except_table 115 8300508
.init_array 16 10399128
.fini_array 8 10399144
.jcr 8 10399152
.dynamic 576 10399160
.got 8 10399736
.got.plt 1912 10399744
.data 439048 10401664
.bss 52424 10840768
.comment 102 0
.debug_aranges 3520 0
.debug_info 4495620 0
.debug_abbrev 51548 0
.debug_line 392017 0
.debug_frame 822328 0
.debug_str 48455 0
.debug_ranges 480 0
.debug_ghc 4727534 0
.debug-ghc-link-info 2044 0
Total 15143379
~/repos/ghc dev*
❯ dwarfdump my/Main |less
~/repos/ghc dev* 31s
❯ ./my/Main $RUN_OPTS
1
10
100
1000
Hi there! :)
Hi there! :)
Hi there! :)
Main: divide by zero
Loading debug data...
Stack trace:
0: base_GHCziReal_divZZeroError_info (using libraries/base/GHC/Real.lhs)
1: rw1_info (using my/Main.hs)
2: Main_c5_info (using my/Main.hs)
3: c1lo_entry (using libraries/base/GHC/Show.lhs)
4: s1K2_info (using libraries/base/System/IO.hs)
5: c45y_entry (using libraries/base/GHC/IO/Handle/Text.hs)
6: stg_ap_v_info (using /tmp/ghc14130_0/ghc14130_1.cmmcpp)
7: cUI_entry (using libraries/base/GHC/Base.lhs)
8: cUI_entry (using libraries/base/GHC/Base.lhs)
9: cUI_entry (using libraries/base/GHC/Base.lhs)
10: cUI_entry (using libraries/base/GHC/Base.lhs)
11: stg_catch_frame_info (using /tmp/ghc21584_0/ghc21584_1.cmmcpp)
~/repos/ghc dev*
❯ ./my/Main $RUN_OPTS
1
10
100
1000
Hi there! :)
Hi there! :)
Hi there! :)
Main: divide by zero
Loading debug data...
Stack trace:
0: base_GHCziReal_divZZeroError_info (using libraries/base/GHC/Real.lhs)
1: rw1_info (using my/Main.hs)
2: Main_c5_info (using my/Main.hs)
3: c1lo_entry (using libraries/base/GHC/Show.lhs)
4: s1K2_info (using libraries/base/System/IO.hs)
5: c45y_entry (using libraries/base/GHC/IO/Handle/Text.hs)
6: stg_ap_v_info (using /tmp/ghc14130_0/ghc14130_1.cmmcpp)
7: cUI_entry (using libraries/base/GHC/Base.lhs)
8: cUI_entry (using libraries/base/GHC/Base.lhs)
9: cUI_entry (using libraries/base/GHC/Base.lhs)
10: cUI_entry (using libraries/base/GHC/Base.lhs)
11: stg_catch_frame_info (using /tmp/ghc21584_0/ghc21584_1.cmmcpp)
~/repos/ghc dev*
❯ ./my/Main $RUN_OPTS
1
10
100
1000
Hi there! :)
Hi there! :)
Hi there! :)
Main: divide by zero
Loading debug data...
Stack trace:
0: base_GHCziReal_divZZeroError_info (using libraries/base/GHC/Real.lhs)
1: rw1_info (using my/Main.hs)
2: Main_c5_info (using my/Main.hs)
3: c1lo_entry (using libraries/base/GHC/Show.lhs)
4: s1K2_info (using libraries/base/System/IO.hs)
5: c45y_entry (using libraries/base/GHC/IO/Handle/Text.hs)
6: stg_ap_v_info (using /tmp/ghc14130_0/ghc14130_1.cmmcpp)
7: cUI_entry (using libraries/base/GHC/Base.lhs)
8: cUI_entry (using libraries/base/GHC/Base.lhs)
9: cUI_entry (using libraries/base/GHC/Base.lhs)
10: cUI_entry (using libraries/base/GHC/Base.lhs)
11: stg_catch_frame_info (using /tmp/ghc21584_0/ghc21584_1.cmmcpp)
~/repos/ghc dev*
❯ objcopy --remove-section='.debug_info' my/Main
~/repos/ghc dev*
❯ ./my/Main $RUN_OPTS
1
10
100
1000
Hi there! :)
Hi there! :)
Hi there! :)
Main: divide by zero
Loading debug data...
Stack trace:
0: base_GHCziReal_divZZeroError_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
1: rw1_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
2: Main_c5_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
3: base_GHCziShow_showSignedInt_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
4: s1K2_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
5: s2AO_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
6: stg_ap_v_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
7: rrh_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
8: rrh_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
9: rrh_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
10: rrh_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
11: stg_catch_frame_info (using SYMTAB: /home/arash/repos/ghc/my/Main)
~/repos/ghc dev*
❯ size --format=SysV my/Main
my/Main :
section size addr
.interp 28 4194872
.note.ABI-tag 32 4194900
.note.gnu.build-id 36 4194932
.gnu.hash 656 4194968
.dynsym 6000 4195624
.dynstr 2545 4201624
.gnu.version 500 4204170
.gnu.version_r 272 4204672
.rela.dyn 96 4204944
.rela.plt 5664 4205040
.init 26 4210704
.plt 3792 4210736
.text 3834576 4214528
.fini 9 8049104
.rodata 198168 8049120
.eh_frame_hdr 10572 8247288
.eh_frame 42644 8257864
.gcc_except_table 115 8300508
.init_array 16 10399128
.fini_array 8 10399144
.jcr 8 10399152
.dynamic 576 10399160
.got 8 10399736
.got.plt 1912 10399744
.data 439048 10401664
.bss 52424 10840768
.comment 102 0
.debug_aranges 3520 0
.debug_abbrev 51548 0
.debug_line 392017 0
.debug_frame 822328 0
.debug_str 48455 0
.debug_ranges 480 0
.debug-ghc-link-info 2044 0
Total 5920225
~/repos/ghc dev*
❯ strip my/Main
~/repos/ghc dev*
❯ ./my/Main $RUN_OPTS
1
10
100
1000
Hi there! :)
Hi there! :)
Hi there! :)
Main: divide by zero
Loading debug data...