Skip to content

Commit 3c2e4ed

Browse files
committed
cmd/objdump: copy gosym.PCValue into internal package
... so we don't have to export gosym.PCValue. Change-Id: Ie8f196d5e5ab63e3e69d1d7b4bfbbf32b7b5e4f5 Reviewed-on: https://go-review.googlesource.com/33791 Run-TryBot: Keith Randall <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 612469a commit 3c2e4ed

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

api/go1.8.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ pkg database/sql, type IsolationLevel int
155155
pkg database/sql, type NamedArg struct
156156
pkg database/sql, type NamedArg struct, Name string
157157
pkg database/sql, type NamedArg struct, Value interface{}
158-
pkg debug/gosym, func PCValue([]uint8, uint64, int) int
159158
pkg debug/pe, method (*COFFSymbol) FullName(StringTable) (string, error)
160159
pkg debug/pe, method (StringTable) String(uint32) (string, error)
161160
pkg debug/pe, type File struct, COFFSymbols []COFFSymbol

src/cmd/internal/objfile/goobj.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,68 @@ func (f *goobjFile) PCToLine(pc uint64) (string, int, *gosym.Func) {
114114
if err != nil {
115115
return "", 0, nil
116116
}
117-
fileID := gosym.PCValue(pcfile, pc-uint64(s.Data.Offset), arch.MinLC)
117+
fileID := int(pcValue(pcfile, pc-uint64(s.Data.Offset), arch))
118118
fileName := s.Func.File[fileID]
119119
pcline := make([]byte, s.Func.PCLine.Size)
120120
_, err = f.f.ReadAt(pcline, s.Func.PCLine.Offset)
121121
if err != nil {
122122
return "", 0, nil
123123
}
124-
line := gosym.PCValue(pcline, pc-uint64(s.Data.Offset), arch.MinLC)
124+
line := int(pcValue(pcline, pc-uint64(s.Data.Offset), arch))
125125
// Note: we provide only the name in the Func structure.
126126
// We could provide more if needed.
127127
return fileName, line, &gosym.Func{Sym: &gosym.Sym{Name: s.Name}}
128128
}
129129
return "", 0, nil
130130
}
131131

132+
// pcValue looks up the given PC in a pc value table. target is the
133+
// offset of the pc from the entry point.
134+
func pcValue(tab []byte, target uint64, arch *sys.Arch) int32 {
135+
val := int32(-1)
136+
var pc uint64
137+
for step(&tab, &pc, &val, pc == 0, arch) {
138+
if target < pc {
139+
return val
140+
}
141+
}
142+
return -1
143+
}
144+
145+
// step advances to the next pc, value pair in the encoded table.
146+
func step(p *[]byte, pc *uint64, val *int32, first bool, arch *sys.Arch) bool {
147+
uvdelta := readvarint(p)
148+
if uvdelta == 0 && !first {
149+
return false
150+
}
151+
if uvdelta&1 != 0 {
152+
uvdelta = ^(uvdelta >> 1)
153+
} else {
154+
uvdelta >>= 1
155+
}
156+
vdelta := int32(uvdelta)
157+
pcdelta := readvarint(p) * uint32(arch.MinLC)
158+
*pc += uint64(pcdelta)
159+
*val += vdelta
160+
return true
161+
}
162+
163+
// readvarint reads, removes, and returns a varint from *p.
164+
func readvarint(p *[]byte) uint32 {
165+
var v, shift uint32
166+
s := *p
167+
for shift = 0; ; shift += 7 {
168+
b := s[0]
169+
s = s[1:]
170+
v |= (uint32(b) & 0x7F) << shift
171+
if b&0x80 == 0 {
172+
break
173+
}
174+
}
175+
*p = s
176+
return v
177+
}
178+
132179
// We treat the whole object file as the text section.
133180
func (f *goobjFile) text() (textStart uint64, text []byte, err error) {
134181
var info os.FileInfo

src/debug/gosym/pclntab.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,6 @@ func (t *LineTable) step(p *[]byte, pc *uint64, val *int32, first bool) bool {
291291
return true
292292
}
293293

294-
// PCValue looks up the given PC in a pc value table. target is the
295-
// offset of the pc from the entry point.
296-
func PCValue(tab []byte, target uint64, quantum int) int {
297-
t := LineTable{Data: tab, quantum: uint32(quantum)}
298-
return int(t.pcvalue(0, 0, target))
299-
}
300-
301294
// pcvalue reports the value associated with the target pc.
302295
// off is the offset to the beginning of the pc-value table,
303296
// and entry is the start PC for the corresponding function.

0 commit comments

Comments
 (0)