This commit is contained in:
Frederic Branczyk 2025-06-20 15:37:07 -04:00 committed by GitHub
commit 61256fb98f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 0 deletions

View File

@ -305,6 +305,9 @@ func (t *LineTable) go12Funcs() []Func {
}() }()
} }
// The start line only exists in pclntab starting at version 1.20.
readStartLine := t.version >= ver120
ft := t.funcTab() ft := t.funcTab()
funcs := make([]Func, ft.Count()) funcs := make([]Func, ft.Count())
syms := make([]Sym, len(funcs)) syms := make([]Sym, len(funcs))
@ -313,6 +316,9 @@ func (t *LineTable) go12Funcs() []Func {
f.Entry = ft.pc(i) f.Entry = ft.pc(i)
f.End = ft.pc(i + 1) f.End = ft.pc(i + 1)
info := t.funcData(uint32(i)) info := t.funcData(uint32(i))
if readStartLine {
f.StartLine = int(info.startLine())
}
f.LineTable = t f.LineTable = t
f.FrameSize = int(info.deferreturn()) f.FrameSize = int(info.deferreturn())
syms[i] = Sym{ syms[i] = Sym{
@ -465,6 +471,7 @@ func (f funcData) deferreturn() uint32 { return f.field(3) }
func (f funcData) pcfile() uint32 { return f.field(5) } func (f funcData) pcfile() uint32 { return f.field(5) }
func (f funcData) pcln() uint32 { return f.field(6) } func (f funcData) pcln() uint32 { return f.field(6) }
func (f funcData) cuOffset() uint32 { return f.field(8) } func (f funcData) cuOffset() uint32 { return f.field(8) }
func (f funcData) startLine() uint32 { return f.field(9) }
// field returns the nth field of the _func struct. // field returns the nth field of the _func struct.
// It panics if n == 0 or n > 9; for n == 0, call f.entryPC. // It panics if n == 0 or n > 9; for n == 0, call f.entryPC.

View File

@ -201,6 +201,24 @@ func TestLineAline(t *testing.T) {
} }
} }
func TestStartLine(t *testing.T) {
dotest(t)
defer endtest()
f, tab := crack(pclinetestBinary, t)
defer f.Close()
sym := tab.LookupFunc("main.main")
wantLine := 6
if sym == nil {
t.Fatal("no main.main")
}
if sym.StartLine != wantLine {
t.Fatalf("StartLine = %d, want %d", sym.StartLine, wantLine)
}
}
func TestPCLine(t *testing.T) { func TestPCLine(t *testing.T) {
dotest(t) dotest(t)
defer endtest() defer endtest()

View File

@ -137,6 +137,7 @@ type Func struct {
FrameSize int FrameSize int
LineTable *LineTable LineTable *LineTable
Obj *Obj Obj *Obj
StartLine int
} }
// An Obj represents a collection of functions in a symbol table. // An Obj represents a collection of functions in a symbol table.