• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*--------------------------------------------------------------------*/
3 /*--- Demangling of C++ mangled names.              vg_libciface.h ---*/
4 /*--------------------------------------------------------------------*/
5 
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9 
10    Copyright (C) 2000-2017 Julian Seward
11       jseward@acm.org
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 
28    The GNU General Public License is contained in the file COPYING.
29 */
30 
31 /* This file contains a bunch of macro definitions etc which are
32    really "impedance matchers".  They make it possible for
33    cp-demangle.c, cplus-dem.c, dyn-string.c and safe-ctype.c (taken
34    from GNU libiberty) to be compiled in the Valgrind framework with a
35    minimum of changes.
36 
37    This file should only be included in files which contain libiberty
38    code. */
39 
40 #include "pub_core_basics.h"
41 #include "pub_core_libcbase.h"
42 #include "pub_core_libcassert.h"
43 #include "pub_core_libcprint.h"
44 #include "pub_core_mallocfree.h"
45 
46 
47 #define abort()              vg_assert(0)
48 #define atoi(_str)           VG_(strtoll10)((_str), NULL)
49 #define free(_pt)            VG_(arena_free)   (VG_AR_DEMANGLE,(_pt))
50 #define memcmp(_s1,_s2,_sz)  VG_(memcmp)((_s1),(_s2),(_sz))
51 #define memcpy(_dd,_ss,_sz)  VG_(memcpy)((_dd),(_ss),(_sz))
52 #define memset(_ss,_cc,_sz)  VG_(memset)((_ss),(_cc),(_sz))
53 #define realloc(_cc,_pt,_sz) VG_(arena_realloc)(VG_AR_DEMANGLE,(_cc),(_pt),(_sz))
54 #define sprintf(_buf,_fmt,_args...)  VG_(sprintf)((_buf),(_fmt),(_args))
55 #define strcat(_dd,_ss)      VG_(strcat)((_dd),(_ss))
56 #define strchr(_ss,_cc)      VG_(strchr)((_ss),(_cc))
57 #define strcmp(_s1,_s2)      VG_(strcmp)((_s1),(_s2))
58 #define strcpy(_dd,_ss)      VG_(strcpy)((_dd),(_ss))
59 #define strcspn(_ss,_rr)     VG_(strcspn)((_ss),(_rr))
60 #define strlen(_str)         VG_(strlen)(_str)
61 #define strncat(_dd,_ss,_nn) VG_(strncat)((_dd),(_ss),(_nn))
62 #define strncmp(_s1,_s2,_sz) VG_(strncmp)((_s1),(_s2),(_sz))
63 #define strncpy(_dd,_ss,_sz) VG_(strncpy)((_dd),(_ss),(_sz))
64 #define strpbrk(_ss,_aa)     VG_(strpbrk)((_ss),(_aa))
65 #define strspn(_ss,_aa)      VG_(strspn)((_ss),(_aa))
66 #define strstr(_hh,_nn)      VG_(strstr)((_hh),(_nn))
67 /* strtol supports base 16 or else assumes it is base 10 */
68 #define strtol(s,r,b)         ((b) == 16 ? \
69                                VG_(strtoll16) ((s),(r)) \
70                                : VG_(strtoll10) ((s),(r)))
71 
72 
73 #define size_t SizeT
74 
75 #define xmalloc(_nn)      \
76    VG_(arena_malloc)(VG_AR_DEMANGLE, "m_demangle.xmalloc", (_nn))
77 #define xmalloc_failed(_sz) abort()
78 #define xrealloc(_pt,_sz) \
79    VG_(arena_realloc)(VG_AR_DEMANGLE,"m_demangle.xrealloc",(_pt),(_sz))
80 #define xstrdup(_str) \
81    VG_(arena_strdup)(VG_AR_DEMANGLE,"m_demangle.xstrdup",(_str))
82 
xmemdup(const void * in,size_t c_size,size_t a_size)83 static inline void *xmemdup(const void *in, size_t c_size, size_t a_size) {
84    void *dst;
85    dst = VG_(arena_malloc)(VG_AR_DEMANGLE, "m_demangle.xmemdup", a_size);
86    if (a_size > c_size)
87       memset ((char *) dst + c_size, 0, a_size - c_size);
88    return memcpy (dst, in, c_size);
89 }
90 
91 /* Required by safe-ctype.h */
92 
93 #undef EOF
94 #define EOF -1
95 
96 /* Taken from libiberty.h: */
97 
98 #define ARRAY_SIZE(_arr) \
99         (sizeof (_arr) / sizeof ((_arr)[0]))
100 
101 #define XNEWVEC(_Ty, _Nn)    \
102         ((_Ty *) xmalloc(sizeof (_Ty) * (_Nn)))
103 
104 #define XRESIZEVEC(_Ty, _Pt, _Nn) \
105         ((_Ty *) xrealloc((void *) (_Pt), sizeof (_Ty) * (_Nn)))
106 
107 #define XRESIZEVAR(_Ty, _Pt, _Sz) \
108         ((_Ty *) xrealloc((_Pt), (_Sz)))
109 
110 #define XNEW(_Ty) \
111         ((_Ty *) xmalloc(sizeof (_Ty)))
112 
113 #define XDELETEVEC(P) \
114 	free ((void*) (P))
115 
116 #define XDUPVEC(T, P, N) \
117 	((T *) xmemdup ((P), sizeof (T) * (N), sizeof (T) * (N)))
118 
119 /*--------------------------------------------------------------------*/
120 /*--- end                                           vg_libciface.h ---*/
121 /*--------------------------------------------------------------------*/
122