[go] debug/gosym: read start line of a function from gopclntab

19 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Mar 4, 2023, 12:25:57 PM3/4/23
to goph...@pubsubhelper.golang.org, Frederic Branczyk, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

debug/gosym: read start line of a function from gopclntab

This field was introduced in go 1.20 therefore we need to safeguard it to only be read for pclntabs of that version or higher, as otherwise nonsensical bytes would be read. The fallback is now the default value of 0.

Fixes #58474

Change-Id: Ie223f3aa8b40bca03de4f9840289043b9bb95b43
GitHub-Last-Rev: 7f5f1787eff2b4c06dfafc92f6e00f75c9852aa8
GitHub-Pull-Request: golang/go#58864
---
M src/debug/gosym/pclntab.go
M src/debug/gosym/pclntab_test.go
M src/debug/gosym/symtab.go
3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/debug/gosym/pclntab.go b/src/debug/gosym/pclntab.go
index a87e6cf..f46a253 100644
--- a/src/debug/gosym/pclntab.go
+++ b/src/debug/gosym/pclntab.go
@@ -301,6 +301,9 @@
}()
}

+ // The start line only exists in pclntab starting at version 1.20.
+ readStartLine := t.version >= ver120
+
ft := t.funcTab()
funcs := make([]Func, ft.Count())
syms := make([]Sym, len(funcs))
@@ -309,6 +312,9 @@
f.Entry = ft.pc(i)
f.End = ft.pc(i + 1)
info := t.funcData(uint32(i))
+ if readStartLine {
+ f.StartLine = int(info.startLine())
+ }
f.LineTable = t
f.FrameSize = int(info.deferreturn())
syms[i] = Sym{
@@ -461,6 +467,7 @@
func (f funcData) pcfile() uint32 { return f.field(5) }
func (f funcData) pcln() uint32 { return f.field(6) }
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.
// It panics if n == 0 or n > 9; for n == 0, call f.entryPC.
diff --git a/src/debug/gosym/pclntab_test.go b/src/debug/gosym/pclntab_test.go
index e380bb5..be0cc3e 100644
--- a/src/debug/gosym/pclntab_test.go
+++ b/src/debug/gosym/pclntab_test.go
@@ -201,6 +201,24 @@
}
}

+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) {
dotest(t)
defer endtest()
diff --git a/src/debug/gosym/symtab.go b/src/debug/gosym/symtab.go
index d87b312..e64d275 100644
--- a/src/debug/gosym/symtab.go
+++ b/src/debug/gosym/symtab.go
@@ -137,6 +137,7 @@
FrameSize int
LineTable *LineTable
Obj *Obj
+ StartLine int
}

// An Obj represents a collection of functions in a symbol table.

To view, visit change 473455. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie223f3aa8b40bca03de4f9840289043b9bb95b43
Gerrit-Change-Number: 473455
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Frederic Branczyk <fbra...@gmail.com>
Gerrit-MessageType: newchange
Reply all
Reply to author
Forward
0 new messages