summaryrefslogtreecommitdiff
path: root/src/cmd/objdump/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/objdump/main.go')
-rw-r--r--src/cmd/objdump/main.go56
1 files changed, 41 insertions, 15 deletions
diff --git a/src/cmd/objdump/main.go b/src/cmd/objdump/main.go
index 79fed9819..ade54366e 100644
--- a/src/cmd/objdump/main.go
+++ b/src/cmd/objdump/main.go
@@ -42,6 +42,7 @@ import (
"debug/macho"
"debug/pe"
"debug/plan9obj"
+ "encoding/binary"
"flag"
"fmt"
"io"
@@ -135,7 +136,7 @@ func main() {
if flag.NArg() == 1 {
// disassembly of entire object - our format
- dump(tab, lookup, disasm, syms, textData, textStart)
+ dump(tab, lookup, disasm, goarch, syms, textData, textStart)
os.Exit(exitCode)
}
@@ -152,7 +153,7 @@ func base(path string) string {
return path
}
-func dump(tab *gosym.Table, lookup lookupFunc, disasm disasmFunc, syms []Sym, textData []byte, textStart uint64) {
+func dump(tab *gosym.Table, lookup lookupFunc, disasm disasmFunc, goarch string, syms []Sym, textData []byte, textStart uint64) {
stdout := bufio.NewWriter(os.Stdout)
defer stdout.Flush()
@@ -178,7 +179,14 @@ func dump(tab *gosym.Table, lookup lookupFunc, disasm disasmFunc, syms []Sym, te
i := pc - textStart
text, size := disasm(textData[i:end-textStart], pc, lookup)
file, line, _ := tab.PCToLine(pc)
- fmt.Fprintf(tw, "\t%s:%d\t%#x\t%x\t%s\n", base(file), line, pc, textData[i:i+uint64(size)], text)
+
+ // ARM is word-based, so show actual word hex, not byte hex.
+ // Since ARM is little endian, they're different.
+ if goarch == "arm" && size == 4 {
+ fmt.Fprintf(tw, "\t%s:%d\t%#x\t%08x\t%s\n", base(file), line, pc, binary.LittleEndian.Uint32(textData[i:i+uint64(size)]), text)
+ } else {
+ fmt.Fprintf(tw, "\t%s:%d\t%#x\t%x\t%s\n", base(file), line, pc, textData[i:i+uint64(size)], text)
+ }
pc += uint64(size)
}
tw.Flush()
@@ -206,19 +214,37 @@ func disasm_x86(code []byte, pc uint64, lookup lookupFunc, arch int) (string, in
return text, size
}
+type textReader struct {
+ code []byte
+ pc uint64
+}
+
+func (r textReader) ReadAt(data []byte, off int64) (n int, err error) {
+ if off < 0 || uint64(off) < r.pc {
+ return 0, io.EOF
+ }
+ d := uint64(off) - r.pc
+ if d >= uint64(len(r.code)) {
+ return 0, io.EOF
+ }
+ n = copy(data, r.code[d:])
+ if n < len(data) {
+ err = io.ErrUnexpectedEOF
+ }
+ return
+}
+
func disasm_arm(code []byte, pc uint64, lookup lookupFunc) (string, int) {
- /*
- inst, size, err := arm_Decode(code, 64)
- var text string
- if err != nil || size == 0 || inst.Op == 0 {
- size = 1
- text = "?"
- } else {
- text = arm_plan9Syntax(inst, pc, lookup)
- }
- return text, size
- */
- return "?", 4
+ inst, err := arm_Decode(code, arm_ModeARM)
+ var text string
+ size := inst.Len
+ if err != nil || size == 0 || inst.Op == 0 {
+ size = 4
+ text = "?"
+ } else {
+ text = arm_plan9Syntax(inst, pc, lookup, textReader{code, pc})
+ }
+ return text, size
}
var disasms = map[string]disasmFunc{