From: Nick Clifton Date: Tue, 11 Oct 2005 16:33:16 +0000 (+0000) Subject: PR binutils/1437 X-Git-Tag: gdb-csl-arm-20051020-branchpoint~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec948987302c988cdde4811c4f04809c8fa0b7a5;p=external%2Fbinutils.git PR binutils/1437 * cxxfilt.c (flags): Remove DMGL_TYPES; (long_options): Rename --no-types to --types. (usage): Likewise. (demangle_it): Add a comment describing why _ and $ prefixes are skipped. Use printf rather than puts to emit the demangled output in order to avoid emitting a new line character. (main): Have the -t flag enable type demangling. Emit a newline after every demangled command line argument. Copy whitespace from stdin to stdout. * doc/binutils.texi (c++filt): Document the change to the -t switch. Document why demangling names on the command line is slightly different to demangling names read from the standard input. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 81b4267..aeaa659 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,20 @@ +2005-10-11 Nick Clifton + + PR binutils/1437 + * cxxfilt.c (flags): Remove DMGL_TYPES; + (long_options): Rename --no-types to --types. + (usage): Likewise. + (demangle_it): Add a comment describing why _ and $ prefixes are + skipped. Use printf rather than puts to emit the demangled output + in order to avoid emitting a new line character. + (main): Have the -t flag enable type demangling. + Emit a newline after every demangled command line argument. + Copy whitespace from stdin to stdout. + * doc/binutils.texi (c++filt): Document the change to the -t + switch. + Document why demangling names on the command line is slightly + different to demangling names read from the standard input. + 2005-10-10 Mark Mitchell * doc/Makefile.am (config.texi): Set top_srcdir. diff --git a/binutils/cxxfilt.c b/binutils/cxxfilt.c index bc69271..e1ce982 100644 --- a/binutils/cxxfilt.c +++ b/binutils/cxxfilt.c @@ -30,7 +30,7 @@ #include "getopt.h" #include "safe-ctype.h" -static int flags = DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE | DMGL_TYPES; +static int flags = DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE; static int strip_underscore = TARGET_PREPENDS_UNDERSCORE; static const struct option long_options[] = @@ -40,8 +40,8 @@ static const struct option long_options[] = {"help", no_argument, NULL, 'h'}, {"no-params", no_argument, NULL, 'p'}, {"no-strip-underscores", no_argument, NULL, 'n'}, - {"no-types", no_argument, NULL, 't'}, {"no-verbose", no_argument, NULL, 'i'}, + {"types", no_argument, NULL, 't'}, {"version", no_argument, NULL, 'v'}, {NULL, no_argument, NULL, 0} }; @@ -52,6 +52,9 @@ demangle_it (char *mangled_name) char *result; unsigned int skip_first = 0; + /* _ and $ are sometimes found at the start of function names + in assembler sources in order to distinguish them from other + names (eg register names). So skip them here. */ if (mangled_name[0] == '.' || mangled_name[0] == '$') ++skip_first; if (strip_underscore && mangled_name[skip_first] == '_') @@ -60,12 +63,12 @@ demangle_it (char *mangled_name) result = cplus_demangle (mangled_name + skip_first, flags); if (result == NULL) - puts (mangled_name); + printf (mangled_name); else { if (mangled_name[0] == '.') putchar ('.'); - puts (result); + printf (result); free (result); } } @@ -99,8 +102,8 @@ Options are:\n\ TARGET_PREPENDS_UNDERSCORE ? "" : " (default)"); fprintf (stream, "\ [-p|--no-params] Do not display function arguments\n\ - [-t|--no-types] Do not try to demangle type encodings\n\ [-i|--no-verbose] Do not show implementation details (if any)\n\ + [-t|--types] Also attempt to demangle type encodings\n\ [-s|--format "); print_demangler_list (stream); fprintf (stream, "]\n"); @@ -191,7 +194,7 @@ main (int argc, char **argv) flags &= ~ DMGL_PARAMS; break; case 't': - flags &= ~ DMGL_TYPES; + flags |= DMGL_TYPES; break; case 'i': flags &= ~ DMGL_VERBOSE; @@ -218,7 +221,10 @@ main (int argc, char **argv) if (optind < argc) { for ( ; optind < argc; optind++) - demangle_it (argv[optind]); + { + demangle_it (argv[optind]); + putchar ('\n'); + } return 0; } @@ -264,11 +270,16 @@ main (int argc, char **argv) { mbuffer[i] = 0; demangle_it (mbuffer); - fflush (stdout); } + if (c == EOF) break; + + /* Echo the whitespace characters so that the output looks + like the input, only with the mangled names demangled. */ + putchar (c); } + fflush (stdout); return 0; } diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index aa4406b..581e8b6 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -2399,7 +2399,7 @@ the Info entries for @file{binutils}. c++filt [@option{-_}|@option{--strip-underscores}] [@option{-n}|@option{--no-strip-underscores}] [@option{-p}|@option{--no-params}] - [@option{-t}|@option{--no-types}] + [@option{-t}|@option{--types}] [@option{-i}|@option{--no-verbose}] [@option{-s} @var{format}|@option{--format=}@var{format}] [@option{--help}] [@option{--version}] [@var{symbol}@dots{}] @@ -2409,31 +2409,67 @@ c++filt [@option{-_}|@option{--strip-underscores}] @c man begin DESCRIPTION cxxfilt @kindex cxxfilt -The C++ and Java languages provides function overloading, which means -that you can write many functions with the same name (providing each -takes parameters of different types). All C++ and Java function names -are encoded into a low-level assembly label (this process is known as -@dfn{mangling}). The @command{c++filt} -@footnote{MS-DOS does not allow @kbd{+} characters in file names, so on +The C++ and Java languages provide function overloading, which means +that you can write many functions with the same name, providing that +each function takes parameters of different types. In order to be +able to distinguish these similarly named functions C++ and Java +encode them into a low-level assembler name which uniquely identifies +each different version. This process is known as @dfn{mangling}. The +@command{c++filt} +@footnote{MS-DOS does not allow @kbd{+} characters in file names, so on MS-DOS this program is named @command{CXXFILT}.} program does the inverse mapping: it decodes (@dfn{demangles}) low-level -names into user-level names so that the linker can keep these overloaded -functions from clashing. +names into user-level names so that they can be read. Every alphanumeric word (consisting of letters, digits, underscores, dollars, or periods) seen in the input is a potential mangled name. If the name decodes into a C++ name, the C++ name replaces the -low-level name in the output. +low-level name in the output, otherwise the original word is output. +In this way you can pass an entire assembler source file, containing +mangled names, through @command{c++filt} and see the same source file +containing demangled names. -You can use @command{c++filt} to decipher individual symbols: +You can also use @command{c++filt} to decipher individual symbols by +passing them on the command line: @example c++filt @var{symbol} @end example If no @var{symbol} arguments are given, @command{c++filt} reads symbol -names from the standard input and writes the demangled names to the -standard output. All results are printed on the standard output. +names from the standard input instead. All the results are printed on +the standard output. The difference between reading names from the +command line versus reading names from the standard input is that +command line arguments are expected to be just mangled names and no +checking is performed to seperate them from surrounding text. Thus +for example: + +@smallexample +c++filt -n _Z1fv +@end smallexample + +will work and demangle the name to ``f()'' whereas: + +@smallexample +c++filt -n _Z1fv, +@end smallexample + +will not work. (Note the extra comma at the end of the mangled +name which makes it invalid). This command however will work: + +@smallexample +echo _Z1fv, | c++filt -n +@end smallexample + +and will display ``f(),'' ie the demangled name followed by a +trailing comma. This behaviour is because when the names are read +from the standard input it is expected that they might be part of an +assembler source file where there might be extra, extraneous +characters trailing after a mangled name. eg: + +@smallexample + .type _Z1fv, @@function +@end smallexample @c man end @@ -2462,9 +2498,12 @@ When demangling the name of a function, do not display the types of the function's parameters. @item -t -@itemx --no-types -Do not attempt to demangle types. This is enabled by default, but it -may not be desired if you are interested in mangled function names. +@itemx --types +Attempt to demangle types as well as function names. This is disabled +by default since mangled types are normally only used internally in +the compiler, and they can be confused with non-mangled names. eg +a function called ``a'' treated as a mangled type name would be +demangled to ``signed char''. @item -i @itemx --no-verbose diff --git a/binutils/objcopy.c b/binutils/objcopy.c index d46d093..de0746b 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -1349,6 +1349,13 @@ copy_object (bfd *ibfd, bfd *obfd) bfd_nonfatal (gnu_debuglink_filename); return FALSE; } + + if (bfd_get_flavour (obfd) == bfd_target_coff_flavour) + /* Try to set the VMA of the section to some non-zero value so + that it will work for PE format files. (We have no way to + distinguish between COFF and PE flavours). If this does not + work, just ignore the failure. */ + bfd_set_section_vma (obfd, gnu_debuglink_section, 0xf0000000); } if (bfd_count_sections (obfd) == 0)