[WIP] llvmGen: Produce debug information metadata for functions
Needs ReviewPublic

Authored by bgamari on Jun 18 2016, 5:54 AM.

Details

Summary

It turns out that providing debug information in LLVM is relatively
straightforward. At this moment this only provides debug information with
procedure-level granularity.

Test Plan

Validate, look at DWARF output, try poking around in GDB

bgamari updated this revision to Diff 7998.Jun 18 2016, 5:54 AM
bgamari retitled this revision from to [WIP] llvmGen: Produce debug information metadata for functions.
bgamari updated this object.
bgamari edited the test plan for this revision. (Show Details)
bgamari added a reviewer: simonmar.
scpmw edited edge metadata.Jun 18 2016, 10:59 AM

Good work. Seems LLVM's DWARF representation has matured a bit since I touched it. Adding debug annotations for the blocks shouldn't be that hard either, right? I added a few more or less obvious remarks.

compiler/llvmGen/Llvm/MetaData.hs
136

According to the docs there's a "distinct" modifier too. I suspect that this might solve the problems I had with blocks before - namely that if two blocks happen to have the same meta data (same line) LLVM assumed that they were the same. But no pressing reason yet to introduce it, I suppose.

compiler/llvmGen/LlvmCodeGen.hs
104–153

Might want to factor this out? Feels a bit verbose to put into llvmCodeGen'.

116

I think this should be the compiler's working directory. Can't quite remember how strong my evidence for that was.

121

cProjectName ++ " " ++ cProjectVersion would be consistent with nativeGen/Dwarf.hs.

126

Unused, as above you use an inline MetaStruct in the compile unit meta.

How's this coming along?

bgamari marked 4 inline comments as done.Apr 17 2017, 12:30 PM

I can try to dust this off sometime this week.

cocreature added a comment.EditedApr 17 2017, 12:51 PM

I can try to dust this off sometime this week.

I did start playing around with this patch a few days ago. You can find my progress here https://github.com/cocreature/ghc/commits/llvm-dwarf (sorry for the terrible commit messages, I was planning to clean this up at some point). I updated it for LLVM 4 and GHC master. However, setting breakpoints in gdb/lldb doesn’t seem to work. I made some progress in that they no longer complain about not knowing the file but they still don’t know the line number. After playing around with the LLVM generated from C code by Clang, I got the impression that this requires DILocation annotations but so far adding them doesn’t seem to help (ignoring the fact that I currently just attach it to the first instruction in the corresponding block which is probably not a good idea). I don’t know when I’ll get around to work on this again so feel free to pick up what I’ve got (if it’s useful).

I can try to dust this off sometime this week.

I did start playing around with this patch a few days ago. You can find my progress here https://github.com/cocreature/ghc/commits/llvm-dwarf (sorry for the terrible commit messages, I was planning to clean this up at some point). I updated it for LLVM 4 and GHC master. However, setting breakpoints in gdb/lldb doesn’t seem to work. I made some progress in that they no longer complain about not knowing the file but they still don’t know the line number. After playing around with the LLVM generated from C code by Clang, I got the impression that this requires DILocation annotations but so far adding them doesn’t seem to help (ignoring the fact that I currently just attach it to the first instruction in the corresponding block which is probably not a good idea). I don’t know when I’ll get around to work on this again so feel free to pick up what I’ve got (if it’s useful).

Ahh, great! Thanks @cocreature. I'll continue working off of your branch.

bgamari updated this revision to Diff 13918.Sep 15 2017, 6:44 PM

Rebase, update for LLVM 3.8

Still need to test with LLVM 4.0

bgamari updated this revision to Diff 13919.Sep 15 2017, 7:26 PM

Ooops, include full patch set

simonmar edited edge metadata.Sep 18 2017, 2:58 AM
simonmar added subscribers: kavon, angerman.

Should probably have @angerman and @kavon take a look at this.

austin resigned from this revision.Nov 6 2017, 3:53 PM

This still applies cleanly to master fwiw.