github.com/tencent/goom@v1.0.1/internal/bytecode/ins_amd64.go (about)

     1  package bytecode
     2  
     3  import (
     4  	"github.com/tencent/goom/internal/arch/x86asm"
     5  	"github.com/tencent/goom/internal/logger"
     6  )
     7  
     8  // ParseIns parse instruction
     9  func ParseIns(pos int, copyOrigin []byte) (*x86asm.Inst, []byte, error) {
    10  	if pos >= len(copyOrigin) {
    11  		return nil, nil, nil
    12  	}
    13  	// read 16 bytes at most each time
    14  	endPos := pos + 16
    15  	if endPos > len(copyOrigin) {
    16  		endPos = len(copyOrigin)
    17  	}
    18  
    19  	code := copyOrigin[pos:endPos]
    20  	ins, err := x86asm.Decode(code, 64)
    21  	if err != nil {
    22  		logger.Error("decode assembly code err:", err)
    23  	}
    24  	return &ins, code, err
    25  }