diff --git a/chore/nmdump/nmdump.go b/chore/nmdump/nmdump.go index 5998905a..d14a6b5e 100644 --- a/chore/nmdump/nmdump.go +++ b/chore/nmdump/nmdump.go @@ -18,9 +18,10 @@ package main import ( "fmt" + "log" "os" - "github.com/goplus/llgo/x/nm" + "github.com/goplus/llgo/x/env/llvm" ) func main() { @@ -29,9 +30,8 @@ func main() { return } - nm := nm.New("nm") + nm := llvm.New().Nm() items, err := nm.List(os.Args[1]) - check(err) for _, item := range items { if item.File != "" { fmt.Printf("\n%s:\n", item.File) @@ -44,10 +44,7 @@ func main() { } } } -} - -func check(err error) { if err != nil { - panic(err) + log.Println(err) } } diff --git a/chore/nmindex/nmindex.go b/chore/nmindex/nmindex.go index b20bc53e..29e7304d 100644 --- a/chore/nmindex/nmindex.go +++ b/chore/nmindex/nmindex.go @@ -64,6 +64,7 @@ func makeIndex() { usrLib(true), stdLib("LLGO_STDROOT"), stdLib("LLGO_USRROOT"), + pythonLib(), } err := b.Index(libDirs, idxDir, func(path string) { fmt.Println("==>", path) @@ -103,6 +104,10 @@ func usrLib(local bool) string { return "/usr/lib" } +func pythonLib() string { + return os.Getenv("LLGO_PYTHON_ROOT") +} + func check(err error) { if err != nil { panic(err) diff --git a/x/nm/nm.go b/x/nm/nm.go index 6a909c2b..23ff57db 100644 --- a/x/nm/nm.go +++ b/x/nm/nm.go @@ -83,14 +83,15 @@ func (p *Cmd) List(arfile string) (items []*ObjectFile, err error) { cmd := exec.Command(p.app, arfile) cmd.Stdout = &stdout cmd.Stderr = &stderr - err = cmd.Run() + e := cmd.Run() if stderr.Len() > 0 { listError(stderr.Bytes()) } - if err != nil { - return + items, err = listOutput(stdout.Bytes()) + if err == nil { + err = e } - return listOutput(stdout.Bytes()) + return } func listError(data []byte) { @@ -138,7 +139,7 @@ func listOutput(data []byte) (items []*ObjectFile, err error) { Name: string(line[19:]), Type: SymbolType(line[17]), } - if sym.FAddr = line[0] != ' '; sym.FAddr { + if sym.FAddr = hasAddr(line); sym.FAddr { sym.Addr = hexUint64(line) } } else { @@ -146,7 +147,7 @@ func listOutput(data []byte) (items []*ObjectFile, err error) { Name: string(line[11:]), Type: SymbolType(line[9]), } - if sym.FAddr = line[0] != ' '; sym.FAddr { + if sym.FAddr = hasAddr(line); sym.FAddr { sym.Addr = uint64(hexUint32(line)) } } @@ -155,6 +156,11 @@ func listOutput(data []byte) (items []*ObjectFile, err error) { return } +func hasAddr(line []byte) bool { + c := line[0] + return c != ' ' && c != '-' +} + func is64bits(line []byte) bool { if line[0] != ' ' { return line[8] != ' '