Thread overview
[Issue 3214] New: Incorrect DWARF line number debugging information on Linux
Jul 29, 2009
nfxjfg@gmail.com
Jul 30, 2009
nfxjfg@gmail.com
Sep 08, 2009
Robert Clipsham
Nov 22, 2009
nfxjfg@gmail.com
Nov 23, 2009
nfxjfg@gmail.com
Apr 01, 2010
nfxjfg@gmail.com
Jan 07, 2011
nfxjfg@gmail.com
Jan 07, 2011
Brad Roberts
Apr 04, 2011
Walter Bright
July 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3214

           Summary: Incorrect DWARF line number debugging information on
                    Linux
           Product: D
           Version: 1.046
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: nfxjfg@gmail.com


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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 30, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3214





--- Comment #1 from nfxjfg@gmail.com  2009-07-29 21:19:56 PDT ---
Created an attachment (id=435)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=435)
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 08, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3214


Robert Clipsham <robert@octarineparrot.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |robert@octarineparrot.com


--- Comment #2 from Robert Clipsham <robert@octarineparrot.com> 2009-09-08 05:49:22 PDT ---
Don't forget to add the patch keyword along with the patch so it doesn't get missed :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 22, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3214


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |3540


--- Comment #3 from nfxjfg@gmail.com 2009-11-21 18:28:15 PST ---
Also see 3540.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3214



--- Comment #4 from nfxjfg@gmail.com 2009-11-22 21:40:49 PST ---
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?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3214



--- Comment #5 from nfxjfg@gmail.com 2010-04-01 05:58:19 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 07, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3214


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 07, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3214


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |braddr@puremagic.com
         Resolution|WONTFIX                     |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 04, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3214


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> 2011-04-04 12:36:33 PDT ---
https://github.com/D-Programming-Language/dmd/commit/01aab6459cfba2eb85feb1481c01c17b8a3badfe

https://github.com/D-Programming-Language/dmd/commit/5f1a6afb1363fe950d2392748fc35f5914c6c6f5

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------