sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Demangling of C++ mangled names. ---*/ |
| 4 | /*--- vg_demangle.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, an x86 protected-mode emulator |
| 9 | designed for debugging and profiling binaries on x86-Unixes. |
| 10 | |
| 11 | Copyright (C) 2000-2002 Julian Seward |
| 12 | jseward@acm.org |
| 13 | Julian_Seward@muraroa.demon.co.uk |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or |
| 16 | modify it under the terms of the GNU General Public License as |
| 17 | published by the Free Software Foundation; either version 2 of the |
| 18 | License, or (at your option) any later version. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, but |
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the Free Software |
| 27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 28 | 02111-1307, USA. |
| 29 | |
| 30 | The GNU General Public License is contained in the file LICENSE. |
| 31 | */ |
| 32 | |
| 33 | #include "vg_include.h" |
| 34 | #include "demangle.h" |
| 35 | |
| 36 | #define ADD_TO_RESULT(zzstr,zzn) \ |
| 37 | { \ |
| 38 | Char* zz = (zzstr); \ |
| 39 | Int nn = (zzn); \ |
| 40 | Int ii; \ |
| 41 | for (ii = 0; ii < nn; ii++) { \ |
| 42 | result[n_result] = zz[ii]; \ |
| 43 | if (n_result < result_size-1) n_result++; \ |
| 44 | result[n_result] = 0; \ |
| 45 | } \ |
| 46 | } |
| 47 | |
| 48 | void VG_(demangle) ( Char* orig, Char* result, Int result_size ) |
| 49 | { |
| 50 | Int n_result = 0; |
| 51 | Char* demangled = VG_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS ); |
| 52 | if (demangled) { |
| 53 | ADD_TO_RESULT(demangled, VG_(strlen)(demangled)); |
| 54 | VG_(free) (VG_AR_DEMANGLE, demangled); |
| 55 | } else { |
| 56 | ADD_TO_RESULT(orig, VG_(strlen)(orig)); |
| 57 | } |
| 58 | |
| 59 | /* Check that the demangler isn't leaking. */ |
| 60 | /* 15 Feb 02: if this assertion fails, this is not a disaster. |
| 61 | Comment it out, and let me know. (jseward@acm.org). */ |
| 62 | vg_assert(VG_(is_empty_arena)(VG_AR_DEMANGLE)); |
| 63 | |
| 64 | /* VG_(show_all_arena_stats)(); */ |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /*--------------------------------------------------------------------*/ |
| 69 | /*--- end vg_demangle.c ---*/ |
| 70 | /*--------------------------------------------------------------------*/ |