github.com/undoio/delve@v1.9.0/pkg/dwarf/dwarfbuilder/loc.go (about)

     1  package dwarfbuilder
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/undoio/delve/pkg/dwarf/op"
     7  	"github.com/undoio/delve/pkg/dwarf/util"
     8  )
     9  
    10  // LocEntry represents one entry of debug_loc.
    11  type LocEntry struct {
    12  	Lowpc  uint64
    13  	Highpc uint64
    14  	Loc    []byte
    15  }
    16  
    17  // LocationBlock returns a DWARF expression corresponding to the list of
    18  // arguments.
    19  func LocationBlock(args ...interface{}) []byte {
    20  	var buf bytes.Buffer
    21  	for _, arg := range args {
    22  		switch x := arg.(type) {
    23  		case op.Opcode:
    24  			buf.WriteByte(byte(x))
    25  		case int:
    26  			util.EncodeSLEB128(&buf, int64(x))
    27  		case uint:
    28  			util.EncodeULEB128(&buf, uint64(x))
    29  		default:
    30  			panic("unsupported value type")
    31  		}
    32  	}
    33  	return buf.Bytes()
    34  }