3214 – Incorrect DWARF line number debugging information on Linux

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3214 - Incorrect DWARF line number debugging information on Linux
Summary: Incorrect DWARF line number debugging information on Linux
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on: 3540
Blocks: 4044
Show dependency tree / graph
Reported: 2009年07月29日 12:58 UTC by nfxjfg
Modified: 2014年04月18日 09:12 UTC (History)
3 users (show)

See Also:


Attachments
dmd patch to fix the problem (against dmd 1.046) (377 bytes, patch)
2009年07月29日 21:19 UTC, nfxjfg
Details | Diff
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description nfxjfg 2009年07月29日 12:58:59 UTC
Here's an example that shows that dmd obviously/probably generates incorrect DWARF line number debugging information under Linux. The example consists of several modules, and I don't know if it's further reducible, or where the problem actually is. (I'm happy that's it's reproducible at all.)
a.d >>>
module a;
import b;
void main(char[][] args) {
 throw new Exception("huh");
}
<<<
b.d >>>
module b;
import c;
void foo1() {
}
<<<
c.d >>>
module c;
class Foo2 : Exception {
 this() {
 super("huh");
 }
}
<<<
Compile exactly like this:
 dmd -c a.d b.d c.d -od. -g
 dmd a.o b.o c.o -ofa -g
Now look what is wrong and check if the symbol "_D1c4Foo25_ctorMFZC1c4Foo2" is correct:
1. Get address:
 nm a|grep _D1c4Foo25_ctorMFZC1c4Foo2 |cut -f2 -d: | cut -f1 -d' '
(outputs something like "08049b64")
2. Resolve the address:
 addr2line -e a 0x08049b64
This outputs "/tmp/test/xx/b.d:5", although the symbol is in c.d. Somehow, the address is incorrectly resolved, which suggests that the compiler might generate incorrect debugging information.
Comment 1 nfxjfg 2009年07月29日 21:19:56 UTC
Created attachment 435 [details] 
dmd patch to fix the problem (against dmd 1.046)
I think I found out why it doesn't work: when compiling several files at once, the object writer's state isn't reset correctly. Now I don't know how the hell the backend works; I just noticed that the DWARF writer still tried to write line numbers from the previous file (also notice what's added by objlinnum()). In this case, c.o contained some line number information from b.o, which is why addr2line resolved the address mentioned to b.d.
I'm posting a trivial 3 line patch that seems to solve the problem. It simply makes obj_init() forget about the SegData from the previous object file. I don't know if it's correct or complete, but with my test cases (the one posted above and a larger, non-trivial heap of code) it seemed to work very well. The patch causes a little memory leak, but that'd trivial to fix (maybe not setting seg_max to 0 does it).
There's just one more problem. When resolving some invalid address with addr2line, I get this output:
BFD: Dwarf Error: mangled line number section (bad file number).
BFD: Dwarf Error: mangled line number section (bad file number).
BFD: Dwarf Error: Could not find abbrev number 1014.
BFD: Dwarf Error: Could not find abbrev number 119.
BFD: Dwarf Error: Could not find abbrev number 651.
BFD: Dwarf Error: Could not find abbrev number 53.
BFD: Dwarf Error: Could not find abbrev number 84.
BFD: Dwarf Error: Could not find abbrev number 657.
BFD: Dwarf Error: Could not find abbrev number 1230.
I have no idea what's up with that and I can't reproduce it with a simpler testcase.
Comment 2 Robert Clipsham 2009年09月08日 05:49:22 UTC
Don't forget to add the patch keyword along with the patch so it doesn't get missed :)
Comment 3 nfxjfg 2009年11月21日 18:28:15 UTC
Also see 3540.
Comment 4 nfxjfg 2009年11月22日 21:40:49 UTC
Problem still persists in dmd 1.051 and the dmd svn version (as of revision 267).
I assume there is some other problem, that doesn't make fixing the bug as simple as it seems?
Comment 5 nfxjfg 2010年04月01日 05:58:19 UTC
It's strange...
With my patch, my executable has a size of 16 MB, with a .debug_line section size of ca. 500 KB.
Without my patch, it's 32 MB, of which .debug_line takes up 16 MB.
PS:
With the fix for bug 3987, the addr2line error messages go away (when compiling with -gc).
Which means my patch doesn't cause additional problems at least in this aspect.


AltStyle によって変換されたページ (->オリジナル) /