From: Nick Clifton Date: Thu, 1 May 2008 14:34:51 +0000 (+0000) Subject: * readelf.c (print_symbol): Add code to display non-printing characters. X-Git-Tag: msnyder-reverse-20080609-branchpoint~381 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=961c521ff952676089e85d64d712fcd3d192e4e0;p=platform%2Fupstream%2Fbinutils.git * readelf.c (print_symbol): Add code to display non-printing characters. --- 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 + + * readelf.c (print_symbol): Add code to display non-printing + characters. + 2008-04-30 John Heidemann * 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