blob: d32b6deea1278c6fb3c1ba90bed2d54174bdca5c [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
njn53612422005-03-12 16:22:54 +000011 Copyright (C) 2000-2005 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
njnf4d483b2005-03-16 03:49:59 +000035static void add_to_result ( Char* result, Char* s, Int result_size )
36{
37 VG_(strncpy)(result, s, result_size);
38 result[result_size-1] = 0; // just in case no NUL was copied
sewardjde4a1d02002-03-22 01:27:54 +000039}
40
41void VG_(demangle) ( Char* orig, Char* result, Int result_size )
42{
sewardjfce1c8e2002-04-16 02:05:49 +000043 Char* demangled = NULL;
44
njn25e49d8e72002-09-23 09:36:25 +000045 VGP_PUSHCC(VgpDemangle);
46
sewardjfce1c8e2002-04-16 02:05:49 +000047 if (VG_(clo_demangle))
48 demangled = VG_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS );
49
sewardjde4a1d02002-03-22 01:27:54 +000050 if (demangled) {
njnf4d483b2005-03-16 03:49:59 +000051 add_to_result(result, demangled, result_size);
njn25e49d8e72002-09-23 09:36:25 +000052 VG_(arena_free) (VG_AR_DEMANGLE, demangled);
sewardjde4a1d02002-03-22 01:27:54 +000053 } else {
njnf4d483b2005-03-16 03:49:59 +000054 add_to_result(result, orig, result_size);
sewardjde4a1d02002-03-22 01:27:54 +000055 }
56
njndac1e452005-03-13 14:28:39 +000057 // 13 Mar 2005: We used to check here that the demangler wasn't leaking
58 // by calling the (now-removed) function VG_(is_empty_arena)(). But,
59 // very rarely (ie. I've heard of it twice in 3 years), the demangler
60 // does leak. But, we can't do much about it, and it's not a disaster,
61 // so we just let it slide without aborting or telling the user.
njn25e49d8e72002-09-23 09:36:25 +000062
63 VGP_POPCC(VgpDemangle);
sewardjde4a1d02002-03-22 01:27:54 +000064}
65
66
67/*--------------------------------------------------------------------*/
njndac1e452005-03-13 14:28:39 +000068/*--- end ---*/
sewardjde4a1d02002-03-22 01:27:54 +000069/*--------------------------------------------------------------------*/