github.com/undoio/delve@v1.9.0/pkg/proc/i386_disasm.go (about)

     1  // TODO: disassembler support should be compiled in unconditionally,
     2  // instead of being decided by the build-target architecture, and be
     3  // part of the Arch object instead.
     4  
     5  package proc
     6  
     7  import (
     8  	"github.com/undoio/delve/pkg/dwarf/op"
     9  	"github.com/undoio/delve/pkg/dwarf/regnum"
    10  
    11  	"golang.org/x/arch/x86/x86asm"
    12  )
    13  
    14  func i386AsmDecode(asmInst *AsmInstruction, mem []byte, regs *op.DwarfRegisters, memrw MemoryReadWriter, bi *BinaryInfo) error {
    15  	return x86AsmDecode(asmInst, mem, regs, memrw, bi, 32)
    16  }
    17  
    18  // Possible stacksplit prologues are inserted by stacksplit in
    19  // $GOROOT/src/cmd/internal/obj/x86/obj6.go.
    20  // If 386 on linux when pie, the stacksplit prologue beigin with `call __x86.get_pc_thunk.` sometime.
    21  var prologuesI386 []opcodeSeq
    22  
    23  func init() {
    24  	var i386GetPcIns = opcodeSeq{uint64(x86asm.CALL)}
    25  	var tinyStacksplit = opcodeSeq{uint64(x86asm.CMP), uint64(x86asm.JBE)}
    26  	var smallStacksplit = opcodeSeq{uint64(x86asm.LEA), uint64(x86asm.CMP), uint64(x86asm.JBE)}
    27  	var bigStacksplit = opcodeSeq{uint64(x86asm.MOV), uint64(x86asm.CMP), uint64(x86asm.JE), uint64(x86asm.LEA), uint64(x86asm.SUB), uint64(x86asm.CMP), uint64(x86asm.JBE)}
    28  	var unixGetG = opcodeSeq{uint64(x86asm.MOV), uint64(x86asm.MOV)}
    29  
    30  	prologuesI386 = make([]opcodeSeq, 0, 2*3)
    31  	for _, getPcIns := range []opcodeSeq{{}, i386GetPcIns} {
    32  		for _, getG := range []opcodeSeq{unixGetG} { // TODO(chainhelen), need to support other OSs.
    33  			for _, stacksplit := range []opcodeSeq{tinyStacksplit, smallStacksplit, bigStacksplit} {
    34  				prologue := make(opcodeSeq, 0, len(getPcIns)+len(getG)+len(stacksplit))
    35  				prologue = append(prologue, getPcIns...)
    36  				prologue = append(prologue, getG...)
    37  				prologue = append(prologue, stacksplit...)
    38  				prologuesI386 = append(prologuesI386, prologue)
    39  			}
    40  		}
    41  	}
    42  }
    43  
    44  var i386AsmRegisters = map[int]asmRegister{
    45  	// 8-bit
    46  	int(x86asm.AL):  asmRegister{regnum.I386_Eax, 0, mask8},
    47  	int(x86asm.CL):  asmRegister{regnum.I386_Ecx, 0, mask8},
    48  	int(x86asm.DL):  asmRegister{regnum.I386_Edx, 0, mask8},
    49  	int(x86asm.BL):  asmRegister{regnum.I386_Ebx, 0, mask8},
    50  	int(x86asm.AH):  asmRegister{regnum.I386_Eax, 8, mask8},
    51  	int(x86asm.CH):  asmRegister{regnum.I386_Ecx, 8, mask8},
    52  	int(x86asm.DH):  asmRegister{regnum.I386_Edx, 8, mask8},
    53  	int(x86asm.BH):  asmRegister{regnum.I386_Ebx, 8, mask8},
    54  	int(x86asm.SPB): asmRegister{regnum.I386_Esp, 0, mask8},
    55  	int(x86asm.BPB): asmRegister{regnum.I386_Ebp, 0, mask8},
    56  	int(x86asm.SIB): asmRegister{regnum.I386_Esi, 0, mask8},
    57  	int(x86asm.DIB): asmRegister{regnum.I386_Edi, 0, mask8},
    58  
    59  	// 16-bit
    60  	int(x86asm.AX): asmRegister{regnum.I386_Eax, 0, mask16},
    61  	int(x86asm.CX): asmRegister{regnum.I386_Ecx, 0, mask16},
    62  	int(x86asm.DX): asmRegister{regnum.I386_Edx, 0, mask16},
    63  	int(x86asm.BX): asmRegister{regnum.I386_Ebx, 0, mask16},
    64  	int(x86asm.SP): asmRegister{regnum.I386_Esp, 0, mask16},
    65  	int(x86asm.BP): asmRegister{regnum.I386_Ebp, 0, mask16},
    66  	int(x86asm.SI): asmRegister{regnum.I386_Esi, 0, mask16},
    67  	int(x86asm.DI): asmRegister{regnum.I386_Edi, 0, mask16},
    68  
    69  	// 32-bit
    70  	int(x86asm.EAX): asmRegister{regnum.I386_Eax, 0, mask32},
    71  	int(x86asm.ECX): asmRegister{regnum.I386_Ecx, 0, mask32},
    72  	int(x86asm.EDX): asmRegister{regnum.I386_Edx, 0, mask32},
    73  	int(x86asm.EBX): asmRegister{regnum.I386_Ebx, 0, mask32},
    74  	int(x86asm.ESP): asmRegister{regnum.I386_Esp, 0, mask32},
    75  	int(x86asm.EBP): asmRegister{regnum.I386_Ebp, 0, mask32},
    76  	int(x86asm.ESI): asmRegister{regnum.I386_Esi, 0, mask32},
    77  	int(x86asm.EDI): asmRegister{regnum.I386_Edi, 0, mask32},
    78  }