cxxfilt 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,194 @@
1
+ /* Internal demangler interface for g++ V3 ABI.
2
+ Copyright (C) 2003-2018 Free Software Foundation, Inc.
3
+ Written by Ian Lance Taylor <ian@wasabisystems.com>.
4
+
5
+ This file is part of the libiberty library, which is part of GCC.
6
+
7
+ This file is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation; either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ In addition to the permissions in the GNU General Public License, the
13
+ Free Software Foundation gives you unlimited permission to link the
14
+ compiled version of this file into combinations with other programs,
15
+ and to distribute those combinations without any restriction coming
16
+ from the use of this file. (The General Public License restrictions
17
+ do apply in other respects; for example, they cover modification of
18
+ the file, and distribution when not linked into a combined
19
+ executable.)
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
29
+ */
30
+
31
+ /* This file provides some definitions shared by cp-demangle.c and
32
+ cp-demint.c. It should not be included by any other files. */
33
+
34
+ /* Information we keep for operators. */
35
+
36
+ struct demangle_operator_info
37
+ {
38
+ /* Mangled name. */
39
+ const char *code;
40
+ /* Real name. */
41
+ const char *name;
42
+ /* Length of real name. */
43
+ int len;
44
+ /* Number of arguments. */
45
+ int args;
46
+ };
47
+
48
+ /* How to print the value of a builtin type. */
49
+
50
+ enum d_builtin_type_print
51
+ {
52
+ /* Print as (type)val. */
53
+ D_PRINT_DEFAULT,
54
+ /* Print as integer. */
55
+ D_PRINT_INT,
56
+ /* Print as unsigned integer, with trailing "u". */
57
+ D_PRINT_UNSIGNED,
58
+ /* Print as long, with trailing "l". */
59
+ D_PRINT_LONG,
60
+ /* Print as unsigned long, with trailing "ul". */
61
+ D_PRINT_UNSIGNED_LONG,
62
+ /* Print as long long, with trailing "ll". */
63
+ D_PRINT_LONG_LONG,
64
+ /* Print as unsigned long long, with trailing "ull". */
65
+ D_PRINT_UNSIGNED_LONG_LONG,
66
+ /* Print as bool. */
67
+ D_PRINT_BOOL,
68
+ /* Print as float--put value in square brackets. */
69
+ D_PRINT_FLOAT,
70
+ /* Print in usual way, but here to detect void. */
71
+ D_PRINT_VOID
72
+ };
73
+
74
+ /* Information we keep for a builtin type. */
75
+
76
+ struct demangle_builtin_type_info
77
+ {
78
+ /* Type name. */
79
+ const char *name;
80
+ /* Length of type name. */
81
+ int len;
82
+ /* Type name when using Java. */
83
+ const char *java_name;
84
+ /* Length of java name. */
85
+ int java_len;
86
+ /* How to print a value of this type. */
87
+ enum d_builtin_type_print print;
88
+ };
89
+
90
+ /* The information structure we pass around. */
91
+
92
+ struct d_info
93
+ {
94
+ /* The string we are demangling. */
95
+ const char *s;
96
+ /* The end of the string we are demangling. */
97
+ const char *send;
98
+ /* The options passed to the demangler. */
99
+ int options;
100
+ /* The next character in the string to consider. */
101
+ const char *n;
102
+ /* The array of components. */
103
+ struct demangle_component *comps;
104
+ /* The index of the next available component. */
105
+ int next_comp;
106
+ /* The number of available component structures. */
107
+ int num_comps;
108
+ /* The array of substitutions. */
109
+ struct demangle_component **subs;
110
+ /* The index of the next substitution. */
111
+ int next_sub;
112
+ /* The number of available entries in the subs array. */
113
+ int num_subs;
114
+ /* The last name we saw, for constructors and destructors. */
115
+ struct demangle_component *last_name;
116
+ /* A running total of the length of large expansions from the
117
+ mangled name to the demangled name, such as standard
118
+ substitutions and builtin types. */
119
+ int expansion;
120
+ /* Non-zero if we are parsing an expression. */
121
+ int is_expression;
122
+ /* Non-zero if we are parsing the type operand of a conversion
123
+ operator, but not when in an expression. */
124
+ int is_conversion;
125
+ };
126
+
127
+ /* To avoid running past the ending '\0', don't:
128
+ - call d_peek_next_char if d_peek_char returned '\0'
129
+ - call d_advance with an 'i' that is too large
130
+ - call d_check_char(di, '\0')
131
+ Everything else is safe. */
132
+ #define d_peek_char(di) (*((di)->n))
133
+ #ifndef CHECK_DEMANGLER
134
+ # define d_peek_next_char(di) ((di)->n[1])
135
+ # define d_advance(di, i) ((di)->n += (i))
136
+ #endif
137
+ #define d_check_char(di, c) (d_peek_char(di) == c ? ((di)->n++, 1) : 0)
138
+ #define d_next_char(di) (d_peek_char(di) == '\0' ? '\0' : *((di)->n++))
139
+ #define d_str(di) ((di)->n)
140
+
141
+ #ifdef CHECK_DEMANGLER
142
+ static inline char
143
+ d_peek_next_char (const struct d_info *di)
144
+ {
145
+ if (!di->n[0])
146
+ abort ();
147
+ return di->n[1];
148
+ }
149
+
150
+ static inline void
151
+ d_advance (struct d_info *di, int i)
152
+ {
153
+ if (i < 0)
154
+ abort ();
155
+ while (i--)
156
+ {
157
+ if (!di->n[0])
158
+ abort ();
159
+ di->n++;
160
+ }
161
+ }
162
+ #endif
163
+
164
+ /* Functions and arrays in cp-demangle.c which are referenced by
165
+ functions in cp-demint.c. */
166
+ #ifdef IN_GLIBCPP_V3
167
+ #define CP_STATIC_IF_GLIBCPP_V3 static
168
+ #else
169
+ #define CP_STATIC_IF_GLIBCPP_V3 extern
170
+ #endif
171
+
172
+ #ifndef IN_GLIBCPP_V3
173
+ extern const struct demangle_operator_info cplus_demangle_operators[];
174
+ #endif
175
+
176
+ #define D_BUILTIN_TYPE_COUNT (33)
177
+
178
+ CP_STATIC_IF_GLIBCPP_V3
179
+ const struct demangle_builtin_type_info
180
+ cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT];
181
+
182
+ CP_STATIC_IF_GLIBCPP_V3
183
+ struct demangle_component *
184
+ cplus_demangle_mangled_name (struct d_info *, int);
185
+
186
+ CP_STATIC_IF_GLIBCPP_V3
187
+ struct demangle_component *
188
+ cplus_demangle_type (struct d_info *);
189
+
190
+ extern void
191
+ cplus_demangle_init_info (const char *, int, size_t, struct d_info *);
192
+
193
+ /* cp-demangle.c needs to define this a little differently */
194
+ #undef CP_STATIC_IF_GLIBCPP_V3
@@ -0,0 +1,237 @@
1
+ /* Demangler component interface functions.
2
+ Copyright (C) 2004-2018 Free Software Foundation, Inc.
3
+ Written by Ian Lance Taylor <ian@wasabisystems.com>.
4
+
5
+ This file is part of the libiberty library, which is part of GCC.
6
+
7
+ This file is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation; either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ In addition to the permissions in the GNU General Public License, the
13
+ Free Software Foundation gives you unlimited permission to link the
14
+ compiled version of this file into combinations with other programs,
15
+ and to distribute those combinations without any restriction coming
16
+ from the use of this file. (The General Public License restrictions
17
+ do apply in other respects; for example, they cover modification of
18
+ the file, and distribution when not linked into a combined
19
+ executable.)
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
29
+ */
30
+
31
+ /* This file implements a few interface functions which are provided
32
+ for use with struct demangle_component trees. These functions are
33
+ declared in demangle.h. These functions are closely tied to the
34
+ demangler code in cp-demangle.c, and other interface functions can
35
+ be found in that file. We put these functions in a separate file
36
+ because they are not needed by the demangler, and so we avoid
37
+ having them pulled in by programs which only need the
38
+ demangler. */
39
+
40
+ #ifdef HAVE_CONFIG_H
41
+ #include "config.h"
42
+ #endif
43
+
44
+ #ifdef HAVE_STDLIB_H
45
+ #include <stdlib.h>
46
+ #endif
47
+ #ifdef HAVE_STRING_H
48
+ #include <string.h>
49
+ #endif
50
+
51
+ #include "ansidecl.h"
52
+ #include "libiberty.h"
53
+ #include "demangle.h"
54
+ #include "cp-demangle.h"
55
+
56
+ /* Fill in most component types. */
57
+
58
+ int
59
+ cplus_demangle_fill_component (struct demangle_component *p,
60
+ enum demangle_component_type type,
61
+ struct demangle_component *left,
62
+ struct demangle_component *right)
63
+ {
64
+ if (p == NULL)
65
+ return 0;
66
+ switch (type)
67
+ {
68
+ case DEMANGLE_COMPONENT_QUAL_NAME:
69
+ case DEMANGLE_COMPONENT_LOCAL_NAME:
70
+ case DEMANGLE_COMPONENT_TYPED_NAME:
71
+ case DEMANGLE_COMPONENT_TEMPLATE:
72
+ case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
73
+ case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
74
+ case DEMANGLE_COMPONENT_FUNCTION_TYPE:
75
+ case DEMANGLE_COMPONENT_ARRAY_TYPE:
76
+ case DEMANGLE_COMPONENT_PTRMEM_TYPE:
77
+ case DEMANGLE_COMPONENT_ARGLIST:
78
+ case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
79
+ case DEMANGLE_COMPONENT_UNARY:
80
+ case DEMANGLE_COMPONENT_BINARY:
81
+ case DEMANGLE_COMPONENT_BINARY_ARGS:
82
+ case DEMANGLE_COMPONENT_TRINARY:
83
+ case DEMANGLE_COMPONENT_TRINARY_ARG1:
84
+ case DEMANGLE_COMPONENT_TRINARY_ARG2:
85
+ case DEMANGLE_COMPONENT_LITERAL:
86
+ case DEMANGLE_COMPONENT_LITERAL_NEG:
87
+ break;
88
+
89
+ /* These component types only have one subtree. */
90
+ case DEMANGLE_COMPONENT_VTABLE:
91
+ case DEMANGLE_COMPONENT_VTT:
92
+ case DEMANGLE_COMPONENT_TYPEINFO:
93
+ case DEMANGLE_COMPONENT_TYPEINFO_NAME:
94
+ case DEMANGLE_COMPONENT_TYPEINFO_FN:
95
+ case DEMANGLE_COMPONENT_THUNK:
96
+ case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
97
+ case DEMANGLE_COMPONENT_COVARIANT_THUNK:
98
+ case DEMANGLE_COMPONENT_JAVA_CLASS:
99
+ case DEMANGLE_COMPONENT_GUARD:
100
+ case DEMANGLE_COMPONENT_REFTEMP:
101
+ case DEMANGLE_COMPONENT_RESTRICT:
102
+ case DEMANGLE_COMPONENT_VOLATILE:
103
+ case DEMANGLE_COMPONENT_CONST:
104
+ case DEMANGLE_COMPONENT_RESTRICT_THIS:
105
+ case DEMANGLE_COMPONENT_VOLATILE_THIS:
106
+ case DEMANGLE_COMPONENT_CONST_THIS:
107
+ case DEMANGLE_COMPONENT_POINTER:
108
+ case DEMANGLE_COMPONENT_REFERENCE:
109
+ case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
110
+ case DEMANGLE_COMPONENT_COMPLEX:
111
+ case DEMANGLE_COMPONENT_IMAGINARY:
112
+ case DEMANGLE_COMPONENT_VENDOR_TYPE:
113
+ case DEMANGLE_COMPONENT_CAST:
114
+ case DEMANGLE_COMPONENT_CONVERSION:
115
+ if (right != NULL)
116
+ return 0;
117
+ break;
118
+
119
+ default:
120
+ /* Other types do not use subtrees. */
121
+ return 0;
122
+ }
123
+
124
+ p->type = type;
125
+ p->u.s_binary.left = left;
126
+ p->u.s_binary.right = right;
127
+ p->d_printing = 0;
128
+
129
+ return 1;
130
+ }
131
+
132
+ /* Fill in a DEMANGLE_COMPONENT_BUILTIN_TYPE. */
133
+
134
+ int
135
+ cplus_demangle_fill_builtin_type (struct demangle_component *p,
136
+ const char *type_name)
137
+ {
138
+ int len;
139
+ unsigned int i;
140
+
141
+ if (p == NULL || type_name == NULL)
142
+ return 0;
143
+ len = strlen (type_name);
144
+ for (i = 0; i < D_BUILTIN_TYPE_COUNT; ++i)
145
+ {
146
+ if (len == cplus_demangle_builtin_types[i].len
147
+ && strcmp (type_name, cplus_demangle_builtin_types[i].name) == 0)
148
+ {
149
+ p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
150
+ p->u.s_builtin.type = &cplus_demangle_builtin_types[i];
151
+ p->d_printing = 0;
152
+ return 1;
153
+ }
154
+ }
155
+ return 0;
156
+ }
157
+
158
+ /* Fill in a DEMANGLE_COMPONENT_OPERATOR. */
159
+
160
+ int
161
+ cplus_demangle_fill_operator (struct demangle_component *p,
162
+ const char *opname, int args)
163
+ {
164
+ int len;
165
+ unsigned int i;
166
+
167
+ if (p == NULL || opname == NULL)
168
+ return 0;
169
+ len = strlen (opname);
170
+ for (i = 0; cplus_demangle_operators[i].name != NULL; ++i)
171
+ {
172
+ if (len == cplus_demangle_operators[i].len
173
+ && args == cplus_demangle_operators[i].args
174
+ && strcmp (opname, cplus_demangle_operators[i].name) == 0)
175
+ {
176
+ p->type = DEMANGLE_COMPONENT_OPERATOR;
177
+ p->u.s_operator.op = &cplus_demangle_operators[i];
178
+ p->d_printing = 0;
179
+ return 1;
180
+ }
181
+ }
182
+ return 0;
183
+ }
184
+
185
+ /* Translate a mangled name into components. */
186
+
187
+ struct demangle_component *
188
+ cplus_demangle_v3_components (const char *mangled, int options, void **mem)
189
+ {
190
+ size_t len;
191
+ int type;
192
+ struct d_info di;
193
+ struct demangle_component *dc;
194
+
195
+ len = strlen (mangled);
196
+
197
+ if (mangled[0] == '_' && mangled[1] == 'Z')
198
+ type = 0;
199
+ else
200
+ {
201
+ if ((options & DMGL_TYPES) == 0)
202
+ return NULL;
203
+ type = 1;
204
+ }
205
+
206
+ cplus_demangle_init_info (mangled, options, len, &di);
207
+
208
+ di.comps = ((struct demangle_component *)
209
+ malloc (di.num_comps * sizeof (struct demangle_component)));
210
+ di.subs = ((struct demangle_component **)
211
+ malloc (di.num_subs * sizeof (struct demangle_component *)));
212
+ if (di.comps == NULL || di.subs == NULL)
213
+ {
214
+ free (di.comps);
215
+ free (di.subs);
216
+ return NULL;
217
+ }
218
+
219
+ if (! type)
220
+ dc = cplus_demangle_mangled_name (&di, 1);
221
+ else
222
+ dc = cplus_demangle_type (&di);
223
+
224
+ /* If DMGL_PARAMS is set, then if we didn't consume the entire
225
+ mangled string, then we didn't successfully demangle it. */
226
+ if ((options & DMGL_PARAMS) != 0 && d_peek_char (&di) != '\0')
227
+ dc = NULL;
228
+
229
+ free (di.subs);
230
+
231
+ if (dc != NULL)
232
+ *mem = di.comps;
233
+ else
234
+ free (di.comps);
235
+
236
+ return dc;
237
+ }