llgo/xtool/nm/nmindex
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/goplus/llgo/xtool/env/llvm"
|
"github.com/goplus/llgo/xtool/env/llvm"
|
||||||
"github.com/goplus/llgo/xtool/nm"
|
"github.com/goplus/llgo/xtool/nm/nmindex"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -58,7 +58,7 @@ func makeIndex() {
|
|||||||
idxDir := indexDir()
|
idxDir := indexDir()
|
||||||
os.MkdirAll(idxDir, 0755)
|
os.MkdirAll(idxDir, 0755)
|
||||||
|
|
||||||
b := nm.NewIndexBuilder(env.Nm())
|
b := nmindex.NewIndexBuilder(env.Nm())
|
||||||
libDirs := []string{
|
libDirs := []string{
|
||||||
usrLib(false),
|
usrLib(false),
|
||||||
usrLib(true),
|
usrLib(true),
|
||||||
@@ -78,7 +78,7 @@ func query(q string) {
|
|||||||
q = "_" + q
|
q = "_" + q
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
files, err := nm.Query(indexDir(), q)
|
files, err := nmindex.Query(indexDir(), q)
|
||||||
check(err)
|
check(err)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
fmt.Printf("%s:\n", f.ArFile)
|
fmt.Printf("%s:\n", f.ArFile)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package nm
|
package nmindex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -24,13 +24,15 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/xtool/nm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexBuilder struct {
|
type IndexBuilder struct {
|
||||||
nm *Cmd
|
nm *nm.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIndexBuilder(nm *Cmd) *IndexBuilder {
|
func NewIndexBuilder(nm *nm.Cmd) *IndexBuilder {
|
||||||
return &IndexBuilder{nm}
|
return &IndexBuilder{nm}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,12 +97,12 @@ func (p *IndexBuilder) IndexFile(arFile, outFile string) (err error) {
|
|||||||
}
|
}
|
||||||
for _, sym := range item.Symbols {
|
for _, sym := range item.Symbols {
|
||||||
switch sym.Type {
|
switch sym.Type {
|
||||||
case Text, Data, BSS, Rodata, 'S', 'C', 'W', 'A':
|
case nm.Text, nm.Data, nm.BSS, nm.Rodata, 'S', 'C', 'W', 'A':
|
||||||
b.WriteByte(byte(sym.Type))
|
b.WriteByte(byte(sym.Type))
|
||||||
b.WriteByte(' ')
|
b.WriteByte(' ')
|
||||||
b.WriteString(sym.Name)
|
b.WriteString(sym.Name)
|
||||||
b.WriteByte('\n')
|
b.WriteByte('\n')
|
||||||
case Undefined, LocalText, LocalData, LocalBSS, LocalASym, 'I', 'i', 'a', 'w':
|
case nm.Undefined, nm.LocalText, nm.LocalData, nm.LocalBSS, nm.LocalASym, 'I', 'i', 'a', 'w':
|
||||||
/*
|
/*
|
||||||
if sym.Type != Undefined && strings.Contains(sym.Name, "fprintf") {
|
if sym.Type != Undefined && strings.Contains(sym.Name, "fprintf") {
|
||||||
log.Printf("skip symbol type %c: %s\n", sym.Type, sym.Name)
|
log.Printf("skip symbol type %c: %s\n", sym.Type, sym.Name)
|
||||||
@@ -14,19 +14,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package nm
|
package nmindex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/xtool/nm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MatchedItem represents a matched item
|
// MatchedItem represents a matched item
|
||||||
type MatchedItem struct {
|
type MatchedItem struct {
|
||||||
ObjFile string
|
ObjFile string
|
||||||
Symbol string
|
Symbol string
|
||||||
Type SymbolType
|
Type nm.SymbolType
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchedFile represents a matched file
|
// MatchedFile represents a matched file
|
||||||
@@ -88,7 +90,7 @@ func queryIndex(files []*MatchedFile, idxFile, query string) []*MatchedFile {
|
|||||||
items = append(items, &MatchedItem{
|
items = append(items, &MatchedItem{
|
||||||
ObjFile: objFile,
|
ObjFile: objFile,
|
||||||
Symbol: sym,
|
Symbol: sym,
|
||||||
Type: SymbolType(typ),
|
Type: nm.SymbolType(typ),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if len(items) > 0 {
|
if len(items) > 0 {
|
||||||
Reference in New Issue
Block a user