sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | 44e1368 | 2005-05-10 04:56:56 +0000 | [diff] [blame] | 3 | /*--- Demangling of C++ mangled names. demangle.c ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 9 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 11 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 31 | #include "pub_core_basics.h" |
njn | e6efe0a | 2005-05-17 21:02:03 +0000 | [diff] [blame] | 32 | #include "pub_core_demangle.h" |
njn | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame] | 33 | #include "pub_core_libcbase.h" |
njn | af1d7df | 2005-06-11 01:31:52 +0000 | [diff] [blame] | 34 | #include "pub_core_mallocfree.h" |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 35 | #include "pub_core_options.h" |
njn | 31513b4 | 2005-06-01 03:09:59 +0000 | [diff] [blame] | 36 | #include "pub_core_profile.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 37 | #include "demangle.h" |
| 38 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 39 | void VG_(demangle) ( Char* orig, Char* result, Int result_size ) |
| 40 | { |
sewardj | fce1c8e | 2002-04-16 02:05:49 +0000 | [diff] [blame] | 41 | Char* demangled = NULL; |
| 42 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 43 | VGP_PUSHCC(VgpDemangle); |
| 44 | |
sewardj | fce1c8e | 2002-04-16 02:05:49 +0000 | [diff] [blame] | 45 | if (VG_(clo_demangle)) |
| 46 | demangled = VG_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS ); |
| 47 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 48 | if (demangled) { |
njn | be73f43 | 2005-03-26 21:34:45 +0000 | [diff] [blame] | 49 | VG_(strncpy_safely)(result, demangled, result_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 50 | VG_(arena_free) (VG_AR_DEMANGLE, demangled); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 51 | } else { |
njn | be73f43 | 2005-03-26 21:34:45 +0000 | [diff] [blame] | 52 | VG_(strncpy_safely)(result, orig, result_size); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 53 | } |
| 54 | |
njn | dac1e45 | 2005-03-13 14:28:39 +0000 | [diff] [blame] | 55 | // 13 Mar 2005: We used to check here that the demangler wasn't leaking |
| 56 | // by calling the (now-removed) function VG_(is_empty_arena)(). But, |
| 57 | // very rarely (ie. I've heard of it twice in 3 years), the demangler |
| 58 | // does leak. But, we can't do much about it, and it's not a disaster, |
| 59 | // so we just let it slide without aborting or telling the user. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 60 | |
| 61 | VGP_POPCC(VgpDemangle); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 62 | } |
| 63 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 64 | /*--------------------------------------------------------------------*/ |
njn | dac1e45 | 2005-03-13 14:28:39 +0000 | [diff] [blame] | 65 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 66 | /*--------------------------------------------------------------------*/ |