?? cplus-dem.c
字號:
/* Demangler for GNU C++ Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.uucp) Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling Modified by Satish Pai (pai@apollo.hp.com) for HP demanglingThis file is part of the libiberty library.Libiberty is free software; you can redistribute it and/ormodify it under the terms of the GNU Library General PublicLicense as published by the Free Software Foundation; eitherversion 2 of the License, or (at your option) any later version.In addition to the permissions in the GNU Library General PublicLicense, the Free Software Foundation gives you unlimited permissionto link the compiled version of this file into combinations with otherprograms, and to distribute those combinations without any restrictioncoming from the use of this file. (The Library Public Licenserestrictions do apply in other respects; for example, they covermodification of the file, and distribution when not linked into acombined executable.)Libiberty is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULibrary General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with libiberty; see the file COPYING.LIB. Ifnot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,Boston, MA 02110-1301, USA. *//* This file exports two functions; cplus_mangle_opname and cplus_demangle. This file imports xmalloc and xrealloc, which are like malloc and realloc except that they generate a fatal error if there is no available memory. */#define xmalloc malloc#define xrealloc realloc#define xstrdup strdup/* This file lives in both GCC and libiberty. When making changes, please try not to break either. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "safe-ctype.h"#define bl _sch_isblank#define cn _sch_iscntrl#define di _sch_isdigit#define is _sch_isidst#define lo _sch_islower#define nv _sch_isnvsp#define pn _sch_ispunct#define pr _sch_isprint#define sp _sch_isspace#define up _sch_isupper#define vs _sch_isvsp#define xd _sch_isxdigit#define L (const unsigned short) (lo|is |pr) /* lower case letter */#define XL (const unsigned short) (lo|is|xd|pr) /* lowercase hex digit */#define U (const unsigned short) (up|is |pr) /* upper case letter */#define XU (const unsigned short) (up|is|xd|pr) /* uppercase hex digit */#define D (const unsigned short) (di |xd|pr) /* decimal digit */#define P (const unsigned short) (pn |pr) /* punctuation */#define _ (const unsigned short) (pn|is |pr) /* underscore */#define C (const unsigned short) ( cn) /* control character */#define Z (const unsigned short) (nv |cn) /* NUL */#define M (const unsigned short) (nv|sp |cn) /* cursor movement: \f \v */#define V (const unsigned short) (vs|sp |cn) /* vertical space: \r \n */#define T (const unsigned short) (nv|sp|bl|cn) /* tab */#define S (const unsigned short) (nv|sp|bl|pr) /* space */const unsigned short _sch_istable[256] ={ Z, C, C, C, C, C, C, C, /* NUL SOH STX ETX EOT ENQ ACK BEL */ C, T, V, M, M, V, C, C, /* BS HT LF VT FF CR SO SI */ C, C, C, C, C, C, C, C, /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */ C, C, C, C, C, C, C, C, /* CAN EM SUB ESC FS GS RS US */ S, P, P, P, P, P, P, P, /* SP ! " # $ % & ' */ P, P, P, P, P, P, P, P, /* ( ) * + , - . / */ D, D, D, D, D, D, D, D, /* 0 1 2 3 4 5 6 7 */ D, D, P, P, P, P, P, P, /* 8 9 : ; < = > ? */ P, XU, XU, XU, XU, XU, XU, U, /* @ A B C D E F G */ U, U, U, U, U, U, U, U, /* H I J K L M N O */ U, U, U, U, U, U, U, U, /* P Q R S T U V W */ U, U, U, P, P, P, P, _, /* X Y Z [ \ ] ^ _ */ P, XL, XL, XL, XL, XL, XL, L, /* ` a b c d e f g */ L, L, L, L, L, L, L, L, /* h i j k l m n o */ L, L, L, L, L, L, L, L, /* p q r s t u v w */ L, L, L, P, P, P, P, C, /* x y z { | } ~ DEL */ /* high half of unsigned char is locale-specific, so all tests are false in "C" locale */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};#include <sys/types.h>#include <string.h>#include <stdio.h>#ifdef HAVE_STDLIB_H#include <stdlib.h>#elsechar * malloc ();char * realloc ();#endif#include <demangle.h>#undef CURRENT_DEMANGLING_STYLE#define CURRENT_DEMANGLING_STYLE work->optionsstatic char *ada_demangle (const char *, int);#define min(X,Y) (((X) < (Y)) ? (X) : (Y))/* A value at least one greater than the maximum number of characters that will be output when using the `%d' format with `printf'. */#define INTBUF_SIZE 32extern void fancy_abort (void) ATTRIBUTE_NORETURN;/* In order to allow a single demangler executable to demangle strings using various common values of CPLUS_MARKER, as well as any specific one set at compile time, we maintain a string containing all the commonly used ones, and check to see if the marker we are looking for is in that string. CPLUS_MARKER is usually '$' on systems where the assembler can deal with that. Where the assembler can't, it's usually '.' (but on many systems '.' is used for other things). We put the current defined CPLUS_MARKER first (which defaults to '$'), followed by the next most common value, followed by an explicit '$' in case the value of CPLUS_MARKER is not '$'. We could avoid this if we could just get g++ to tell us what the actual cplus marker character is as part of the debug information, perhaps by ensuring that it is the character that terminates the gcc<n>_compiled marker symbol (FIXME). */#if !defined (CPLUS_MARKER)#define CPLUS_MARKER '$'#endifenum demangling_styles current_demangling_style = auto_demangling;static char cplus_markers[] = { CPLUS_MARKER, '.', '$', '\0' };static char char_str[2] = { '\000', '\000' };voidset_cplus_marker_for_demangling (int ch){ cplus_markers[0] = ch;}typedef struct string /* Beware: these aren't required to be */{ /* '\0' terminated. */ char *b; /* pointer to start of string */ char *p; /* pointer after last character */ char *e; /* pointer after end of allocated space */} string;/* Stuff that is shared between sub-routines. Using a shared structure allows cplus_demangle to be reentrant. */struct work_stuff{ int options; char **typevec; char **ktypevec; char **btypevec; int numk; int numb; int ksize; int bsize; int ntypes; int typevec_size; int constructor; int destructor; int static_type; /* A static member function */ int temp_start; /* index in demangled to start of template args */ int type_quals; /* The type qualifiers. */ int dllimported; /* Symbol imported from a PE DLL */ char **tmpl_argvec; /* Template function arguments. */ int ntmpl_args; /* The number of template function arguments. */ int forgetting_types; /* Nonzero if we are not remembering the types we see. */ string* previous_argument; /* The last function argument demangled. */ int nrepeats; /* The number of times to repeat the previous argument. */};#define PRINT_ANSI_QUALIFIERS (work -> options & DMGL_ANSI)#define PRINT_ARG_TYPES (work -> options & DMGL_PARAMS)static const struct optable{ const char *const in; const char *const out; const int flags;} optable[] = { {"nw", " new", DMGL_ANSI}, /* new (1.92, ansi) */ {"dl", " delete", DMGL_ANSI}, /* new (1.92, ansi) */ {"new", " new", 0}, /* old (1.91, and 1.x) */ {"delete", " delete", 0}, /* old (1.91, and 1.x) */ {"vn", " new []", DMGL_ANSI}, /* GNU, pending ansi */ {"vd", " delete []", DMGL_ANSI}, /* GNU, pending ansi */ {"as", "=", DMGL_ANSI}, /* ansi */ {"ne", "!=", DMGL_ANSI}, /* old, ansi */ {"eq", "==", DMGL_ANSI}, /* old, ansi */ {"ge", ">=", DMGL_ANSI}, /* old, ansi */ {"gt", ">", DMGL_ANSI}, /* old, ansi */ {"le", "<=", DMGL_ANSI}, /* old, ansi */ {"lt", "<", DMGL_ANSI}, /* old, ansi */ {"plus", "+", 0}, /* old */ {"pl", "+", DMGL_ANSI}, /* ansi */ {"apl", "+=", DMGL_ANSI}, /* ansi */ {"minus", "-", 0}, /* old */ {"mi", "-", DMGL_ANSI}, /* ansi */ {"ami", "-=", DMGL_ANSI}, /* ansi */ {"mult", "*", 0}, /* old */ {"ml", "*", DMGL_ANSI}, /* ansi */ {"amu", "*=", DMGL_ANSI}, /* ansi (ARM/Lucid) */ {"aml", "*=", DMGL_ANSI}, /* ansi (GNU/g++) */ {"convert", "+", 0}, /* old (unary +) */ {"negate", "-", 0}, /* old (unary -) */ {"trunc_mod", "%", 0}, /* old */ {"md", "%", DMGL_ANSI}, /* ansi */ {"amd", "%=", DMGL_ANSI}, /* ansi */ {"trunc_div", "/", 0}, /* old */ {"dv", "/", DMGL_ANSI}, /* ansi */ {"adv", "/=", DMGL_ANSI}, /* ansi */ {"truth_andif", "&&", 0}, /* old */ {"aa", "&&", DMGL_ANSI}, /* ansi */ {"truth_orif", "||", 0}, /* old */ {"oo", "||", DMGL_ANSI}, /* ansi */ {"truth_not", "!", 0}, /* old */ {"nt", "!", DMGL_ANSI}, /* ansi */ {"postincrement","++", 0}, /* old */ {"pp", "++", DMGL_ANSI}, /* ansi */ {"postdecrement","--", 0}, /* old */ {"mm", "--", DMGL_ANSI}, /* ansi */ {"bit_ior", "|", 0}, /* old */ {"or", "|", DMGL_ANSI}, /* ansi */ {"aor", "|=", DMGL_ANSI}, /* ansi */ {"bit_xor", "^", 0}, /* old */ {"er", "^", DMGL_ANSI}, /* ansi */ {"aer", "^=", DMGL_ANSI}, /* ansi */ {"bit_and", "&", 0}, /* old */ {"ad", "&", DMGL_ANSI}, /* ansi */ {"aad", "&=", DMGL_ANSI}, /* ansi */ {"bit_not", "~", 0}, /* old */ {"co", "~", DMGL_ANSI}, /* ansi */ {"call", "()", 0}, /* old */ {"cl", "()", DMGL_ANSI}, /* ansi */ {"alshift", "<<", 0}, /* old */ {"ls", "<<", DMGL_ANSI}, /* ansi */ {"als", "<<=", DMGL_ANSI}, /* ansi */ {"arshift", ">>", 0}, /* old */ {"rs", ">>", DMGL_ANSI}, /* ansi */ {"ars", ">>=", DMGL_ANSI}, /* ansi */ {"component", "->", 0}, /* old */ {"pt", "->", DMGL_ANSI}, /* ansi; Lucid C++ form */ {"rf", "->", DMGL_ANSI}, /* ansi; ARM/GNU form */ {"indirect", "*", 0}, /* old */ {"method_call", "->()", 0}, /* old */ {"addr", "&", 0}, /* old (unary &) */ {"array", "[]", 0}, /* old */ {"vc", "[]", DMGL_ANSI}, /* ansi */ {"compound", ", ", 0}, /* old */ {"cm", ", ", DMGL_ANSI}, /* ansi */ {"cond", "?:", 0}, /* old */ {"cn", "?:", DMGL_ANSI}, /* pseudo-ansi */ {"max", ">?", 0}, /* old */ {"mx", ">?", DMGL_ANSI}, /* pseudo-ansi */ {"min", "<?", 0}, /* old */ {"mn", "<?", DMGL_ANSI}, /* pseudo-ansi */ {"nop", "", 0}, /* old (for operator=) */ {"rm", "->*", DMGL_ANSI}, /* ansi */ {"sz", "sizeof ", DMGL_ANSI} /* pseudo-ansi */};/* These values are used to indicate the various type varieties. They are all non-zero so that they can be used as `success' values. */typedef enum type_kind_t{ tk_none, tk_pointer, tk_reference, tk_integral, tk_bool, tk_char, tk_real} type_kind_t;const struct demangler_engine libiberty_demanglers[] ={ { NO_DEMANGLING_STYLE_STRING, no_demangling, "Demangling disabled" } , { AUTO_DEMANGLING_STYLE_STRING, auto_demangling, "Automatic selection based on executable" } , { GNU_DEMANGLING_STYLE_STRING, gnu_demangling, "GNU (g++) style demangling" } , { LUCID_DEMANGLING_STYLE_STRING, lucid_demangling, "Lucid (lcc) style demangling" } , { ARM_DEMANGLING_STYLE_STRING, arm_demangling, "ARM style demangling" } , { HP_DEMANGLING_STYLE_STRING, hp_demangling, "HP (aCC) style demangling" } , { EDG_DEMANGLING_STYLE_STRING, edg_demangling, "EDG style demangling" } , { GNU_V3_DEMANGLING_STYLE_STRING, gnu_v3_demangling, "GNU (g++) V3 ABI-style demangling" } , { JAVA_DEMANGLING_STYLE_STRING, java_demangling, "Java style demangling" } , { GNAT_DEMANGLING_STYLE_STRING, gnat_demangling, "GNAT style demangling" } , { NULL, unknown_demangling, NULL }};#define STRING_EMPTY(str) ((str) -> b == (str) -> p)#define APPEND_BLANK(str) {if (!STRING_EMPTY(str)) \ string_append(str, " ");}#define LEN_STRING(str) ( (STRING_EMPTY(str))?0:((str)->p - (str)->b))/* The scope separator appropriate for the language being demangled. */#define SCOPE_STRING(work) ((work->options & DMGL_JAVA) ? "." : "::")#define ARM_VTABLE_STRING "__vtbl__" /* Lucid/ARM virtual table prefix */#define ARM_VTABLE_STRLEN 8 /* strlen (ARM_VTABLE_STRING) *//* Prototypes for local functions */static void delete_work_stuff (struct work_stuff *);static void delete_non_B_K_work_stuff (struct work_stuff *);static char *mop_up (struct work_stuff *, string *, int);static void squangle_mop_up (struct work_stuff *);static void work_stuff_copy_to_from (struct work_stuff *, struct work_stuff *);#if 0static intdemangle_method_args (struct work_stuff *, const char **, string *);#endifstatic char *internal_cplus_demangle (struct work_stuff *, const char *);static intdemangle_template_template_parm (struct work_stuff *work, const char **, string *);static intdemangle_template (struct work_stuff *work, const char **, string *, string *, int, int);static intarm_pt (struct work_stuff *, const char *, int, const char **, const char **);static intdemangle_class_name (struct work_stuff *, const char **, string *);static intdemangle_qualified (struct work_stuff *, const char **, string *, int, int);static int demangle_class (struct work_stuff *, const char **, string *);static int demangle_fund_type (struct work_stuff *, const char **, string *);static int demangle_signature (struct work_stuff *, const char **, string *);static int demangle_prefix (struct work_stuff *, const char **, string *);static int gnu_special (struct work_stuff *, const char **, string *);static int arm_special (const char **, string *);static void string_need (string *, int);static void string_delete (string *);static voidstring_init (string *);static void string_clear (string *);#if 0static int string_empty (string *);#endifstatic void string_append (string *, const char *);static void string_appends (string *, string *);static void string_appendn (string *, const char *, int);static void string_prepend (string *, const char *);static void string_prependn (string *, const char *, int);static void string_append_template_idx (string *, int);static int get_count (const char **, int *);static int consume_count (const char **);static int consume_count_with_underscores (const char**);static int demangle_args (struct work_stuff *, const char **, string *);static int demangle_nested_args (struct work_stuff*, const char**, string*);static int do_type (struct work_stuff *, const char **, string *);static int do_arg (struct work_stuff *, const char **, string *);static intdemangle_function_name (struct work_stuff *, const char **, string *, const char *);static intiterate_demangle_function (struct work_stuff *, const char **, string *, const char *);static void remember_type (struct work_stuff *, const char *, int);static void remember_Btype (struct work_stuff *, const char *, int, int);static int register_Btype (struct work_stuff *);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -