Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(607)

Unified Diff: src/cmd/objdump/main.go

Issue 104770046: code review 104770046: cmd/objdump: add arm disassembler (Closed)
Patch Set: diff -r 5dd1aec48e8f https://code.google.com/p/go/ Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/cmd/objdump/armasm.go ('k') | src/cmd/objdump/objdump_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/cmd/objdump/main.go
===================================================================
--- a/src/cmd/objdump/main.go
+++ b/src/cmd/objdump/main.go
@@ -42,6 +42,7 @@
"debug/macho"
"debug/pe"
"debug/plan9obj"
+ "encoding/binary"
"flag"
"fmt"
"io"
@@ -135,7 +136,7 @@
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 @@
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 @@
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 @@
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{
« no previous file with comments | « src/cmd/objdump/armasm.go ('k') | src/cmd/objdump/objdump_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b