From 01d0338851a3c3cbeaa6fc8ab3856c81bccf0d95 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Mon, 29 Jul 2024 17:21:32 +0800 Subject: [PATCH] c/clang/symg:use llvm to demangle name --- chore/_xtool/llcppsymg/llcppsymg.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/chore/_xtool/llcppsymg/llcppsymg.go b/chore/_xtool/llcppsymg/llcppsymg.go index cfc05998..00486d13 100644 --- a/chore/_xtool/llcppsymg/llcppsymg.go +++ b/chore/_xtool/llcppsymg/llcppsymg.go @@ -32,6 +32,7 @@ import ( "github.com/goplus/llgo/c" "github.com/goplus/llgo/c/cjson" "github.com/goplus/llgo/chore/llcppg/types" + "github.com/goplus/llgo/cpp/llvm" ) func main() { @@ -53,8 +54,8 @@ func main() { if err != nil { fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile) } - symbols, err := parseDylibSymbols(config.Libs) + check(err) files, err := parseHeaderFile(config) @@ -109,7 +110,7 @@ func getConf(data []byte) (config types.Config, err error) { func parseDylibSymbols(lib string) ([]types.CPPSymbol, error) { dylibPath, _ := generateDylibPath(lib) nmCmd := exec.Command("nm", "-gU", dylibPath) - nmOutput, err := nmCmd.Output() + nmOutput, err := nmCmd.Output() // maybe lock if err != nil { return nil, errors.New("failed to execute nm command") } @@ -171,13 +172,9 @@ func parseNmOutput(output []byte) []types.CPPSymbol { } func decodeSymbolName(symbolName string) (string, error) { - cppfiltCmd := exec.Command("c++filt", symbolName) - cppfiltOutput, err := cppfiltCmd.Output() - if err != nil { - return "", errors.New("failed to execute c++filt command") - } - - decodedName := strings.TrimSpace(string(cppfiltOutput)) + llvm.ItaniumDemangle(symbolName, true) + demangleName := c.GoString(llvm.ItaniumDemangle(symbolName, true)) + decodedName := strings.TrimSpace(string(demangleName)) decodedName = strings.ReplaceAll(decodedName, "std::__1::basic_string, std::__1::allocator > const", "std::string") return decodedName, nil }