howto demangle const types?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The attached code produces output:

int const=int

IOW, the abi::__cxa_demangle strips const qualifiers.

Looking at:

  http://gcc.gnu.org/viewcvs/trunk/libiberty/cp-demangle.h?view=markup

shows:

99 	 /* The options passed to the demangler. */
...
165 	extern void
166 	cplus_demangle_init_info (const char *, int, size_t, struct d_info *);

and the following:


http://gcc.gnu.org/viewcvs/trunk/libiberty/cp-demangle.c?revision=166810&view=markup

shows:


1129    if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0)
1130      {
1131        /* Strip off any initial CV-qualifiers, as they really apply
1132           to the `this' parameter, and they were not output by the
1133           v2 demangler without DMGL_PARAMS. */

so maybe I just need to pass the proper di->options to some function,
probably the one mentioned here:

43      This file will normally define the following functions, q.v.:
44      char *cplus_demangle_v3(const char *mangled, int options)

However, the only documentation of options in this file are:

4865 	/* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4866 	name, return a buffer allocated with malloc holding the demangled
4867 	name. OPTIONS is the usual libiberty demangler options. On
4868 	success, this sets *PALC to the allocated size of the returned
4869 	buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4870 	a memory allocation failure, and returns NULL. */
4871 	
4872 	static char *
4873 	d_demangle (const char *mangled, int options, size_t *palc)

However, there's no link to where these "usual libiberty demangler
options" are described.

Also, how can I allow the linker to find cplus_demangle_v3?

TIA.

-Larry




//Purpose:
//  See if demangler shows const for const type.
//
#include <cxxabi.h>
#include <typeinfo>
#include <string>
#include <iostream>

//#define CPLUS_DEMANGLE
#ifdef CPLUS_DEMANGLE
char *
cplus_demangle_v3 (const char *mangled, int options)
;
#endif

  template
  < typename Type
  >
  std::string
demangle(void)
  {
  ; std::type_info const& my_typeinfo(typeid(Type))
  ; char const* yes_mangled=my_typeinfo.name()
  #ifndef CPLUS_DEMANGLE
  ; std::size_t const inbuf=2*1048
  ; std::size_t iobuf = inbuf
  ; char buffer[inbuf]
  ; int status
  #endif
  ; char* not_mangled=
  #ifndef CPLUS_DEMANGLE
    abi::__cxa_demangle(yes_mangled, buffer, &iobuf, &status)
  #else
    cplus_demangle_v3 (yes_mangled, 0)
  #endif
  ; std::string demangled(not_mangled);
  #ifdef CPLUS_DEMANGLE
  ; delete[] not_mangled;
  #endif
  ; return demangled
  ;}

int main(void)
  {
  ; std::cout<<"int const="<<demangle<int const>()<<"\n"
  ; return 0
  ;}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux