From: Alan Modra Date: Thu, 11 Nov 2021 09:51:32 +0000 (+1030) Subject: Fix demangle style usage info X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0d64622696e02ad649d048f4af3a3f293481f89f;p=binutils-gdb.git Fix demangle style usage info Extract allowed styles from libiberty, so we don't have to worry about our help messages getting out of date. The function probably belongs in libiberty/cplus-dem.c but it can be here for a while to iron out bugs. PR 28581 * demanguse.c: New file. * demanguse.h: New file. * nm.c (usage): Break up output. Use display_demangler_styles. * objdump.c (usage): Use display_demangler_styles. * readelf.c (usage): Likewise. * Makefile.am: Add demanguse.c and demanguse.h. * Makefile.in: Regenerate. * po/POTFILESin: Regenerate. --- diff --git a/binutils/Makefile.am b/binutils/Makefile.am index 00416cb635e..7f4c24c213b 100644 --- a/binutils/Makefile.am +++ b/binutils/Makefile.am @@ -122,7 +122,7 @@ AM_CPPFLAGS = -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) \ HFILES = \ arsup.h binemul.h bucomm.h budbg.h \ - coffgrok.h debug.h dlltool.h dwarf.h elfcomm.h \ + coffgrok.h debug.h demanguse.h dlltool.h dwarf.h elfcomm.h \ objdump.h sysdep.h unwind-ia64.h windres.h winduni.h windint.h \ windmc.h @@ -132,7 +132,7 @@ BUILT_SOURCES = $(GENERATED_HFILES) CFILES = \ addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \ coffdump.c coffgrok.c cxxfilt.c \ - dwarf.c debug.c dlltool.c dllwrap.c \ + dwarf.c debug.c demanguse.c dlltool.c dllwrap.c \ elfcomm.c emul_aix.c emul_vanilla.c filemode.c \ is-ranlib.c is-strip.c maybe-ranlib.c maybe-strip.c \ nm.c not-ranlib.c not-strip.c \ @@ -252,7 +252,7 @@ objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) strings_SOURCES = strings.c $(BULIBS) -readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c $(ELFLIBS) +readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c demanguse.c $(ELFLIBS) readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(DEBUGINFOD_LIBS) elfedit_SOURCES = elfedit.c version.c $(ELFLIBS) @@ -260,9 +260,9 @@ elfedit_LDADD = $(LIBINTL) $(LIBIBERTY) strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) -nm_new_SOURCES = nm.c $(BULIBS) +nm_new_SOURCES = nm.c demanguse.c $(BULIBS) -objdump_SOURCES = objdump.c dwarf.c prdbg.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS) +objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS) EXTRA_objdump_SOURCES = od-xcoff.c objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) diff --git a/binutils/Makefile.in b/binutils/Makefile.in index bed8fef64d8..5252ef18b5c 100644 --- a/binutils/Makefile.in +++ b/binutils/Makefile.in @@ -212,7 +212,7 @@ am__objects_2 = elfcomm.$(OBJEXT) am_elfedit_OBJECTS = elfedit.$(OBJEXT) version.$(OBJEXT) \ $(am__objects_2) elfedit_OBJECTS = $(am_elfedit_OBJECTS) -am_nm_new_OBJECTS = nm.$(OBJEXT) $(am__objects_1) +am_nm_new_OBJECTS = nm.$(OBJEXT) demanguse.$(OBJEXT) $(am__objects_1) nm_new_OBJECTS = $(am_nm_new_OBJECTS) nm_new_LDADD = $(LDADD) am__objects_3 = rddbg.$(OBJEXT) debug.$(OBJEXT) stabs.$(OBJEXT) \ @@ -223,7 +223,8 @@ am_objcopy_OBJECTS = objcopy.$(OBJEXT) not-strip.$(OBJEXT) \ objcopy_OBJECTS = $(am_objcopy_OBJECTS) objcopy_LDADD = $(LDADD) am_objdump_OBJECTS = objdump.$(OBJEXT) dwarf.$(OBJEXT) prdbg.$(OBJEXT) \ - $(am__objects_3) $(am__objects_1) $(am__objects_2) + demanguse.$(OBJEXT) $(am__objects_3) $(am__objects_1) \ + $(am__objects_2) objdump_OBJECTS = $(am_objdump_OBJECTS) @ENABLE_LIBCTF_TRUE@am__DEPENDENCIES_2 = ../libctf/libctf.la am_ranlib_OBJECTS = ar.$(OBJEXT) is-ranlib.$(OBJEXT) arparse.$(OBJEXT) \ @@ -231,7 +232,8 @@ am_ranlib_OBJECTS = ar.$(OBJEXT) is-ranlib.$(OBJEXT) arparse.$(OBJEXT) \ binemul.$(OBJEXT) emul_$(EMULATION).$(OBJEXT) $(am__objects_1) ranlib_OBJECTS = $(am_ranlib_OBJECTS) am_readelf_OBJECTS = readelf.$(OBJEXT) version.$(OBJEXT) \ - unwind-ia64.$(OBJEXT) dwarf.$(OBJEXT) $(am__objects_2) + unwind-ia64.$(OBJEXT) dwarf.$(OBJEXT) demanguse.$(OBJEXT) \ + $(am__objects_2) readelf_OBJECTS = $(am_readelf_OBJECTS) @ENABLE_LIBCTF_TRUE@am__DEPENDENCIES_3 = ../libctf/libctf-nobfd.la am_size_OBJECTS = size.$(OBJEXT) $(am__objects_1) @@ -632,7 +634,7 @@ AM_CPPFLAGS = -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) \ HFILES = \ arsup.h binemul.h bucomm.h budbg.h \ - coffgrok.h debug.h dlltool.h dwarf.h elfcomm.h \ + coffgrok.h debug.h demanguse.h dlltool.h dwarf.h elfcomm.h \ objdump.h sysdep.h unwind-ia64.h windres.h winduni.h windint.h \ windmc.h @@ -641,7 +643,7 @@ BUILT_SOURCES = $(GENERATED_HFILES) CFILES = \ addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \ coffdump.c coffgrok.c cxxfilt.c \ - dwarf.c debug.c dlltool.c dllwrap.c \ + dwarf.c debug.c demanguse.c dlltool.c dllwrap.c \ elfcomm.c emul_aix.c emul_vanilla.c filemode.c \ is-ranlib.c is-strip.c maybe-ranlib.c maybe-strip.c \ nm.c not-ranlib.c not-strip.c \ @@ -720,13 +722,13 @@ LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL) size_SOURCES = size.c $(BULIBS) objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) strings_SOURCES = strings.c $(BULIBS) -readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c $(ELFLIBS) +readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c demanguse.c $(ELFLIBS) readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(DEBUGINFOD_LIBS) elfedit_SOURCES = elfedit.c version.c $(ELFLIBS) elfedit_LDADD = $(LIBINTL) $(LIBIBERTY) strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) -nm_new_SOURCES = nm.c $(BULIBS) -objdump_SOURCES = objdump.c dwarf.c prdbg.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS) +nm_new_SOURCES = nm.c demanguse.c $(BULIBS) +objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS) EXTRA_objdump_SOURCES = od-xcoff.c objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) cxxfilt_SOURCES = cxxfilt.c $(BULIBS) @@ -1049,6 +1051,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/debug.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/deflex.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/defparse.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/demanguse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dlltool.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dllwrap.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dwarf.Po@am__quote@ diff --git a/binutils/demanguse.c b/binutils/demanguse.c new file mode 100644 index 00000000000..578a3ef56fe --- /dev/null +++ b/binutils/demanguse.c @@ -0,0 +1,54 @@ +/* demanguse.c -- libiberty demangler usage + Copyright (C) 2021 Free Software Foundation, Inc. + + This file is part of GNU Binutils. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. */ + +#include +#include +#include "demangle.h" +#include "demanguse.h" + +/* Print the list of demangling styles to STREAM. A one line MSG is + printed before the styles. Output is limited to 80 columns, with + continuation lines being indented by leading spaces in MSG. */ + +void +display_demangler_styles (FILE *stream, const char *msg) +{ + const struct demangler_engine *info = libiberty_demanglers; + int col; + int lead_spaces = 0; + const char *cont = ""; + + while (msg[lead_spaces] == ' ') + ++lead_spaces; + col = fprintf (stream, "%s", msg); + while (info->demangling_style_name) + { + if (col + strlen (info->demangling_style_name) >= 75) + { + fprintf (stream, "%.1s\n", cont); + col = fprintf (stream, "%.*s", lead_spaces, msg); + cont = ""; + } + col += fprintf (stream, "%s\"%s\"", cont, info->demangling_style_name); + cont = ", "; + ++info; + } + fprintf (stream, "\n"); +} diff --git a/binutils/demanguse.h b/binutils/demanguse.h new file mode 100644 index 00000000000..965f116682d --- /dev/null +++ b/binutils/demanguse.h @@ -0,0 +1,34 @@ +/* demanguse.h -- libiberty demangler usage + Copyright (C) 2021 Free Software Foundation, Inc. + + This file is part of GNU Binutils. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. */ + +#ifndef DEMANGUSE_H +#define DEMANGUSE_H + +#ifdef __cplusplus +extern "C" { +#endif + +void display_demangler_styles (FILE *, const char *); + +#ifdef __cplusplus +} +#endif + +#endif /* DEMANGUSE_H */ diff --git a/binutils/nm.c b/binutils/nm.c index e7ed6f829af..7adeaa1e904 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -36,6 +36,7 @@ #include "coff/internal.h" #include "libcoff.h" #include "bucomm.h" +#include "demanguse.h" #include "plugin-api.h" #include "plugin.h" #include "safe-ctype.h" @@ -291,54 +292,88 @@ usage (FILE *stream, int status) { fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name); fprintf (stream, _(" List symbols in [file(s)] (a.out by default).\n")); - fprintf (stream, _(" The options are:\n\ - -a, --debug-syms Display debugger-only symbols\n\ - -A, --print-file-name Print name of the input file before every symbol\n\ - -B Same as --format=bsd\n\ - -C, --demangle[=STYLE] Decode low-level symbol names into user-level names\n\ - The STYLE, if specified, can be `auto' (the default),\n\ - `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ - or `gnat'\n\ - --no-demangle Do not demangle low-level symbol names\n\ - --recurse-limit Enable a demangling recursion limit. This is the default.\n\ - --no-recurse-limit Disable a demangling recursion limit.\n\ - -D, --dynamic Display dynamic symbols instead of normal symbols\n\ - --defined-only Display only defined symbols\n\ - -e (ignored)\n\ + fprintf (stream, _(" The options are:\n")); + fprintf (stream, _("\ + -a, --debug-syms Display debugger-only symbols\n")); + fprintf (stream, _("\ + -A, --print-file-name Print name of the input file before every symbol\n")); + fprintf (stream, _("\ + -B Same as --format=bsd\n")); + fprintf (stream, _("\ + -C, --demangle[=STYLE] Decode mangled/processed symbol names\n")); + display_demangler_styles (stream, _("\ + STYLE can be ")); + fprintf (stream, _("\ + --no-demangle Do not demangle low-level symbol names\n")); + fprintf (stream, _("\ + --recurse-limit Enable a demangling recursion limit. (default)\n")); + fprintf (stream, _("\ + --no-recurse-limit Disable a demangling recursion limit.\n")); + fprintf (stream, _("\ + -D, --dynamic Display dynamic symbols instead of normal symbols\n")); + fprintf (stream, _("\ + --defined-only Display only defined symbols\n")); + fprintf (stream, _("\ + -e (ignored)\n")); + fprintf (stream, _("\ -f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',\n\ - `sysv', `posix' or 'just-symbols'. The default is `bsd'\n\ - -g, --extern-only Display only external symbols\n\ - --ifunc-chars=CHARS Characters to use when displaying ifunc symbols\n\ - -j, --just-symbols Same as --format=just-symbols\n\ + `sysv', `posix' or 'just-symbols'.\n\ + The default is `bsd'\n")); + fprintf (stream, _("\ + -g, --extern-only Display only external symbols\n")); + fprintf (stream, _("\ + --ifunc-chars=CHARS Characters to use when displaying ifunc symbols\n")); + fprintf (stream, _("\ + -j, --just-symbols Same as --format=just-symbols\n")); + fprintf (stream, _("\ -l, --line-numbers Use debugging information to find a filename and\n\ - line number for each symbol\n\ - -n, --numeric-sort Sort symbols numerically by address\n\ - -o Same as -A\n\ - -p, --no-sort Do not sort the symbols\n\ - -P, --portability Same as --format=posix\n\ + line number for each symbol\n")); + fprintf (stream, _("\ + -n, --numeric-sort Sort symbols numerically by address\n")); + fprintf (stream, _("\ + -o Same as -A\n")); + fprintf (stream, _("\ + -p, --no-sort Do not sort the symbols\n")); + fprintf (stream, _("\ + -P, --portability Same as --format=posix\n")); + fprintf (stream, _("\ -r, --reverse-sort Reverse the sense of the sort\n")); #if BFD_SUPPORTS_PLUGINS fprintf (stream, _("\ --plugin NAME Load the specified plugin\n")); #endif fprintf (stream, _("\ - -S, --print-size Print size of defined symbols\n\ - -s, --print-armap Include index for symbols from archive members\n\ - --quiet Suppress \"no symbols\" diagnostic\n\ - --size-sort Sort symbols by size\n\ - --special-syms Include special symbols in the output\n\ - --synthetic Display synthetic symbols as well\n\ - -t, --radix=RADIX Use RADIX for printing symbol values\n\ - --target=BFDNAME Specify the target object format as BFDNAME\n\ - -u, --undefined-only Display only undefined symbols\n\ + -S, --print-size Print size of defined symbols\n")); + fprintf (stream, _("\ + -s, --print-armap Include index for symbols from archive members\n")); + fprintf (stream, _("\ + --quiet Suppress \"no symbols\" diagnostic\n")); + fprintf (stream, _("\ + --size-sort Sort symbols by size\n")); + fprintf (stream, _("\ + --special-syms Include special symbols in the output\n")); + fprintf (stream, _("\ + --synthetic Display synthetic symbols as well\n")); + fprintf (stream, _("\ + -t, --radix=RADIX Use RADIX for printing symbol values\n")); + fprintf (stream, _("\ + --target=BFDNAME Specify the target object format as BFDNAME\n")); + fprintf (stream, _("\ + -u, --undefined-only Display only undefined symbols\n")); + fprintf (stream, _("\ -U {d|s|i|x|e|h} Specify how to treat UTF-8 encoded unicode characters\n\ - --unicode={default|show|invalid|hex|escape|highlight}\n\ - --with-symbol-versions Display version strings after symbol names\n\ - -X 32_64 (ignored)\n\ - @FILE Read options from FILE\n\ - -h, --help Display this information\n\ - -V, --version Display this program's version number\n\ -\n")); + --unicode={default|show|invalid|hex|escape|highlight}\n")); + fprintf (stream, _("\ + --with-symbol-versions Display version strings after symbol names\n")); + fprintf (stream, _("\ + -X 32_64 (ignored)\n")); + fprintf (stream, _("\ + @FILE Read options from FILE\n")); + fprintf (stream, _("\ + -h, --help Display this information\n")); + fprintf (stream, _("\ + -V, --version Display this program's version number\n")); + list_supported_targets (program_name, stream); if (REPORT_BUGS_TO[0] && status == 0) fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO); diff --git a/binutils/objdump.c b/binutils/objdump.c index cf9cedc71ad..1811e70df93 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -55,6 +55,7 @@ #include "progress.h" #include "bucomm.h" #include "elfcomm.h" +#include "demanguse.h" #include "dwarf.h" #include "ctf-api.h" #include "getopt.h" @@ -330,10 +331,9 @@ usage (FILE *stream, int status) fprintf (stream, _("\ -F, --file-offsets Include file offsets when displaying information\n")); fprintf (stream, _("\ - -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\ - The STYLE, if specified, can be `auto', `gnu',\n\ - `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ - or `gnat'\n")); + -C, --demangle[=STYLE] Decode mangled/processed symbol names\n")); + display_demangler_styles (stream, _("\ + STYLE can be ")); fprintf (stream, _("\ --recurse-limit Enable a limit on recursion whilst demangling\n\ (default)\n")); diff --git a/binutils/po/POTFILES.in b/binutils/po/POTFILES.in index 9a1443fbf19..376f1340c3f 100644 --- a/binutils/po/POTFILES.in +++ b/binutils/po/POTFILES.in @@ -15,6 +15,8 @@ cxxfilt.c debug.c debug.c debug.h +demanguse.c +demanguse.h dlltool.c dlltool.h dllwrap.c diff --git a/binutils/readelf.c b/binutils/readelf.c index 5a87728d3e9..19c64918c06 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -57,6 +57,7 @@ #include "bfd.h" #include "bucomm.h" #include "elfcomm.h" +#include "demanguse.h" #include "dwarf.h" #include "ctf-api.h" #include "demangle.h" @@ -4944,10 +4945,9 @@ usage (FILE * stream) Force base for symbol sizes. The options are \n\ mixed (the default), octal, decimal, hexadecimal.\n")); fprintf (stream, _("\ - -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\ - The STYLE, if specified, can be `auto' (the default),\n\ - `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ - or `gnat'\n")); + -C --demangle[=STYLE] Decode mangled/processed symbol names\n")); + display_demangler_styles (stream, _("\ + STYLE can be ")); fprintf (stream, _("\ --no-demangle Do not demangle low-level symbol names. (default)\n")); fprintf (stream, _("\