OLD | NEW |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Objdump disassembles executable files. | 5 // Objdump disassembles executable files. |
6 // | 6 // |
7 // Usage: | 7 // Usage: |
8 // | 8 // |
9 // go tool objdump [-s symregexp] binary | 9 // go tool objdump [-s symregexp] binary |
10 // | 10 // |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 "flag" | 43 "flag" |
44 "fmt" | 44 "fmt" |
45 "io" | 45 "io" |
46 "log" | 46 "log" |
47 "os" | 47 "os" |
48 "regexp" | 48 "regexp" |
49 "sort" | 49 "sort" |
50 "strconv" | 50 "strconv" |
51 "strings" | 51 "strings" |
52 "text/tabwriter" | 52 "text/tabwriter" |
| 53 |
| 54 "cmd/internal/rsc.io/arm/armasm" |
| 55 "cmd/internal/rsc.io/x86/x86asm" |
53 ) | 56 ) |
54 | 57 |
55 var symregexp = flag.String("s", "", "only dump symbols matching this regexp") | 58 var symregexp = flag.String("s", "", "only dump symbols matching this regexp") |
56 var symRE *regexp.Regexp | 59 var symRE *regexp.Regexp |
57 | 60 |
58 func usage() { | 61 func usage() { |
59 fmt.Fprintf(os.Stderr, "usage: go tool objdump [-s symregexp] binary [st
art end]\n\n") | 62 fmt.Fprintf(os.Stderr, "usage: go tool objdump [-s symregexp] binary [st
art end]\n\n") |
60 flag.PrintDefaults() | 63 flag.PrintDefaults() |
61 os.Exit(2) | 64 os.Exit(2) |
62 } | 65 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 195 |
193 func disasm_386(code []byte, pc uint64, lookup lookupFunc) (string, int) { | 196 func disasm_386(code []byte, pc uint64, lookup lookupFunc) (string, int) { |
194 return disasm_x86(code, pc, lookup, 32) | 197 return disasm_x86(code, pc, lookup, 32) |
195 } | 198 } |
196 | 199 |
197 func disasm_amd64(code []byte, pc uint64, lookup lookupFunc) (string, int) { | 200 func disasm_amd64(code []byte, pc uint64, lookup lookupFunc) (string, int) { |
198 return disasm_x86(code, pc, lookup, 64) | 201 return disasm_x86(code, pc, lookup, 64) |
199 } | 202 } |
200 | 203 |
201 func disasm_x86(code []byte, pc uint64, lookup lookupFunc, arch int) (string, in
t) { | 204 func disasm_x86(code []byte, pc uint64, lookup lookupFunc, arch int) (string, in
t) { |
202 » inst, err := x86_Decode(code, 64) | 205 » inst, err := x86asm.Decode(code, 64) |
203 var text string | 206 var text string |
204 size := inst.Len | 207 size := inst.Len |
205 if err != nil || size == 0 || inst.Op == 0 { | 208 if err != nil || size == 0 || inst.Op == 0 { |
206 size = 1 | 209 size = 1 |
207 text = "?" | 210 text = "?" |
208 } else { | 211 } else { |
209 » » text = x86_plan9Syntax(inst, pc, lookup) | 212 » » text = x86asm.Plan9Syntax(inst, pc, lookup) |
210 } | 213 } |
211 return text, size | 214 return text, size |
212 } | 215 } |
213 | 216 |
214 type textReader struct { | 217 type textReader struct { |
215 code []byte | 218 code []byte |
216 pc uint64 | 219 pc uint64 |
217 } | 220 } |
218 | 221 |
219 func (r textReader) ReadAt(data []byte, off int64) (n int, err error) { | 222 func (r textReader) ReadAt(data []byte, off int64) (n int, err error) { |
220 if off < 0 || uint64(off) < r.pc { | 223 if off < 0 || uint64(off) < r.pc { |
221 return 0, io.EOF | 224 return 0, io.EOF |
222 } | 225 } |
223 d := uint64(off) - r.pc | 226 d := uint64(off) - r.pc |
224 if d >= uint64(len(r.code)) { | 227 if d >= uint64(len(r.code)) { |
225 return 0, io.EOF | 228 return 0, io.EOF |
226 } | 229 } |
227 n = copy(data, r.code[d:]) | 230 n = copy(data, r.code[d:]) |
228 if n < len(data) { | 231 if n < len(data) { |
229 err = io.ErrUnexpectedEOF | 232 err = io.ErrUnexpectedEOF |
230 } | 233 } |
231 return | 234 return |
232 } | 235 } |
233 | 236 |
234 func disasm_arm(code []byte, pc uint64, lookup lookupFunc) (string, int) { | 237 func disasm_arm(code []byte, pc uint64, lookup lookupFunc) (string, int) { |
235 » inst, err := arm_Decode(code, arm_ModeARM) | 238 » inst, err := armasm.Decode(code, armasm.ModeARM) |
236 var text string | 239 var text string |
237 size := inst.Len | 240 size := inst.Len |
238 if err != nil || size == 0 || inst.Op == 0 { | 241 if err != nil || size == 0 || inst.Op == 0 { |
239 size = 4 | 242 size = 4 |
240 text = "?" | 243 text = "?" |
241 } else { | 244 } else { |
242 » » text = arm_plan9Syntax(inst, pc, lookup, textReader{code, pc}) | 245 » » text = armasm.Plan9Syntax(inst, pc, lookup, textReader{code, pc}
) |
243 } | 246 } |
244 return text, size | 247 return text, size |
245 } | 248 } |
246 | 249 |
247 var disasms = map[string]disasmFunc{ | 250 var disasms = map[string]disasmFunc{ |
248 "386": disasm_386, | 251 "386": disasm_386, |
249 "amd64": disasm_amd64, | 252 "amd64": disasm_amd64, |
250 "arm": disasm_arm, | 253 "arm": disasm_arm, |
251 } | 254 } |
252 | 255 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 {[]byte("\x00\x00\x04\x07"), plan9Symbols}, // mips | 521 {[]byte("\x00\x00\x04\x07"), plan9Symbols}, // mips |
519 {[]byte("\x00\x00\x06\x47"), plan9Symbols}, // arm | 522 {[]byte("\x00\x00\x06\x47"), plan9Symbols}, // arm |
520 {[]byte("\x00\x00\x8A\x97"), plan9Symbols}, // amd64 | 523 {[]byte("\x00\x00\x8A\x97"), plan9Symbols}, // amd64 |
521 } | 524 } |
522 | 525 |
523 type byAddr []Sym | 526 type byAddr []Sym |
524 | 527 |
525 func (x byAddr) Len() int { return len(x) } | 528 func (x byAddr) Len() int { return len(x) } |
526 func (x byAddr) Swap(i, j int) { x[i], x[j] = x[j], x[i] } | 529 func (x byAddr) Swap(i, j int) { x[i], x[j] = x[j], x[i] } |
527 func (x byAddr) Less(i, j int) bool { return x[i].Addr < x[j].Addr } | 530 func (x byAddr) Less(i, j int) bool { return x[i].Addr < x[j].Addr } |
OLD | NEW |