mirror of
				https://github.com/go-delve/delve.git
				synced 2025-11-04 06:32:16 +08:00 
			
		
		
		
	Support multiple file / directory tables for multiple compilation units. - added a type DebugLines that can hold number of DebugLineInfo - added a supporting attribute to DebugLineInfo called 'Lookup' which is to be used to quickly lookup if file exists in FileNames slice - added supporting methods to lookup and return corresponding DebugLineInfo - changed the debug_line parsing behavior to read all the available tables and push them to DebugLines - since Process.lineInfo is now a slice, it was breaking AllPCsBetween as well - updated that function's definition to accept a new filename parameter to be able to extract related DebugLineInfo - updated calls to AllPCsBetween - fixed tests that were broken due to attribute type change in Process - updated _fixtures/cgotest program to include stdio.h, so that it updates .debug_line header - added a test to check 'next' in a cgo binary - OSX - 1.4 does not support cgo, handle that in new testcase
		
			
				
	
	
		
			105 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			105 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package line
 | 
						|
 | 
						|
import (
 | 
						|
	"debug/elf"
 | 
						|
	"debug/macho"
 | 
						|
	"os"
 | 
						|
	"os/exec"
 | 
						|
	"path/filepath"
 | 
						|
	"strings"
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/davecheney/profile"
 | 
						|
)
 | 
						|
 | 
						|
func grabDebugLineSection(p string, t *testing.T) []byte {
 | 
						|
	f, err := os.Open(p)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatal(err)
 | 
						|
	}
 | 
						|
	defer f.Close()
 | 
						|
 | 
						|
	ef, err := elf.NewFile(f)
 | 
						|
	if err == nil {
 | 
						|
		data, _ := ef.Section(".debug_line").Data()
 | 
						|
		return data
 | 
						|
	}
 | 
						|
 | 
						|
	mf, _ := macho.NewFile(f)
 | 
						|
	data, _ := mf.Section("__debug_line").Data()
 | 
						|
 | 
						|
	return data
 | 
						|
}
 | 
						|
 | 
						|
func TestDebugLinePrologueParser(t *testing.T) {
 | 
						|
	// Test against known good values, from readelf --debug-dump=rawline _fixtures/testnextprog
 | 
						|
	p, err := filepath.Abs("../../_fixtures/testnextprog")
 | 
						|
	if err != nil {
 | 
						|
		t.Fatal(err)
 | 
						|
	}
 | 
						|
 | 
						|
	err = exec.Command("go", "build", "-gcflags=-N -l", "-o", p, p+".go").Run()
 | 
						|
	if err != nil {
 | 
						|
		t.Fatal("Could not compile test file", p, err)
 | 
						|
	}
 | 
						|
	defer os.Remove(p)
 | 
						|
	data := grabDebugLineSection(p, t)
 | 
						|
	debugLines := Parse(data)
 | 
						|
	dbl := debugLines[0]
 | 
						|
	prologue := dbl.Prologue
 | 
						|
 | 
						|
	if prologue.Version != uint16(2) {
 | 
						|
		t.Fatal("Version not parsed correctly", prologue.Version)
 | 
						|
	}
 | 
						|
 | 
						|
	if prologue.MinInstrLength != uint8(1) {
 | 
						|
		t.Fatal("Minimun Instruction Length not parsed correctly", prologue.MinInstrLength)
 | 
						|
	}
 | 
						|
 | 
						|
	if prologue.InitialIsStmt != uint8(1) {
 | 
						|
		t.Fatal("Initial value of 'is_stmt' not parsed correctly", prologue.InitialIsStmt)
 | 
						|
	}
 | 
						|
 | 
						|
	if prologue.LineBase != int8(-1) {
 | 
						|
		t.Fatal("Line base not parsed correctly", prologue.LineBase)
 | 
						|
	}
 | 
						|
 | 
						|
	if prologue.LineRange != uint8(4) {
 | 
						|
		t.Fatal("Line Range not parsed correctly", prologue.LineRange)
 | 
						|
	}
 | 
						|
 | 
						|
	if prologue.OpcodeBase != uint8(10) {
 | 
						|
		t.Fatal("Opcode Base not parsed correctly", prologue.OpcodeBase)
 | 
						|
	}
 | 
						|
 | 
						|
	lengths := []uint8{0, 1, 1, 1, 1, 0, 0, 0, 1}
 | 
						|
	for i, l := range prologue.StdOpLengths {
 | 
						|
		if l != lengths[i] {
 | 
						|
			t.Fatal("Length not parsed correctly", l)
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	if len(dbl.IncludeDirs) != 0 {
 | 
						|
		t.Fatal("Include dirs not parsed correctly")
 | 
						|
	}
 | 
						|
 | 
						|
	if !strings.Contains(dbl.FileNames[0].Name, "/delve/_fixtures/testnextprog.go") {
 | 
						|
		t.Fatal("First file entry not parsed correctly")
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func BenchmarkLineParser(b *testing.B) {
 | 
						|
	defer profile.Start(profile.MemProfile).Stop()
 | 
						|
	p, err := filepath.Abs("../../_fixtures/testnextprog")
 | 
						|
	if err != nil {
 | 
						|
		b.Fatal(err)
 | 
						|
	}
 | 
						|
 | 
						|
	data := grabDebugLineSection(p, nil)
 | 
						|
 | 
						|
	b.ResetTimer()
 | 
						|
	for i := 0; i < b.N; i++ {
 | 
						|
		_ = Parse(data)
 | 
						|
	}
 | 
						|
}
 |