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