github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/third_party/gofrontend/libgo/go/debug/dwarf/line_test.go (about)

     1  // Copyright 2012 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package dwarf_test
     6  
     7  import (
     8  	. "debug/dwarf"
     9  	"path/filepath"
    10  	"testing"
    11  )
    12  
    13  type lineTest struct {
    14  	pc   uint64
    15  	file string
    16  	line int
    17  }
    18  
    19  var elfLineTests = [...]lineTest{
    20  	{0x4004c4, "typedef.c", 83},
    21  	{0x4004c8, "typedef.c", 84},
    22  	{0x4004ca, "typedef.c", 84},
    23  	{0x4003e0, "", 0},
    24  }
    25  
    26  var machoLineTests = [...]lineTest{
    27  	{0x0, "typedef.c", 83},
    28  }
    29  
    30  func TestLineElf(t *testing.T) {
    31  	testLine(t, elfData(t, "testdata/typedef.elf"), elfLineTests[:], "elf")
    32  }
    33  
    34  func TestLineMachO(t *testing.T) {
    35  	testLine(t, machoData(t, "testdata/typedef.macho"), machoLineTests[:], "macho")
    36  }
    37  
    38  func testLine(t *testing.T, d *Data, tests []lineTest, kind string) {
    39  	for _, v := range tests {
    40  		file, line, err := d.FileLine(v.pc)
    41  		if err != nil {
    42  			t.Errorf("%s: %v", kind, err)
    43  			continue
    44  		}
    45  		if file != "" {
    46  			file = filepath.Base(file)
    47  		}
    48  		if file != v.file || line != v.line {
    49  			t.Errorf("%s: for %d have %q:%d want %q:%d",
    50  				kind, v.pc, file, line, v.file, v.line)
    51  		}
    52  	}
    53  }