Reputation: 641
I'm working on a debugging/memory tool. I want to display symbols coming from C++, the problem is that they are very verbose. At the moment I'm just using __cxa_demangle
, but this often results in huge strings of more than 500 characters, due to the inclusion of default template parameters.
clang++
can clearly do clever things when it reports symbols, is there any way I can take advantage of it?
As a simple example, let's take:
std::map<std::string const, unsigned int, std::less<std::string const>, std::allocator<std::pair<std::string const, unsigned int> > >::find(std::string const&)
Which clearly could be reported as:
std::map<std::string const, unsigned int>::find(std::string const&)
.. if I had a smart enough tool. It's clear that this is hard to do in general without additional knowledge (like the includes which were originally used - I can potentially get at these), but I'd be grateful for any pointers.
So far I've been pointed at libcxxabi, but apart from not having a public interface to the parse tree (which wouldn't stop me by itself), it seems like I'd have to do the hard work determining which parameters were defaults. It would be great if I could somehow trick clang into doing this for me.
Upvotes: 4
Views: 802
Reputation: 725
STLFilt could help you. There are two perl scripts, STLFilt.pl (for Visual C++) and gSTLFilt.p (for gcc). It's designed to be used for error messages simplification, but I've already used it for postprocessing __cxa_demangle's output.
Used on your simple example without any options:
echo "std::map<std::string const, unsigned int, std::less<std::string const>, std::allocator<std::pair<std::string const, unsigned int> > >::find(std::string const&)" \
| perl ./gSTLFilt.pl
Gets output:
BD Software STL Message Decryptor v3.10 for gcc 2/3/4
map<string const, unsigned int>::find(string const &)
If you want to play with it's options, you should be able to get customized reformating (I haven't tried it).
Upvotes: 6