diff options
author | Nick Clifton <nickc@redhat.com> | 2008-05-01 14:34:51 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2008-05-01 14:34:51 +0000 |
commit | 961c521ff952676089e85d64d712fcd3d192e4e0 (patch) | |
tree | 1c5457bcee37e4fffa082ca2dc7b37f36a8b86fd /binutils | |
parent | cfc0146143bf79d840bbd26b3e94d8e4660dde6d (diff) | |
download | binutils-961c521ff952676089e85d64d712fcd3d192e4e0.zip binutils-961c521ff952676089e85d64d712fcd3d192e4e0.tar.gz binutils-961c521ff952676089e85d64d712fcd3d192e4e0.tar.bz2 |
* readelf.c (print_symbol): Add code to display non-printing characters.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/ChangeLog | 5 | ||||
-rw-r--r-- | binutils/readelf.c | 82 |
2 files changed, 79 insertions, 8 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 200acd6..a45b6e0 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,8 @@ +2008-05-01 Nick Clifton <nickc@redhat.com> + + * readelf.c (print_symbol): Add code to display non-printing + characters. + 2008-04-30 John Heidemann <johnh@isi.edu> * doc/binutils.texi (strings): Add "unicode" to the documentation diff --git a/binutils/readelf.c b/binutils/readelf.c index 4964fa8..3498b30 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -542,21 +542,87 @@ print_vma (bfd_vma vma, print_mode mode) return 0; } -/* Display a symbol on stdout. If do_wide is not true then - format the symbol to be at most WIDTH characters, - truncating as necessary. If WIDTH is negative then - format the string to be exactly - WIDTH characters, - truncating or padding as necessary. */ +/* Display a symbol on stdout. Handles the display of + non-printing characters. + If DO_WIDE is not true then format the symbol to be + at most WIDTH characters, truncating as necessary. + If WIDTH is negative then format the string to be + exactly - WIDTH characters, truncating or padding + as necessary. */ static void print_symbol (int width, const char *symbol) { + const char * format_string; + const char * c; + if (do_wide) - printf ("%s", symbol); + { + format_string = "%.*s"; + /* Set the width to a very large value. This simplifies the code below. */ + width = INT_MAX; + } else if (width < 0) - printf ("%-*.*s", width, width, symbol); + { + format_string = "%-*.*2s"; + /* Keep the width positive. This also helps. */ + width = - width; + } else - printf ("%-.*s", width, symbol); + { + format_string = "%-.*s"; + } + + while (width) + { + int len; + + c = symbol; + + /* Look for non-printing symbols inside the symbol's name. + This test is triggered in particular by the names generated + by the assembler for local labels. */ + while (ISPRINT (* c)) + c++; + + len = c - symbol; + + if (len) + { + if (len > width) + len = width; + + printf (format_string, len, symbol); + + width -= len; + } + + if (* c == 0 || width == 0) + break; + + /* Now display the non-printing character, if + there is room left in which to dipslay it. */ + if (*c < 32) + { + if (width < 2) + break; + + printf ("^%c", *c + 0x40); + + width -= 2; + } + else + { + if (width < 6) + break; + + printf ("<0x%.2x>", *c); + + width -= 6; + } + + symbol = c + 1; + } } static void |