diff options
Diffstat (limited to 'libstdc++-v3/docs/html')
-rw-r--r-- | libstdc++-v3/docs/html/17_intro/howto.html | 3 | ||||
-rw-r--r-- | libstdc++-v3/docs/html/18_support/howto.html | 63 |
2 files changed, 65 insertions, 1 deletions
diff --git a/libstdc++-v3/docs/html/17_intro/howto.html b/libstdc++-v3/docs/html/17_intro/howto.html index 914213a..21f83f9 100644 --- a/libstdc++-v3/docs/html/17_intro/howto.html +++ b/libstdc++-v3/docs/html/17_intro/howto.html @@ -205,7 +205,8 @@ classes publicly derived from it, simply returns the name of the class. But they are the <em>mangled</em> names; you will need to call <code>c++filt</code> and pass the names as command-line parameters to - demangle them. + demangle them, or call a + <a href="../18_support/howto.html#5">runtime demangler function</a>. (The classes in <code><stdexcept></code> have constructors which require an argument to use later for <code>what()</code> calls, so the question does not arise in most user-defined exceptions.) diff --git a/libstdc++-v3/docs/html/18_support/howto.html b/libstdc++-v3/docs/html/18_support/howto.html index 13adbfd..10c74a9 100644 --- a/libstdc++-v3/docs/html/18_support/howto.html +++ b/libstdc++-v3/docs/html/18_support/howto.html @@ -31,6 +31,7 @@ <li><a href="#2">Implementation properties</a> <li><a href="#3">Start and Termination</a> <li><a href="#4">Dynamic memory management</a> + <li><a href="#5">RTTI, the ABI, and demangling</a> </ul> <hr> @@ -255,6 +256,68 @@ <a href="../faq/index.html">to the FAQ</a>. </p> +<hr> +<h2><a name="5">RTTI, the ABI, and demangling</a></h2> + <p>If you have read the <a href="../documentation.html#4">source + documentation</a> for <code> namespace abi </code> then you are aware + of the cross-vendor C++ ABI which we use. One of the exposed + functions is the one which we use for demangling in programs like + <code>c++filt</code>, and you can use it yourself as well. + </p> + <p>(The function itself might use different demanglers, but that's the + whole point of abstract interfaces. If we change the implementation, + you won't notice.) + </p> + <p>Probably the only times you'll be interested in demangling at runtime + are when you're seeing <code>typeid</code> strings in RTTI, or when + you're handling the runtime-support exception classes. For example: + <pre> +#include <exception> +#include <iostream> +#include <cxxabi.h> + +struct empty { }; + +template <typename T, int N> + struct bar { }; + + +int main() +{ + int status; + char *realname; + + // exception classes not in <stdexcept>, thrown by the implementation + // instead of the user + std::bad_exception e; + realname = abi::__cxa_demangle(e.what(), 0, 0, &status); + std::cout << e.what() << "\t=> " << realname << "\t: " << status << '\n'; + free(realname); + + + // typeid + bar<empty,17> u; + const std::type_info &ti = typeid(u); + + realname = abi::__cxa_demangle(ti.name(), 0, 0, &status); + std::cout << ti.name() << "\t=> " << realname << "\t: " << status << '\n'; + free(realname); + + return 0; +}</pre></p> + <p>With GCC 3.1 and later, this prints<pre> + St13bad_exception => std::bad_exception : 0 + 3barI5emptyLi17EE => bar<empty, 17> : 0</pre> + </p> + <p>The demangler interface is described in the source documentation + linked to above. It is actually written in C, so you don't need to + be writing C++ in order to demangle C++. (That also means we have to + use crummy memory management facilities, so don't forget to free() + the returned char array.) + </p> + <p>Return <a href="#top">to top of page</a> or + <a href="../faq/index.html">to the FAQ</a>. + </p> <!-- ####################################################### --> |