If you want to get the original name by a library function, as Jonathan mentioned, you can call __cxa_demangle in cxxabi.h. However, this API is only available in gcc. If you want something more portable, try glog or libibert, notice libibert is GPL licensed. On Thu, Dec 11, 2014 at 7:57 AM, Roel Jordans <r.jordans at tue.nl> wrote:> When a C++ compiler translates source code it will perform name mangling > to avoid name collisions due to type overloading. You can use a tool like > c++filt to de-mangle the generated names > > Cheers, > Roel > > > On 11/12/14 11:52, zy jj wrote: > >> Hi, everyone! >> I'm new here trapped by a simple problem for days. >> When LLVM translates C++ source code to IR, it will add a prefix to >> the function name. For example: >> source code: >> int foo(){ >> return 1; >> } >> IR form: >> define i32 @_Z3foov() #0 { >> entry: >> ret i32 1, !dbg !20 >> } >> The getName() method returns _Z3foov, then how can I get foo? I >> know the debugging information is contained in metadata, but I've no >> idea on using it. >> Thanks a lot for any help. >> >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- - Welson -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141211/5db3d7de/attachment.html>
Nick Lewycky
2014-Dec-11 20:24 UTC
[LLVMdev] How to get the original function name in C++?
Welson Sun wrote:> If you want to get the original name by a library function, as Jonathan > mentioned, you can call __cxa_demangle in cxxabi.h. However, this API is > only available in gcc.Huh? It's defined in the C++ ABI standard: http://mentorembedded.github.io/cxx-abi/abi.html#demangler There are implementations in libstdc++, libcxxabi and libcxxrt. If you want something more portable, try glog or> libibert, notice libibert is GPL licensed. > > On Thu, Dec 11, 2014 at 7:57 AM, Roel Jordans <r.jordans at tue.nl > <mailto:r.jordans at tue.nl>> wrote: > > When a C++ compiler translates source code it will perform name > mangling to avoid name collisions due to type overloading. You can > use a tool like c++filt to de-mangle the generated names > > Cheers, > Roel > > > On 11/12/14 11:52, zy jj wrote: > > Hi, everyone! > I'm new here trapped by a simple problem for days. > When LLVM translates C++ source code to IR, it will add a > prefix to > the function name. For example: > source code: > int foo(){ > return 1; > } > IR form: > define i32 @_Z3foov() #0 { > entry: > ret i32 1, !dbg !20 > } > The getName() method returns _Z3foov, then how can I get > foo? I > know the debugging information is contained in metadata, but I've no > idea on using it. > Thanks a lot for any help. > > > > > ______________________________ _________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> > http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/ mailman/listinfo/llvmdev > <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> > > ______________________________ _________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/ mailman/listinfo/llvmdev > <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> > > > > > -- > - Welson > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Nick is right. Sorry for the confusion. I am actually trying to find one demangle library (for Itanium C++ ABI) that is not GPL, and can be compiled with Visual C++. I am currently using the one in glog, but just bumped into a bug which failed on demangling a function name. libcxxabi says only support OSX, I compiled it fine with xcode 6.1, but Linux gcc-4.8.0 emits a lot of errors, haven't tried Visual C yet. Anybody tried libstdc++, libcxxrt with Visual C++ yet? -Welson On Thu, Dec 11, 2014 at 12:24 PM, Nick Lewycky <nicholas at mxc.ca> wrote:> Welson Sun wrote: > >> If you want to get the original name by a library function, as Jonathan >> mentioned, you can call __cxa_demangle in cxxabi.h. However, this API is >> only available in gcc. >> > > Huh? It's defined in the C++ ABI standard: http://mentorembedded.github. > io/cxx-abi/abi.html#demangler > > There are implementations in libstdc++, libcxxabi and libcxxrt. > > If you want something more portable, try glog or > >> libibert, notice libibert is GPL licensed. >> >> On Thu, Dec 11, 2014 at 7:57 AM, Roel Jordans <r.jordans at tue.nl >> <mailto:r.jordans at tue.nl>> wrote: >> >> When a C++ compiler translates source code it will perform name >> mangling to avoid name collisions due to type overloading. You can >> use a tool like c++filt to de-mangle the generated names >> >> Cheers, >> Roel >> >> >> On 11/12/14 11:52, zy jj wrote: >> >> Hi, everyone! >> I'm new here trapped by a simple problem for days. >> When LLVM translates C++ source code to IR, it will add a >> prefix to >> the function name. For example: >> source code: >> int foo(){ >> return 1; >> } >> IR form: >> define i32 @_Z3foov() #0 { >> entry: >> ret i32 1, !dbg !20 >> } >> The getName() method returns _Z3foov, then how can I get >> foo? I >> know the debugging information is contained in metadata, but I've >> no >> idea on using it. >> Thanks a lot for any help. >> >> >> >> >> ______________________________ _________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> >> http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/ mailman/listinfo/llvmdev >> <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> >> >> ______________________________ _________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> >> http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/ mailman/listinfo/llvmdev >> <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> >> >> >> >> >> -- >> - Welson >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > >-- - Welson -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141211/d2c31ee7/attachment.html>