2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2018 Jason King
20 #include <sys/debug.h>
21 #include <demangle-sys.h>
22 #include "demangle_int.h"
24 #define DEMANGLE_DEBUG "DEMANGLE_DEBUG"
26 static pthread_once_t debug_once
= PTHREAD_ONCE_INIT
;
27 volatile boolean_t demangle_debug
;
30 detect_lang(const char *str
)
32 size_t n
= strlen(str
);
34 if (n
< 3 || str
[0] != '_')
35 return (SYSDEM_LANG_AUTO
);
39 return (SYSDEM_LANG_CPP
);
45 return (SYSDEM_LANG_AUTO
);
48 /* why they use ___Z sometimes is puzzling... *sigh* */
49 if (str
[2] == '_' && str
[3] == 'Z')
50 return (SYSDEM_LANG_CPP
);
52 return (SYSDEM_LANG_AUTO
);
58 if (getenv(DEMANGLE_DEBUG
))
59 demangle_debug
= B_TRUE
;
63 sysdemangle(const char *str
, sysdem_lang_t lang
, sysdem_ops_t
*ops
)
65 VERIFY0(pthread_once(&debug_once
, check_debug
));
68 ops
= sysdem_ops_default
;
70 if (lang
== SYSDEM_LANG_AUTO
) {
71 lang
= detect_lang(str
);
72 if (lang
== SYSDEM_LANG_AUTO
) {
79 case SYSDEM_LANG_AUTO
:
82 return (cpp_demangle(str
, ops
));