summaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@gcc.gnu.org>2003-02-27 16:57:26 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2003-02-27 16:57:26 +0000
commit4ffbd0777c9cc458ce64322e0be0c6f3840ce5b4 (patch)
tree8d12c9d5a4a7461c12b0ca8e016cd1bb154e4fcb /libstdc++-v3/src
parent986704f1c14f3931286ce1a8e632024e4a2b954c (diff)
downloadgcc-4ffbd0777c9cc458ce64322e0be0c6f3840ce5b4.tar.gz
[multiple changes]
2003-02-27 Benjamin Kosnik <bkoz@redhat.com> * src/Makefile.am (sources): Add demangle.cc. (demangle.o): Add. (demangle.lo): Add. * src/Makefile.in: Regenerate. * libsupc++/Makefile.am: Remove old __cxa_demangle bits. * libsupc++/Makefile.in: Regenerate. * testsuite/testsuite_hooks.h (__gnu_cxx_test::verify_demangle): New. * testsuite/testsuite_hooks.cc: Define. 2003-02-27 Carlo Wood <carlo@alinoe.com> * src/demangle.cc: New. * libsupc++/demangle.h: New. 2003-02-27 Benjamin Kosnik <bkoz@redhat.com> Carlo Wood <carlo@alinoe.com> * testsuite/demangle/abi_examples/01.cc: New. * testsuite/demangle/abi_examples/02.cc: New. * testsuite/demangle/abi_examples/03.cc: New. * testsuite/demangle/abi_examples/04.cc: New. * testsuite/demangle/abi_examples/05.cc: New. * testsuite/demangle/abi_examples/06.cc: New. * testsuite/demangle/abi_examples/07.cc: New. * testsuite/demangle/abi_examples/08.cc: New. * testsuite/demangle/abi_examples/09.cc: New. * testsuite/demangle/abi_examples/10.cc: New. * testsuite/demangle/abi_examples/11.cc: New. * testsuite/demangle/abi_examples/12.cc: New. * testsuite/demangle/abi_examples/13.cc: New. * testsuite/demangle/abi_examples/14.cc: New. * testsuite/demangle/abi_examples/15.cc: New. * testsuite/demangle/abi_examples/16.cc: New. * testsuite/demangle/abi_examples/17.cc: New. * testsuite/demangle/abi_examples/18.cc: New. * testsuite/demangle/abi_examples/19.cc: New. * testsuite/demangle/abi_examples/20.cc: New. * testsuite/demangle/abi_examples/21.cc: New. * testsuite/demangle/abi_examples/22.cc: New. * testsuite/demangle/abi_examples/23.cc: New. * testsuite/demangle/abi_examples/24.cc: New. * testsuite/demangle/abi_examples/25.cc: New. * testsuite/demangle/abi_examples/26.cc: New. * testsuite/demangle/abi_text/01.cc: New. * testsuite/demangle/abi_text/02.cc: New. * testsuite/demangle/abi_text/03.cc: New. * testsuite/demangle/abi_text/04.cc: New. * testsuite/demangle/abi_text/05.cc: New. * testsuite/demangle/abi_text/06.cc: New. * testsuite/demangle/abi_text/07.cc: New. * testsuite/demangle/abi_text/08.cc: New. * testsuite/demangle/abi_text/09.cc: New. * testsuite/demangle/abi_text/10.cc: New. * testsuite/demangle/abi_text/11.cc: New. * testsuite/demangle/abi_text/12.cc: New. * testsuite/demangle/abi_text/13.cc: New. * testsuite/demangle/abi_text/14.cc: New. * testsuite/demangle/regression/3111-1.cc: New. * testsuite/demangle/regression/3111-2.cc: New. * testsuite/demangle/regression/7986-01.cc: New. * testsuite/demangle/regression/7986-02.cc: New. * testsuite/demangle/regression/7986-03.cc: New. * testsuite/demangle/regression/7986-04.cc: New. * testsuite/demangle/regression/7986-05.cc: New. * testsuite/demangle/regression/7986-06.cc: New. * testsuite/demangle/regression/7986-07.cc: New. * testsuite/demangle/regression/7986-08.cc: New. * testsuite/demangle/regression/7986-09.cc: New. * testsuite/demangle/regression/7986-10.cc: New. * testsuite/demangle/regression/7986-11.cc: New. * testsuite/demangle/regression/7986-12.cc: New. * testsuite/demangle/regression/7986.cc: New. * testsuite/demangle/regression/8897.cc: New. * testsuite/demangle/regression/cw-01.cc: New. * testsuite/demangle/regression/cw-02.cc: New. * testsuite/demangle/regression/cw-03.cc: New. * testsuite/demangle/regression/cw-04.cc: New. * testsuite/demangle/regression/cw-05.cc: New. * testsuite/demangle/regression/cw-06.cc: New. * testsuite/demangle/regression/cw-07.cc: New. * testsuite/demangle/regression/cw-08.cc: New. * testsuite/demangle/regression/cw-09.cc: New. * testsuite/demangle/regression/cw-10.cc: New. * testsuite/demangle/regression/cw-11.cc: New. * testsuite/demangle/regression/cw-12.cc: New. * testsuite/demangle/regression/cw-13.cc: New. * testsuite/demangle/regression/cw-14.cc: New. * testsuite/demangle/regression/old.cc: New. From-SVN: r63513
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r--libstdc++-v3/src/Makefile.am8
-rw-r--r--libstdc++-v3/src/Makefile.in14
-rw-r--r--libstdc++-v3/src/demangle.cc170
3 files changed, 189 insertions, 3 deletions
diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index 21ff70c5367..3800860ca1e 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -121,6 +121,7 @@ sources = \
complex_io.cc \
concept-inst.cc \
ctype.cc \
+ demangle.cc \
ext-inst.cc \
fstream.cc \
fstream-inst.cc \
@@ -177,6 +178,13 @@ concept-inst.lo: concept-inst.cc
concept-inst.o: concept-inst.cc
$(CXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -fimplicit-templates -c $<
+# Use special rules for the demangler, so that an additional implicit
+# instantiation file is not necessary.
+demangle.lo: demangle.cc
+ $(LTCXXCOMPILE) -fimplicit-templates -c $<
+demangle.o: demangle.cc
+ $(CXXCOMPILE) -fimplicit-templates -c $<
+
# AM_CXXFLAGS needs to be in each subdirectory so that it can be
# modified in a per-library or per-sub-library way. Need to manually
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
index fdba02e1f82..4212497a4c6 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -203,6 +203,7 @@ sources = \
complex_io.cc \
concept-inst.cc \
ctype.cc \
+ demangle.cc \
ext-inst.cc \
fstream.cc \
fstream-inst.cc \
@@ -305,9 +306,9 @@ CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libstdc___la_OBJECTS = codecvt.lo complex_io.lo concept-inst.lo \
-ctype.lo ext-inst.lo fstream.lo fstream-inst.lo functexcept.lo \
-globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo locale.lo \
-locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
+ctype.lo demangle.lo ext-inst.lo fstream.lo fstream-inst.lo \
+functexcept.lo globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo \
+locale.lo locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
sstream-inst.lo stdexcept.lo stl-inst.lo streambuf-inst.lo \
string-inst.lo strstream.lo valarray-inst.lo wstring-inst.lo \
codecvt_members.lo collate_members.lo ctype_members.lo \
@@ -582,6 +583,13 @@ concept-inst.lo: concept-inst.cc
concept-inst.o: concept-inst.cc
$(CXXCOMPILE) -D_GLIBCPP_CONCEPT_CHECKS -fimplicit-templates -c $<
+# Use special rules for the demangler, so that an additional implicit
+# instantiation file is not necessary.
+demangle.lo: demangle.cc
+ $(LTCXXCOMPILE) -fimplicit-templates -c $<
+demangle.o: demangle.cc
+ $(CXXCOMPILE) -fimplicit-templates -c $<
+
# Added bits to build debug library.
@GLIBCPP_BUILD_DEBUG_TRUE@all-local: build_debug
@GLIBCPP_BUILD_DEBUG_TRUE@install-data-local: install_debug
diff --git a/libstdc++-v3/src/demangle.cc b/libstdc++-v3/src/demangle.cc
new file mode 100644
index 00000000000..93956502070
--- /dev/null
+++ b/libstdc++-v3/src/demangle.cc
@@ -0,0 +1,170 @@
+// C++ IA64 / g++ v3 demangler -*- C++ -*-
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Written by Carlo Wood <carlo@alinoe.com>
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <cxxabi.h>
+#include "demangle.h"
+
+// __cxa_demangle
+//
+// Demangle a C++ symbol or type name.
+//
+// `mangled-name' is a pointer to a null-terminated array of characters.
+// It may be either an external name, i.e. with a "_Z" prefix, or an
+// internal NTBS mangling, e.g. of a type for type_info.
+//
+// `buf' may be null. If it is non-null, then n must also be non-null,
+// and buf is a pointer to an array, of at least *n characters, that
+// was allocated using malloc.
+//
+// `status' points to an int that is used as an error indicator. It is
+// permitted to be null, in which case the user just doesn't get any
+// detailed error information.
+//
+// Returns: a pointer to a null-terminated array of characters, the
+// demangled name. Or NULL in case of failure.
+//
+// If there is an error in demangling, the return value is a null pointer.
+// The user can examine *status to find out what kind of error occurred.
+// Meaning of error indications:
+//
+// * 0: success
+// * -1: memory allocation failure
+// * -2: invalid mangled name
+// * -3: invalid arguments (e.g. buf nonnull and n null)
+//
+
+namespace __cxxabiv1
+{
+ namespace
+ {
+ char* const error = 0;
+
+ enum status_codes
+ {
+ success = 0,
+ memory_allocation_failure = -1,
+ invalid_mangled_name = -2,
+ invalid_argument = -3
+ };
+
+ inline char*
+ failure(status_codes error_code, int* status)
+ {
+ if (status)
+ *status = error_code;
+ return error;
+ }
+
+ char*
+ finish(char const* demangled_name, size_t demangled_name_size,
+ char* buf, size_t* n, int* status)
+ {
+ if (!buf || *n < demangled_name_size + 1)
+ {
+ if (n)
+ *n = demangled_name_size + 1;
+ buf = (char*)realloc(buf, demangled_name_size + 1);
+ if (!buf)
+ return failure(memory_allocation_failure, status);
+ }
+ if (status)
+ *status = success;
+ std::strncpy(buf, demangled_name, demangled_name_size);
+ buf[demangled_name_size] = 0;
+ return buf;
+ }
+ } // namespace
+
+ char*
+ __cxa_demangle(char const* mangled_name, char* buf, std::size_t* n,
+ int* status)
+ {
+ using namespace __gnu_cxx;
+ typedef demangler::session<std::allocator<char> > session_type;
+
+ if (!mangled_name || (buf && !n))
+ return failure(invalid_argument, status);
+
+ std::string result;
+ if (mangled_name[0] == '_')
+ {
+ // External name?
+ if (mangled_name[1] == 'Z')
+ {
+ // C++ name?
+ int cnt = session_type::
+ decode_encoding(result, mangled_name + 2, INT_MAX);
+ if (cnt < 0 || mangled_name[cnt + 2] != 0)
+ return failure(invalid_mangled_name, status);
+ return finish(result.data(), result.size(), buf, n, status);
+ }
+ else if (mangled_name[1] == 'G')
+ {
+ // Possible _GLOBAL__ extension?
+ if (!std::strncmp(mangled_name, "_GLOBAL__", 9)
+ && (mangled_name[9] == 'D' || mangled_name[9] == 'I')
+ && mangled_name[10] == '_' && mangled_name[11] == '_'
+ && mangled_name[12] == 'Z')
+ {
+ if (mangled_name[9] == 'D')
+ result.assign("global destructors keyed to ", 28);
+ else
+ result.assign("global constructors keyed to ", 29);
+ int cnt = session_type::
+ decode_encoding(result, mangled_name + 13, INT_MAX);
+ if (cnt < 0 || mangled_name[cnt + 13] != 0)
+ return failure(invalid_mangled_name, status);
+ return finish(result.data(), result.size(), buf, n, status);
+ }
+ }
+ }
+
+ // Ambiguities are possible between extern "C" object names and
+ // internal built-in type names, e.g. "i" may be either an object
+ // named "i" or the built-in "int" type. Such ambiguities should
+ // be resolved to user names over built-in names. Builtin types
+ // are any single lower case character. Any other single
+ // character is not a mangled type so we can treat those the same
+ // here.
+ if (mangled_name[1] == 0)
+ return finish(mangled_name, 1, buf, n, status);
+
+ // Not a built-in type or external name, try to demangle input as
+ // NTBS mangled type name.
+ session_type demangler_session(mangled_name, INT_MAX);
+ if (!demangler_session.decode_type(result)
+ || demangler_session.remaining_input_characters())
+ {
+ // Failure to demangle, assume extern "C" name.
+ result = mangled_name;
+ }
+ return finish(result.data(), result.size(), buf, n, status);
+ }
+} // namespace __cxxabiv1