github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/agent/ebpfspy/symtab/simple.go (about)

     1  package symtab
     2  
     3  import (
     4  	"sort"
     5  )
     6  
     7  type SimpleSymbolTableEntry struct {
     8  	Entry uint64
     9  	End   uint64
    10  	Name  string
    11  }
    12  type SimpleSymbolTable struct {
    13  	symbols   []SimpleSymbolTableEntry
    14  	base      uint64
    15  	endOffset uint64
    16  }
    17  
    18  func NewSimpleSymbolTable(symbols []SimpleSymbolTableEntry) *SimpleSymbolTable {
    19  	return &SimpleSymbolTable{symbols: symbols}
    20  }
    21  
    22  func (t *SimpleSymbolTable) Rebase(base uint64) {
    23  	t.base = base
    24  }
    25  
    26  func (t *SimpleSymbolTable) Resolve(addr uint64) string {
    27  	if len(t.symbols) == 0 {
    28  		return ""
    29  	}
    30  	addr -= t.base
    31  	if addr < t.symbols[0].Entry || addr > t.symbols[len(t.symbols)-1].End {
    32  		return ""
    33  	}
    34  	i := sort.Search(len(t.symbols), func(i int) bool {
    35  		return addr < t.symbols[i].End
    36  	})
    37  	if i >= len(t.symbols) {
    38  		return ""
    39  	}
    40  	return t.symbols[i].Name
    41  }