Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Go Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style | |
3 // license that can be found in the LICENSE file. | |
4 | |
5 // Package arch contains architecture-specific definitions. | |
6 package arch | |
7 | |
8 import ( | |
9 "encoding/binary" | |
10 ) | |
11 | |
12 const MaxBreakpointSize = 4 // TODO | |
13 | |
14 // Architecture defines the architecture-specific details for a given machine. | |
15 type Architecture struct { | |
16 // The size of a breakpoint instruction, in bytes. | |
nigeltao
2014/04/09 05:23:49
The comment convention is to start with the name o
| |
17 BreakpointSize int | |
18 // The size of the int type, in bytes. | |
19 IntSize int | |
20 // The size of a pointer, in bytes. | |
21 PointerSize int | |
22 // The byte order for I/O. | |
23 ByteOrder binary.ByteOrder | |
24 BreakpointInstr []byte | |
nigeltao
2014/04/09 05:23:49
Would it be more consistent with a breakpoint.orig
| |
25 } | |
26 | |
27 func (a *Architecture) Int(buf []byte) int64 { | |
28 return int64(a.Uint(buf)) | |
29 } | |
30 | |
31 func (a *Architecture) Uint(buf []byte) uint64 { | |
32 if len(buf) != a.IntSize { | |
33 panic("uint size") | |
34 } | |
35 switch a.IntSize { | |
36 case 4: | |
37 return uint64(a.ByteOrder.Uint32(buf[:4])) | |
38 case 8: | |
39 return a.ByteOrder.Uint64(buf[:8]) | |
40 default: | |
nigeltao
2014/04/09 05:23:49
Slightly shorter is to drop the default and move t
| |
41 panic("no uint size") | |
nigeltao
2014/04/09 05:23:49
s/no/bad/ ?
| |
42 } | |
43 } | |
44 | |
45 var AMD64 = Architecture{ | |
46 BreakpointSize: 1, | |
47 IntSize: 8, | |
48 PointerSize: 8, | |
49 ByteOrder: binary.LittleEndian, | |
50 BreakpointInstr: []byte{0xCC}, // INT 3 | |
51 } | |
52 | |
53 var X86 = Architecture{ | |
54 BreakpointSize: 1, | |
55 IntSize: 4, | |
56 PointerSize: 4, | |
57 ByteOrder: binary.LittleEndian, | |
58 BreakpointInstr: []byte{0xCC}, // INT 3 | |
59 } | |
60 | |
61 var ARM = Architecture{ | |
62 BreakpointSize: 4, // TODO | |
63 IntSize: 4, | |
64 PointerSize: 4, | |
65 ByteOrder: binary.LittleEndian, | |
66 BreakpointInstr: []byte{0x00, 0x00, 0x00, 0x00}, // TODO | |
67 } | |
OLD | NEW |