2 * Copyright (c) 2007, 2008 Hyogeol Lee <hyogeollee@gmail.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/types.h>
37 * @file cpp_demangle.c
38 * @brief Decode IA-64 C++ ABI style implementation.
40 * IA-64 standard ABI(Itanium C++ ABI) references.
42 * http://www.codesourcery.com/cxx-abi/abi.html#mangling \n
43 * http://www.codesourcery.com/cxx-abi/abi-mangling.html
46 /** @brief Dynamic vector data for string. */
56 #define BUFFER_GROWFACTOR 1.618
57 #define VECTOR_DEF_CAPACITY 8
58 #define ELFTC_ISDIGIT(C) (isdigit((C) & 0xFF))
61 TYPE_PTR
, TYPE_REF
, TYPE_CMX
, TYPE_IMG
, TYPE_EXT
, TYPE_RST
, TYPE_VAT
,
65 struct vector_type_qualifier
{
66 size_t size
, capacity
;
67 enum type_qualifier
*q_container
;
68 struct vector_str ext_name
;
72 READ_FAIL
, READ_NEST
, READ_TMPL
, READ_EXPR
, READ_EXPL
, READ_LOCAL
,
73 READ_TYPE
, READ_FUNC
, READ_PTRMEM
76 struct vector_read_cmd
{
77 size_t size
, capacity
;
78 enum read_cmd
*r_container
;
81 struct cpp_demangle_data
{
82 struct vector_str output
; /* output string vector */
83 struct vector_str output_tmp
;
84 struct vector_str subst
; /* substitution string vector */
85 struct vector_str tmpl
;
86 struct vector_str class_type
;
87 struct vector_read_cmd cmd
;
88 bool paren
; /* parenthesis opened */
89 bool pfirst
; /* first element of parameter */
90 bool mem_rst
; /* restrict member function */
91 bool mem_vat
; /* volatile member function */
92 bool mem_cst
; /* const member function */
94 const char *cur
; /* current mangled name ptr */
95 const char *last_sname
; /* last source name */
99 #define CPP_DEMANGLE_TRY_LIMIT 128
100 #define FLOAT_SPRINTF_TRY_LIMIT 5
101 #define FLOAT_QUADRUPLE_BYTES 16
102 #define FLOAT_EXTENED_BYTES 10
104 #define SIMPLE_HASH(x,y) (64 * x + y)
106 static size_t get_strlen_sum(const struct vector_str
*v
);
107 static bool vector_str_grow(struct vector_str
*v
);
110 get_strlen_sum(const struct vector_str
*v
)
119 for (i
= 0; i
< v
->size
; ++i
)
120 len
+= strlen(v
->container
[i
]);
126 * @brief Deallocate resource in vector_str.
129 vector_str_dest(struct vector_str
*v
)
136 for (i
= 0; i
< v
->size
; ++i
)
137 free(v
->container
[i
]);
143 * @brief Find string in vector_str.
144 * @param v Destination vector.
145 * @param o String to find.
146 * @param l Length of the string.
147 * @return -1 at failed, 0 at not found, 1 at found.
150 vector_str_find(const struct vector_str
*v
, const char *o
, size_t l
)
154 if (v
== NULL
|| o
== NULL
)
157 for (i
= 0; i
< v
->size
; ++i
)
158 if (strncmp(v
->container
[i
], o
, l
) == 0)
165 * @brief Get new allocated flat string from vector.
167 * If l is not NULL, return length of the string.
168 * @param v Destination vector.
169 * @param l Length of the string.
170 * @return NULL at failed or NUL terminated new allocated string.
173 vector_str_get_flat(const struct vector_str
*v
, size_t *l
)
175 ssize_t elem_pos
, elem_size
, rtn_size
;
179 if (v
== NULL
|| v
->size
== 0)
182 if ((rtn_size
= get_strlen_sum(v
)) == 0)
185 if ((rtn
= malloc(sizeof(char) * (rtn_size
+ 1))) == NULL
)
189 for (i
= 0; i
< v
->size
; ++i
) {
190 elem_size
= strlen(v
->container
[i
]);
192 memcpy(rtn
+ elem_pos
, v
->container
[i
], elem_size
);
194 elem_pos
+= elem_size
;
197 rtn
[rtn_size
] = '\0';
206 vector_str_grow(struct vector_str
*v
)
214 assert(v
->capacity
> 0);
216 tmp_cap
= v
->capacity
* BUFFER_GROWFACTOR
;
218 assert(tmp_cap
> v
->capacity
);
220 if ((tmp_ctn
= malloc(sizeof(char *) * tmp_cap
)) == NULL
)
223 for (i
= 0; i
< v
->size
; ++i
)
224 tmp_ctn
[i
] = v
->container
[i
];
228 v
->container
= tmp_ctn
;
229 v
->capacity
= tmp_cap
;
235 * @brief Initialize vector_str.
236 * @return false at failed, true at success.
239 vector_str_init(struct vector_str
*v
)
246 v
->capacity
= VECTOR_DEF_CAPACITY
;
248 assert(v
->capacity
> 0);
250 if ((v
->container
= malloc(sizeof(char *) * v
->capacity
)) == NULL
)
253 assert(v
->container
!= NULL
);
259 * @brief Remove last element in vector_str.
260 * @return false at failed, true at success.
263 vector_str_pop(struct vector_str
*v
)
274 free(v
->container
[v
->size
]);
275 v
->container
[v
->size
] = NULL
;
281 * @brief Push back string to vector.
282 * @return false at failed, true at success.
285 vector_str_push(struct vector_str
*v
, const char *str
, size_t len
)
288 if (v
== NULL
|| str
== NULL
)
291 if (v
->size
== v
->capacity
&& vector_str_grow(v
) == false)
294 if ((v
->container
[v
->size
] = malloc(sizeof(char) * (len
+ 1))) == NULL
)
297 snprintf(v
->container
[v
->size
], len
+ 1, "%s", str
);
305 * @brief Push front org vector to det vector.
306 * @return false at failed, true at success.
309 vector_str_push_vector_head(struct vector_str
*dst
, struct vector_str
*org
)
311 size_t i
, j
, tmp_cap
;
314 if (dst
== NULL
|| org
== NULL
)
317 tmp_cap
= (dst
->size
+ org
->size
) * BUFFER_GROWFACTOR
;
319 if ((tmp_ctn
= malloc(sizeof(char *) * tmp_cap
)) == NULL
)
322 for (i
= 0; i
< org
->size
; ++i
)
323 if ((tmp_ctn
[i
] = strdup(org
->container
[i
])) == NULL
) {
324 for (j
= 0; j
< i
; ++j
)
332 for (i
= 0; i
< dst
->size
; ++i
)
333 tmp_ctn
[i
+ org
->size
] = dst
->container
[i
];
335 free(dst
->container
);
337 dst
->container
= tmp_ctn
;
338 dst
->capacity
= tmp_cap
;
339 dst
->size
+= org
->size
;
345 * @brief Get new allocated flat string from vector between begin and end.
347 * If r_len is not NULL, string length will be returned.
348 * @return NULL at failed or NUL terminated new allocated string.
351 vector_str_substr(const struct vector_str
*v
, size_t begin
, size_t end
,
357 if (v
== NULL
|| begin
> end
)
361 for (i
= begin
; i
< end
+ 1; ++i
)
362 len
+= strlen(v
->container
[i
]);
364 if ((rtn
= malloc(sizeof(char) * (len
+ 1))) == NULL
)
371 for (i
= begin
; i
< end
+ 1; ++i
) {
372 len
= strlen(v
->container
[i
]);
373 memcpy(rtn
+ cur
, v
->container
[i
], len
);
381 static void cpp_demangle_data_dest(struct cpp_demangle_data
*);
382 static int cpp_demangle_data_init(struct cpp_demangle_data
*,
384 static int cpp_demangle_get_subst(struct cpp_demangle_data
*, size_t);
385 static int cpp_demangle_get_tmpl_param(struct cpp_demangle_data
*, size_t);
386 static int cpp_demangle_push_fp(struct cpp_demangle_data
*,
387 char *(*)(const char *, size_t));
388 static int cpp_demangle_push_str(struct cpp_demangle_data
*, const char *,
390 static int cpp_demangle_push_subst(struct cpp_demangle_data
*,
391 const char *, size_t);
392 static int cpp_demangle_push_subst_v(struct cpp_demangle_data
*,
393 struct vector_str
*);
394 static int cpp_demangle_push_type_qualifier(struct cpp_demangle_data
*,
395 struct vector_type_qualifier
*, const char *);
396 static int cpp_demangle_read_array(struct cpp_demangle_data
*);
397 static int cpp_demangle_read_encoding(struct cpp_demangle_data
*);
398 static int cpp_demangle_read_expr_primary(struct cpp_demangle_data
*);
399 static int cpp_demangle_read_expression(struct cpp_demangle_data
*);
400 static int cpp_demangle_read_expression_flat(struct cpp_demangle_data
*,
402 static int cpp_demangle_read_expression_binary(struct cpp_demangle_data
*,
403 const char *, size_t);
404 static int cpp_demangle_read_expression_unary(struct cpp_demangle_data
*,
405 const char *, size_t);
406 static int cpp_demangle_read_expression_trinary(struct cpp_demangle_data
*,
407 const char *, size_t, const char *, size_t);
408 static int cpp_demangle_read_function(struct cpp_demangle_data
*, int *,
409 struct vector_type_qualifier
*);
410 static int cpp_demangle_local_source_name(struct cpp_demangle_data
*ddata
);
411 static int cpp_demangle_read_local_name(struct cpp_demangle_data
*);
412 static int cpp_demangle_read_name(struct cpp_demangle_data
*);
413 static int cpp_demangle_read_name_flat(struct cpp_demangle_data
*,
415 static int cpp_demangle_read_nested_name(struct cpp_demangle_data
*);
416 static int cpp_demangle_read_number(struct cpp_demangle_data
*, long *);
417 static int cpp_demangle_read_number_as_string(struct cpp_demangle_data
*,
419 static int cpp_demangle_read_nv_offset(struct cpp_demangle_data
*);
420 static int cpp_demangle_read_offset(struct cpp_demangle_data
*);
421 static int cpp_demangle_read_offset_number(struct cpp_demangle_data
*);
422 static int cpp_demangle_read_pointer_to_member(struct cpp_demangle_data
*);
423 static int cpp_demangle_read_sname(struct cpp_demangle_data
*);
424 static int cpp_demangle_read_subst(struct cpp_demangle_data
*);
425 static int cpp_demangle_read_subst_std(struct cpp_demangle_data
*);
426 static int cpp_demangle_read_subst_stdtmpl(struct cpp_demangle_data
*,
427 const char *, size_t);
428 static int cpp_demangle_read_tmpl_arg(struct cpp_demangle_data
*);
429 static int cpp_demangle_read_tmpl_args(struct cpp_demangle_data
*);
430 static int cpp_demangle_read_tmpl_param(struct cpp_demangle_data
*);
431 static int cpp_demangle_read_type(struct cpp_demangle_data
*, int);
432 static int cpp_demangle_read_type_flat(struct cpp_demangle_data
*,
434 static int cpp_demangle_read_uqname(struct cpp_demangle_data
*);
435 static int cpp_demangle_read_v_offset(struct cpp_demangle_data
*);
436 static char *decode_fp_to_double(const char *, size_t);
437 static char *decode_fp_to_float(const char *, size_t);
438 static char *decode_fp_to_float128(const char *, size_t);
439 static char *decode_fp_to_float80(const char *, size_t);
440 static char *decode_fp_to_long_double(const char *, size_t);
441 static int hex_to_dec(char);
442 static void vector_read_cmd_dest(struct vector_read_cmd
*);
443 static int vector_read_cmd_find(struct vector_read_cmd
*, enum read_cmd
);
444 static int vector_read_cmd_init(struct vector_read_cmd
*);
445 static int vector_read_cmd_pop(struct vector_read_cmd
*);
446 static int vector_read_cmd_push(struct vector_read_cmd
*, enum read_cmd
);
447 static void vector_type_qualifier_dest(struct vector_type_qualifier
*);
448 static int vector_type_qualifier_init(struct vector_type_qualifier
*);
449 static int vector_type_qualifier_push(struct vector_type_qualifier
*,
450 enum type_qualifier
);
453 * @brief Decode the input string by IA-64 C++ ABI style.
455 * GNU GCC v3 use IA-64 standard ABI.
456 * @return New allocated demangled string or NULL if failed.
457 * @todo 1. Testing and more test case. 2. Code cleaning.
460 __cxa_demangle_gnu3(const char *org
)
462 struct cpp_demangle_data ddata
;
470 org_len
= strlen(org
);
471 if (org_len
> 11 && !strncmp(org
, "_GLOBAL__I_", 11)) {
472 if ((rtn
= malloc(org_len
+ 19)) == NULL
)
474 snprintf(rtn
, org_len
+ 19,
475 "global constructors keyed to %s", org
+ 11);
479 // Try demangling as a type for short encodings
480 if ((org_len
< 2) || (org
[0] != '_' || org
[1] != 'Z' )) {
481 if (!cpp_demangle_data_init(&ddata
, org
))
483 if (!cpp_demangle_read_type(&ddata
, 0))
485 rtn
= vector_str_get_flat(&ddata
.output
, (size_t *) NULL
);
490 if (!cpp_demangle_data_init(&ddata
, org
+ 2))
495 if (!cpp_demangle_read_encoding(&ddata
))
499 while (*ddata
.cur
!= '\0') {
501 * Breaking at some gcc info at tail. e.g) @@GLIBCXX_3.4
503 if (*ddata
.cur
== '@' && *(ddata
.cur
+ 1) == '@')
505 if (!cpp_demangle_read_type(&ddata
, 1))
507 if (limit
++ > CPP_DEMANGLE_TRY_LIMIT
)
511 if (ddata
.output
.size
== 0)
513 if (ddata
.paren
&& !vector_str_push(&ddata
.output
, ")", 1))
515 if (ddata
.mem_vat
&& !vector_str_push(&ddata
.output
, " volatile", 9))
517 if (ddata
.mem_cst
&& !vector_str_push(&ddata
.output
, " const", 6))
519 if (ddata
.mem_rst
&& !vector_str_push(&ddata
.output
, " restrict", 9))
522 rtn
= vector_str_get_flat(&ddata
.output
, (size_t *) NULL
);
525 cpp_demangle_data_dest(&ddata
);
531 cpp_demangle_data_dest(struct cpp_demangle_data
*d
)
537 vector_read_cmd_dest(&d
->cmd
);
538 vector_str_dest(&d
->class_type
);
539 vector_str_dest(&d
->tmpl
);
540 vector_str_dest(&d
->subst
);
541 vector_str_dest(&d
->output_tmp
);
542 vector_str_dest(&d
->output
);
546 cpp_demangle_data_init(struct cpp_demangle_data
*d
, const char *cur
)
549 if (d
== NULL
|| cur
== NULL
)
552 if (!vector_str_init(&d
->output
))
554 if (!vector_str_init(&d
->output_tmp
))
556 if (!vector_str_init(&d
->subst
))
558 if (!vector_str_init(&d
->tmpl
))
560 if (!vector_str_init(&d
->class_type
))
562 if (!vector_read_cmd_init(&d
->cmd
))
565 assert(d
->output
.container
!= NULL
);
566 assert(d
->output_tmp
.container
!= NULL
);
567 assert(d
->subst
.container
!= NULL
);
568 assert(d
->tmpl
.container
!= NULL
);
569 assert(d
->class_type
.container
!= NULL
);
578 d
->last_sname
= NULL
;
584 vector_str_dest(&d
->class_type
);
586 vector_str_dest(&d
->tmpl
);
588 vector_str_dest(&d
->subst
);
590 vector_str_dest(&d
->output_tmp
);
592 vector_str_dest(&d
->output
);
598 cpp_demangle_push_fp(struct cpp_demangle_data
*ddata
,
599 char *(*decoder
)(const char *, size_t))
606 if (ddata
== NULL
|| decoder
== NULL
)
610 while (*ddata
->cur
!= 'E')
613 if ((f
= decoder(fp
, ddata
->cur
- fp
)) == NULL
)
617 if ((len
= strlen(f
)) > 0)
618 rtn
= cpp_demangle_push_str(ddata
, f
, len
);
628 cpp_demangle_push_str(struct cpp_demangle_data
*ddata
, const char *str
,
632 if (ddata
== NULL
|| str
== NULL
|| len
== 0)
635 if (ddata
->push_head
> 0)
636 return (vector_str_push(&ddata
->output_tmp
, str
, len
));
638 return (vector_str_push(&ddata
->output
, str
, len
));
642 cpp_demangle_push_subst(struct cpp_demangle_data
*ddata
, const char *str
,
646 if (ddata
== NULL
|| str
== NULL
|| len
== 0)
649 if (!vector_str_find(&ddata
->subst
, str
, len
))
650 return (vector_str_push(&ddata
->subst
, str
, len
));
656 cpp_demangle_push_subst_v(struct cpp_demangle_data
*ddata
, struct vector_str
*v
)
662 if (ddata
== NULL
|| v
== NULL
)
665 if ((str
= vector_str_get_flat(v
, &str_len
)) == NULL
)
668 rtn
= cpp_demangle_push_subst(ddata
, str
, str_len
);
676 cpp_demangle_push_type_qualifier(struct cpp_demangle_data
*ddata
,
677 struct vector_type_qualifier
*v
, const char *type_str
)
679 struct vector_str subst_v
;
680 size_t idx
, e_idx
, e_len
;
684 if (ddata
== NULL
|| v
== NULL
)
687 if ((idx
= v
->size
) == 0)
691 if (type_str
!= NULL
) {
692 if (!vector_str_init(&subst_v
))
694 if (!vector_str_push(&subst_v
, type_str
, strlen(type_str
)))
700 switch (v
->q_container
[idx
- 1]) {
702 if (!cpp_demangle_push_str(ddata
, "*", 1))
704 if (type_str
!= NULL
) {
705 if (!vector_str_push(&subst_v
, "*", 1))
707 if (!cpp_demangle_push_subst_v(ddata
,
714 if (!cpp_demangle_push_str(ddata
, "&", 1))
716 if (type_str
!= NULL
) {
717 if (!vector_str_push(&subst_v
, "&", 1))
719 if (!cpp_demangle_push_subst_v(ddata
,
726 if (!cpp_demangle_push_str(ddata
, " complex", 8))
728 if (type_str
!= NULL
) {
729 if (!vector_str_push(&subst_v
, " complex", 8))
731 if (!cpp_demangle_push_subst_v(ddata
,
738 if (!cpp_demangle_push_str(ddata
, " imaginary", 10))
740 if (type_str
!= NULL
) {
741 if (!vector_str_push(&subst_v
, " imaginary",
744 if (!cpp_demangle_push_subst_v(ddata
,
751 if (v
->ext_name
.size
== 0 ||
752 e_idx
> v
->ext_name
.size
- 1)
754 if ((e_len
= strlen(v
->ext_name
.container
[e_idx
])) ==
757 if ((buf
= malloc(e_len
+ 2)) == NULL
)
759 snprintf(buf
, e_len
+ 2, " %s",
760 v
->ext_name
.container
[e_idx
]);
762 if (!cpp_demangle_push_str(ddata
, buf
, e_len
+ 1)) {
767 if (type_str
!= NULL
) {
768 if (!vector_str_push(&subst_v
, buf
,
773 if (!cpp_demangle_push_subst_v(ddata
,
784 if (!cpp_demangle_push_str(ddata
, " restrict", 9))
786 if (type_str
!= NULL
) {
787 if (!vector_str_push(&subst_v
, " restrict", 9))
789 if (!cpp_demangle_push_subst_v(ddata
,
796 if (!cpp_demangle_push_str(ddata
, " volatile", 9))
798 if (type_str
!= NULL
) {
799 if (!vector_str_push(&subst_v
, " volatile", 9))
801 if (!cpp_demangle_push_subst_v(ddata
,
808 if (!cpp_demangle_push_str(ddata
, " const", 6))
810 if (type_str
!= NULL
) {
811 if (!vector_str_push(&subst_v
, " const", 6))
813 if (!cpp_demangle_push_subst_v(ddata
,
820 if (v
->ext_name
.size
== 0 ||
821 e_idx
> v
->ext_name
.size
- 1)
823 if ((e_len
= strlen(v
->ext_name
.container
[e_idx
])) ==
826 if ((buf
= malloc(e_len
+ 12)) == NULL
)
828 snprintf(buf
, e_len
+ 12, " __vector(%s)",
829 v
->ext_name
.container
[e_idx
]);
830 if (!cpp_demangle_push_str(ddata
, buf
, e_len
+ 11)) {
834 if (type_str
!= NULL
) {
835 if (!vector_str_push(&subst_v
, buf
,
840 if (!cpp_demangle_push_subst_v(ddata
,
855 if (type_str
!= NULL
)
856 vector_str_dest(&subst_v
);
862 cpp_demangle_get_subst(struct cpp_demangle_data
*ddata
, size_t idx
)
866 if (ddata
== NULL
|| ddata
->subst
.size
<= idx
)
868 if ((len
= strlen(ddata
->subst
.container
[idx
])) == 0)
870 if (!cpp_demangle_push_str(ddata
, ddata
->subst
.container
[idx
], len
))
880 cpp_demangle_get_tmpl_param(struct cpp_demangle_data
*ddata
, size_t idx
)
884 if (ddata
== NULL
|| ddata
->tmpl
.size
<= idx
)
886 if ((len
= strlen(ddata
->tmpl
.container
[idx
])) == 0)
888 if (!cpp_demangle_push_str(ddata
, ddata
->tmpl
.container
[idx
], len
))
897 cpp_demangle_read_array(struct cpp_demangle_data
*ddata
)
899 size_t i
, num_len
, exp_len
, p_idx
, idx
;
903 if (ddata
== NULL
|| *(++ddata
->cur
) == '\0')
906 if (*ddata
->cur
== '_') {
907 if (*(++ddata
->cur
) == '\0')
910 if (!cpp_demangle_read_type(ddata
, 0))
913 if (!cpp_demangle_push_str(ddata
, "[]", 2))
916 if (ELFTC_ISDIGIT(*ddata
->cur
) != 0) {
918 while (ELFTC_ISDIGIT(*ddata
->cur
) != 0)
920 if (*ddata
->cur
!= '_')
922 num_len
= ddata
->cur
- num
;
924 if (*(++ddata
->cur
) == '\0')
926 if (!cpp_demangle_read_type(ddata
, 0))
928 if (!cpp_demangle_push_str(ddata
, "[", 1))
930 if (!cpp_demangle_push_str(ddata
, num
, num_len
))
932 if (!cpp_demangle_push_str(ddata
, "]", 1))
935 p_idx
= ddata
->output
.size
;
936 if (!cpp_demangle_read_expression(ddata
))
938 if ((exp
= vector_str_substr(&ddata
->output
, p_idx
,
939 ddata
->output
.size
- 1, &exp_len
)) == NULL
)
941 idx
= ddata
->output
.size
;
942 for (i
= p_idx
; i
< idx
; ++i
)
943 if (!vector_str_pop(&ddata
->output
)) {
947 if (*ddata
->cur
!= '_') {
952 if (*ddata
->cur
== '\0') {
956 if (!cpp_demangle_read_type(ddata
, 0)) {
960 if (!cpp_demangle_push_str(ddata
, "[", 1)) {
964 if (!cpp_demangle_push_str(ddata
, exp
, exp_len
)) {
968 if (!cpp_demangle_push_str(ddata
, "]", 1)) {
980 cpp_demangle_read_expr_primary(struct cpp_demangle_data
*ddata
)
984 if (ddata
== NULL
|| *(++ddata
->cur
) == '\0')
987 if (*ddata
->cur
== '_' && *(ddata
->cur
+ 1) == 'Z') {
989 if (*ddata
->cur
== '\0')
991 if (!cpp_demangle_read_encoding(ddata
))
997 switch (*ddata
->cur
) {
999 if (*(ddata
->cur
+ 2) != 'E')
1001 switch (*(++ddata
->cur
)) {
1004 return (cpp_demangle_push_str(ddata
, "false", 5));
1007 return (cpp_demangle_push_str(ddata
, "true", 4));
1014 return (cpp_demangle_push_fp(ddata
, decode_fp_to_double
));
1018 if (sizeof(long double) == 10)
1019 return (cpp_demangle_push_fp(ddata
,
1020 decode_fp_to_double
));
1021 return (cpp_demangle_push_fp(ddata
, decode_fp_to_float80
));
1025 return (cpp_demangle_push_fp(ddata
, decode_fp_to_float
));
1029 if (sizeof(long double) == 16)
1030 return (cpp_demangle_push_fp(ddata
,
1031 decode_fp_to_double
));
1032 return (cpp_demangle_push_fp(ddata
, decode_fp_to_float128
));
1043 if (*(++ddata
->cur
) == 'n') {
1044 if (!cpp_demangle_push_str(ddata
, "-", 1))
1049 while (*ddata
->cur
!= 'E') {
1050 if (!ELFTC_ISDIGIT(*ddata
->cur
))
1055 return (cpp_demangle_push_str(ddata
, num
,
1056 ddata
->cur
- num
- 1));
1064 cpp_demangle_read_expression(struct cpp_demangle_data
*ddata
)
1067 if (ddata
== NULL
|| *ddata
->cur
== '\0')
1070 switch (SIMPLE_HASH(*ddata
->cur
, *(ddata
->cur
+ 1))) {
1071 case SIMPLE_HASH('s', 't'):
1073 return (cpp_demangle_read_type(ddata
, 0));
1075 case SIMPLE_HASH('s', 'r'):
1077 if (!cpp_demangle_read_type(ddata
, 0))
1079 if (!cpp_demangle_read_uqname(ddata
))
1081 if (*ddata
->cur
== 'I')
1082 return (cpp_demangle_read_tmpl_args(ddata
));
1085 case SIMPLE_HASH('a', 'a'):
1088 return (cpp_demangle_read_expression_binary(ddata
, "&&", 2));
1090 case SIMPLE_HASH('a', 'd'):
1091 /* operator & (unary) */
1093 return (cpp_demangle_read_expression_unary(ddata
, "&", 1));
1095 case SIMPLE_HASH('a', 'n'):
1098 return (cpp_demangle_read_expression_binary(ddata
, "&", 1));
1100 case SIMPLE_HASH('a', 'N'):
1103 return (cpp_demangle_read_expression_binary(ddata
, "&=", 2));
1105 case SIMPLE_HASH('a', 'S'):
1108 return (cpp_demangle_read_expression_binary(ddata
, "=", 1));
1110 case SIMPLE_HASH('c', 'l'):
1113 return (cpp_demangle_read_expression_binary(ddata
, "()", 2));
1115 case SIMPLE_HASH('c', 'm'):
1118 return (cpp_demangle_read_expression_binary(ddata
, ",", 1));
1120 case SIMPLE_HASH('c', 'o'):
1123 return (cpp_demangle_read_expression_binary(ddata
, "~", 1));
1125 case SIMPLE_HASH('c', 'v'):
1126 /* operator (cast) */
1128 return (cpp_demangle_read_expression_binary(ddata
, "(cast)", 6));
1130 case SIMPLE_HASH('d', 'a'):
1131 /* operator delete [] */
1133 return (cpp_demangle_read_expression_unary(ddata
, "delete []", 9));
1135 case SIMPLE_HASH('d', 'e'):
1136 /* operator * (unary) */
1138 return (cpp_demangle_read_expression_unary(ddata
, "*", 1));
1140 case SIMPLE_HASH('d', 'l'):
1141 /* operator delete */
1143 return (cpp_demangle_read_expression_unary(ddata
, "delete", 6));
1145 case SIMPLE_HASH('d', 'v'):
1148 return (cpp_demangle_read_expression_binary(ddata
, "/", 1));
1150 case SIMPLE_HASH('d', 'V'):
1153 return (cpp_demangle_read_expression_binary(ddata
, "/=", 2));
1155 case SIMPLE_HASH('e', 'o'):
1158 return (cpp_demangle_read_expression_binary(ddata
, "^", 1));
1160 case SIMPLE_HASH('e', 'O'):
1163 return (cpp_demangle_read_expression_binary(ddata
, "^=", 2));
1165 case SIMPLE_HASH('e', 'q'):
1168 return (cpp_demangle_read_expression_binary(ddata
, "==", 2));
1170 case SIMPLE_HASH('g', 'e'):
1173 return (cpp_demangle_read_expression_binary(ddata
, ">=", 2));
1175 case SIMPLE_HASH('g', 't'):
1178 return (cpp_demangle_read_expression_binary(ddata
, ">", 1));
1180 case SIMPLE_HASH('i', 'x'):
1183 return (cpp_demangle_read_expression_binary(ddata
, "[]", 2));
1185 case SIMPLE_HASH('l', 'e'):
1188 return (cpp_demangle_read_expression_binary(ddata
, "<=", 2));
1190 case SIMPLE_HASH('l', 's'):
1193 return (cpp_demangle_read_expression_binary(ddata
, "<<", 2));
1195 case SIMPLE_HASH('l', 'S'):
1198 return (cpp_demangle_read_expression_binary(ddata
, "<<=", 3));
1200 case SIMPLE_HASH('l', 't'):
1203 return (cpp_demangle_read_expression_binary(ddata
, "<", 1));
1205 case SIMPLE_HASH('m', 'i'):
1208 return (cpp_demangle_read_expression_binary(ddata
, "-", 1));
1210 case SIMPLE_HASH('m', 'I'):
1213 return (cpp_demangle_read_expression_binary(ddata
, "-=", 2));
1215 case SIMPLE_HASH('m', 'l'):
1218 return (cpp_demangle_read_expression_binary(ddata
, "*", 1));
1220 case SIMPLE_HASH('m', 'L'):
1223 return (cpp_demangle_read_expression_binary(ddata
, "*=", 2));
1225 case SIMPLE_HASH('m', 'm'):
1228 return (cpp_demangle_read_expression_binary(ddata
, "--", 2));
1230 case SIMPLE_HASH('n', 'a'):
1231 /* operator new[] */
1233 return (cpp_demangle_read_expression_unary(ddata
, "new []", 6));
1235 case SIMPLE_HASH('n', 'e'):
1238 return (cpp_demangle_read_expression_binary(ddata
, "!=", 2));
1240 case SIMPLE_HASH('n', 'g'):
1241 /* operator - (unary) */
1243 return (cpp_demangle_read_expression_unary(ddata
, "-", 1));
1245 case SIMPLE_HASH('n', 't'):
1248 return (cpp_demangle_read_expression_binary(ddata
, "!", 1));
1250 case SIMPLE_HASH('n', 'w'):
1253 return (cpp_demangle_read_expression_unary(ddata
, "new", 3));
1255 case SIMPLE_HASH('o', 'o'):
1258 return (cpp_demangle_read_expression_binary(ddata
, "||", 2));
1260 case SIMPLE_HASH('o', 'r'):
1263 return (cpp_demangle_read_expression_binary(ddata
, "|", 1));
1265 case SIMPLE_HASH('o', 'R'):
1268 return (cpp_demangle_read_expression_binary(ddata
, "|=", 2));
1270 case SIMPLE_HASH('p', 'l'):
1273 return (cpp_demangle_read_expression_binary(ddata
, "+", 1));
1275 case SIMPLE_HASH('p', 'L'):
1278 return (cpp_demangle_read_expression_binary(ddata
, "+=", 2));
1280 case SIMPLE_HASH('p', 'm'):
1283 return (cpp_demangle_read_expression_binary(ddata
, "->*", 3));
1285 case SIMPLE_HASH('p', 'p'):
1288 return (cpp_demangle_read_expression_binary(ddata
, "++", 2));
1290 case SIMPLE_HASH('p', 's'):
1291 /* operator + (unary) */
1293 return (cpp_demangle_read_expression_unary(ddata
, "+", 1));
1295 case SIMPLE_HASH('p', 't'):
1298 return (cpp_demangle_read_expression_binary(ddata
, "->", 2));
1300 case SIMPLE_HASH('q', 'u'):
1303 return (cpp_demangle_read_expression_trinary(ddata
, "?", 1,
1306 case SIMPLE_HASH('r', 'm'):
1309 return (cpp_demangle_read_expression_binary(ddata
, "%", 1));
1311 case SIMPLE_HASH('r', 'M'):
1314 return (cpp_demangle_read_expression_binary(ddata
, "%=", 2));
1316 case SIMPLE_HASH('r', 's'):
1319 return (cpp_demangle_read_expression_binary(ddata
, ">>", 2));
1321 case SIMPLE_HASH('r', 'S'):
1324 return (cpp_demangle_read_expression_binary(ddata
, ">>=", 3));
1326 case SIMPLE_HASH('r', 'z'):
1327 /* operator sizeof */
1329 return (cpp_demangle_read_expression_unary(ddata
, "sizeof", 6));
1331 case SIMPLE_HASH('s', 'v'):
1332 /* operator sizeof */
1334 return (cpp_demangle_read_expression_unary(ddata
, "sizeof", 6));
1337 switch (*ddata
->cur
) {
1339 return (cpp_demangle_read_expr_primary(ddata
));
1341 return (cpp_demangle_read_tmpl_param(ddata
));
1348 cpp_demangle_read_expression_flat(struct cpp_demangle_data
*ddata
, char **str
)
1350 struct vector_str
*output
;
1351 size_t i
, p_idx
, idx
, exp_len
;
1354 output
= ddata
->push_head
> 0 ? &ddata
->output_tmp
:
1357 p_idx
= output
->size
;
1359 if (!cpp_demangle_read_expression(ddata
))
1362 if ((exp
= vector_str_substr(output
, p_idx
, output
->size
- 1,
1367 for (i
= p_idx
; i
< idx
; ++i
) {
1368 if (!vector_str_pop(output
)) {
1380 cpp_demangle_read_expression_binary(struct cpp_demangle_data
*ddata
,
1381 const char *name
, size_t len
)
1384 if (ddata
== NULL
|| name
== NULL
|| len
== 0)
1386 if (!cpp_demangle_read_expression(ddata
))
1388 if (!cpp_demangle_push_str(ddata
, name
, len
))
1391 return (cpp_demangle_read_expression(ddata
));
1395 cpp_demangle_read_expression_unary(struct cpp_demangle_data
*ddata
,
1396 const char *name
, size_t len
)
1399 if (ddata
== NULL
|| name
== NULL
|| len
== 0)
1401 if (!cpp_demangle_read_expression(ddata
))
1404 return (cpp_demangle_push_str(ddata
, name
, len
));
1408 cpp_demangle_read_expression_trinary(struct cpp_demangle_data
*ddata
,
1409 const char *name1
, size_t len1
, const char *name2
, size_t len2
)
1412 if (ddata
== NULL
|| name1
== NULL
|| len1
== 0 || name2
== NULL
||
1416 if (!cpp_demangle_read_expression(ddata
))
1418 if (!cpp_demangle_push_str(ddata
, name1
, len1
))
1420 if (!cpp_demangle_read_expression(ddata
))
1422 if (!cpp_demangle_push_str(ddata
, name2
, len2
))
1425 return (cpp_demangle_read_expression(ddata
));
1429 cpp_demangle_read_function(struct cpp_demangle_data
*ddata
, int *ext_c
,
1430 struct vector_type_qualifier
*v
)
1432 size_t class_type_size
, class_type_len
, limit
;
1433 const char *class_type
;
1435 if (ddata
== NULL
|| *ddata
->cur
!= 'F' || v
== NULL
)
1439 if (*ddata
->cur
== 'Y') {
1444 if (!cpp_demangle_read_type(ddata
, 0))
1446 if (*ddata
->cur
!= 'E') {
1447 if (!cpp_demangle_push_str(ddata
, "(", 1))
1449 if (vector_read_cmd_find(&ddata
->cmd
, READ_PTRMEM
)) {
1450 if ((class_type_size
= ddata
->class_type
.size
) == 0)
1453 ddata
->class_type
.container
[class_type_size
- 1];
1454 if (class_type
== NULL
)
1456 if ((class_type_len
= strlen(class_type
)) == 0)
1458 if (!cpp_demangle_push_str(ddata
, class_type
,
1461 if (!cpp_demangle_push_str(ddata
, "::*", 3))
1465 if (!cpp_demangle_push_type_qualifier(ddata
, v
,
1466 (const char *) NULL
))
1468 vector_type_qualifier_dest(v
);
1469 if (!vector_type_qualifier_init(v
))
1473 if (!cpp_demangle_push_str(ddata
, ")(", 2))
1478 if (!cpp_demangle_read_type(ddata
, 0))
1480 if (*ddata
->cur
== 'E')
1482 if (limit
++ > CPP_DEMANGLE_TRY_LIMIT
)
1486 if (vector_read_cmd_find(&ddata
->cmd
, READ_PTRMEM
) == 1) {
1487 if (!cpp_demangle_push_type_qualifier(ddata
, v
,
1488 (const char *) NULL
))
1490 vector_type_qualifier_dest(v
);
1491 if (!vector_type_qualifier_init(v
))
1495 if (!cpp_demangle_push_str(ddata
, ")", 1))
1504 /* read encoding, encoding are function name, data name, special-name */
1506 cpp_demangle_read_encoding(struct cpp_demangle_data
*ddata
)
1508 char *name
, *type
, *num_str
;
1512 if (ddata
== NULL
|| *ddata
->cur
== '\0')
1516 switch (SIMPLE_HASH(*ddata
->cur
, *(ddata
->cur
+ 1))) {
1517 case SIMPLE_HASH('G', 'A'):
1518 if (!cpp_demangle_push_str(ddata
, "hidden alias for ", 17))
1521 if (*ddata
->cur
== '\0')
1523 return (cpp_demangle_read_encoding(ddata
));
1525 case SIMPLE_HASH('G', 'R'):
1526 if (!cpp_demangle_push_str(ddata
, "reference temporary #", 21))
1529 if (*ddata
->cur
== '\0')
1531 if (!cpp_demangle_read_name_flat(ddata
, &name
))
1534 if (!cpp_demangle_read_number_as_string(ddata
, &num_str
))
1536 if (!cpp_demangle_push_str(ddata
, num_str
, strlen(num_str
)))
1538 if (!cpp_demangle_push_str(ddata
, " for ", 5))
1540 if (!cpp_demangle_push_str(ddata
, name
, strlen(name
)))
1549 case SIMPLE_HASH('G', 'T'):
1551 if (*ddata
->cur
== '\0')
1553 switch (*ddata
->cur
) {
1555 if (!cpp_demangle_push_str(ddata
,
1556 "non-transaction clone for ", 26))
1560 if (!cpp_demangle_push_str(ddata
,
1561 "transaction clone for ", 22))
1565 return (cpp_demangle_read_encoding(ddata
));
1567 case SIMPLE_HASH('G', 'V'):
1568 /* sentry object for 1 time init */
1569 if (!cpp_demangle_push_str(ddata
, "guard variable for ", 20))
1574 case SIMPLE_HASH('T', 'c'):
1575 /* virtual function covariant override thunk */
1576 if (!cpp_demangle_push_str(ddata
,
1577 "virtual function covariant override ", 36))
1580 if (*ddata
->cur
== '\0')
1582 if (!cpp_demangle_read_offset(ddata
))
1584 if (!cpp_demangle_read_offset(ddata
))
1586 return (cpp_demangle_read_encoding(ddata
));
1588 case SIMPLE_HASH('T', 'C'):
1589 /* construction vtable */
1590 if (!cpp_demangle_push_str(ddata
, "construction vtable for ",
1594 if (*ddata
->cur
== '\0')
1596 if (!cpp_demangle_read_type_flat(ddata
, &type
))
1599 if (!cpp_demangle_read_number(ddata
, &offset
))
1601 if (*ddata
->cur
++ != '_')
1603 if (!cpp_demangle_read_type(ddata
, 0))
1605 if (!cpp_demangle_push_str(ddata
, "-in-", 4))
1607 if (!cpp_demangle_push_str(ddata
, type
, strlen(type
)))
1614 case SIMPLE_HASH('T', 'D'):
1615 /* typeinfo common proxy */
1618 case SIMPLE_HASH('T', 'F'):
1620 if (!cpp_demangle_push_str(ddata
, "typeinfo fn for ", 16))
1623 if (*ddata
->cur
== '\0')
1625 return (cpp_demangle_read_type(ddata
, 0));
1627 case SIMPLE_HASH('T', 'h'):
1628 /* virtual function non-virtual override thunk */
1629 if (!cpp_demangle_push_str(ddata
,
1630 "virtual function non-virtual override ", 38))
1633 if (*ddata
->cur
== '\0')
1635 if (!cpp_demangle_read_nv_offset(ddata
))
1637 return (cpp_demangle_read_encoding(ddata
));
1639 case SIMPLE_HASH('T', 'H'):
1640 /* TLS init function */
1641 if (!cpp_demangle_push_str(ddata
, "TLS init function for ",
1645 if (*ddata
->cur
== '\0')
1649 case SIMPLE_HASH('T', 'I'):
1650 /* typeinfo structure */
1651 if (!cpp_demangle_push_str(ddata
, "typeinfo for ", 13))
1654 if (*ddata
->cur
== '\0')
1656 return (cpp_demangle_read_type(ddata
, 0));
1658 case SIMPLE_HASH('T', 'J'):
1660 if (!cpp_demangle_push_str(ddata
, "java Class for ", 15))
1663 if (*ddata
->cur
== '\0')
1665 return (cpp_demangle_read_type(ddata
, 0));
1667 case SIMPLE_HASH('T', 'S'):
1668 /* RTTI name (NTBS) */
1669 if (!cpp_demangle_push_str(ddata
, "typeinfo name for ", 18))
1672 if (*ddata
->cur
== '\0')
1674 return (cpp_demangle_read_type(ddata
, 0));
1676 case SIMPLE_HASH('T', 'T'):
1678 if (!cpp_demangle_push_str(ddata
, "VTT for ", 8))
1681 if (*ddata
->cur
== '\0')
1683 return (cpp_demangle_read_type(ddata
, 0));
1685 case SIMPLE_HASH('T', 'v'):
1686 /* virtual function virtual override thunk */
1687 if (!cpp_demangle_push_str(ddata
,
1688 "virtual function virtual override ", 34))
1691 if (*ddata
->cur
== '\0')
1693 if (!cpp_demangle_read_v_offset(ddata
))
1695 return (cpp_demangle_read_encoding(ddata
));
1697 case SIMPLE_HASH('T', 'V'):
1699 if (!cpp_demangle_push_str(ddata
, "vtable for ", 12))
1702 if (*ddata
->cur
== '\0')
1704 return (cpp_demangle_read_type(ddata
, 0));
1706 case SIMPLE_HASH('T', 'W'):
1707 /* TLS wrapper function */
1708 if (!cpp_demangle_push_str(ddata
, "TLS wrapper function for ",
1712 if (*ddata
->cur
== '\0')
1717 return (cpp_demangle_read_name(ddata
));
1721 cpp_demangle_read_local_name(struct cpp_demangle_data
*ddata
)
1727 if (*(++ddata
->cur
) == '\0')
1729 if (!cpp_demangle_read_encoding(ddata
))
1734 if (!cpp_demangle_read_type(ddata
, 1))
1736 if (*ddata
->cur
== 'E')
1738 if (limit
++ > CPP_DEMANGLE_TRY_LIMIT
)
1741 if (*(++ddata
->cur
) == '\0')
1743 if (ddata
->paren
== true) {
1744 if (!cpp_demangle_push_str(ddata
, ")", 1))
1746 ddata
->paren
= false;
1748 if (*ddata
->cur
== 's')
1751 if (!cpp_demangle_push_str(ddata
, "::", 2))
1753 if (!cpp_demangle_read_name(ddata
))
1756 if (*ddata
->cur
== '_') {
1758 while (ELFTC_ISDIGIT(*ddata
->cur
) != 0)
1766 cpp_demangle_read_name(struct cpp_demangle_data
*ddata
)
1768 struct vector_str
*output
, v
;
1769 size_t p_idx
, subst_str_len
;
1773 if (ddata
== NULL
|| *ddata
->cur
== '\0')
1776 output
= ddata
->push_head
> 0 ? &ddata
->output_tmp
: &ddata
->output
;
1780 switch (*ddata
->cur
) {
1782 return (cpp_demangle_read_subst(ddata
));
1784 return (cpp_demangle_read_nested_name(ddata
));
1786 return (cpp_demangle_read_local_name(ddata
));
1789 if (!vector_str_init(&v
))
1792 p_idx
= output
->size
;
1794 if (!cpp_demangle_read_uqname(ddata
))
1796 if ((subst_str
= vector_str_substr(output
, p_idx
, output
->size
- 1,
1797 &subst_str_len
)) == NULL
)
1799 if (subst_str_len
> 8 && strstr(subst_str
, "operator") != NULL
) {
1803 if (!vector_str_push(&v
, subst_str
, subst_str_len
))
1805 if (!cpp_demangle_push_subst_v(ddata
, &v
))
1808 if (*ddata
->cur
== 'I') {
1809 p_idx
= output
->size
;
1810 if (!cpp_demangle_read_tmpl_args(ddata
))
1813 if ((subst_str
= vector_str_substr(output
, p_idx
,
1814 output
->size
- 1, &subst_str_len
)) == NULL
)
1816 if (!vector_str_push(&v
, subst_str
, subst_str_len
))
1818 if (!cpp_demangle_push_subst_v(ddata
, &v
))
1826 vector_str_dest(&v
);
1832 cpp_demangle_read_name_flat(struct cpp_demangle_data
*ddata
, char **str
)
1834 struct vector_str
*output
;
1835 size_t i
, p_idx
, idx
, name_len
;
1838 output
= ddata
->push_head
> 0 ? &ddata
->output_tmp
:
1841 p_idx
= output
->size
;
1843 if (!cpp_demangle_read_name(ddata
))
1846 if ((name
= vector_str_substr(output
, p_idx
, output
->size
- 1,
1847 &name_len
)) == NULL
)
1851 for (i
= p_idx
; i
< idx
; ++i
) {
1852 if (!vector_str_pop(output
)) {
1864 cpp_demangle_read_nested_name(struct cpp_demangle_data
*ddata
)
1866 struct vector_str
*output
, v
;
1867 size_t limit
, p_idx
, subst_str_len
;
1871 if (ddata
== NULL
|| *ddata
->cur
!= 'N')
1873 if (*(++ddata
->cur
) == '\0')
1876 while (*ddata
->cur
== 'r' || *ddata
->cur
== 'V' ||
1877 *ddata
->cur
== 'K') {
1878 switch (*ddata
->cur
) {
1880 ddata
->mem_rst
= true;
1883 ddata
->mem_vat
= true;
1886 ddata
->mem_cst
= true;
1892 output
= ddata
->push_head
> 0 ? &ddata
->output_tmp
: &ddata
->output
;
1893 if (!vector_str_init(&v
))
1899 p_idx
= output
->size
;
1900 switch (*ddata
->cur
) {
1902 if (!cpp_demangle_read_tmpl_args(ddata
))
1906 if (!cpp_demangle_read_subst(ddata
))
1910 if (!cpp_demangle_read_tmpl_param(ddata
))
1914 if (!cpp_demangle_read_uqname(ddata
))
1918 if ((subst_str
= vector_str_substr(output
, p_idx
,
1919 output
->size
- 1, &subst_str_len
)) == NULL
)
1921 if (!vector_str_push(&v
, subst_str
, subst_str_len
)) {
1927 if (!cpp_demangle_push_subst_v(ddata
, &v
))
1929 if (*ddata
->cur
== 'E')
1931 else if (*ddata
->cur
!= 'I' &&
1932 *ddata
->cur
!= 'C' && *ddata
->cur
!= 'D') {
1933 if (!cpp_demangle_push_str(ddata
, "::", 2))
1935 if (!vector_str_push(&v
, "::", 2))
1938 if (limit
++ > CPP_DEMANGLE_TRY_LIMIT
)
1946 vector_str_dest(&v
);
1953 * number ::= [n] <decimal>
1956 cpp_demangle_read_number(struct cpp_demangle_data
*ddata
, long *rtn
)
1958 long len
, negative_factor
;
1960 if (ddata
== NULL
|| rtn
== NULL
)
1963 negative_factor
= 1;
1964 if (*ddata
->cur
== 'n') {
1965 negative_factor
= -1;
1969 if (ELFTC_ISDIGIT(*ddata
->cur
) == 0)
1973 if ((len
= strtol(ddata
->cur
, (char **) NULL
, 10)) == 0 &&
1977 while (ELFTC_ISDIGIT(*ddata
->cur
) != 0)
1981 assert(negative_factor
== 1 || negative_factor
== -1);
1983 *rtn
= len
* negative_factor
;
1989 cpp_demangle_read_number_as_string(struct cpp_demangle_data
*ddata
, char **str
)
1993 if (!cpp_demangle_read_number(ddata
, &n
)) {
1998 if (asprintf(str
, "%ld", n
) < 0) {
2007 cpp_demangle_read_nv_offset(struct cpp_demangle_data
*ddata
)
2013 if (!cpp_demangle_push_str(ddata
, "offset : ", 9))
2016 return (cpp_demangle_read_offset_number(ddata
));
2019 /* read offset, offset are nv-offset, v-offset */
2021 cpp_demangle_read_offset(struct cpp_demangle_data
*ddata
)
2027 if (*ddata
->cur
== 'h') {
2029 return (cpp_demangle_read_nv_offset(ddata
));
2030 } else if (*ddata
->cur
== 'v') {
2032 return (cpp_demangle_read_v_offset(ddata
));
2039 cpp_demangle_read_offset_number(struct cpp_demangle_data
*ddata
)
2044 if (ddata
== NULL
|| *ddata
->cur
== '\0')
2047 /* offset could be negative */
2048 if (*ddata
->cur
== 'n') {
2050 start
= ddata
->cur
+ 1;
2056 while (*ddata
->cur
!= '_')
2059 if (negative
&& !cpp_demangle_push_str(ddata
, "-", 1))
2062 assert(start
!= NULL
);
2064 if (!cpp_demangle_push_str(ddata
, start
, ddata
->cur
- start
))
2066 if (!cpp_demangle_push_str(ddata
, " ", 1))
2075 cpp_demangle_read_pointer_to_member(struct cpp_demangle_data
*ddata
)
2077 size_t class_type_len
, i
, idx
, p_idx
;
2078 int p_func_type
, rtn
;
2081 if (ddata
== NULL
|| *ddata
->cur
!= 'M' || *(++ddata
->cur
) == '\0')
2084 p_idx
= ddata
->output
.size
;
2085 if (!cpp_demangle_read_type(ddata
, 0))
2088 if ((class_type
= vector_str_substr(&ddata
->output
, p_idx
,
2089 ddata
->output
.size
- 1, &class_type_len
)) == NULL
)
2093 idx
= ddata
->output
.size
;
2094 for (i
= p_idx
; i
< idx
; ++i
)
2095 if (!vector_str_pop(&ddata
->output
))
2098 if (!vector_read_cmd_push(&ddata
->cmd
, READ_PTRMEM
))
2101 if (!vector_str_push(&ddata
->class_type
, class_type
, class_type_len
))
2104 p_func_type
= ddata
->func_type
;
2105 if (!cpp_demangle_read_type(ddata
, 0))
2108 if (p_func_type
== ddata
->func_type
) {
2109 if (!cpp_demangle_push_str(ddata
, " ", 1))
2111 if (!cpp_demangle_push_str(ddata
, class_type
, class_type_len
))
2113 if (!cpp_demangle_push_str(ddata
, "::*", 3))
2119 if (!vector_str_pop(&ddata
->class_type
))
2122 if (!vector_read_cmd_pop(&ddata
->cmd
))
2130 /* read source-name, source-name is <len> <ID> */
2132 cpp_demangle_read_sname(struct cpp_demangle_data
*ddata
)
2137 if (ddata
== NULL
|| cpp_demangle_read_number(ddata
, &len
) == 0 ||
2141 if (len
== 12 && (memcmp("_GLOBAL__N_1", ddata
->cur
, 12) == 0))
2142 err
= cpp_demangle_push_str(ddata
, "(anonymous namespace)", 21);
2144 err
= cpp_demangle_push_str(ddata
, ddata
->cur
, len
);
2149 assert(ddata
->output
.size
> 0);
2150 if (vector_read_cmd_find(&ddata
->cmd
, READ_TMPL
) == 0)
2152 ddata
->output
.container
[ddata
->output
.size
- 1];
2160 cpp_demangle_read_subst(struct cpp_demangle_data
*ddata
)
2164 if (ddata
== NULL
|| *ddata
->cur
== '\0')
2167 /* abbreviations of the form Sx */
2168 switch (SIMPLE_HASH(*ddata
->cur
, *(ddata
->cur
+ 1))) {
2169 case SIMPLE_HASH('S', 'a'):
2170 /* std::allocator */
2171 if (cpp_demangle_push_str(ddata
, "std::allocator", 14) == 0)
2174 if (*ddata
->cur
== 'I')
2175 return (cpp_demangle_read_subst_stdtmpl(ddata
,
2176 "std::allocator", 14));
2179 case SIMPLE_HASH('S', 'b'):
2180 /* std::basic_string */
2181 if (!cpp_demangle_push_str(ddata
, "std::basic_string", 17))
2184 if (*ddata
->cur
== 'I')
2185 return (cpp_demangle_read_subst_stdtmpl(ddata
,
2186 "std::basic_string", 17));
2189 case SIMPLE_HASH('S', 'd'):
2190 /* std::basic_iostream<char, std::char_traits<char> > */
2191 if (!cpp_demangle_push_str(ddata
, "std::iostream", 19))
2193 ddata
->last_sname
= "iostream";
2195 if (*ddata
->cur
== 'I')
2196 return (cpp_demangle_read_subst_stdtmpl(ddata
,
2197 "std::iostream", 19));
2200 case SIMPLE_HASH('S', 'i'):
2201 /* std::basic_istream<char, std::char_traits<char> > */
2202 if (!cpp_demangle_push_str(ddata
, "std::istream", 18))
2204 ddata
->last_sname
= "istream";
2206 if (*ddata
->cur
== 'I')
2207 return (cpp_demangle_read_subst_stdtmpl(ddata
,
2208 "std::istream", 18));
2211 case SIMPLE_HASH('S', 'o'):
2212 /* std::basic_ostream<char, std::char_traits<char> > */
2213 if (!cpp_demangle_push_str(ddata
, "std::ostream", 18))
2215 ddata
->last_sname
= "istream";
2217 if (*ddata
->cur
== 'I')
2218 return (cpp_demangle_read_subst_stdtmpl(ddata
,
2219 "std::ostream", 18));
2222 case SIMPLE_HASH('S', 's'):
2224 * std::basic_string<char, std::char_traits<char>,
2225 * std::allocator<char> >
2229 if (!cpp_demangle_push_str(ddata
, "std::string", 11))
2231 ddata
->last_sname
= "string";
2233 if (*ddata
->cur
== 'I')
2234 return (cpp_demangle_read_subst_stdtmpl(ddata
,
2235 "std::string", 11));
2238 case SIMPLE_HASH('S', 't'):
2240 return (cpp_demangle_read_subst_std(ddata
));
2243 if (*(++ddata
->cur
) == '\0')
2247 if (*ddata
->cur
== '_')
2248 return (cpp_demangle_get_subst(ddata
, 0));
2251 /* substitution number is base 36 */
2252 if ((nth
= strtol(ddata
->cur
, (char **) NULL
, 36)) == 0 &&
2256 /* first was '_', so increase one */
2259 while (*ddata
->cur
!= '_')
2264 return (cpp_demangle_get_subst(ddata
, nth
));
2272 cpp_demangle_read_subst_std(struct cpp_demangle_data
*ddata
)
2274 struct vector_str
*output
, v
;
2275 size_t p_idx
, subst_str_len
;
2282 if (!vector_str_init(&v
))
2287 if (!cpp_demangle_push_str(ddata
, "std::", 5))
2290 if (!vector_str_push(&v
, "std::", 5))
2295 output
= ddata
->push_head
> 0 ? &ddata
->output_tmp
: &ddata
->output
;
2297 p_idx
= output
->size
;
2298 if (!cpp_demangle_read_uqname(ddata
))
2301 if ((subst_str
= vector_str_substr(output
, p_idx
, output
->size
- 1,
2302 &subst_str_len
)) == NULL
)
2305 if (!vector_str_push(&v
, subst_str
, subst_str_len
))
2308 if (!cpp_demangle_push_subst_v(ddata
, &v
))
2311 if (*ddata
->cur
== 'I') {
2312 p_idx
= output
->size
;
2313 if (!cpp_demangle_read_tmpl_args(ddata
))
2316 if ((subst_str
= vector_str_substr(output
, p_idx
,
2317 output
->size
- 1, &subst_str_len
)) == NULL
)
2319 if (!vector_str_push(&v
, subst_str
, subst_str_len
))
2321 if (!cpp_demangle_push_subst_v(ddata
, &v
))
2328 vector_str_dest(&v
);
2334 cpp_demangle_read_subst_stdtmpl(struct cpp_demangle_data
*ddata
,
2335 const char *str
, size_t len
)
2337 struct vector_str
*output
;
2338 size_t p_idx
, substr_len
;
2340 char *subst_str
, *substr
;
2342 if (ddata
== NULL
|| str
== NULL
|| len
== 0)
2345 output
= ddata
->push_head
> 0 ? &ddata
->output_tmp
: &ddata
->output
;
2347 p_idx
= output
->size
;
2351 if (!cpp_demangle_read_tmpl_args(ddata
))
2353 if ((substr
= vector_str_substr(output
, p_idx
, output
->size
- 1,
2354 &substr_len
)) == NULL
)
2358 if ((subst_str
= malloc(sizeof(char) * (substr_len
+ len
+ 1))) ==
2362 memcpy(subst_str
, str
, len
);
2363 memcpy(subst_str
+ len
, substr
, substr_len
);
2364 subst_str
[substr_len
+ len
] = '\0';
2366 if (!cpp_demangle_push_subst(ddata
, subst_str
, substr_len
+ len
))
2378 cpp_demangle_read_tmpl_arg(struct cpp_demangle_data
*ddata
)
2381 if (ddata
== NULL
|| *ddata
->cur
== '\0')
2384 switch (*ddata
->cur
) {
2386 return (cpp_demangle_read_expr_primary(ddata
));
2388 return (cpp_demangle_read_expression(ddata
));
2391 return (cpp_demangle_read_type(ddata
, 0));
2395 cpp_demangle_read_tmpl_args(struct cpp_demangle_data
*ddata
)
2397 struct vector_str
*v
;
2398 size_t arg_len
, idx
, limit
, size
;
2401 if (ddata
== NULL
|| *ddata
->cur
== '\0')
2406 if (!vector_read_cmd_push(&ddata
->cmd
, READ_TMPL
))
2409 if (!cpp_demangle_push_str(ddata
, "<", 1))
2413 v
= ddata
->push_head
> 0 ? &ddata
->output_tmp
: &ddata
->output
;
2416 if (!cpp_demangle_read_tmpl_arg(ddata
))
2418 if ((arg
= vector_str_substr(v
, idx
, v
->size
- 1, &arg_len
)) ==
2421 if (!vector_str_find(&ddata
->tmpl
, arg
, arg_len
) &&
2422 !vector_str_push(&ddata
->tmpl
, arg
, arg_len
)) {
2429 if (*ddata
->cur
== 'E') {
2433 if (!strncmp(v
->container
[size
- 1], ">", 1)) {
2434 if (!cpp_demangle_push_str(ddata
, " >", 2))
2436 } else if (!cpp_demangle_push_str(ddata
, ">", 1))
2439 } else if (*ddata
->cur
!= 'I' &&
2440 !cpp_demangle_push_str(ddata
, ", ", 2))
2443 if (limit
++ > CPP_DEMANGLE_TRY_LIMIT
)
2447 return (vector_read_cmd_pop(&ddata
->cmd
));
2451 * Read template parameter that forms in 'T[number]_'.
2452 * This function much like to read_subst but only for types.
2455 cpp_demangle_read_tmpl_param(struct cpp_demangle_data
*ddata
)
2459 if (ddata
== NULL
|| *ddata
->cur
!= 'T')
2464 if (*ddata
->cur
== '_')
2465 return (cpp_demangle_get_tmpl_param(ddata
, 0));
2469 if ((nth
= strtol(ddata
->cur
, (char **) NULL
, 36)) == 0 &&
2476 while (*ddata
->cur
!= '_')
2481 return (cpp_demangle_get_tmpl_param(ddata
, nth
));
2489 cpp_demangle_read_type(struct cpp_demangle_data
*ddata
, int delimit
)
2491 struct vector_type_qualifier v
;
2492 struct vector_str
*output
;
2493 size_t p_idx
, type_str_len
;
2494 int extern_c
, is_builtin
;
2496 char *type_str
, *exp_str
, *num_str
;
2501 output
= &ddata
->output
;
2502 if (ddata
->output
.size
> 0 && !strncmp(ddata
->output
.container
[ddata
->output
.size
- 1], ">", 1)) {
2504 output
= &ddata
->output_tmp
;
2505 } else if (delimit
== 1) {
2506 if (ddata
->paren
== false) {
2507 if (!cpp_demangle_push_str(ddata
, "(", 1))
2509 if (ddata
->output
.size
< 2)
2511 ddata
->paren
= true;
2512 ddata
->pfirst
= true;
2513 /* Need pop function name */
2514 if (ddata
->subst
.size
== 1 &&
2515 !vector_str_pop(&ddata
->subst
))
2520 ddata
->pfirst
= false;
2521 else if (*ddata
->cur
!= 'I' &&
2522 !cpp_demangle_push_str(ddata
, ", ", 2))
2526 assert(output
!= NULL
);
2528 * [r, V, K] [P, R, C, G, U] builtin, function, class-enum, array
2529 * pointer-to-member, template-param, template-template-param, subst
2532 if (!vector_type_qualifier_init(&v
))
2537 p_idx
= output
->size
;
2538 type_str
= exp_str
= num_str
= NULL
;
2541 switch (*ddata
->cur
) {
2544 if (!cpp_demangle_push_str(ddata
, "signed char", 11))
2551 if (!cpp_demangle_read_array(ddata
))
2558 if (!cpp_demangle_push_str(ddata
, "bool", 4))
2565 if (!vector_type_qualifier_push(&v
, TYPE_CMX
))
2572 if (!cpp_demangle_push_str(ddata
, "char", 4))
2579 if (!cpp_demangle_push_str(ddata
, "double", 6))
2586 switch (*ddata
->cur
) {
2588 /* IEEE 754r decimal floating point (64 bits) */
2589 if (!cpp_demangle_push_str(ddata
, "decimal64", 9))
2594 /* IEEE 754r decimal floating point (128 bits) */
2595 if (!cpp_demangle_push_str(ddata
, "decimal128", 10))
2600 /* IEEE 754r decimal floating point (32 bits) */
2601 if (!cpp_demangle_push_str(ddata
, "decimal32", 9))
2606 /* IEEE 754r half-precision floating point (16 bits) */
2607 if (!cpp_demangle_push_str(ddata
, "half", 4))
2613 if (!cpp_demangle_push_str(ddata
, "char32_t", 8))
2618 /* std::nullptr_t (i.e., decltype(nullptr)) */
2619 if (!cpp_demangle_push_str(ddata
, "decltype(nullptr)",
2626 if (!cpp_demangle_push_str(ddata
, "char16_t", 8))
2631 /* gcc vector_size extension. */
2633 if (*ddata
->cur
== '_') {
2635 if (!cpp_demangle_read_expression_flat(ddata
,
2638 if (!vector_str_push(&v
.ext_name
, exp_str
,
2642 if (!cpp_demangle_read_number_as_string(ddata
,
2645 if (!vector_str_push(&v
.ext_name
, num_str
,
2649 if (*ddata
->cur
!= '_')
2652 if (!vector_type_qualifier_push(&v
, TYPE_VEC
))
2662 if (!cpp_demangle_push_str(ddata
, "long double", 11))
2669 if (!cpp_demangle_push_str(ddata
, "float", 5))
2676 if (!cpp_demangle_read_function(ddata
, &extern_c
, &v
))
2683 if (!cpp_demangle_push_str(ddata
, "__float128", 10))
2690 if (!vector_type_qualifier_push(&v
, TYPE_IMG
))
2697 if (!cpp_demangle_push_str(ddata
, "unsigned char", 13))
2704 if (!cpp_demangle_push_str(ddata
, "int", 3))
2711 if (!cpp_demangle_push_str(ddata
, "unsigned int", 12))
2718 if (!vector_type_qualifier_push(&v
, TYPE_CST
))
2725 if (!cpp_demangle_push_str(ddata
, "long", 4))
2732 if (!cpp_demangle_push_str(ddata
, "unsigned long", 13))
2739 /* pointer to member */
2740 if (!cpp_demangle_read_pointer_to_member(ddata
))
2747 if (!cpp_demangle_push_str(ddata
, "__int128", 8))
2753 /* unsigned __int128 */
2754 if (!cpp_demangle_push_str(ddata
, "unsigned __int128", 17))
2761 if (!vector_type_qualifier_push(&v
, TYPE_PTR
))
2768 if (!vector_type_qualifier_push(&v
, TYPE_RST
))
2775 if (!vector_type_qualifier_push(&v
, TYPE_REF
))
2781 /* short, local string */
2782 if (!cpp_demangle_push_str(ddata
, "short", 5))
2789 if (!cpp_demangle_read_subst(ddata
))
2795 /* unsigned short */
2796 if (!cpp_demangle_push_str(ddata
, "unsigned short", 14))
2802 /* template parameter */
2803 if (!cpp_demangle_read_tmpl_param(ddata
))
2809 /* vendor extended builtin */
2811 if (!cpp_demangle_read_sname(ddata
))
2817 /* vendor extended type qualifier */
2818 if (!cpp_demangle_read_number(ddata
, &len
))
2822 if (!vector_str_push(&v
.ext_name
, ddata
->cur
, len
))
2825 if (!vector_type_qualifier_push(&v
, TYPE_EXT
))
2831 if (!cpp_demangle_push_str(ddata
, "void", 4))
2838 if (!vector_type_qualifier_push(&v
, TYPE_VAT
))
2845 if (!cpp_demangle_push_str(ddata
, "wchar_t", 6))
2852 if (!cpp_demangle_push_str(ddata
, "long long", 9))
2858 /* unsigned long long */
2859 if (!cpp_demangle_push_str(ddata
, "unsigned long long", 18))
2866 if (!cpp_demangle_push_str(ddata
, "ellipsis", 8))
2872 if (!cpp_demangle_read_name(ddata
))
2877 if ((type_str
= vector_str_substr(output
, p_idx
, output
->size
- 1,
2878 &type_str_len
)) == NULL
)
2881 if (is_builtin
== 0) {
2882 if (!vector_str_find(&ddata
->subst
, type_str
, type_str_len
) &&
2883 !vector_str_push(&ddata
->subst
, type_str
, type_str_len
))
2887 if (!cpp_demangle_push_type_qualifier(ddata
, &v
, type_str
))
2893 vector_type_qualifier_dest(&v
);
2895 if (ddata
->push_head
> 0) {
2896 if (*ddata
->cur
== 'I' && cpp_demangle_read_tmpl_args(ddata
)
2900 if (--ddata
->push_head
> 0)
2903 if (!vector_str_push(&ddata
->output_tmp
, " ", 1))
2906 if (!vector_str_push_vector_head(&ddata
->output
,
2907 &ddata
->output_tmp
))
2910 vector_str_dest(&ddata
->output_tmp
);
2911 if (!vector_str_init(&ddata
->output_tmp
))
2914 if (!cpp_demangle_push_str(ddata
, "(", 1))
2917 ddata
->paren
= true;
2918 ddata
->pfirst
= true;
2926 vector_type_qualifier_dest(&v
);
2932 cpp_demangle_read_type_flat(struct cpp_demangle_data
*ddata
, char **str
)
2934 struct vector_str
*output
;
2935 size_t i
, p_idx
, idx
, type_len
;
2938 output
= ddata
->push_head
> 0 ? &ddata
->output_tmp
:
2941 p_idx
= output
->size
;
2943 if (!cpp_demangle_read_type(ddata
, 0))
2946 if ((type
= vector_str_substr(output
, p_idx
, output
->size
- 1,
2947 &type_len
)) == NULL
)
2951 for (i
= p_idx
; i
< idx
; ++i
) {
2952 if (!vector_str_pop(output
)) {
2964 * read unqualified-name, unqualified name are operator-name, ctor-dtor-name,
2968 cpp_demangle_read_uqname(struct cpp_demangle_data
*ddata
)
2972 if (ddata
== NULL
|| *ddata
->cur
== '\0')
2976 switch (SIMPLE_HASH(*ddata
->cur
, *(ddata
->cur
+ 1))) {
2977 case SIMPLE_HASH('a', 'a'):
2979 if (!cpp_demangle_push_str(ddata
, "operator&&", 10))
2984 case SIMPLE_HASH('a', 'd'):
2985 /* operator & (unary) */
2986 if (!cpp_demangle_push_str(ddata
, "operator&", 9))
2991 case SIMPLE_HASH('a', 'n'):
2993 if (!cpp_demangle_push_str(ddata
, "operator&", 9))
2998 case SIMPLE_HASH('a', 'N'):
3000 if (!cpp_demangle_push_str(ddata
, "operator&=", 10))
3005 case SIMPLE_HASH('a', 'S'):
3007 if (!cpp_demangle_push_str(ddata
, "operator=", 9))
3012 case SIMPLE_HASH('c', 'l'):
3014 if (!cpp_demangle_push_str(ddata
, "operator()", 10))
3019 case SIMPLE_HASH('c', 'm'):
3021 if (!cpp_demangle_push_str(ddata
, "operator,", 9))
3026 case SIMPLE_HASH('c', 'o'):
3028 if (!cpp_demangle_push_str(ddata
, "operator~", 9))
3033 case SIMPLE_HASH('c', 'v'):
3034 /* operator (cast) */
3035 if (!cpp_demangle_push_str(ddata
, "operator(cast)", 14))
3038 return (cpp_demangle_read_type(ddata
, 1));
3040 case SIMPLE_HASH('d', 'a'):
3041 /* operator delete [] */
3042 if (!cpp_demangle_push_str(ddata
, "operator delete []", 18))
3047 case SIMPLE_HASH('d', 'e'):
3048 /* operator * (unary) */
3049 if (!cpp_demangle_push_str(ddata
, "operator*", 9))
3054 case SIMPLE_HASH('d', 'l'):
3055 /* operator delete */
3056 if (!cpp_demangle_push_str(ddata
, "operator delete", 15))
3061 case SIMPLE_HASH('d', 'v'):
3063 if (!cpp_demangle_push_str(ddata
, "operator/", 9))
3068 case SIMPLE_HASH('d', 'V'):
3070 if (!cpp_demangle_push_str(ddata
, "operator/=", 10))
3075 case SIMPLE_HASH('e', 'o'):
3077 if (!cpp_demangle_push_str(ddata
, "operator^", 9))
3082 case SIMPLE_HASH('e', 'O'):
3084 if (!cpp_demangle_push_str(ddata
, "operator^=", 10))
3089 case SIMPLE_HASH('e', 'q'):
3091 if (!cpp_demangle_push_str(ddata
, "operator==", 10))
3096 case SIMPLE_HASH('g', 'e'):
3098 if (!cpp_demangle_push_str(ddata
, "operator>=", 10))
3103 case SIMPLE_HASH('g', 't'):
3105 if (!cpp_demangle_push_str(ddata
, "operator>", 9))
3110 case SIMPLE_HASH('i', 'x'):
3112 if (!cpp_demangle_push_str(ddata
, "operator[]", 10))
3117 case SIMPLE_HASH('l', 'e'):
3119 if (!cpp_demangle_push_str(ddata
, "operator<=", 10))
3124 case SIMPLE_HASH('l', 's'):
3126 if (!cpp_demangle_push_str(ddata
, "operator<<", 10))
3131 case SIMPLE_HASH('l', 'S'):
3133 if (!cpp_demangle_push_str(ddata
, "operator<<=", 11))
3138 case SIMPLE_HASH('l', 't'):
3140 if (!cpp_demangle_push_str(ddata
, "operator<", 9))
3145 case SIMPLE_HASH('m', 'i'):
3147 if (!cpp_demangle_push_str(ddata
, "operator-", 9))
3152 case SIMPLE_HASH('m', 'I'):
3154 if (!cpp_demangle_push_str(ddata
, "operator-=", 10))
3159 case SIMPLE_HASH('m', 'l'):
3161 if (!cpp_demangle_push_str(ddata
, "operator*", 9))
3166 case SIMPLE_HASH('m', 'L'):
3168 if (!cpp_demangle_push_str(ddata
, "operator*=", 10))
3173 case SIMPLE_HASH('m', 'm'):
3175 if (!cpp_demangle_push_str(ddata
, "operator--", 10))
3180 case SIMPLE_HASH('n', 'a'):
3181 /* operator new[] */
3182 if (!cpp_demangle_push_str(ddata
, "operator new []", 15))
3187 case SIMPLE_HASH('n', 'e'):
3189 if (!cpp_demangle_push_str(ddata
, "operator!=", 10))
3194 case SIMPLE_HASH('n', 'g'):
3195 /* operator - (unary) */
3196 if (!cpp_demangle_push_str(ddata
, "operator-", 9))
3201 case SIMPLE_HASH('n', 't'):
3203 if (!cpp_demangle_push_str(ddata
, "operator!", 9))
3208 case SIMPLE_HASH('n', 'w'):
3210 if (!cpp_demangle_push_str(ddata
, "operator new", 12))
3215 case SIMPLE_HASH('o', 'o'):
3217 if (!cpp_demangle_push_str(ddata
, "operator||", 10))
3222 case SIMPLE_HASH('o', 'r'):
3224 if (!cpp_demangle_push_str(ddata
, "operator|", 9))
3229 case SIMPLE_HASH('o', 'R'):
3231 if (!cpp_demangle_push_str(ddata
, "operator|=", 10))
3236 case SIMPLE_HASH('p', 'l'):
3238 if (!cpp_demangle_push_str(ddata
, "operator+", 9))
3243 case SIMPLE_HASH('p', 'L'):
3245 if (!cpp_demangle_push_str(ddata
, "operator+=", 10))
3250 case SIMPLE_HASH('p', 'm'):
3252 if (!cpp_demangle_push_str(ddata
, "operator->*", 11))
3257 case SIMPLE_HASH('p', 'p'):
3259 if (!cpp_demangle_push_str(ddata
, "operator++", 10))
3264 case SIMPLE_HASH('p', 's'):
3265 /* operator + (unary) */
3266 if (!cpp_demangle_push_str(ddata
, "operator+", 9))
3271 case SIMPLE_HASH('p', 't'):
3273 if (!cpp_demangle_push_str(ddata
, "operator->", 10))
3278 case SIMPLE_HASH('q', 'u'):
3280 if (!cpp_demangle_push_str(ddata
, "operator?", 9))
3285 case SIMPLE_HASH('r', 'm'):
3287 if (!cpp_demangle_push_str(ddata
, "operator%", 9))
3292 case SIMPLE_HASH('r', 'M'):
3294 if (!cpp_demangle_push_str(ddata
, "operator%=", 10))
3299 case SIMPLE_HASH('r', 's'):
3301 if (!cpp_demangle_push_str(ddata
, "operator>>", 10))
3306 case SIMPLE_HASH('r', 'S'):
3308 if (!cpp_demangle_push_str(ddata
, "operator>>=", 11))
3313 case SIMPLE_HASH('r', 'z'):
3314 /* operator sizeof */
3315 if (!cpp_demangle_push_str(ddata
, "operator sizeof ", 16))
3320 case SIMPLE_HASH('s', 'r'):
3321 /* scope resolution operator */
3322 if (!cpp_demangle_push_str(ddata
, "scope resolution operator ",
3328 case SIMPLE_HASH('s', 'v'):
3329 /* operator sizeof */
3330 if (!cpp_demangle_push_str(ddata
, "operator sizeof ", 16))
3336 /* vendor extened operator */
3337 if (*ddata
->cur
== 'v' && ELFTC_ISDIGIT(*(ddata
->cur
+ 1))) {
3338 if (!cpp_demangle_push_str(ddata
, "vendor extened operator ",
3341 if (!cpp_demangle_push_str(ddata
, ddata
->cur
+ 1, 1))
3344 return (cpp_demangle_read_sname(ddata
));
3347 /* ctor-dtor-name */
3348 switch (SIMPLE_HASH(*ddata
->cur
, *(ddata
->cur
+ 1))) {
3349 case SIMPLE_HASH('C', '1'):
3351 case SIMPLE_HASH('C', '2'):
3353 case SIMPLE_HASH('C', '3'):
3354 if (ddata
->last_sname
== NULL
)
3356 if ((len
= strlen(ddata
->last_sname
)) == 0)
3358 if (!cpp_demangle_push_str(ddata
, "::", 2))
3360 if (!cpp_demangle_push_str(ddata
, ddata
->last_sname
, len
))
3365 case SIMPLE_HASH('D', '0'):
3367 case SIMPLE_HASH('D', '1'):
3369 case SIMPLE_HASH('D', '2'):
3370 if (ddata
->last_sname
== NULL
)
3372 if ((len
= strlen(ddata
->last_sname
)) == 0)
3374 if (!cpp_demangle_push_str(ddata
, "::~", 3))
3376 if (!cpp_demangle_push_str(ddata
, ddata
->last_sname
, len
))
3383 if (ELFTC_ISDIGIT(*ddata
->cur
) != 0)
3384 return (cpp_demangle_read_sname(ddata
));
3386 /* local source name */
3387 if (*ddata
->cur
== 'L')
3388 return (cpp_demangle_local_source_name(ddata
));
3394 * Read local source name.
3397 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31775
3398 * http://gcc.gnu.org/viewcvs?view=rev&revision=124467
3401 cpp_demangle_local_source_name(struct cpp_demangle_data
*ddata
)
3404 if (ddata
== NULL
|| *ddata
->cur
!= 'L')
3409 if (!cpp_demangle_read_sname(ddata
))
3413 if (*ddata
->cur
== '_') {
3415 while (ELFTC_ISDIGIT(*ddata
->cur
) != 0)
3423 cpp_demangle_read_v_offset(struct cpp_demangle_data
*ddata
)
3429 if (!cpp_demangle_push_str(ddata
, "offset : ", 9))
3432 if (!cpp_demangle_read_offset_number(ddata
))
3435 if (!cpp_demangle_push_str(ddata
, "virtual offset : ", 17))
3438 return (!cpp_demangle_read_offset_number(ddata
));
3442 * Decode floating point representation to string
3443 * Return new allocated string or NULL
3446 * Replace these functions to macro.
3449 decode_fp_to_double(const char *p
, size_t len
)
3452 size_t rtn_len
, limit
, i
;
3456 if (p
== NULL
|| len
== 0 || len
% 2 != 0 || len
/ 2 > sizeof(double))
3459 memset(&f
, 0, sizeof(double));
3461 for (i
= 0; i
< len
/ 2; ++i
) {
3462 byte
= hex_to_dec(p
[len
- i
* 2 - 1]) +
3463 hex_to_dec(p
[len
- i
* 2 - 2]) * 16;
3465 if (byte
< 0 || byte
> 255)
3468 #if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
3469 ((unsigned char *)&f
)[i
] = (unsigned char)(byte
);
3470 #else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3471 ((unsigned char *)&f
)[sizeof(double) - i
- 1] =
3472 (unsigned char)(byte
);
3473 #endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3479 if ((rtn
= malloc(sizeof(char) * rtn_len
)) == NULL
)
3482 if (snprintf(rtn
, rtn_len
, "%fld", f
) >= (int)rtn_len
) {
3484 if (limit
++ > FLOAT_SPRINTF_TRY_LIMIT
)
3486 rtn_len
*= BUFFER_GROWFACTOR
;
3494 decode_fp_to_float(const char *p
, size_t len
)
3496 size_t i
, rtn_len
, limit
;
3501 if (p
== NULL
|| len
== 0 || len
% 2 != 0 || len
/ 2 > sizeof(float))
3504 memset(&f
, 0, sizeof(float));
3506 for (i
= 0; i
< len
/ 2; ++i
) {
3507 byte
= hex_to_dec(p
[len
- i
* 2 - 1]) +
3508 hex_to_dec(p
[len
- i
* 2 - 2]) * 16;
3509 if (byte
< 0 || byte
> 255)
3511 #if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
3512 ((unsigned char *)&f
)[i
] = (unsigned char)(byte
);
3513 #else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3514 ((unsigned char *)&f
)[sizeof(float) - i
- 1] =
3515 (unsigned char)(byte
);
3516 #endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3522 if ((rtn
= malloc(sizeof(char) * rtn_len
)) == NULL
)
3525 if (snprintf(rtn
, rtn_len
, "%ff", f
) >= (int)rtn_len
) {
3527 if (limit
++ > FLOAT_SPRINTF_TRY_LIMIT
)
3529 rtn_len
*= BUFFER_GROWFACTOR
;
3537 decode_fp_to_float128(const char *p
, size_t len
)
3540 size_t rtn_len
, limit
, i
;
3542 unsigned char buf
[FLOAT_QUADRUPLE_BYTES
];
3545 switch(sizeof(long double)) {
3546 case FLOAT_QUADRUPLE_BYTES
:
3547 return (decode_fp_to_long_double(p
, len
));
3548 case FLOAT_EXTENED_BYTES
:
3549 if (p
== NULL
|| len
== 0 || len
% 2 != 0 ||
3550 len
/ 2 > FLOAT_QUADRUPLE_BYTES
)
3553 memset(buf
, 0, FLOAT_QUADRUPLE_BYTES
);
3555 for (i
= 0; i
< len
/ 2; ++i
) {
3556 byte
= hex_to_dec(p
[len
- i
* 2 - 1]) +
3557 hex_to_dec(p
[len
- i
* 2 - 2]) * 16;
3558 if (byte
< 0 || byte
> 255)
3560 #if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
3561 buf
[i
] = (unsigned char)(byte
);
3562 #else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3563 buf
[FLOAT_QUADRUPLE_BYTES
- i
-1] =
3564 (unsigned char)(byte
);
3565 #endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3567 memset(&f
, 0, FLOAT_EXTENED_BYTES
);
3569 #if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
3570 memcpy(&f
, buf
, FLOAT_EXTENED_BYTES
);
3571 #else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3572 memcpy(&f
, buf
+ 6, FLOAT_EXTENED_BYTES
);
3573 #endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3578 if ((rtn
= malloc(sizeof(char) * rtn_len
)) == NULL
)
3581 if (snprintf(rtn
, rtn_len
, "%Lfd", f
) >= (int)rtn_len
) {
3583 if (limit
++ > FLOAT_SPRINTF_TRY_LIMIT
)
3585 rtn_len
*= BUFFER_GROWFACTOR
;
3596 decode_fp_to_float80(const char *p
, size_t len
)
3599 size_t rtn_len
, limit
, i
;
3601 unsigned char buf
[FLOAT_EXTENED_BYTES
];
3604 switch(sizeof(long double)) {
3605 case FLOAT_QUADRUPLE_BYTES
:
3606 if (p
== NULL
|| len
== 0 || len
% 2 != 0 ||
3607 len
/ 2 > FLOAT_EXTENED_BYTES
)
3610 memset(buf
, 0, FLOAT_EXTENED_BYTES
);
3612 for (i
= 0; i
< len
/ 2; ++i
) {
3613 byte
= hex_to_dec(p
[len
- i
* 2 - 1]) +
3614 hex_to_dec(p
[len
- i
* 2 - 2]) * 16;
3616 if (byte
< 0 || byte
> 255)
3619 #if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
3620 buf
[i
] = (unsigned char)(byte
);
3621 #else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3622 buf
[FLOAT_EXTENED_BYTES
- i
-1] =
3623 (unsigned char)(byte
);
3624 #endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3627 memset(&f
, 0, FLOAT_QUADRUPLE_BYTES
);
3629 #if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
3630 memcpy(&f
, buf
, FLOAT_EXTENED_BYTES
);
3631 #else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3632 memcpy((unsigned char *)(&f
) + 6, buf
, FLOAT_EXTENED_BYTES
);
3633 #endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3638 if ((rtn
= malloc(sizeof(char) * rtn_len
)) == NULL
)
3641 if (snprintf(rtn
, rtn_len
, "%Lfd", f
) >= (int)rtn_len
) {
3643 if (limit
++ > FLOAT_SPRINTF_TRY_LIMIT
)
3645 rtn_len
*= BUFFER_GROWFACTOR
;
3650 case FLOAT_EXTENED_BYTES
:
3651 return (decode_fp_to_long_double(p
, len
));
3658 decode_fp_to_long_double(const char *p
, size_t len
)
3661 size_t rtn_len
, limit
, i
;
3665 if (p
== NULL
|| len
== 0 || len
% 2 != 0 ||
3666 len
/ 2 > sizeof(long double))
3669 memset(&f
, 0, sizeof(long double));
3671 for (i
= 0; i
< len
/ 2; ++i
) {
3672 byte
= hex_to_dec(p
[len
- i
* 2 - 1]) +
3673 hex_to_dec(p
[len
- i
* 2 - 2]) * 16;
3675 if (byte
< 0 || byte
> 255)
3678 #if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
3679 ((unsigned char *)&f
)[i
] = (unsigned char)(byte
);
3680 #else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3681 ((unsigned char *)&f
)[sizeof(long double) - i
- 1] =
3682 (unsigned char)(byte
);
3683 #endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
3689 if ((rtn
= malloc(sizeof(char) * rtn_len
)) == NULL
)
3692 if (snprintf(rtn
, rtn_len
, "%Lfd", f
) >= (int)rtn_len
) {
3694 if (limit
++ > FLOAT_SPRINTF_TRY_LIMIT
)
3696 rtn_len
*= BUFFER_GROWFACTOR
;
3703 /* Simple hex to integer function used by decode_to_* function. */
3747 vector_read_cmd_dest(struct vector_read_cmd
*v
)
3753 free(v
->r_container
);
3756 /* return -1 at failed, 0 at not found, 1 at found. */
3758 vector_read_cmd_find(struct vector_read_cmd
*v
, enum read_cmd dst
)
3762 if (v
== NULL
|| dst
== READ_FAIL
)
3765 for (i
= 0; i
< v
->size
; ++i
)
3766 if (v
->r_container
[i
] == dst
)
3773 vector_read_cmd_init(struct vector_read_cmd
*v
)
3780 v
->capacity
= VECTOR_DEF_CAPACITY
;
3782 if ((v
->r_container
= malloc(sizeof(enum read_cmd
) * v
->capacity
))
3790 vector_read_cmd_pop(struct vector_read_cmd
*v
)
3793 if (v
== NULL
|| v
->size
== 0)
3797 v
->r_container
[v
->size
] = READ_FAIL
;
3803 vector_read_cmd_push(struct vector_read_cmd
*v
, enum read_cmd cmd
)
3805 enum read_cmd
*tmp_r_ctn
;
3812 if (v
->size
== v
->capacity
) {
3813 tmp_cap
= v
->capacity
* BUFFER_GROWFACTOR
;
3814 if ((tmp_r_ctn
= malloc(sizeof(enum read_cmd
) * tmp_cap
))
3817 for (i
= 0; i
< v
->size
; ++i
)
3818 tmp_r_ctn
[i
] = v
->r_container
[i
];
3819 free(v
->r_container
);
3820 v
->r_container
= tmp_r_ctn
;
3821 v
->capacity
= tmp_cap
;
3824 v
->r_container
[v
->size
] = cmd
;
3831 vector_type_qualifier_dest(struct vector_type_qualifier
*v
)
3837 free(v
->q_container
);
3838 vector_str_dest(&v
->ext_name
);
3841 /* size, capacity, ext_name */
3843 vector_type_qualifier_init(struct vector_type_qualifier
*v
)
3850 v
->capacity
= VECTOR_DEF_CAPACITY
;
3852 if ((v
->q_container
= malloc(sizeof(enum type_qualifier
) * v
->capacity
))
3856 assert(v
->q_container
!= NULL
);
3858 if (vector_str_init(&v
->ext_name
) == false) {
3859 free(v
->q_container
);
3867 vector_type_qualifier_push(struct vector_type_qualifier
*v
,
3868 enum type_qualifier t
)
3870 enum type_qualifier
*tmp_ctn
;
3877 if (v
->size
== v
->capacity
) {
3878 tmp_cap
= v
->capacity
* BUFFER_GROWFACTOR
;
3879 if ((tmp_ctn
= malloc(sizeof(enum type_qualifier
) * tmp_cap
))
3882 for (i
= 0; i
< v
->size
; ++i
)
3883 tmp_ctn
[i
] = v
->q_container
[i
];
3884 free(v
->q_container
);
3885 v
->q_container
= tmp_ctn
;
3886 v
->capacity
= tmp_cap
;
3889 v
->q_container
[v
->size
] = t
;