]> git.saurik.com Git - apple/xnu.git/blob - libkern/kxld/kxld_demangle.c
xnu-1504.7.4.tar.gz
[apple/xnu.git] / libkern / kxld / kxld_demangle.c
1 #if !KERNEL
2
3 #include <stdlib.h>
4
5 /* This demangler is part of the C++ ABI. We don't include it directly from
6 * <cxxabi.h> so that we can avoid using C++ in the kernel linker.
7 */
8 extern char *
9 __cxa_demangle(const char* __mangled_name, char* __output_buffer,
10 size_t* __length, int* __status);
11
12 #endif /* !KERNEL */
13
14 #include "kxld_demangle.h"
15
16 /*******************************************************************************
17 *******************************************************************************/
18 const char *
19 kxld_demangle(const char *str, char **buffer __unused, size_t *length __unused)
20 {
21 #if KERNEL
22 return str;
23 #else
24 const char *rval = NULL;
25 char *demangled = NULL;
26 int status;
27
28 if (!str) goto finish;
29
30 rval = str;
31
32 if (!buffer || !length) goto finish;
33
34 /* Symbol names in the symbol table have an extra '_' prepended to them,
35 * so we skip the first character to make the demangler happy.
36 */
37 demangled = __cxa_demangle(str+1, *buffer, length, &status);
38 if (!demangled || status) goto finish;
39
40 *buffer = demangled;
41 rval = demangled;
42 finish:
43 return rval;
44 #endif
45 }
46