Skip to content

Commit

Permalink
refactor: move known info files
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Jun 8, 2024
1 parent bdc1f20 commit 3797871
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 264 deletions.
37 changes: 21 additions & 16 deletions internal/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"errors"
"github.com/Zxilly/go-size-analyzer/internal/knowninfo"
"io"
"log/slog"
"path"
Expand Down Expand Up @@ -30,15 +31,15 @@ func Analyze(name string, reader io.ReaderAt, size uint64, options Options) (*re
slog.Info("Parsing binary done")
slog.Info("Finding build info...")

k := &KnownInfo{
k := &knowninfo.KnownInfo{
Size: size,
BuildInfo: file.BuildInfo,

gore: file,
wrapper: wrapper.NewWrapper(file.GetParsedFile()),
Gore: file,
Wrapper: wrapper.NewWrapper(file.GetParsedFile()),
}
k.KnownAddr = entity.NewKnownAddr()
k.UpdateVersionFlag()
k.VersionFlag = k.UpdateVersionFlag()

slog.Info("Build info found")

Expand All @@ -52,21 +53,25 @@ func Analyze(name string, reader io.ReaderAt, size uint64, options Options) (*re
return nil, err
}

if !options.SkipSymbol {
err = k.AnalyzeSymbol()
if err != nil {
if !errors.Is(err, wrapper.ErrNoSymbolTable) {
return nil, err

ok := k.TryLoadDwarf()
if !ok {
// fallback to symbol and disasm
if !options.SkipSymbol {
err = k.AnalyzeSymbol()
if err != nil {
if !errors.Is(err, wrapper.ErrNoSymbolTable) {
return nil, err

}

Check warning on line 65 in internal/analyze.go

View check run for this annotation

Codecov / codecov/patch

internal/analyze.go#L63-L65

Added lines #L63 - L65 were not covered by tests
slog.Warn("Warning: no symbol table found, this can lead to inaccurate results")
}
slog.Warn("Warning: no symbol table found, this can lead to inaccurate results")
}
}

if !options.SkipDisasm {
err = k.Disasm()
if err != nil {
return nil, err
if !options.SkipDisasm {
err = k.Disasm()
if err != nil {
return nil, err
}

Check warning on line 74 in internal/analyze.go

View check run for this annotation

Codecov / codecov/patch

internal/analyze.go#L73-L74

Added lines #L73 - L74 were not covered by tests
}
}

Expand Down
18 changes: 18 additions & 0 deletions internal/entity/knownaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type KnownAddr struct {

Symbol AddrSpace
SymbolCoverage AddrCoverage

Dwarf AddrSpace
}

func NewKnownAddr() *KnownAddr {
Expand Down Expand Up @@ -104,3 +106,19 @@ func (f *KnownAddr) InsertDisasm(entry uint64, size uint64, fn *Function, meta D

fn.disasm.Insert(&cur)
}

func (f *KnownAddr) InsertDwarf(entry uint64, size uint64, typ AddrType, pkg *Package, meta DwarfMeta) {
cur := Addr{
AddrPos: &AddrPos{
Addr: entry,
Size: size,
Type: typ,
},
Pkg: pkg,
Function: nil,
SourceType: AddrSourceDwarf,
Meta: meta,
}

f.Dwarf.Insert(&cur)

Check warning on line 123 in internal/entity/knownaddr.go

View check run for this annotation

Codecov / codecov/patch

internal/entity/knownaddr.go#L110-L123

Added lines #L110 - L123 were not covered by tests
}
3 changes: 3 additions & 0 deletions internal/entity/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ type SymbolMeta struct {
type DisasmMeta struct {
Value string
}

type DwarfMeta struct {
}
1 change: 1 addition & 0 deletions internal/entity/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ const (
AddrSourceGoPclntab AddrSourceType = "pclntab"
AddrSourceSymbol AddrSourceType = "symbol"
AddrSourceDisasm AddrSourceType = "disasm"
AddrSourceDwarf AddrSourceType = "dwarf"
)
229 changes: 0 additions & 229 deletions internal/knowninfo.go

This file was deleted.

Loading

0 comments on commit 3797871

Please sign in to comment.