mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <khr@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
612469ab0b
commit
3c2e4ed8d3
3 changed files with 49 additions and 10 deletions
|
|
@ -155,7 +155,6 @@ pkg database/sql, type IsolationLevel int
|
||||||
pkg database/sql, type NamedArg struct
|
pkg database/sql, type NamedArg struct
|
||||||
pkg database/sql, type NamedArg struct, Name string
|
pkg database/sql, type NamedArg struct, Name string
|
||||||
pkg database/sql, type NamedArg struct, Value interface{}
|
pkg database/sql, type NamedArg struct, Value interface{}
|
||||||
pkg debug/gosym, func PCValue([]uint8, uint64, int) int
|
|
||||||
pkg debug/pe, method (*COFFSymbol) FullName(StringTable) (string, error)
|
pkg debug/pe, method (*COFFSymbol) FullName(StringTable) (string, error)
|
||||||
pkg debug/pe, method (StringTable) String(uint32) (string, error)
|
pkg debug/pe, method (StringTable) String(uint32) (string, error)
|
||||||
pkg debug/pe, type File struct, COFFSymbols []COFFSymbol
|
pkg debug/pe, type File struct, COFFSymbols []COFFSymbol
|
||||||
|
|
|
||||||
|
|
@ -114,14 +114,14 @@ func (f *goobjFile) PCToLine(pc uint64) (string, int, *gosym.Func) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil
|
return "", 0, nil
|
||||||
}
|
}
|
||||||
fileID := gosym.PCValue(pcfile, pc-uint64(s.Data.Offset), arch.MinLC)
|
fileID := int(pcValue(pcfile, pc-uint64(s.Data.Offset), arch))
|
||||||
fileName := s.Func.File[fileID]
|
fileName := s.Func.File[fileID]
|
||||||
pcline := make([]byte, s.Func.PCLine.Size)
|
pcline := make([]byte, s.Func.PCLine.Size)
|
||||||
_, err = f.f.ReadAt(pcline, s.Func.PCLine.Offset)
|
_, err = f.f.ReadAt(pcline, s.Func.PCLine.Offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil
|
return "", 0, nil
|
||||||
}
|
}
|
||||||
line := gosym.PCValue(pcline, pc-uint64(s.Data.Offset), arch.MinLC)
|
line := int(pcValue(pcline, pc-uint64(s.Data.Offset), arch))
|
||||||
// Note: we provide only the name in the Func structure.
|
// Note: we provide only the name in the Func structure.
|
||||||
// We could provide more if needed.
|
// We could provide more if needed.
|
||||||
return fileName, line, &gosym.Func{Sym: &gosym.Sym{Name: s.Name}}
|
return fileName, line, &gosym.Func{Sym: &gosym.Sym{Name: s.Name}}
|
||||||
|
|
@ -129,6 +129,53 @@ func (f *goobjFile) PCToLine(pc uint64) (string, int, *gosym.Func) {
|
||||||
return "", 0, nil
|
return "", 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pcValue looks up the given PC in a pc value table. target is the
|
||||||
|
// offset of the pc from the entry point.
|
||||||
|
func pcValue(tab []byte, target uint64, arch *sys.Arch) int32 {
|
||||||
|
val := int32(-1)
|
||||||
|
var pc uint64
|
||||||
|
for step(&tab, &pc, &val, pc == 0, arch) {
|
||||||
|
if target < pc {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// step advances to the next pc, value pair in the encoded table.
|
||||||
|
func step(p *[]byte, pc *uint64, val *int32, first bool, arch *sys.Arch) bool {
|
||||||
|
uvdelta := readvarint(p)
|
||||||
|
if uvdelta == 0 && !first {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if uvdelta&1 != 0 {
|
||||||
|
uvdelta = ^(uvdelta >> 1)
|
||||||
|
} else {
|
||||||
|
uvdelta >>= 1
|
||||||
|
}
|
||||||
|
vdelta := int32(uvdelta)
|
||||||
|
pcdelta := readvarint(p) * uint32(arch.MinLC)
|
||||||
|
*pc += uint64(pcdelta)
|
||||||
|
*val += vdelta
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// readvarint reads, removes, and returns a varint from *p.
|
||||||
|
func readvarint(p *[]byte) uint32 {
|
||||||
|
var v, shift uint32
|
||||||
|
s := *p
|
||||||
|
for shift = 0; ; shift += 7 {
|
||||||
|
b := s[0]
|
||||||
|
s = s[1:]
|
||||||
|
v |= (uint32(b) & 0x7F) << shift
|
||||||
|
if b&0x80 == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*p = s
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// We treat the whole object file as the text section.
|
// We treat the whole object file as the text section.
|
||||||
func (f *goobjFile) text() (textStart uint64, text []byte, err error) {
|
func (f *goobjFile) text() (textStart uint64, text []byte, err error) {
|
||||||
var info os.FileInfo
|
var info os.FileInfo
|
||||||
|
|
|
||||||
|
|
@ -291,13 +291,6 @@ func (t *LineTable) step(p *[]byte, pc *uint64, val *int32, first bool) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// PCValue looks up the given PC in a pc value table. target is the
|
|
||||||
// offset of the pc from the entry point.
|
|
||||||
func PCValue(tab []byte, target uint64, quantum int) int {
|
|
||||||
t := LineTable{Data: tab, quantum: uint32(quantum)}
|
|
||||||
return int(t.pcvalue(0, 0, target))
|
|
||||||
}
|
|
||||||
|
|
||||||
// pcvalue reports the value associated with the target pc.
|
// pcvalue reports the value associated with the target pc.
|
||||||
// off is the offset to the beginning of the pc-value table,
|
// off is the offset to the beginning of the pc-value table,
|
||||||
// and entry is the start PC for the corresponding function.
|
// and entry is the start PC for the corresponding function.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue