[PATCH] readelf: display non-printing characters in symbol names

Nick Clifton nickc@redhat.com
Thu May 1 14:34:00 GMT 2008


Hi Guys,

  I am going to apply the patch below so improve readelf so that it
  can display symbol names which contain non-printing characters.  (I
  ran across this problem whilst investigating an issue with local
  labels created by GAS).

Cheers
  Nick

binutils/ChangeLog
2008-05-01  Nick Clifton  <nickc@redhat.com>

	* readelf.c (print_symbol): Add code to display non-printing
	characters.

Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.408
diff -c -3 -p -r1.408 readelf.c
*** binutils/readelf.c	30 Apr 2008 02:09:48 -0000	1.408
--- binutils/readelf.c	1 May 2008 14:01:19 -0000
*************** print_vma (bfd_vma vma, print_mode mode)
*** 542,562 ****
    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.  */
  
  static void
  print_symbol (int width, const char *symbol)
  {
    if (do_wide)
!     printf ("%s", symbol);
    else if (width < 0)
!     printf ("%-*.*s", width, width, symbol);
    else
!     printf ("%-.*s", width, symbol);
  }
  
  static void
--- 542,628 ----
    return 0;
  }
  
! /* 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)
!     {
!       format_string = "%.*s";
!       /* Set the width to a very large value.  This simplifies the code below.  */
!       width = INT_MAX;
!     }
    else if (width < 0)
!     {
!       format_string = "%-*.*2s";
!       /* Keep the width positive.  This also helps.  */
!       width = - width;
!     }
    else
!     {
!       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



More information about the Binutils mailing list