Date: Wed, 11 Jun 2014 16:53:41 -0400 From: Ed Maste <emaste@freebsd.org> To: David Chisnall <theraven@freebsd.org> Cc: freebsd-toolchain@freebsd.org, Ryan Stone <rysto32@gmail.com> Subject: Re: abi::__cxa_demangle provides invalid result on non-mangled symbols Message-ID: <CAPyFy2CgKKPwRjnYj1mciQN%2B49qpe3et1nhEjwxAv9oaGOdthA@mail.gmail.com> In-Reply-To: <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org> References: <CAFMmRNw_9hS3YuDbjFJH0btvoPADJ7_4=L13z2sK71gctPzXhQ@mail.gmail.com> <CAPyFy2Buh4BUEuYW5nfQFdEMio9=yaDAkivg1zXPnEBzr_CzJQ@mail.gmail.com> <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 10 June 2014 02:38, David Chisnall <theraven@freebsd.org> wrote: > > If you know that the thing that you are demangling is a symbol name, then= you can use the _Z check, which isn't really a hack - it's a marker added = to identify C++ symbols. Note that, if you're writing portable code, you n= eed to remember that some systems prepend an underscore to all compiler-gen= erated symbols, so you may also need to check for __Z and trim the leading = _. Right, it just feels hackish to have to know this detail of the ABI. I think I'd like an explicit __cxa_demangle_symbol interface, or perhaps __cxa_is_mangled_symbol to query a string. > The __cxa_demangle() function has to handle things that are not just symb= ols (types and so on) and so can't do this test itself. Its most common us= e is generating a human-friendly error for an uncaught exception, where it = is just parsing a type encoding. My use, and I suspect Ryan's, is demangling symbols obtained from introspection interfaces like backtrace_symbols(3). In any case, our libelftc __cxa_demangle accepts strings that are neither symbols nor NTBS manglings, and can return a bogus demangled name for them. Of course, it's a mistake to rely on __cxa_demangle rejecting these for arbitrary input.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPyFy2CgKKPwRjnYj1mciQN%2B49qpe3et1nhEjwxAv9oaGOdthA>