vgdb: Handle EAGAIN in read_buf
[valgrind.git] / coregrind / m_demangle / vg_libciface.h
blobd64d5a70c1ab6bc02e5a6a7393edb02c3fd2a542
2 /*--------------------------------------------------------------------*/
3 /*--- Demangling of C++ mangled names. vg_libciface.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Julian Seward
11 jseward@acm.org
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 /* This file contains a bunch of macro definitions etc which are
30 really "impedance matchers". They make it possible for
31 cp-demangle.c, cplus-dem.c, dyn-string.c and safe-ctype.c (taken
32 from GNU libiberty) to be compiled in the Valgrind framework with a
33 minimum of changes.
35 This file should only be included in files which contain libiberty
36 code. */
38 #include "pub_core_basics.h"
39 #include "pub_core_libcbase.h"
40 #include "pub_core_libcassert.h"
41 #include "pub_core_libcprint.h"
42 #include "pub_core_mallocfree.h"
45 #define abort() vg_assert(0)
46 #define atoi(_str) VG_(strtoll10)((_str), NULL)
47 #define free(_pt) VG_(arena_free) (VG_AR_DEMANGLE,(_pt))
48 #define memcmp(_s1,_s2,_sz) VG_(memcmp)((_s1),(_s2),(_sz))
49 #define memcpy(_dd,_ss,_sz) VG_(memcpy)((_dd),(_ss),(_sz))
50 #define memmove(_dd,_ss,_sz) VG_(memmove)((_dd),(_ss),(_sz))
51 #define memset(_ss,_cc,_sz) VG_(memset)((_ss),(_cc),(_sz))
52 #define realloc(_cc,_pt,_sz) VG_(arena_realloc)(VG_AR_DEMANGLE,(_cc),(_pt),(_sz))
53 #define sprintf(_buf,_fmt,_args...) VG_(sprintf)((_buf),(_fmt),(_args))
54 #define snprintf(_buf,_size,_fmt,_args...) VG_(snprintf)((_buf),(_size),(_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)))
73 #define size_t SizeT
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))
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);
91 /* Required by safe-ctype.h */
93 #undef EOF
94 #define EOF -1
96 /* Taken from libiberty.h: */
98 #define ARRAY_SIZE(_arr) \
99 (sizeof (_arr) / sizeof ((_arr)[0]))
101 #define XNEWVEC(_Ty, _Nn) \
102 ((_Ty *) xmalloc(sizeof (_Ty) * (_Nn)))
104 #define XRESIZEVEC(_Ty, _Pt, _Nn) \
105 ((_Ty *) xrealloc((void *) (_Pt), sizeof (_Ty) * (_Nn)))
107 #define XRESIZEVAR(_Ty, _Pt, _Sz) \
108 ((_Ty *) xrealloc((_Pt), (_Sz)))
110 #define XNEW(_Ty) \
111 ((_Ty *) xmalloc(sizeof (_Ty)))
113 #define XDELETEVEC(P) \
114 free ((void*) (P))
116 #define XDUPVEC(T, P, N) \
117 ((T *) xmemdup ((P), sizeof (T) * (N), sizeof (T) * (N)))
119 /*--------------------------------------------------------------------*/
120 /*--- end vg_libciface.h ---*/
121 /*--------------------------------------------------------------------*/