File: i386_disasm.go

package info (click to toggle)
delve 1.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,136 kB
  • sloc: ansic: 111,947; sh: 194; asm: 147; makefile: 43; python: 23
file content (78 lines) | stat: -rw-r--r-- 3,185 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// TODO: disassembler support should be compiled in unconditionally,
// instead of being decided by the build-target architecture, and be
// part of the Arch object instead.

package proc

import (
	"github.com/go-delve/delve/pkg/dwarf/op"
	"github.com/go-delve/delve/pkg/dwarf/regnum"

	"golang.org/x/arch/x86/x86asm"
)

func i386AsmDecode(asmInst *AsmInstruction, mem []byte, regs *op.DwarfRegisters, memrw MemoryReadWriter, bi *BinaryInfo) error {
	return x86AsmDecode(asmInst, mem, regs, memrw, bi, 32)
}

// Possible stacksplit prologues are inserted by stacksplit in
// $GOROOT/src/cmd/internal/obj/x86/obj6.go.
// If 386 on linux when pie, the stacksplit prologue begin with `call __x86.get_pc_thunk.` sometime.
var prologuesI386 []opcodeSeq

func init() {
	var i386GetPcIns = opcodeSeq{uint64(x86asm.CALL)}
	var tinyStacksplit = opcodeSeq{uint64(x86asm.CMP), uint64(x86asm.JBE)}
	var smallStacksplit = opcodeSeq{uint64(x86asm.LEA), uint64(x86asm.CMP), uint64(x86asm.JBE)}
	var bigStacksplit = opcodeSeq{uint64(x86asm.MOV), uint64(x86asm.CMP), uint64(x86asm.JE), uint64(x86asm.LEA), uint64(x86asm.SUB), uint64(x86asm.CMP), uint64(x86asm.JBE)}
	var unixGetG = opcodeSeq{uint64(x86asm.MOV), uint64(x86asm.MOV)}

	prologuesI386 = make([]opcodeSeq, 0, 2*3)
	for _, getPcIns := range []opcodeSeq{{}, i386GetPcIns} {
		for _, getG := range []opcodeSeq{unixGetG} { // TODO(chainhelen), need to support other OSs.
			for _, stacksplit := range []opcodeSeq{tinyStacksplit, smallStacksplit, bigStacksplit} {
				prologue := make(opcodeSeq, 0, len(getPcIns)+len(getG)+len(stacksplit))
				prologue = append(prologue, getPcIns...)
				prologue = append(prologue, getG...)
				prologue = append(prologue, stacksplit...)
				prologuesI386 = append(prologuesI386, prologue)
			}
		}
	}
}

var i386AsmRegisters = map[int]asmRegister{
	// 8-bit
	int(x86asm.AL):  {regnum.I386_Eax, 0, mask8},
	int(x86asm.CL):  {regnum.I386_Ecx, 0, mask8},
	int(x86asm.DL):  {regnum.I386_Edx, 0, mask8},
	int(x86asm.BL):  {regnum.I386_Ebx, 0, mask8},
	int(x86asm.AH):  {regnum.I386_Eax, 8, mask8},
	int(x86asm.CH):  {regnum.I386_Ecx, 8, mask8},
	int(x86asm.DH):  {regnum.I386_Edx, 8, mask8},
	int(x86asm.BH):  {regnum.I386_Ebx, 8, mask8},
	int(x86asm.SPB): {regnum.I386_Esp, 0, mask8},
	int(x86asm.BPB): {regnum.I386_Ebp, 0, mask8},
	int(x86asm.SIB): {regnum.I386_Esi, 0, mask8},
	int(x86asm.DIB): {regnum.I386_Edi, 0, mask8},

	// 16-bit
	int(x86asm.AX): {regnum.I386_Eax, 0, mask16},
	int(x86asm.CX): {regnum.I386_Ecx, 0, mask16},
	int(x86asm.DX): {regnum.I386_Edx, 0, mask16},
	int(x86asm.BX): {regnum.I386_Ebx, 0, mask16},
	int(x86asm.SP): {regnum.I386_Esp, 0, mask16},
	int(x86asm.BP): {regnum.I386_Ebp, 0, mask16},
	int(x86asm.SI): {regnum.I386_Esi, 0, mask16},
	int(x86asm.DI): {regnum.I386_Edi, 0, mask16},

	// 32-bit
	int(x86asm.EAX): {regnum.I386_Eax, 0, mask32},
	int(x86asm.ECX): {regnum.I386_Ecx, 0, mask32},
	int(x86asm.EDX): {regnum.I386_Edx, 0, mask32},
	int(x86asm.EBX): {regnum.I386_Ebx, 0, mask32},
	int(x86asm.ESP): {regnum.I386_Esp, 0, mask32},
	int(x86asm.EBP): {regnum.I386_Ebp, 0, mask32},
	int(x86asm.ESI): {regnum.I386_Esi, 0, mask32},
	int(x86asm.EDI): {regnum.I386_Edi, 0, mask32},
}