From a1948edcfd94de6b8cc65b7074bcfdcb42034ef8 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Wed, 19 Jun 2024 23:55:28 +0800 Subject: [PATCH] refactor: update symbol api Signed-off-by: Zxilly --- internal/entity/knownaddr.go | 20 ++++++++++---------- internal/entity/package.go | 4 ++-- internal/knowninfo/dwarf.go | 13 +++++++++---- internal/knowninfo/symbol.go | 6 ++++-- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/internal/entity/knownaddr.go b/internal/entity/knownaddr.go index 248eb592b5..2790052895 100644 --- a/internal/entity/knownaddr.go +++ b/internal/entity/knownaddr.go @@ -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, @@ -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, diff --git a/internal/entity/package.go b/internal/entity/package.go index 8ab0c7ed31..59a1ac0537 100644 --- a/internal/entity/package.go +++ b/internal/entity/package.go @@ -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) } diff --git a/internal/knowninfo/dwarf.go b/internal/knowninfo/dwarf.go index 2bb494f770..315a388f8a 100644 --- a/internal/knowninfo/dwarf.go +++ b/internal/knowninfo/dwarf.go @@ -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 { @@ -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) } } } diff --git a/internal/knowninfo/symbol.go b/internal/knowninfo/symbol.go index d888e4b486..4b7be9d18e 100644 --- a/internal/knowninfo/symbol.go +++ b/internal/knowninfo/symbol.go @@ -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 }