golang/go

cmd/link: Incorrect DWARF scope representation

Open

#12,899 opened on Oct 10, 2015

View on GitHub
 (21 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
DebuggingNeedsFixcompiler/runtimehelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

The DWARF information emitted does not correctly represent the scoping of variables within a procedure.

To illustrate, given the following Go source code:

package main                                                                                                         

import "fmt"

func main() {
        mystr := "foo"
        {
                mystr := "bar"
                fmt.Println(mystr)
        }
        fmt.Println(mystr)
}

The relevant information produced in .debug_info is as follows:

 <1><58>: Abbrev Number: 2 (DW_TAG_subprogram)
    <59>   DW_AT_name        : main.main
    <63>   DW_AT_low_pc      : 0x401000
    <6b>   DW_AT_high_pc     : 0x401240
    <73>   DW_AT_external    : 1   
 <2><74>: Abbrev Number: 4 (DW_TAG_variable)
    <75>   DW_AT_name        : mystr                                                                                 
    <7b>   DW_AT_location    : 5 byte block: 9c 11 80 7f 22 >   (DW_OP_call_frame_cfa; DW_OP_consts: -128; DW_OP_plus)
    <81>   DW_AT_type        : <0x34e72>
 <2><89>: Abbrev Number: 4 (DW_TAG_variable)
    <8a>   DW_AT_name        : mystr 
    <90>   DW_AT_location    : 5 byte block: 9c 11 90 7f 22 >   (DW_OP_call_frame_cfa; DW_OP_consts: -112; DW_OP_plus)
    <96>   DW_AT_type        : <0x34e72>

As you can see, both variables are represented at depth <2> in the tree, however, one should be at depth <3>, following a depth <2> entry of a DW_AT_lexical_block with low/high pc values.

The first solution is to produce a tree that properly reflects the lexical blocks in the source code. Secondly, it would be great for DW_TAG_variable, DW_TAG_formal_parameter and family to include DW_AT_decl_file and DW_AT_decl_line attributes within the entries.

Contributor guide