blob: f07f7f34657c72dd3d6295e0dd8c8c291b48f4bc [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
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
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
29 The GNU General Public License is contained in the file LICENSE.
30*/
31
32#include "vg_include.h"
33#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
52 if (VG_(clo_demangle))
53 demangled = VG_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS );
54
sewardjde4a1d02002-03-22 01:27:54 +000055 if (demangled) {
56 ADD_TO_RESULT(demangled, VG_(strlen)(demangled));
57 VG_(free) (VG_AR_DEMANGLE, demangled);
58 } else {
59 ADD_TO_RESULT(orig, VG_(strlen)(orig));
60 }
61
62 /* Check that the demangler isn't leaking. */
63 /* 15 Feb 02: if this assertion fails, this is not a disaster.
64 Comment it out, and let me know. (jseward@acm.org). */
65 vg_assert(VG_(is_empty_arena)(VG_AR_DEMANGLE));
66
67 /* VG_(show_all_arena_stats)(); */
68}
69
70
71/*--------------------------------------------------------------------*/
72/*--- end vg_demangle.c ---*/
73/*--------------------------------------------------------------------*/