Skip to content

Commit

Permalink
refactor: update symbol api
Browse files Browse the repository at this point in the history
Signed-off-by: Zxilly <[email protected]>
  • Loading branch information
Zxilly committed Jun 19, 2024
1 parent b3cfa6a commit a1948ed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
20 changes: 10 additions & 10 deletions internal/entity/knownaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ func (f *KnownAddr) InsertTextFromDWARF(entry uint64, size uint64, fn *Function,
f.TextAddrSpace.Insert(&cur)
}

func (f *KnownAddr) InsertSymbol(entry uint64, size uint64, p *Package, typ AddrType, meta SymbolMeta) *Addr {
func (f *KnownAddr) InsertSymbol(symbol *Symbol, p *Package, meta SymbolMeta) *Addr {
cur := &Addr{
AddrPos: &AddrPos{
Addr: entry,
Size: size,
Type: typ,
Addr: symbol.Addr,
Size: symbol.Size,
Type: symbol.Type,
},
Pkg: p,
Function: nil,
Symbol: NewSymbol(meta.SymbolName, entry, size, typ),
Symbol: symbol,
SourceType: AddrSourceSymbol,

Meta: meta,
Expand All @@ -70,16 +70,16 @@ func (f *KnownAddr) InsertSymbol(entry uint64, size uint64, p *Package, typ Addr
return cur
}

func (f *KnownAddr) InsertSymbolFromDWARF(entry uint64, size uint64, p *Package, typ AddrType, meta SymbolMeta) *Addr {
func (f *KnownAddr) InsertSymbolFromDWARF(symbol *Symbol, p *Package, meta SymbolMeta) *Addr {
cur := &Addr{
AddrPos: &AddrPos{
Addr: entry,
Size: size,
Type: typ,
Addr: symbol.Addr,
Size: symbol.Size,
Type: symbol.Type,
},
Pkg: p,
Function: nil,
Symbol: NewSymbol(meta.SymbolName, entry, size, typ),
Symbol: symbol,
SourceType: AddrSourceDwarf,

Meta: meta,
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ func (p *Package) AssignPackageSize() {
p.Size = pkgSize
}

func (p *Package) AddSymbol(addr uint64, size uint64, typ AddrType, name string, ap *Addr) {
func (p *Package) AddSymbol(symbol *Symbol, ap *Addr) {
// first, load as coverage
p.symbolAddrSpace.Insert(ap)

// then, add to the symbol list
p.Symbols = append(p.Symbols, NewSymbol(name, addr, size, typ))
p.Symbols = append(p.Symbols, symbol)
}
13 changes: 9 additions & 4 deletions internal/knowninfo/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ func (k *KnownInfo) AddDwarfVariable(entry *dwarf.Entry, d *dwarf.Data, pkg *ent

entryName := utils.Deduplicate(entry.Val(dwarf.AttrName).(string))

ap := k.KnownAddr.InsertSymbolFromDWARF(uint64(addr), typSize, pkg, entity.AddrTypeData, entity.SymbolMeta{
symbol := entity.NewSymbol(entryName, uint64(addr), typSize, entity.AddrTypeData)

ap := k.KnownAddr.InsertSymbolFromDWARF(symbol, pkg, entity.SymbolMeta{
SymbolName: entryName,
PackageName: utils.Deduplicate(pkg.Name),
})

pkg.AddSymbol(uint64(addr), typSize, entity.AddrTypeData, entryName, ap)
pkg.AddSymbol(symbol, ap)

if len(contents) > 0 {
for _, content := range contents {
Expand All @@ -79,12 +81,15 @@ func (k *KnownInfo) AddDwarfVariable(entry *dwarf.Entry, d *dwarf.Data, pkg *ent
}

valueName := utils.Deduplicate(fmt.Sprintf("%s.%s", entryName, content.Name))
ap = k.KnownAddr.InsertSymbolFromDWARF(content.Addr, content.Size, pkg, entity.AddrTypeData, entity.SymbolMeta{

symbol := entity.NewSymbol(valueName, content.Addr, content.Size, entity.AddrTypeData)

ap = k.KnownAddr.InsertSymbolFromDWARF(symbol, pkg, entity.SymbolMeta{
SymbolName: valueName,
PackageName: utils.Deduplicate(pkg.Name),
})

pkg.AddSymbol(content.Addr, content.Size, entity.AddrTypeData, valueName, ap)
pkg.AddSymbol(symbol, ap)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/knowninfo/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ func (k *KnownInfo) MarkSymbol(name string, addr, size uint64, typ entity.AddrTy
}
}

ap := k.KnownAddr.InsertSymbol(addr, size, pkg, typ, entity.SymbolMeta{
symbol := entity.NewSymbol(name, addr, size, typ)

ap := k.KnownAddr.InsertSymbol(symbol, pkg, entity.SymbolMeta{
SymbolName: utils.Deduplicate(name),
PackageName: utils.Deduplicate(pkgName),
})

pkg.AddSymbol(addr, size, typ, name, ap)
pkg.AddSymbol(symbol, ap)

return nil
}
Expand Down

0 comments on commit a1948ed

Please sign in to comment.