blob: 7c52cb53a570abadd8313d2f301c6b9fdab0f02c [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2/*--------------------------------------------------------------------*/
3/*--- Demangling of C++ mangled names. ---*/
4/*--- vg_demangle.c ---*/
5/*--------------------------------------------------------------------*/
6
7/*
njnb9c427c2004-12-01 14:14:42 +00008 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
sewardjde4a1d02002-03-22 01:27:54 +000010
nethercotebb1c9912004-01-04 16:43:23 +000011 Copyright (C) 2000-2004 Julian Seward
sewardjde4a1d02002-03-22 01:27:54 +000012 jseward@acm.org
sewardjde4a1d02002-03-22 01:27:54 +000013
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
njn25e49d8e72002-09-23 09:36:25 +000029 The GNU General Public License is contained in the file COPYING.
sewardjde4a1d02002-03-22 01:27:54 +000030*/
31
nethercotef1e5e152004-09-01 23:58:16 +000032#include "core.h"
sewardjde4a1d02002-03-22 01:27:54 +000033#include "demangle.h"
34
35#define ADD_TO_RESULT(zzstr,zzn) \
36{ \
37 Char* zz = (zzstr); \
38 Int nn = (zzn); \
39 Int ii; \
40 for (ii = 0; ii < nn; ii++) { \
41 result[n_result] = zz[ii]; \
42 if (n_result < result_size-1) n_result++; \
43 result[n_result] = 0; \
44 } \
45}
46
47void VG_(demangle) ( Char* orig, Char* result, Int result_size )
48{
sewardjfce1c8e2002-04-16 02:05:49 +000049 Int n_result = 0;
50 Char* demangled = NULL;
51
njn25e49d8e72002-09-23 09:36:25 +000052 VGP_PUSHCC(VgpDemangle);
53
sewardjfce1c8e2002-04-16 02:05:49 +000054 if (VG_(clo_demangle))
55 demangled = VG_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS );
56
sewardjde4a1d02002-03-22 01:27:54 +000057 if (demangled) {
58 ADD_TO_RESULT(demangled, VG_(strlen)(demangled));
njn25e49d8e72002-09-23 09:36:25 +000059 VG_(arena_free) (VG_AR_DEMANGLE, demangled);
sewardjde4a1d02002-03-22 01:27:54 +000060 } else {
61 ADD_TO_RESULT(orig, VG_(strlen)(orig));
62 }
63
64 /* Check that the demangler isn't leaking. */
65 /* 15 Feb 02: if this assertion fails, this is not a disaster.
66 Comment it out, and let me know. (jseward@acm.org). */
67 vg_assert(VG_(is_empty_arena)(VG_AR_DEMANGLE));
68
69 /* VG_(show_all_arena_stats)(); */
njn25e49d8e72002-09-23 09:36:25 +000070
71 VGP_POPCC(VgpDemangle);
sewardjde4a1d02002-03-22 01:27:54 +000072}
73
74
75/*--------------------------------------------------------------------*/
76/*--- end vg_demangle.c ---*/
77/*--------------------------------------------------------------------*/