[cfe-dev] libc++abi

Christopher Bergström cbergstrom at pathscale.com
Thu May 19 19:57:44 PDT 2011


On Fri, May 20, 2011 at 6:21 AM, Howard Hinnant <hhinnant at apple.com> wrote:

> There is a new project at:
>
> http://libcxxabi.llvm.org/
>
> This is libc++abi, and is meant to be the low-level, Itanium ABI (
> http://www.codesourcery.com/public/cxx-abi/) implementation for libc++.
> There isn't much in there right now (additions welcome!).  So far all that
> is in there is a demangler (__cxa_demangle).
>
> The demangler has been split into three lower-level API's:
>
> __demangle_tree
> __demangle(const char* mangled_name, char* buf, size_t bs)
>
> __demangle_tree
> __demangle(const char* mangled_name);
>
> char*
> __demangle(__demangle_tree dmg_tree, char* buf, size_t* n, int* status);
>
> The first two functions take a mangled name as input and output a
> __demangle_tree.  This is the "parsing part" of demangling.  The reason for
> two functions here is so that you can optionally pass in a buffer, which if
> large enough, will be used instead of allocating memory for the
> __demangle_tree.
>
> The third function takes the __demangle_tree, and outputs an unmangled
> name.
>
> Using this low-level API, __cxa_demangle becomes a trivial wrapper above
> this API:
>
> char*
> __cxa_demangle(const char* mangled_name, char* buf, size_t* n, int* status)
> {
>    if (mangled_name == NULL || (buf != NULL && n == NULL))
>    {
>        if (status)
>            *status = __libcxxabi::invalid_args;
>        return NULL;
>    }
>    const size_t bs = 64 * 1024;
>    char static_buf[bs];
>
>    buf = __libcxxabi::__demangle(__libcxxabi::__demangle(mangled_name,
>                                                          static_buf, bs),
>                                  buf, n, status);
>    return buf;
> }
>
> It is expected that some tools (compilers, debuggers) will want to make use
> of an API on __demangle_tree that has yet to be developed.  E.g. how many
> function arguments and what are they?  How many template arguments and what
> are they? etc.
>

Hi Howard,

I have to let the cat out of the bag a bit early, but there is going to be
BSD licensed code doing this exact thing released very soon.  (Sorry
everyone I'm the bottleneck)

You're of course free to work on what you want, but a few notes

1) It's used in production already
2) It's been tested with LLVM, PathScale and possibly other compilers
3) It's portable across FreeBSD, Linux, Solaris, OSX.. etc
4) Has good inline documentation
5) Smallest/fastest C++ runtime in the industry based on my tests

./C

ps. Someone kick me if it's not in the wild by later today
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110520/d458bc0d/attachment.html>


More information about the cfe-dev mailing list