nmindex support python

This commit is contained in:
xushiwei
2024-05-09 12:03:21 +08:00
parent d4dd0c00ff
commit 329f65a1ad
3 changed files with 21 additions and 13 deletions

View File

@@ -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)
}
}

View File

@@ -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)

View File

@@ -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] != ' '