From e5d789ddae43d4e65b2cbdd3e3eba635b795f35a Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 19 Apr 2024 20:55:23 +0800 Subject: [PATCH] nmdump: support .dylib/.so --- chore/nmdump/nmdump.go | 4 +++- x/nm/nm.go | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/chore/nmdump/nmdump.go b/chore/nmdump/nmdump.go index da9e4ba9..5998905a 100644 --- a/chore/nmdump/nmdump.go +++ b/chore/nmdump/nmdump.go @@ -33,7 +33,9 @@ func main() { items, err := nm.List(os.Args[1]) check(err) for _, item := range items { - fmt.Printf("\n%s:\n", item.File) + if item.File != "" { + fmt.Printf("\n%s:\n", item.File) + } for _, sym := range item.Symbols { if sym.FAddr { fmt.Printf("%016x %c %s\n", sym.Addr, sym.Type, sym.Name) diff --git a/x/nm/nm.go b/x/nm/nm.go index d9a2c161..99c7d65d 100644 --- a/x/nm/nm.go +++ b/x/nm/nm.go @@ -87,10 +87,14 @@ func (p *Cmd) List(arfile string) (items []*ObjectFile, err error) { } func listOutput(data []byte) (items []*ObjectFile, err error) { - var item *ObjectFile - var sep = []byte{'\n'} - for _, line := range bytes.Split(data, sep) { + sep := []byte{'\n'} + item := &ObjectFile{} + lines := bytes.Split(data, sep) + for _, line := range lines { if len(line) == 0 { + if item.File == "" && len(item.Symbols) > 0 { + items = append(items, item) + } item = nil continue }