github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/pkg/dwarf/dwarfbuilder/loc.go (about)

     1  package dwarfbuilder
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/go-delve/delve/pkg/dwarf/leb128"
     7  	"github.com/go-delve/delve/pkg/dwarf/op"
     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  			leb128.EncodeSigned(&buf, int64(x))
    27  		case uint:
    28  			leb128.EncodeUnsigned(&buf, uint64(x))
    29  		default:
    30  			panic("unsupported value type")
    31  		}
    32  	}
    33  	return buf.Bytes()
    34  }