mirror of
https://github.com/golang/go
synced 2024-11-18 10:04:43 -07:00
cmd/internal/objfile: add ppc64/ppc64le disassembler support
Change-Id: I7d213b4f8e4cda73ea7687fb97dbd22e58163948 Reviewed-on: https://go-review.googlesource.com/9682 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
ed0a956746
commit
94cf54e861
@ -16,6 +16,7 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"golang.org/x/arch/arm/armasm"
|
||||
"golang.org/x/arch/ppc64/ppc64asm"
|
||||
"golang.org/x/arch/x86/x86asm"
|
||||
)
|
||||
|
||||
@ -49,6 +50,7 @@ func (f *File) Disasm() (*Disasm, error) {
|
||||
}
|
||||
|
||||
goarch := f.GOARCH()
|
||||
println("GOARCH", goarch)
|
||||
disasm := disasms[goarch]
|
||||
byteOrder := byteOrders[goarch]
|
||||
if disasm == nil || byteOrder == nil {
|
||||
@ -170,7 +172,7 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6
|
||||
lookup := d.lookup
|
||||
for pc := start; pc < end; {
|
||||
i := pc - d.textStart
|
||||
text, size := d.disasm(code[i:], pc, lookup)
|
||||
text, size := d.disasm(code[i:], pc, lookup, d.byteOrder)
|
||||
file, line, _ := d.pcln.PCToLine(pc)
|
||||
text += "\t"
|
||||
first := true
|
||||
@ -189,13 +191,13 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6
|
||||
}
|
||||
|
||||
type lookupFunc func(addr uint64) (sym string, base uint64)
|
||||
type disasmFunc func(code []byte, pc uint64, lookup lookupFunc) (text string, size int)
|
||||
type disasmFunc func(code []byte, pc uint64, lookup lookupFunc, ord binary.ByteOrder) (text string, size int)
|
||||
|
||||
func disasm_386(code []byte, pc uint64, lookup lookupFunc) (string, int) {
|
||||
func disasm_386(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder) (string, int) {
|
||||
return disasm_x86(code, pc, lookup, 32)
|
||||
}
|
||||
|
||||
func disasm_amd64(code []byte, pc uint64, lookup lookupFunc) (string, int) {
|
||||
func disasm_amd64(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder) (string, int) {
|
||||
return disasm_x86(code, pc, lookup, 64)
|
||||
}
|
||||
|
||||
@ -232,7 +234,7 @@ func (r textReader) ReadAt(data []byte, off int64) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func disasm_arm(code []byte, pc uint64, lookup lookupFunc) (string, int) {
|
||||
func disasm_arm(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder) (string, int) {
|
||||
inst, err := armasm.Decode(code, armasm.ModeARM)
|
||||
var text string
|
||||
size := inst.Len
|
||||
@ -245,10 +247,25 @@ func disasm_arm(code []byte, pc uint64, lookup lookupFunc) (string, int) {
|
||||
return text, size
|
||||
}
|
||||
|
||||
func disasm_ppc64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.ByteOrder) (string, int) {
|
||||
inst, err := ppc64asm.Decode(code, byteOrder)
|
||||
var text string
|
||||
size := inst.Len
|
||||
if err != nil || size == 0 || inst.Op == 0 {
|
||||
size = 4
|
||||
text = "?"
|
||||
} else {
|
||||
text = ppc64asm.GoSyntax(inst, pc, lookup)
|
||||
}
|
||||
return text, size
|
||||
}
|
||||
|
||||
var disasms = map[string]disasmFunc{
|
||||
"386": disasm_386,
|
||||
"amd64": disasm_amd64,
|
||||
"arm": disasm_arm,
|
||||
"386": disasm_386,
|
||||
"amd64": disasm_amd64,
|
||||
"arm": disasm_arm,
|
||||
"ppc64": disasm_ppc64,
|
||||
"ppc64le": disasm_ppc64,
|
||||
}
|
||||
|
||||
var byteOrders = map[string]binary.ByteOrder{
|
||||
|
@ -9,6 +9,7 @@ package objfile
|
||||
import (
|
||||
"debug/dwarf"
|
||||
"debug/elf"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
@ -99,6 +100,9 @@ func (f *elfFile) goarch() string {
|
||||
case elf.EM_ARM:
|
||||
return "arm"
|
||||
case elf.EM_PPC64:
|
||||
if f.elf.ByteOrder == binary.LittleEndian {
|
||||
return "ppc64le"
|
||||
}
|
||||
return "ppc64"
|
||||
case elf.EM_S390:
|
||||
return "s390x"
|
||||
|
Loading…
Reference in New Issue
Block a user