Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/winedump/msmangle.c
4388 views
1
/*
2
* Demangle VC++ symbols into C function prototypes
3
*
4
* Copyright 2000 Jon Griffiths
5
* 2004 Eric Pouech
6
*
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*/
21
22
#include "config.h"
23
24
#include "winedump.h"
25
#include "winver.h"
26
#include "imagehlp.h"
27
28
#define UNDNAME_NO_COMPLEX_TYPE (0x8000)
29
30
struct array
31
{
32
unsigned start; /* first valid reference in array */
33
unsigned num; /* total number of used elts */
34
unsigned max;
35
unsigned alloc;
36
char** elts;
37
};
38
39
/* Structure holding a parsed symbol */
40
struct parsed_symbol
41
{
42
unsigned flags; /* the UNDNAME_ flags used for demangling */
43
44
const char* current; /* pointer in input (mangled) string */
45
char* result; /* demangled string */
46
47
struct array names; /* array of names for back reference */
48
struct array args; /* array of arguments for back reference */
49
struct array stack; /* stack of parsed strings */
50
51
void* alloc_list; /* linked list of allocated blocks */
52
unsigned avail_in_first; /* number of available bytes in head block */
53
};
54
55
enum datatype_e
56
{
57
DT_NO_LEADING_WS = 0x01,
58
DT_NO_LRSEP_WS = 0x02,
59
};
60
61
/* Type for parsing mangled types */
62
struct datatype_t
63
{
64
const char* left;
65
const char* right;
66
enum datatype_e flags;
67
};
68
69
static BOOL symbol_demangle(struct parsed_symbol* sym);
70
static char* get_class_name(struct parsed_symbol* sym);
71
72
#define und_alloc(sym,len) xmalloc(len)
73
74
/******************************************************************
75
* str_array_init
76
* Initialises an array of strings
77
*/
78
static void str_array_init(struct array* a)
79
{
80
a->start = a->num = a->max = a->alloc = 0;
81
a->elts = NULL;
82
}
83
84
/******************************************************************
85
* str_array_push
86
* Adding a new string to an array
87
*/
88
static BOOL str_array_push(struct parsed_symbol* sym, const char* ptr, int len,
89
struct array* a)
90
{
91
char** new;
92
93
assert(ptr);
94
assert(a);
95
96
if (!a->alloc)
97
{
98
new = und_alloc(sym, (a->alloc = 32) * sizeof(a->elts[0]));
99
if (!new) return FALSE;
100
a->elts = new;
101
}
102
else if (a->max >= a->alloc)
103
{
104
new = und_alloc(sym, (a->alloc * 2) * sizeof(a->elts[0]));
105
if (!new) return FALSE;
106
memcpy(new, a->elts, a->alloc * sizeof(a->elts[0]));
107
a->alloc *= 2;
108
a->elts = new;
109
}
110
if (len == -1) len = strlen(ptr);
111
a->elts[a->num] = und_alloc(sym, len + 1);
112
assert(a->elts[a->num]);
113
memcpy(a->elts[a->num], ptr, len);
114
a->elts[a->num][len] = '\0';
115
if (++a->num >= a->max) a->max = a->num;
116
return TRUE;
117
}
118
119
/******************************************************************
120
* str_array_get_ref
121
* Extracts a reference from an existing array (doing proper type
122
* checking)
123
*/
124
static char* str_array_get_ref(struct array* cref, unsigned idx)
125
{
126
assert(cref);
127
if (cref->start + idx >= cref->max) return NULL;
128
return cref->elts[cref->start + idx];
129
}
130
131
/******************************************************************
132
* str_printf
133
* Helper for printf type of command (only %s and %c are implemented)
134
* while dynamically allocating the buffer
135
*/
136
static char* WINAPIV str_printf(struct parsed_symbol* sym, const char* format, ...)
137
{
138
va_list args;
139
unsigned int len = 1, i, sz;
140
char* tmp;
141
char* p;
142
char* t;
143
144
va_start(args, format);
145
for (i = 0; format[i]; i++)
146
{
147
if (format[i] == '%')
148
{
149
switch (format[++i])
150
{
151
case 's': t = va_arg(args, char*); if (t) len += strlen(t); break;
152
case 'c': (void)va_arg(args, int); len++; break;
153
default: i--; /* fall through */
154
case '%': len++; break;
155
}
156
}
157
else len++;
158
}
159
va_end(args);
160
if (!(tmp = und_alloc(sym, len))) return NULL;
161
va_start(args, format);
162
for (p = tmp, i = 0; format[i]; i++)
163
{
164
if (format[i] == '%')
165
{
166
switch (format[++i])
167
{
168
case 's':
169
t = va_arg(args, char*);
170
if (t)
171
{
172
sz = strlen(t);
173
memcpy(p, t, sz);
174
p += sz;
175
}
176
break;
177
case 'c':
178
*p++ = (char)va_arg(args, int);
179
break;
180
default: i--; /* fall through */
181
case '%': *p++ = '%'; break;
182
}
183
}
184
else *p++ = format[i];
185
}
186
va_end(args);
187
*p = '\0';
188
return tmp;
189
}
190
191
enum datatype_flags
192
{
193
IN_ARGS = 0x01,
194
WS_AFTER_QUAL_IF = 0x02,
195
};
196
197
/* forward declaration */
198
static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct,
199
enum datatype_flags flags);
200
201
static const char* get_number(struct parsed_symbol* sym)
202
{
203
char* ptr;
204
BOOL sgn = FALSE;
205
206
if (*sym->current == '?')
207
{
208
sgn = TRUE;
209
sym->current++;
210
}
211
if (*sym->current >= '0' && *sym->current <= '8')
212
{
213
ptr = und_alloc(sym, 3);
214
if (sgn) ptr[0] = '-';
215
ptr[sgn ? 1 : 0] = *sym->current + 1;
216
ptr[sgn ? 2 : 1] = '\0';
217
sym->current++;
218
}
219
else if (*sym->current == '9')
220
{
221
ptr = und_alloc(sym, 4);
222
if (sgn) ptr[0] = '-';
223
ptr[sgn ? 1 : 0] = '1';
224
ptr[sgn ? 2 : 1] = '0';
225
ptr[sgn ? 3 : 2] = '\0';
226
sym->current++;
227
}
228
else if (*sym->current >= 'A' && *sym->current <= 'P')
229
{
230
int ret = 0;
231
232
while (*sym->current >= 'A' && *sym->current <= 'P')
233
{
234
ret *= 16;
235
ret += *sym->current++ - 'A';
236
}
237
if (*sym->current != '@') return NULL;
238
239
ptr = und_alloc(sym, 17);
240
sprintf(ptr, "%s%u", sgn ? "-" : "", ret);
241
sym->current++;
242
}
243
else return NULL;
244
return ptr;
245
}
246
247
/******************************************************************
248
* get_args
249
* Parses a list of function/method arguments, creates a string corresponding
250
* to the arguments' list.
251
*/
252
static char* get_args(struct parsed_symbol* sym, BOOL z_term,
253
char open_char, char close_char)
254
255
{
256
struct datatype_t ct;
257
struct array arg_collect;
258
char* args_str = NULL;
259
char* last;
260
unsigned int i;
261
const char *p;
262
263
if (z_term && sym->current[0] == 'X' && sym->current[1] == 'Z')
264
{
265
sym->current += 2;
266
return str_printf(sym, "%cvoid%c", open_char, close_char);
267
}
268
269
str_array_init(&arg_collect);
270
271
/* Now come the function arguments */
272
while (*sym->current)
273
{
274
p = sym->current;
275
276
/* Decode each data type and append it to the argument list */
277
if (*sym->current == '@')
278
{
279
sym->current++;
280
break;
281
}
282
if (z_term && sym->current[0] == 'Z')
283
{
284
sym->current++;
285
if (!str_array_push(sym, "...", -1, &arg_collect))
286
return NULL;
287
break;
288
}
289
/* Handle empty list in variadic template */
290
if (!z_term && sym->current[0] == '$' && sym->current[1] == '$' && sym->current[2] == 'V')
291
{
292
sym->current += 3;
293
continue;
294
}
295
if (!demangle_datatype(sym, &ct, IN_ARGS))
296
return NULL;
297
if (!str_array_push(sym, str_printf(sym, "%s%s", ct.left, ct.right), -1,
298
&arg_collect))
299
return NULL;
300
if (z_term && sym->current - p > 1 && sym->args.num < 20)
301
{
302
if (!str_array_push(sym, ct.left ? ct.left : "", -1, &sym->args) ||
303
!str_array_push(sym, ct.right ? ct.right : "", -1, &sym->args))
304
return NULL;
305
}
306
}
307
/* Functions are always terminated by 'Z'. If we made it this far and
308
* don't find it, we have incorrectly identified a data type.
309
*/
310
if (z_term && *sym->current++ != 'Z') return NULL;
311
312
if (!arg_collect.num) return str_printf(sym, "%c%c", open_char, close_char);
313
for (i = 1; i < arg_collect.num; i++)
314
{
315
args_str = str_printf(sym, "%s,%s", args_str, arg_collect.elts[i]);
316
}
317
318
last = args_str ? args_str : arg_collect.elts[0];
319
if (close_char == '>' && last[strlen(last) - 1] == '>')
320
args_str = str_printf(sym, "%c%s%s %c",
321
open_char, arg_collect.elts[0], args_str, close_char);
322
else
323
args_str = str_printf(sym, "%c%s%s%c",
324
open_char, arg_collect.elts[0], args_str, close_char);
325
326
return args_str;
327
}
328
329
static void append_extended_qualifier(struct parsed_symbol *sym, const char **where,
330
const char *str, BOOL is_ms_keyword)
331
{
332
if (!is_ms_keyword || !(sym->flags & UNDNAME_NO_MS_KEYWORDS))
333
{
334
if (is_ms_keyword && (sym->flags & UNDNAME_NO_LEADING_UNDERSCORES))
335
str += 2;
336
*where = *where ? str_printf(sym, "%s%s%s%s", *where, is_ms_keyword ? " " : "", str, is_ms_keyword ? "" : " ") :
337
str_printf(sym, "%s%s", str, is_ms_keyword ? "" : " ");
338
}
339
}
340
341
static void get_extended_qualifier(struct parsed_symbol *sym, struct datatype_t *xdt)
342
{
343
unsigned fl = 0;
344
xdt->left = xdt->right = NULL;
345
xdt->flags = 0;
346
for (;;)
347
{
348
switch (*sym->current)
349
{
350
case 'E': append_extended_qualifier(sym, &xdt->right, "__ptr64", TRUE); fl |= 2; break;
351
case 'F': append_extended_qualifier(sym, &xdt->left, "__unaligned", TRUE); fl |= 2; break;
352
#ifdef _UCRT
353
case 'G': append_extended_qualifier(sym, &xdt->right, "&", FALSE); fl |= 1; break;
354
case 'H': append_extended_qualifier(sym, &xdt->right, "&&", FALSE); fl |= 1; break;
355
#endif
356
case 'I': append_extended_qualifier(sym, &xdt->right, "__restrict", TRUE); fl |= 2; break;
357
default: if (fl == 1 || (fl == 3 && (sym->flags & UNDNAME_NO_MS_KEYWORDS))) xdt->flags = DT_NO_LRSEP_WS; return;
358
}
359
sym->current++;
360
}
361
}
362
363
/******************************************************************
364
* get_qualifier
365
* Parses the type qualifier. Always returns static strings.
366
*/
367
static BOOL get_qualifier(struct parsed_symbol *sym, struct datatype_t *xdt, const char** pclass)
368
{
369
char ch;
370
const char* qualif;
371
372
get_extended_qualifier(sym, xdt);
373
switch (ch = *sym->current++)
374
{
375
case 'A': qualif = NULL; break;
376
case 'B': qualif = "const"; break;
377
case 'C': qualif = "volatile"; break;
378
case 'D': qualif = "const volatile"; break;
379
case 'Q': qualif = NULL; break;
380
case 'R': qualif = "const"; break;
381
case 'S': qualif = "volatile"; break;
382
case 'T': qualif = "const volatile"; break;
383
default: return FALSE;
384
}
385
if (qualif)
386
{
387
xdt->flags &= ~DT_NO_LRSEP_WS;
388
xdt->left = xdt->left ? str_printf(sym, "%s %s", qualif, xdt->left) : qualif;
389
}
390
if (ch >= 'Q' && ch <= 'T') /* pointer to member, fetch class */
391
{
392
const char* class = get_class_name(sym);
393
if (!class) return FALSE;
394
if (!pclass) return FALSE;
395
*pclass = class;
396
}
397
else if (pclass) *pclass = NULL;
398
return TRUE;
399
}
400
401
static BOOL get_function_qualifier(struct parsed_symbol *sym, const char** qualif)
402
{
403
struct datatype_t xdt;
404
405
if (!get_qualifier(sym, &xdt, NULL)) return FALSE;
406
*qualif = (xdt.left || xdt.right) ?
407
str_printf(sym, "%s%s%s", xdt.left, (xdt.flags & DT_NO_LRSEP_WS) ? "" : " ", xdt.right) : NULL;
408
return TRUE;
409
}
410
411
static BOOL get_qualified_type(struct datatype_t *ct, struct parsed_symbol* sym,
412
char qualif, enum datatype_flags flags)
413
{
414
struct datatype_t xdt1;
415
struct datatype_t xdt2;
416
const char* ref;
417
const char* str_qualif;
418
const char* class;
419
420
get_extended_qualifier(sym, &xdt1);
421
422
switch (qualif)
423
{
424
case 'A': ref = " &"; str_qualif = NULL; break;
425
case 'B': ref = " &"; str_qualif = " volatile"; break;
426
case 'P': ref = " *"; str_qualif = NULL; break;
427
case 'Q': ref = " *"; str_qualif = " const"; break;
428
case 'R': ref = " *"; str_qualif = " volatile"; break;
429
case 'S': ref = " *"; str_qualif = " const volatile"; break;
430
case '?': ref = NULL; str_qualif = NULL; break;
431
case '$': ref = " &&"; str_qualif = NULL; break;
432
default: return FALSE;
433
}
434
ct->right = NULL;
435
ct->flags = 0;
436
437
/* parse managed handle information */
438
if (sym->current[0] == '$' && sym->current[1] == 'A')
439
{
440
sym->current += 2;
441
442
switch (qualif)
443
{
444
case 'A':
445
case 'B':
446
ref = " %";
447
break;
448
case 'P':
449
case 'Q':
450
case 'R':
451
case 'S':
452
ref = " ^";
453
break;
454
default:
455
return FALSE;
456
}
457
}
458
459
if (get_qualifier(sym, &xdt2, &class))
460
{
461
unsigned mark = sym->stack.num;
462
struct datatype_t sub_ct;
463
464
if (ref || str_qualif || xdt1.left || xdt1.right)
465
{
466
if (class)
467
ct->left = str_printf(sym, "%s%s%s%s::%s%s%s",
468
xdt1.left ? " " : NULL, xdt1.left,
469
class ? " " : NULL, class, ref ? ref + 1 : NULL,
470
xdt1.right ? " " : NULL, xdt1.right, str_qualif);
471
else
472
ct->left = str_printf(sym, "%s%s%s%s%s%s",
473
xdt1.left ? " " : NULL, xdt1.left, ref,
474
xdt1.right ? " " : NULL, xdt1.right, str_qualif);
475
}
476
else
477
ct->left = NULL;
478
/* multidimensional arrays */
479
if (*sym->current == 'Y')
480
{
481
const char* n1;
482
int num;
483
484
sym->current++;
485
if (!(n1 = get_number(sym))) return FALSE;
486
num = atoi(n1);
487
488
ct->left = str_printf(sym, " (%s%s", xdt2.left, ct->left && !xdt2.left ? ct->left + 1 : ct->left);
489
ct->right = ")";
490
xdt2.left = NULL;
491
492
while (num--)
493
ct->right = str_printf(sym, "%s[%s]", ct->right, get_number(sym));
494
}
495
496
/* Recurse to get the referred-to type */
497
if (!demangle_datatype(sym, &sub_ct, 0))
498
return FALSE;
499
if (sub_ct.flags & DT_NO_LEADING_WS)
500
ct->left++;
501
ct->left = str_printf(sym, "%s%s%s%s%s", sub_ct.left, xdt2.left ? " " : NULL,
502
xdt2.left, ct->left,
503
((xdt2.left || str_qualif) && (flags & WS_AFTER_QUAL_IF)) ? " " : NULL);
504
if (sub_ct.right) ct->right = str_printf(sym, "%s%s", ct->right, sub_ct.right);
505
sym->stack.num = mark;
506
}
507
else if (ref || str_qualif || xdt1.left || xdt1.right)
508
ct->left = str_printf(sym, "%s%s%s%s%s%s",
509
xdt1.left ? " " : NULL, xdt1.left, ref,
510
xdt1.right ? " " : NULL, xdt1.right, str_qualif);
511
else
512
ct->left = NULL;
513
return TRUE;
514
}
515
516
/******************************************************************
517
* get_literal_string
518
* Gets the literal name from the current position in the mangled
519
* symbol to the first '@' character. It pushes the parsed name to
520
* the symbol names stack and returns a pointer to it or NULL in
521
* case of an error.
522
*/
523
static char* get_literal_string(struct parsed_symbol* sym)
524
{
525
const char *ptr = sym->current;
526
527
do {
528
if (!((*sym->current >= 'A' && *sym->current <= 'Z') ||
529
(*sym->current >= 'a' && *sym->current <= 'z') ||
530
(*sym->current >= '0' && *sym->current <= '9') ||
531
*sym->current == '_' || *sym->current == '$' ||
532
*sym->current == '<' || *sym->current == '>')) {
533
return NULL;
534
}
535
} while (*++sym->current != '@');
536
sym->current++;
537
if (!str_array_push(sym, ptr, sym->current - 1 - ptr, &sym->names))
538
return NULL;
539
540
return str_array_get_ref(&sym->names, sym->names.num - sym->names.start - 1);
541
}
542
543
/******************************************************************
544
* get_template_name
545
* Parses a name with a template argument list and returns it as
546
* a string.
547
* In a template argument list the back reference to the names
548
* table is separately created. '0' points to the class component
549
* name with the template arguments. We use the same stack array
550
* to hold the names but save/restore the stack state before/after
551
* parsing the template argument list.
552
*/
553
static char* get_template_name(struct parsed_symbol* sym)
554
{
555
char *name, *args;
556
unsigned num_mark = sym->names.num;
557
unsigned start_mark = sym->names.start;
558
unsigned stack_mark = sym->stack.num;
559
unsigned args_mark = sym->args.num;
560
561
sym->names.start = sym->names.num;
562
if (!(name = get_literal_string(sym))) {
563
sym->names.start = start_mark;
564
return FALSE;
565
}
566
args = get_args(sym, FALSE, '<', '>');
567
if (args != NULL)
568
name = str_printf(sym, "%s%s", name, args);
569
sym->names.num = num_mark;
570
sym->names.start = start_mark;
571
sym->stack.num = stack_mark;
572
sym->args.num = args_mark;
573
return name;
574
}
575
576
/******************************************************************
577
* get_class
578
* Parses class as a list of parent-classes, terminated by '@' and stores the
579
* result in 'a' array. Each parent-classes, as well as the inner element
580
* (either field/method name or class name), are represented in the mangled
581
* name by a literal name ([a-zA-Z0-9_]+ terminated by '@') or a back reference
582
* ([0-9]) or a name with template arguments ('?$' literal name followed by the
583
* template argument list). The class name components appear in the reverse
584
* order in the mangled name, e.g aaa@bbb@ccc@@ will be demangled to
585
* ccc::bbb::aaa
586
* For each of these class name components a string will be allocated in the
587
* array.
588
*/
589
static BOOL get_class(struct parsed_symbol* sym)
590
{
591
const char* name = NULL;
592
593
while (*sym->current != '@')
594
{
595
switch (*sym->current)
596
{
597
case '\0': return FALSE;
598
599
case '0': case '1': case '2': case '3':
600
case '4': case '5': case '6': case '7':
601
case '8': case '9':
602
name = str_array_get_ref(&sym->names, *sym->current++ - '0');
603
break;
604
case '?':
605
switch (*++sym->current)
606
{
607
case '$':
608
sym->current++;
609
if ((name = get_template_name(sym)) &&
610
!str_array_push(sym, name, -1, &sym->names))
611
return FALSE;
612
break;
613
case '?':
614
{
615
struct array stack = sym->stack;
616
unsigned int start = sym->names.start;
617
unsigned int num = sym->names.num;
618
619
str_array_init( &sym->stack );
620
if (symbol_demangle( sym )) name = str_printf( sym, "`%s'", sym->result );
621
sym->names.start = start;
622
sym->names.num = num;
623
sym->stack = stack;
624
}
625
break;
626
default:
627
if (!(name = get_number( sym ))) return FALSE;
628
name = str_printf( sym, "`%s'", name );
629
break;
630
}
631
break;
632
default:
633
name = get_literal_string(sym);
634
break;
635
}
636
if (!name || !str_array_push(sym, name, -1, &sym->stack))
637
return FALSE;
638
}
639
sym->current++;
640
return TRUE;
641
}
642
643
/******************************************************************
644
* get_class_string
645
* From an array collected by get_class in sym->stack, constructs the
646
* corresponding (allocated) string
647
*/
648
static char* get_class_string(struct parsed_symbol* sym, int start)
649
{
650
int i;
651
unsigned int len, sz;
652
char* ret;
653
struct array *a = &sym->stack;
654
655
for (len = 0, i = start; i < a->num; i++)
656
{
657
assert(a->elts[i]);
658
len += 2 + strlen(a->elts[i]);
659
}
660
if (!(ret = und_alloc(sym, len - 1))) return NULL;
661
for (len = 0, i = a->num - 1; i >= start; i--)
662
{
663
sz = strlen(a->elts[i]);
664
memcpy(ret + len, a->elts[i], sz);
665
len += sz;
666
if (i > start)
667
{
668
ret[len++] = ':';
669
ret[len++] = ':';
670
}
671
}
672
ret[len] = '\0';
673
return ret;
674
}
675
676
/******************************************************************
677
* get_class_name
678
* Wrapper around get_class and get_class_string.
679
*/
680
static char* get_class_name(struct parsed_symbol* sym)
681
{
682
unsigned mark = sym->stack.num;
683
char* s = NULL;
684
685
if (get_class(sym))
686
s = get_class_string(sym, mark);
687
sym->stack.num = mark;
688
return s;
689
}
690
691
/******************************************************************
692
* get_calling_convention
693
* Returns a static string corresponding to the calling convention described
694
* by char 'ch'. Sets export to TRUE iff the calling convention is exported.
695
*/
696
static BOOL get_calling_convention(char ch, const char** call_conv,
697
const char** exported, unsigned flags)
698
{
699
*call_conv = *exported = NULL;
700
701
if (!(flags & (UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ALLOCATION_LANGUAGE)))
702
{
703
if (flags & UNDNAME_NO_LEADING_UNDERSCORES)
704
{
705
if (((ch - 'A') % 2) == 1) *exported = "dll_export ";
706
switch (ch)
707
{
708
case 'A': case 'B': *call_conv = "cdecl"; break;
709
case 'C': case 'D': *call_conv = "pascal"; break;
710
case 'E': case 'F': *call_conv = "thiscall"; break;
711
case 'G': case 'H': *call_conv = "stdcall"; break;
712
case 'I': case 'J': *call_conv = "fastcall"; break;
713
case 'K': case 'L': break;
714
case 'M': *call_conv = "clrcall"; break;
715
default: return FALSE;
716
}
717
}
718
else
719
{
720
if (((ch - 'A') % 2) == 1) *exported = "__dll_export ";
721
switch (ch)
722
{
723
case 'A': case 'B': *call_conv = "__cdecl"; break;
724
case 'C': case 'D': *call_conv = "__pascal"; break;
725
case 'E': case 'F': *call_conv = "__thiscall"; break;
726
case 'G': case 'H': *call_conv = "__stdcall"; break;
727
case 'I': case 'J': *call_conv = "__fastcall"; break;
728
case 'K': case 'L': break;
729
case 'M': *call_conv = "__clrcall"; break;
730
default: return FALSE;
731
}
732
}
733
}
734
return TRUE;
735
}
736
737
/*******************************************************************
738
* get_simple_type
739
* Return a string containing an allocated string for a simple data type
740
*/
741
static const char* get_simple_type(char c)
742
{
743
const char* type_string;
744
745
switch (c)
746
{
747
case 'C': type_string = "signed char"; break;
748
case 'D': type_string = "char"; break;
749
case 'E': type_string = "unsigned char"; break;
750
case 'F': type_string = "short"; break;
751
case 'G': type_string = "unsigned short"; break;
752
case 'H': type_string = "int"; break;
753
case 'I': type_string = "unsigned int"; break;
754
case 'J': type_string = "long"; break;
755
case 'K': type_string = "unsigned long"; break;
756
case 'M': type_string = "float"; break;
757
case 'N': type_string = "double"; break;
758
case 'O': type_string = "long double"; break;
759
case 'X': type_string = "void"; break;
760
/* case 'Z': (...) variadic function arguments. Handled in get_args() */
761
default: type_string = NULL; break;
762
}
763
return type_string;
764
}
765
766
/*******************************************************************
767
* get_extended_type
768
* Return a string containing an allocated string for a simple data type
769
*/
770
static const char* get_extended_type(char c)
771
{
772
const char* type_string;
773
774
switch (c)
775
{
776
case 'D': type_string = "__int8"; break;
777
case 'E': type_string = "unsigned __int8"; break;
778
case 'F': type_string = "__int16"; break;
779
case 'G': type_string = "unsigned __int16"; break;
780
case 'H': type_string = "__int32"; break;
781
case 'I': type_string = "unsigned __int32"; break;
782
case 'J': type_string = "__int64"; break;
783
case 'K': type_string = "unsigned __int64"; break;
784
case 'L': type_string = "__int128"; break;
785
case 'M': type_string = "unsigned __int128"; break;
786
case 'N': type_string = "bool"; break;
787
case 'Q': type_string = "char8_t"; break;
788
case 'S': type_string = "char16_t"; break;
789
case 'U': type_string = "char32_t"; break;
790
case 'W': type_string = "wchar_t"; break;
791
default: type_string = NULL; break;
792
}
793
return type_string;
794
}
795
796
struct function_signature
797
{
798
const char* call_conv;
799
const char* exported;
800
struct datatype_t return_ct;
801
const char* arguments;
802
};
803
804
static BOOL get_function_signature(struct parsed_symbol* sym, struct function_signature* fs)
805
{
806
unsigned mark = sym->stack.num;
807
808
if (!get_calling_convention(*sym->current++,
809
&fs->call_conv, &fs->exported,
810
sym->flags & ~UNDNAME_NO_ALLOCATION_LANGUAGE) ||
811
!demangle_datatype(sym, &fs->return_ct, 0))
812
return FALSE;
813
814
if (!(fs->arguments = get_args(sym, TRUE, '(', ')')))
815
return FALSE;
816
sym->stack.num = mark;
817
818
return TRUE;
819
}
820
821
/*******************************************************************
822
* demangle_datatype
823
*
824
* Attempt to demangle a C++ data type, which may be datatype.
825
* a datatype type is made up of a number of simple types. e.g:
826
* char** = (pointer to (pointer to (char)))
827
*/
828
static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct,
829
enum datatype_flags flags)
830
{
831
char dt;
832
833
assert(ct);
834
ct->left = ct->right = NULL;
835
ct->flags = 0;
836
837
switch (dt = *sym->current++)
838
{
839
case '_':
840
/* MS type: __int8,__int16 etc */
841
ct->left = get_extended_type(*sym->current++);
842
break;
843
case 'C': case 'D': case 'E': case 'F': case 'G':
844
case 'H': case 'I': case 'J': case 'K': case 'M':
845
case 'N': case 'O': case 'X': case 'Z':
846
/* Simple data types */
847
ct->left = get_simple_type(dt);
848
break;
849
case 'T': /* union */
850
case 'U': /* struct */
851
case 'V': /* class */
852
case 'Y': /* cointerface */
853
/* Class/struct/union/cointerface */
854
{
855
const char* struct_name = NULL;
856
const char* type_name = NULL;
857
858
if (!(struct_name = get_class_name(sym)))
859
goto done;
860
if (!(sym->flags & UNDNAME_NO_COMPLEX_TYPE))
861
{
862
switch (dt)
863
{
864
case 'T': type_name = "union "; break;
865
case 'U': type_name = "struct "; break;
866
case 'V': type_name = "class "; break;
867
case 'Y': type_name = "cointerface "; break;
868
}
869
}
870
ct->left = str_printf(sym, "%s%s", type_name, struct_name);
871
}
872
break;
873
case '?':
874
/* not all the time is seems */
875
if (flags & IN_ARGS)
876
{
877
const char* ptr;
878
if (!(ptr = get_number(sym))) goto done;
879
ct->left = str_printf(sym, "`template-parameter-%s'", ptr);
880
}
881
else
882
{
883
if (!get_qualified_type(ct, sym, '?', flags)) goto done;
884
}
885
break;
886
case 'A': /* reference */
887
case 'B': /* volatile reference */
888
if (!get_qualified_type(ct, sym, dt, flags)) goto done;
889
break;
890
case 'P': /* Pointer */
891
case 'Q': /* const pointer */
892
case 'R': /* volatile pointer */
893
case 'S': /* const volatile pointer */
894
if (!(flags & IN_ARGS)) dt = 'P';
895
if (isdigit(*sym->current))
896
{
897
const char *ptr_qualif;
898
switch (dt)
899
{
900
default:
901
case 'P': ptr_qualif = NULL; break;
902
case 'Q': ptr_qualif = "const"; break;
903
case 'R': ptr_qualif = "volatile"; break;
904
case 'S': ptr_qualif = "const volatile"; break;
905
}
906
/* FIXME:
907
* P6 = Function pointer
908
* P8 = Member function pointer
909
* others who knows.. */
910
if (*sym->current == '8')
911
{
912
struct function_signature fs;
913
const char* class;
914
const char* function_qualifier;
915
916
sym->current++;
917
918
if (!(class = get_class_name(sym)))
919
goto done;
920
if (!get_function_qualifier(sym, &function_qualifier))
921
goto done;
922
if (!get_function_signature(sym, &fs))
923
goto done;
924
925
ct->left = str_printf(sym, "%s%s (%s %s::*%s",
926
fs.return_ct.left, fs.return_ct.right, fs.call_conv, class, ptr_qualif);
927
ct->right = str_printf(sym, ")%s%s", fs.arguments, function_qualifier);
928
}
929
else if (*sym->current == '6')
930
{
931
struct function_signature fs;
932
933
sym->current++;
934
935
if (!get_function_signature(sym, &fs))
936
goto done;
937
938
ct->left = str_printf(sym, "%s%s (%s*%s",
939
fs.return_ct.left, fs.return_ct.right, fs.call_conv, ptr_qualif);
940
ct->flags = DT_NO_LEADING_WS;
941
ct->right = str_printf(sym, ")%s", fs.arguments);
942
}
943
else goto done;
944
}
945
else if (!get_qualified_type(ct, sym, dt, flags)) goto done;
946
break;
947
case 'W':
948
if (*sym->current == '4')
949
{
950
char* enum_name;
951
sym->current++;
952
if (!(enum_name = get_class_name(sym)))
953
goto done;
954
if (sym->flags & UNDNAME_NO_COMPLEX_TYPE)
955
ct->left = enum_name;
956
else
957
ct->left = str_printf(sym, "enum %s", enum_name);
958
}
959
else goto done;
960
break;
961
case '0': case '1': case '2': case '3': case '4':
962
case '5': case '6': case '7': case '8': case '9':
963
/* Referring back to previously parsed type */
964
/* left and right are pushed as two separate strings */
965
ct->left = str_array_get_ref(&sym->args, (dt - '0') * 2);
966
ct->right = str_array_get_ref(&sym->args, (dt - '0') * 2 + 1);
967
if (!ct->left) goto done;
968
break;
969
case '$':
970
switch (*sym->current++)
971
{
972
case '0':
973
if (!(ct->left = get_number(sym))) goto done;
974
break;
975
case 'D':
976
{
977
const char* ptr;
978
if (!(ptr = get_number(sym))) goto done;
979
ct->left = str_printf(sym, "`template-parameter%s'", ptr);
980
}
981
break;
982
case 'F':
983
{
984
const char* p1;
985
const char* p2;
986
if (!(p1 = get_number(sym))) goto done;
987
if (!(p2 = get_number(sym))) goto done;
988
ct->left = str_printf(sym, "{%s,%s}", p1, p2);
989
}
990
break;
991
case 'G':
992
{
993
const char* p1;
994
const char* p2;
995
const char* p3;
996
if (!(p1 = get_number(sym))) goto done;
997
if (!(p2 = get_number(sym))) goto done;
998
if (!(p3 = get_number(sym))) goto done;
999
ct->left = str_printf(sym, "{%s,%s,%s}", p1, p2, p3);
1000
}
1001
break;
1002
case 'Q':
1003
{
1004
const char* ptr;
1005
if (!(ptr = get_number(sym))) goto done;
1006
ct->left = str_printf(sym, "`non-type-template-parameter%s'", ptr);
1007
}
1008
break;
1009
case '$':
1010
if (*sym->current == 'A')
1011
{
1012
sym->current++;
1013
if (*sym->current == '6')
1014
{
1015
struct function_signature fs;
1016
1017
sym->current++;
1018
1019
if (!get_function_signature(sym, &fs))
1020
goto done;
1021
ct->left = str_printf(sym, "%s%s %s%s",
1022
fs.return_ct.left, fs.return_ct.right, fs.call_conv, fs.arguments);
1023
}
1024
}
1025
else if (*sym->current == 'B')
1026
{
1027
unsigned mark = sym->stack.num;
1028
struct datatype_t sub_ct;
1029
const char* arr = NULL;
1030
sym->current++;
1031
1032
/* multidimensional arrays */
1033
if (*sym->current == 'Y')
1034
{
1035
const char* n1;
1036
int num;
1037
1038
sym->current++;
1039
if (!(n1 = get_number(sym))) goto done;
1040
num = atoi(n1);
1041
1042
while (num--)
1043
arr = str_printf(sym, "%s[%s]", arr, get_number(sym));
1044
}
1045
1046
if (!demangle_datatype(sym, &sub_ct, 0)) goto done;
1047
1048
if (arr)
1049
ct->left = str_printf(sym, "%s %s", sub_ct.left, arr);
1050
else
1051
ct->left = sub_ct.left;
1052
ct->right = sub_ct.right;
1053
sym->stack.num = mark;
1054
}
1055
else if (*sym->current == 'C')
1056
{
1057
struct datatype_t xdt;
1058
1059
sym->current++;
1060
if (!get_qualifier(sym, &xdt, NULL)) goto done;
1061
if (!demangle_datatype(sym, ct, flags)) goto done;
1062
ct->left = str_printf(sym, "%s %s", ct->left, xdt.left);
1063
}
1064
else if (*sym->current == 'Q')
1065
{
1066
sym->current++;
1067
if (!get_qualified_type(ct, sym, '$', flags)) goto done;
1068
}
1069
else if (*sym->current == 'T')
1070
{
1071
sym->current++;
1072
ct->left = str_printf(sym, "std::nullptr_t");
1073
}
1074
break;
1075
}
1076
break;
1077
default :
1078
break;
1079
}
1080
done:
1081
1082
return ct->left != NULL;
1083
}
1084
1085
/******************************************************************
1086
* handle_data
1087
* Does the final parsing and handling for a variable or a field in
1088
* a class.
1089
*/
1090
static BOOL handle_data(struct parsed_symbol* sym)
1091
{
1092
const char* access = NULL;
1093
const char* member_type = NULL;
1094
struct datatype_t xdt = {NULL};
1095
struct datatype_t ct;
1096
char* name = NULL;
1097
BOOL ret = FALSE;
1098
1099
/* 0 private static
1100
* 1 protected static
1101
* 2 public static
1102
* 3 private non-static
1103
* 4 protected non-static
1104
* 5 public non-static
1105
* 6 ?? static
1106
* 7 ?? static
1107
*/
1108
1109
if (!(sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS))
1110
{
1111
/* we only print the access for static members */
1112
switch (*sym->current)
1113
{
1114
case '0': access = "private: "; break;
1115
case '1': access = "protected: "; break;
1116
case '2': access = "public: "; break;
1117
}
1118
}
1119
1120
if (!(sym->flags & UNDNAME_NO_MEMBER_TYPE))
1121
{
1122
if (*sym->current >= '0' && *sym->current <= '2')
1123
member_type = "static ";
1124
}
1125
1126
name = get_class_string(sym, 0);
1127
1128
switch (*sym->current++)
1129
{
1130
case '0': case '1': case '2':
1131
case '3': case '4': case '5':
1132
{
1133
unsigned mark = sym->stack.num;
1134
const char* class;
1135
1136
if (!demangle_datatype(sym, &ct, 0)) goto done;
1137
if (!get_qualifier(sym, &xdt, &class)) goto done; /* class doesn't seem to be displayed */
1138
if (xdt.left && xdt.right) xdt.left = str_printf(sym, "%s %s", xdt.left, xdt.right);
1139
else if (!xdt.left) xdt.left = xdt.right;
1140
sym->stack.num = mark;
1141
}
1142
break;
1143
case '6' : /* compiler generated static */
1144
case '7' : /* compiler generated static */
1145
ct.left = ct.right = NULL;
1146
if (!get_qualifier(sym, &xdt, NULL)) goto done;
1147
if (*sym->current != '@')
1148
{
1149
char* cls = NULL;
1150
1151
if (!(cls = get_class_name(sym)))
1152
goto done;
1153
ct.right = str_printf(sym, "{for `%s'}", cls);
1154
}
1155
break;
1156
case '8':
1157
case '9':
1158
xdt.left = ct.left = ct.right = NULL;
1159
break;
1160
default: goto done;
1161
}
1162
if (sym->flags & UNDNAME_NAME_ONLY) ct.left = ct.right = xdt.left = NULL;
1163
1164
sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s", access,
1165
member_type, ct.left,
1166
xdt.left && ct.left ? " " : NULL, xdt.left,
1167
xdt.left || ct.left ? " " : NULL, name, ct.right);
1168
ret = TRUE;
1169
done:
1170
return ret;
1171
}
1172
1173
/******************************************************************
1174
* handle_method
1175
* Does the final parsing and handling for a function or a method in
1176
* a class.
1177
*/
1178
static BOOL handle_method(struct parsed_symbol* sym, BOOL cast_op)
1179
{
1180
char accmem;
1181
const char* access = NULL;
1182
int access_id = -1;
1183
const char* member_type = NULL;
1184
struct datatype_t ct_ret;
1185
const char* call_conv;
1186
const char* function_qualifier = NULL;
1187
const char* exported;
1188
const char* args_str = NULL;
1189
const char* name = NULL;
1190
BOOL ret = FALSE, has_args = TRUE, has_ret = TRUE;
1191
unsigned mark;
1192
1193
/* FIXME: why 2 possible letters for each option?
1194
* 'A' private:
1195
* 'B' private:
1196
* 'C' private: static
1197
* 'D' private: static
1198
* 'E' private: virtual
1199
* 'F' private: virtual
1200
* 'G' private: thunk
1201
* 'H' private: thunk
1202
* 'I' protected:
1203
* 'J' protected:
1204
* 'K' protected: static
1205
* 'L' protected: static
1206
* 'M' protected: virtual
1207
* 'N' protected: virtual
1208
* 'O' protected: thunk
1209
* 'P' protected: thunk
1210
* 'Q' public:
1211
* 'R' public:
1212
* 'S' public: static
1213
* 'T' public: static
1214
* 'U' public: virtual
1215
* 'V' public: virtual
1216
* 'W' public: thunk
1217
* 'X' public: thunk
1218
* 'Y'
1219
* 'Z'
1220
* "$0" private: thunk vtordisp
1221
* "$1" private: thunk vtordisp
1222
* "$2" protected: thunk vtordisp
1223
* "$3" protected: thunk vtordisp
1224
* "$4" public: thunk vtordisp
1225
* "$5" public: thunk vtordisp
1226
* "$B" vcall thunk
1227
* "$R" thunk vtordispex
1228
*/
1229
accmem = *sym->current++;
1230
if (accmem == '$')
1231
{
1232
if (*sym->current >= '0' && *sym->current <= '5')
1233
access_id = (*sym->current - '0') / 2;
1234
else if (*sym->current == 'R')
1235
access_id = (sym->current[1] - '0') / 2;
1236
else if (*sym->current != 'B')
1237
goto done;
1238
}
1239
else if (accmem >= 'A' && accmem <= 'Z')
1240
access_id = (accmem - 'A') / 8;
1241
else
1242
goto done;
1243
1244
switch (access_id)
1245
{
1246
case 0: access = "private: "; break;
1247
case 1: access = "protected: "; break;
1248
case 2: access = "public: "; break;
1249
}
1250
if (accmem == '$' || (accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7)
1251
access = str_printf(sym, "[thunk]:%s", access ? access : " ");
1252
1253
if (accmem == '$' && *sym->current != 'B')
1254
member_type = "virtual ";
1255
else if (accmem <= 'X')
1256
{
1257
switch ((accmem - 'A') % 8)
1258
{
1259
case 2: case 3: member_type = "static "; break;
1260
case 4: case 5: case 6: case 7: member_type = "virtual "; break;
1261
}
1262
}
1263
1264
if (sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS)
1265
access = NULL;
1266
if (sym->flags & UNDNAME_NO_MEMBER_TYPE)
1267
member_type = NULL;
1268
1269
name = get_class_string(sym, 0);
1270
1271
if (accmem == '$' && *sym->current == 'B') /* vcall thunk */
1272
{
1273
const char *n;
1274
1275
sym->current++;
1276
n = get_number(sym);
1277
1278
if(!n || *sym->current++ != 'A') goto done;
1279
name = str_printf(sym, "%s{%s,{flat}}' }'", name, n);
1280
has_args = FALSE;
1281
has_ret = FALSE;
1282
}
1283
else if (accmem == '$' && *sym->current == 'R') /* vtordispex thunk */
1284
{
1285
const char *n1, *n2, *n3, *n4;
1286
1287
sym->current += 2;
1288
n1 = get_number(sym);
1289
n2 = get_number(sym);
1290
n3 = get_number(sym);
1291
n4 = get_number(sym);
1292
1293
if(!n1 || !n2 || !n3 || !n4) goto done;
1294
name = str_printf(sym, "%s`vtordispex{%s,%s,%s,%s}' ", name, n1, n2, n3, n4);
1295
}
1296
else if (accmem == '$') /* vtordisp thunk */
1297
{
1298
const char *n1, *n2;
1299
1300
sym->current++;
1301
n1 = get_number(sym);
1302
n2 = get_number(sym);
1303
1304
if (!n1 || !n2) goto done;
1305
name = str_printf(sym, "%s`vtordisp{%s,%s}' ", name, n1, n2);
1306
}
1307
else if ((accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7) /* a thunk */
1308
name = str_printf(sym, "%s`adjustor{%s}' ", name, get_number(sym));
1309
1310
if (has_args && (accmem == '$' ||
1311
(accmem <= 'X' && (accmem - 'A') % 8 != 2 && (accmem - 'A') % 8 != 3)))
1312
{
1313
/* Implicit 'this' pointer */
1314
if (!get_function_qualifier(sym, &function_qualifier)) goto done;
1315
}
1316
1317
if (!get_calling_convention(*sym->current++, &call_conv, &exported,
1318
sym->flags))
1319
goto done;
1320
1321
/* Return type, or @ if 'void' */
1322
if (has_ret && *sym->current == '@')
1323
{
1324
ct_ret.left = "void";
1325
ct_ret.right = NULL;
1326
sym->current++;
1327
}
1328
else if (has_ret)
1329
{
1330
if (!demangle_datatype(sym, &ct_ret, cast_op ? WS_AFTER_QUAL_IF : 0))
1331
goto done;
1332
}
1333
if (!has_ret || sym->flags & UNDNAME_NO_FUNCTION_RETURNS)
1334
ct_ret.left = ct_ret.right = NULL;
1335
if (cast_op)
1336
{
1337
name = str_printf(sym, "%s %s%s", name, ct_ret.left, ct_ret.right);
1338
ct_ret.left = ct_ret.right = NULL;
1339
}
1340
1341
mark = sym->stack.num;
1342
if (has_args && !(args_str = get_args(sym, TRUE, '(', ')'))) goto done;
1343
if (sym->flags & UNDNAME_NAME_ONLY) args_str = function_qualifier = NULL;
1344
if (sym->flags & UNDNAME_NO_THISTYPE) function_qualifier = NULL;
1345
sym->stack.num = mark;
1346
1347
/* Note: '()' after 'Z' means 'throws', but we don't care here
1348
* Yet!!! FIXME
1349
*/
1350
sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s%s%s%s",
1351
access, member_type, ct_ret.left,
1352
(ct_ret.left && !ct_ret.right) ? " " : NULL,
1353
call_conv, call_conv ? " " : NULL, exported,
1354
name, args_str, function_qualifier, ct_ret.right);
1355
ret = TRUE;
1356
done:
1357
return ret;
1358
}
1359
1360
/*******************************************************************
1361
* symbol_demangle
1362
* Demangle a C++ linker symbol
1363
*/
1364
static BOOL symbol_demangle(struct parsed_symbol* sym)
1365
{
1366
BOOL ret = FALSE;
1367
enum {
1368
PP_NONE,
1369
PP_CONSTRUCTOR,
1370
PP_DESTRUCTOR,
1371
PP_CAST_OPERATOR,
1372
} post_process = PP_NONE;
1373
1374
/* FIXME seems wrong as name, as it demangles a simple data type */
1375
if (sym->flags & UNDNAME_NO_ARGUMENTS)
1376
{
1377
struct datatype_t ct;
1378
1379
if (demangle_datatype(sym, &ct, 0))
1380
{
1381
sym->result = str_printf(sym, "%s%s", ct.left, ct.right);
1382
ret = TRUE;
1383
}
1384
goto done;
1385
}
1386
1387
/* MS mangled names always begin with '?' */
1388
if (*sym->current != '?') return FALSE;
1389
sym->current++;
1390
1391
/* Then function name or operator code */
1392
if (*sym->current == '?')
1393
{
1394
const char* function_name = NULL;
1395
BOOL in_template = FALSE;
1396
1397
if (sym->current[1] == '$' && sym->current[2] == '?')
1398
{
1399
in_template = TRUE;
1400
sym->current += 2;
1401
}
1402
1403
/* C++ operator code (one character, or two if the first is '_') */
1404
switch (*++sym->current)
1405
{
1406
case '0': function_name = ""; post_process = PP_CONSTRUCTOR; break;
1407
case '1': function_name = ""; post_process = PP_DESTRUCTOR; break;
1408
case '2': function_name = "operator new"; break;
1409
case '3': function_name = "operator delete"; break;
1410
case '4': function_name = "operator="; break;
1411
case '5': function_name = "operator>>"; break;
1412
case '6': function_name = "operator<<"; break;
1413
case '7': function_name = "operator!"; break;
1414
case '8': function_name = "operator=="; break;
1415
case '9': function_name = "operator!="; break;
1416
case 'A': function_name = "operator[]"; break;
1417
case 'B': function_name = "operator"; post_process = PP_CAST_OPERATOR; break;
1418
case 'C': function_name = "operator->"; break;
1419
case 'D': function_name = "operator*"; break;
1420
case 'E': function_name = "operator++"; break;
1421
case 'F': function_name = "operator--"; break;
1422
case 'G': function_name = "operator-"; break;
1423
case 'H': function_name = "operator+"; break;
1424
case 'I': function_name = "operator&"; break;
1425
case 'J': function_name = "operator->*"; break;
1426
case 'K': function_name = "operator/"; break;
1427
case 'L': function_name = "operator%"; break;
1428
case 'M': function_name = "operator<"; break;
1429
case 'N': function_name = "operator<="; break;
1430
case 'O': function_name = "operator>"; break;
1431
case 'P': function_name = "operator>="; break;
1432
case 'Q': function_name = "operator,"; break;
1433
case 'R': function_name = "operator()"; break;
1434
case 'S': function_name = "operator~"; break;
1435
case 'T': function_name = "operator^"; break;
1436
case 'U': function_name = "operator|"; break;
1437
case 'V': function_name = "operator&&"; break;
1438
case 'W': function_name = "operator||"; break;
1439
case 'X': function_name = "operator*="; break;
1440
case 'Y': function_name = "operator+="; break;
1441
case 'Z': function_name = "operator-="; break;
1442
case '_':
1443
switch (*++sym->current)
1444
{
1445
case '0': function_name = "operator/="; break;
1446
case '1': function_name = "operator%="; break;
1447
case '2': function_name = "operator>>="; break;
1448
case '3': function_name = "operator<<="; break;
1449
case '4': function_name = "operator&="; break;
1450
case '5': function_name = "operator|="; break;
1451
case '6': function_name = "operator^="; break;
1452
case '7': function_name = "`vftable'"; break;
1453
case '8': function_name = "`vbtable'"; break;
1454
case '9': function_name = "`vcall'"; break;
1455
case 'A': function_name = "`typeof'"; break;
1456
case 'B': function_name = "`local static guard'"; break;
1457
case 'C': sym->result = (char*)"`string'"; /* string literal: followed by string encoding (native never undecode it) */
1458
/* FIXME: should unmangle the whole string for error reporting */
1459
if (*sym->current && sym->current[strlen(sym->current) - 1] == '@') ret = TRUE;
1460
goto done;
1461
case 'D': function_name = "`vbase destructor'"; break;
1462
case 'E': function_name = "`vector deleting destructor'"; break;
1463
case 'F': function_name = "`default constructor closure'"; break;
1464
case 'G': function_name = "`scalar deleting destructor'"; break;
1465
case 'H': function_name = "`vector constructor iterator'"; break;
1466
case 'I': function_name = "`vector destructor iterator'"; break;
1467
case 'J': function_name = "`vector vbase constructor iterator'"; break;
1468
case 'K': function_name = "`virtual displacement map'"; break;
1469
case 'L': function_name = "`eh vector constructor iterator'"; break;
1470
case 'M': function_name = "`eh vector destructor iterator'"; break;
1471
case 'N': function_name = "`eh vector vbase constructor iterator'"; break;
1472
case 'O': function_name = "`copy constructor closure'"; break;
1473
case 'R':
1474
sym->flags |= UNDNAME_NO_FUNCTION_RETURNS;
1475
switch (*++sym->current)
1476
{
1477
case '0':
1478
{
1479
struct datatype_t ct;
1480
1481
sym->current++;
1482
if (!demangle_datatype(sym, &ct, 0))
1483
goto done;
1484
function_name = str_printf(sym, "%s%s `RTTI Type Descriptor'",
1485
ct.left, ct.right);
1486
sym->current--;
1487
}
1488
break;
1489
case '1':
1490
{
1491
const char* n1, *n2, *n3, *n4;
1492
sym->current++;
1493
n1 = get_number(sym);
1494
n2 = get_number(sym);
1495
n3 = get_number(sym);
1496
n4 = get_number(sym);
1497
sym->current--;
1498
function_name = str_printf(sym, "`RTTI Base Class Descriptor at (%s,%s,%s,%s)'",
1499
n1, n2, n3, n4);
1500
}
1501
break;
1502
case '2': function_name = "`RTTI Base Class Array'"; break;
1503
case '3': function_name = "`RTTI Class Hierarchy Descriptor'"; break;
1504
case '4': function_name = "`RTTI Complete Object Locator'"; break;
1505
default:
1506
break;
1507
}
1508
break;
1509
case 'S': function_name = "`local vftable'"; break;
1510
case 'T': function_name = "`local vftable constructor closure'"; break;
1511
case 'U': function_name = "operator new[]"; break;
1512
case 'V': function_name = "operator delete[]"; break;
1513
case 'X': function_name = "`placement delete closure'"; break;
1514
case 'Y': function_name = "`placement delete[] closure'"; break;
1515
case '_':
1516
switch (*++sym->current)
1517
{
1518
case 'K':
1519
sym->current++;
1520
function_name = str_printf(sym, "operator \"\" %s", get_literal_string(sym));
1521
--sym->current;
1522
break;
1523
default:
1524
return FALSE;
1525
}
1526
break;
1527
default:
1528
return FALSE;
1529
}
1530
break;
1531
case '$':
1532
sym->current++;
1533
if (!(function_name = get_template_name(sym))) goto done;
1534
--sym->current;
1535
break;
1536
default:
1537
/* FIXME: Other operators */
1538
return FALSE;
1539
}
1540
sym->current++;
1541
if (in_template)
1542
{
1543
unsigned args_mark = sym->args.num;
1544
const char *args;
1545
1546
args = get_args(sym, FALSE, '<', '>');
1547
if (args) function_name = function_name ? str_printf(sym, "%s%s", function_name, args) : args;
1548
sym->args.num = args_mark;
1549
sym->names.num = 0;
1550
}
1551
if (!str_array_push(sym, function_name, -1, &sym->stack))
1552
return FALSE;
1553
}
1554
else if (*sym->current == '$')
1555
{
1556
/* Strange construct, it's a name with a template argument list
1557
and that's all. */
1558
sym->current++;
1559
ret = (sym->result = get_template_name(sym)) != NULL;
1560
goto done;
1561
}
1562
1563
/* Either a class name, or '@' if the symbol is not a class member */
1564
switch (*sym->current)
1565
{
1566
case '@': sym->current++; break;
1567
case '$': break;
1568
default:
1569
/* Class the function is associated with, terminated by '@@' */
1570
if (!get_class(sym)) goto done;
1571
break;
1572
}
1573
1574
switch (post_process)
1575
{
1576
case PP_NONE: default: break;
1577
case PP_CONSTRUCTOR: case PP_DESTRUCTOR:
1578
/* it's time to set the member name for ctor & dtor */
1579
if (sym->stack.num <= 1) goto done;
1580
sym->stack.elts[0] = str_printf(sym, "%s%s%s", post_process == PP_DESTRUCTOR ? "~" : NULL,
1581
sym->stack.elts[1], sym->stack.elts[0]);
1582
/* ctors and dtors don't have return type */
1583
sym->flags |= UNDNAME_NO_FUNCTION_RETURNS;
1584
break;
1585
case PP_CAST_OPERATOR:
1586
sym->flags &= ~UNDNAME_NO_FUNCTION_RETURNS;
1587
break;
1588
}
1589
1590
/* Function/Data type and access level */
1591
if (*sym->current >= '0' && *sym->current <= '9')
1592
ret = handle_data(sym);
1593
else if ((*sym->current >= 'A' && *sym->current <= 'Z') || *sym->current == '$')
1594
ret = handle_method(sym, post_process == PP_CAST_OPERATOR);
1595
else ret = FALSE;
1596
done:
1597
return ret;
1598
}
1599
1600
char *demangle( const char *mangled )
1601
{
1602
struct parsed_symbol sym;
1603
1604
memset(&sym, 0, sizeof(struct parsed_symbol));
1605
sym.current = mangled;
1606
str_array_init( &sym.names );
1607
str_array_init( &sym.stack );
1608
return symbol_demangle(&sym) ? sym.result : NULL;
1609
}
1610
1611