[cfe-dev] libc++abi

Howard Hinnant hhinnant at apple.com
Thu May 19 16:21:35 PDT 2011


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.

Howard




More information about the cfe-dev mailing list