4

When I build my source code using two steps:

localhost % clang -g -c factorial.s       
localhost % clang -o factorial factorial.o

I get debug info about the assembly source.

localhost % lldb factorial
(lldb) target create "factorial"
Current executable set to '/Users/chris/Dev/assembly/learning-assembly/chapter11/factorial' (x86_64).
(lldb) source info -f factorial.s 

Lines found for file factorial.s in compilation unit factorial.s in `factorial
[0x0000000100003f89-0x0000000100003f8b): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:10
[0x0000000100003f8b-0x0000000100003f8d): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:13
[0x0000000100003f92-0x0000000100003f93): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:15
[0x0000000100003f93-0x0000000100003f95): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:16
[0x0000000100003f95-0x0000000100003f9c): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:19
[0x0000000100003f9c-0x0000000100003f9d): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:22
[0x0000000100003f9d-0x0000000100003fa1): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:25
[0x0000000100003fa1-0x0000000100003fa7): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:26
[0x0000000100003fa7-0x0000000100003faa): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:29
[0x0000000100003faa-0x0000000100003fac): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:30
[0x0000000100003fac-0x0000000100003faf): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:33
[0x0000000100003faf-0x0000000100003fb6): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:34
[0x0000000100003fb6-0x0000000100003fb8): /Users/chris/Dev/assembly/learning-assembly/chapter11/factorial.s:35
(lldb)  

If I do this in one step I don't:

localhost % clang -g -o factorial factorial.s 
localhost % lldb factorial
(lldb) target create "factorial"
Current executable set to '/Users/chris/Dev/assembly/learning-assembly/chapter11/factorial' (x86_64).
(lldb) source info -f factorial.s
error: No source filenames matched 'factorial.s'.
(lldb) 

In another example, I did the one step build from source of a main.c along with function.s. In that case lldb knew about the main.c file, but not the assembly file.

Is there an option when building in one step with clang to get it to give me dwarf info for the assembly too?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Chris
  • 342
  • 1
  • 12
  • 1
    What did the llvm/clang folks say about this when you asked? – old_timer Sep 20 '22 at 10:23
  • You know, I didn't think to ask on their discourse/discord platform. I've gotten used to asking questions here at SO. But now that you mention it... – Chris Sep 21 '22 at 12:08
  • 1
    Are you on MacOS or Linux? On Darwin, the `clang` command has an extra step at the end which calls `dsymutil` to gather up debug-info and package them into a `dSYM` bundle; that's the only difference between the two I'm aware of – 137 Sep 21 '22 at 12:48
  • Also what does running `llvm-dwarfdump` (simply `dwarfdump` on MacOS) on the object-file show you? – 137 Sep 21 '22 at 15:02
  • Following advice from @old_timer. I posted over on the LLVM discourse. TL;DR — .o debug info + executable debug map is supposed to be the same as dSYM bundle, but in the case of assembly it turns out it isn't. probably a bug. Here's the post: https://discourse.llvm.org/t/why-is-lldb-not-showing-debug-info-for-my-assembly-file/65412/14?u=chris-miner – Chris Sep 21 '22 at 18:41

1 Answers1

2

This answer is the same as the one buried in a comment, but I thought it would be easier to find it here.

TL;DR — .o debug info + executable debug map is supposed to be the same as dSYM bundle, but in the case of assembly it turns out it isn't.

The complete discussion can be found at Why is LLDB not showing debug info for my assembly file?

Chris
  • 342
  • 1
  • 12