github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/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/go-delve/delve/pkg/dwarf/op"
     9  	"github.com/go-delve/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 begin 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):  {regnum.I386_Eax, 0, mask8},
    47  	int(x86asm.CL):  {regnum.I386_Ecx, 0, mask8},
    48  	int(x86asm.DL):  {regnum.I386_Edx, 0, mask8},
    49  	int(x86asm.BL):  {regnum.I386_Ebx, 0, mask8},
    50  	int(x86asm.AH):  {regnum.I386_Eax, 8, mask8},
    51  	int(x86asm.CH):  {regnum.I386_Ecx, 8, mask8},
    52  	int(x86asm.DH):  {regnum.I386_Edx, 8, mask8},
    53  	int(x86asm.BH):  {regnum.I386_Ebx, 8, mask8},
    54  	int(x86asm.SPB): {regnum.I386_Esp, 0, mask8},
    55  	int(x86asm.BPB): {regnum.I386_Ebp, 0, mask8},
    56  	int(x86asm.SIB): {regnum.I386_Esi, 0, mask8},
    57  	int(x86asm.DIB): {regnum.I386_Edi, 0, mask8},
    58  
    59  	// 16-bit
    60  	int(x86asm.AX): {regnum.I386_Eax, 0, mask16},
    61  	int(x86asm.CX): {regnum.I386_Ecx, 0, mask16},
    62  	int(x86asm.DX): {regnum.I386_Edx, 0, mask16},
    63  	int(x86asm.BX): {regnum.I386_Ebx, 0, mask16},
    64  	int(x86asm.SP): {regnum.I386_Esp, 0, mask16},
    65  	int(x86asm.BP): {regnum.I386_Ebp, 0, mask16},
    66  	int(x86asm.SI): {regnum.I386_Esi, 0, mask16},
    67  	int(x86asm.DI): {regnum.I386_Edi, 0, mask16},
    68  
    69  	// 32-bit
    70  	int(x86asm.EAX): {regnum.I386_Eax, 0, mask32},
    71  	int(x86asm.ECX): {regnum.I386_Ecx, 0, mask32},
    72  	int(x86asm.EDX): {regnum.I386_Edx, 0, mask32},
    73  	int(x86asm.EBX): {regnum.I386_Ebx, 0, mask32},
    74  	int(x86asm.ESP): {regnum.I386_Esp, 0, mask32},
    75  	int(x86asm.EBP): {regnum.I386_Ebp, 0, mask32},
    76  	int(x86asm.ESI): {regnum.I386_Esi, 0, mask32},
    77  	int(x86asm.EDI): {regnum.I386_Edi, 0, mask32},
    78  }