llgo/xtool/nm/nmindex

This commit is contained in:
xushiwei
2024-07-28 22:51:35 +08:00
parent 3a8642b1e0
commit bae40c82b9
3 changed files with 15 additions and 11 deletions

View File

@@ -21,7 +21,7 @@ import (
"os"
"github.com/goplus/llgo/xtool/env/llvm"
"github.com/goplus/llgo/xtool/nm"
"github.com/goplus/llgo/xtool/nm/nmindex"
)
func main() {
@@ -58,7 +58,7 @@ func makeIndex() {
idxDir := indexDir()
os.MkdirAll(idxDir, 0755)
b := nm.NewIndexBuilder(env.Nm())
b := nmindex.NewIndexBuilder(env.Nm())
libDirs := []string{
usrLib(false),
usrLib(true),
@@ -78,7 +78,7 @@ func query(q string) {
q = "_" + q
}
}
files, err := nm.Query(indexDir(), q)
files, err := nmindex.Query(indexDir(), q)
check(err)
for _, f := range files {
fmt.Printf("%s:\n", f.ArFile)

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package nm
package nmindex
import (
"bytes"
@@ -24,13 +24,15 @@ import (
"os"
"path/filepath"
"strings"
"github.com/goplus/llgo/xtool/nm"
)
type IndexBuilder struct {
nm *Cmd
nm *nm.Cmd
}
func NewIndexBuilder(nm *Cmd) *IndexBuilder {
func NewIndexBuilder(nm *nm.Cmd) *IndexBuilder {
return &IndexBuilder{nm}
}
@@ -95,12 +97,12 @@ func (p *IndexBuilder) IndexFile(arFile, outFile string) (err error) {
}
for _, sym := range item.Symbols {
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(' ')
b.WriteString(sym.Name)
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") {
log.Printf("skip symbol type %c: %s\n", sym.Type, sym.Name)

View File

@@ -14,19 +14,21 @@
* limitations under the License.
*/
package nm
package nmindex
import (
"bufio"
"os"
"strings"
"github.com/goplus/llgo/xtool/nm"
)
// MatchedItem represents a matched item
type MatchedItem struct {
ObjFile string
Symbol string
Type SymbolType
Type nm.SymbolType
}
// MatchedFile represents a matched file
@@ -88,7 +90,7 @@ func queryIndex(files []*MatchedFile, idxFile, query string) []*MatchedFile {
items = append(items, &MatchedItem{
ObjFile: objFile,
Symbol: sym,
Type: SymbolType(typ),
Type: nm.SymbolType(typ),
})
}
if len(items) > 0 {