This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [patch] readelf.c - dump .eh_frame sections


What about this?

Andrew.

2000-12-07  Andrew Haley  <aph@redhat.com>

	* readelf.c (display_debug_frames): Only display columns that are
	referenced by the frame debug info.

Index: readelf.c
===================================================================
RCS file: /cvs/cvsfiles/devo/binutils/readelf.c,v
retrieving revision 1.122.2.1.2.1
diff -p -2 -c -r1.122.2.1.2.1 readelf.c
*** readelf.c	2000/12/07 15:54:00	1.122.2.1.2.1
--- readelf.c	2000/12/07 20:11:36
*************** typedef struct Frame_Chunk
*** 6470,6475 ****
    unsigned char *chunk_start;
    int ncols;
!   /* DW_CFA_{undefined,same_value,offset,register} */
!   unsigned char *col_type;
    int *col_offset;
    char *augmentation;
--- 6470,6475 ----
    unsigned char *chunk_start;
    int ncols;
!   /* DW_CFA_{undefined,same_value,offset,register, unreferenced} */
!   short int *col_type;
    int *col_offset;
    char *augmentation;
*************** typedef struct Frame_Chunk
*** 6480,6483 ****
--- 6480,6487 ----
  Frame_Chunk;
  
+ /* A marker for a col_type that means this column was never referenced
+    in the frame info.  */
+ #define DW_CFA_unreferenced (-1)
+ 
  static void
  frame_need_space (Frame_Chunk *fc, int reg)
*************** frame_need_space (Frame_Chunk *fc, int r
*** 6487,6492 ****
      return;
    fc->ncols = reg + 1;
!   fc->col_type = (unsigned char *) xrealloc (fc->col_type,
! 					     fc->ncols * sizeof (unsigned char));
    fc->col_offset = (int *) xrealloc (fc->col_offset,
  				     fc->ncols * sizeof (int));
--- 6491,6496 ----
      return;
    fc->ncols = reg + 1;
!   fc->col_type = (short int *) xrealloc (fc->col_type,
! 					 fc->ncols * sizeof (short int));
    fc->col_offset = (int *) xrealloc (fc->col_offset,
  				     fc->ncols * sizeof (int));
*************** frame_need_space (Frame_Chunk *fc, int r
*** 6494,6498 ****
    while (prev < fc->ncols)
      {
!       fc->col_type[prev] = DW_CFA_undefined;
        fc->col_offset[prev] = 0;
        prev++;
--- 6498,6502 ----
    while (prev < fc->ncols)
      {
!       fc->col_type[prev] = DW_CFA_unreferenced;
        fc->col_offset[prev] = 0;
        prev++;
*************** frame_display_row (Frame_Chunk *fc, int 
*** 6512,6519 ****
        printf ("   LOC   CFA      ");
        for (r=0; r<*max_regs; r++)
! 	if (r == fc->ra)
! 	  printf ("ra   ");
! 	else
! 	  printf ("r%-4d", r);
        printf ("\n");
      }
--- 6516,6526 ----
        printf ("   LOC   CFA      ");
        for (r=0; r<*max_regs; r++)
! 	if (fc->col_type[r] != DW_CFA_unreferenced)
! 	  {
! 	    if (r == fc->ra)
! 	      printf ("ra   ");
! 	    else
! 	      printf ("r%-4d", r);
! 	  }
        printf ("\n");
      }
*************** frame_display_row (Frame_Chunk *fc, int 
*** 6522,6546 ****
    printf ("%-8s ", tmp);
    for (r=0; r<fc->ncols; r++)
!     {
!       switch (fc->col_type[r])
! 	{
! 	case DW_CFA_undefined:
! 	  strcpy (tmp, "u");
! 	  break;
! 	case DW_CFA_same_value:
! 	  strcpy (tmp, "u");
! 	  break;
! 	case DW_CFA_offset:
! 	  sprintf (tmp, "c%+d", fc->col_offset[r]);
! 	  break;
! 	case DW_CFA_register:
! 	  sprintf (tmp, "r%d", fc->col_offset[r]);
! 	  break;
! 	default:
! 	  strcpy (tmp, "n/a");
! 	  break;
! 	}
!       printf ("%-5s", tmp);
!     }
    printf ("\n");
  }
--- 6529,6554 ----
    printf ("%-8s ", tmp);
    for (r=0; r<fc->ncols; r++)
!     if (fc->col_type[r] != DW_CFA_unreferenced)
!       {
! 	switch (fc->col_type[r])
! 	  {
! 	  case DW_CFA_undefined:
! 	    strcpy (tmp, "u");
! 	    break;
! 	  case DW_CFA_same_value:
! 	    strcpy (tmp, "u");
! 	    break;
! 	  case DW_CFA_offset:
! 	    sprintf (tmp, "c%+d", fc->col_offset[r]);
! 	    break;
! 	  case DW_CFA_register:
! 	    sprintf (tmp, "r%d", fc->col_offset[r]);
! 	    break;
! 	  default:
! 	    strcpy (tmp, "n/a");
! 	    break;
! 	  }
! 	printf ("%-5s", tmp);
!       }
    printf ("\n");
  }
*************** display_debug_frames (section, start, fi
*** 6593,6597 ****
  	  fc->chunk_start = saved_start;
  	  fc->ncols = 0;
! 	  fc->col_type = (unsigned char *) xmalloc (sizeof (unsigned char));
  	  fc->col_offset = (int *) xmalloc (sizeof (int));
  	  frame_need_space (fc, max_regs-1);
--- 6601,6605 ----
  	  fc->chunk_start = saved_start;
  	  fc->ncols = 0;
! 	  fc->col_type = (short int *) xmalloc (sizeof (short int));
  	  fc->col_offset = (int *) xmalloc (sizeof (int));
  	  frame_need_space (fc, max_regs-1);
*************** display_debug_frames (section, start, fi
*** 6647,6651 ****
  	      start = block_end;
  	      fc->ncols = 0;
! 	      fc->col_type = (unsigned char *) xmalloc (sizeof (unsigned char));
  	      fc->col_offset = (int *) xmalloc (sizeof (int));
  	      frame_need_space (fc, max_regs-1);
--- 6655,6659 ----
  	      start = block_end;
  	      fc->ncols = 0;
! 	      fc->col_type = (short int *) xmalloc (sizeof (short int));
  	      fc->col_offset = (int *) xmalloc (sizeof (int));
  	      frame_need_space (fc, max_regs-1);
*************** display_debug_frames (section, start, fi
*** 6656,6662 ****
  	    {
  	      fc->ncols = cie->ncols;
! 	      fc->col_type = (unsigned char *) xmalloc (fc->ncols * sizeof (unsigned char));
  	      fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
! 	      memcpy (fc->col_type, cie->col_type, fc->ncols);
  	      memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
  	      fc->augmentation = cie->augmentation;
--- 6664,6670 ----
  	    {
  	      fc->ncols = cie->ncols;
! 	      fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
  	      fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
! 	      memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
  	      memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
  	      fc->augmentation = cie->augmentation;
*************** display_debug_frames (section, start, fi
*** 6686,6689 ****
--- 6694,6796 ----
  #define FDEBUG 0
  
+       {
+ 	/* Start by making a pass over the chunk, allocating storage
+            and taking note of what registers are used.  */
+ 
+ 	unsigned char *tmp = start;
+ 	while (start < block_end)
+ 	  {
+ 	    unsigned op, opa;
+ 	    unsigned long reg;
+ 	    bfd_vma vma;
+ 	    
+ 	    op = *start++;
+ 	    opa = op & 0x3f;
+ 	    if (op & 0xc0)
+ 	      op &= 0xc0;
+ 	    
+ 	    switch (op)
+ 	      {
+ 	      case DW_CFA_advance_loc:
+ 		break;
+ 	      case DW_CFA_offset:
+ 		LEB ();
+ 		frame_need_space (fc, opa);
+ 		fc->col_type[opa] = DW_CFA_undefined;
+ 		break;
+ 	      case DW_CFA_restore:
+ 		frame_need_space (fc, opa);
+ 		fc->col_type[opa] = DW_CFA_undefined;
+ 		break;
+ 	      case DW_CFA_set_loc:
+ 		start += sizeof (vma);
+ 		break;
+ 	      case DW_CFA_advance_loc1:
+ 		start += 1;
+ 		break;
+ 	      case DW_CFA_advance_loc2:
+ 		start += 2;
+ 		break;
+ 	      case DW_CFA_advance_loc4:
+ 		start += 4;
+ 		break;
+ 	      case DW_CFA_offset_extended:
+ 		reg = LEB (); LEB ();
+ 		frame_need_space (fc, reg);
+ 		fc->col_type[reg] = DW_CFA_undefined;
+ 		break;
+ 	      case DW_CFA_restore_extended:
+ 		reg = LEB ();
+ 		frame_need_space (fc, reg);
+ 		fc->col_type[reg] = DW_CFA_undefined;
+ 		break;
+ 	      case DW_CFA_undefined:
+ 		reg = LEB ();
+ 		frame_need_space (fc, reg);
+ 		fc->col_type[reg] = DW_CFA_undefined;
+ 		break;
+ 	      case DW_CFA_same_value:
+ 		reg = LEB ();
+ 		frame_need_space (fc, reg);
+ 		fc->col_type[reg] = DW_CFA_undefined;
+ 		break;
+ 	      case DW_CFA_register:
+ 		reg = LEB (); LEB ();
+ 		frame_need_space (fc, reg);
+ 		fc->col_type[reg] = DW_CFA_undefined;
+ 		break;
+ 	      case DW_CFA_def_cfa:
+ 		LEB (); LEB ();
+ 		break;
+ 	      case DW_CFA_def_cfa_register:
+ 		LEB ();
+ 		break;
+ 	      case DW_CFA_def_cfa_offset:
+ 		LEB ();
+ 		break;
+ #ifndef DW_CFA_GNU_args_size
+ #define DW_CFA_GNU_args_size 0x2e
+ #endif
+ 	      case DW_CFA_GNU_args_size:
+ 		LEB ();
+ 		break;		
+ #ifndef DW_CFA_GNU_negative_offset_extended
+ #define DW_CFA_GNU_negative_offset_extended 0x2f
+ #endif
+ 	      case DW_CFA_GNU_negative_offset_extended:
+ 		reg = LEB (); LEB ();      
+ 		frame_need_space (fc, reg);
+ 		fc->col_type[reg] = DW_CFA_undefined;
+ 		
+ 	      default:
+ 		break;
+ 	      }
+ 	  }
+ 	start = tmp;
+       }
+ 
+       /* Now we know what registers are used, make a second pass over
+          the chunk, this time actually printing out the info.  */
+ 
        while (start < block_end)
  	{
*************** display_debug_frames (section, start, fi
*** 6710,6714 ****
  
  	    case DW_CFA_offset:
- 	      frame_need_space (fc, opa);
  	      roffs = LEB ();
  #if FDEBUG
--- 6817,6820 ----
*************** display_debug_frames (section, start, fi
*** 6720,6724 ****
  
  	    case DW_CFA_restore:
- 	      frame_need_space (fc, opa);
  #if FDEBUG
  	      printf ("  DW_CFA_restore: r%d\n", opa);
--- 6826,6829 ----
*************** display_debug_frames (section, start, fi
*** 6770,6774 ****
  	      reg = LEB ();
  	      roffs = LEB ();
- 	      frame_need_space (fc, reg);
  #if FDEBUG
  	      printf ("  DW_CFA_offset_extended: r%d = cfa[%d*%d]\n", reg, roffs, fc->data_factor);
--- 6875,6878 ----
*************** display_debug_frames (section, start, fi
*** 6780,6784 ****
  	    case DW_CFA_restore_extended:
  	      reg = LEB ();
- 	      frame_need_space (fc, reg);
  #if FDEBUG
  	      printf ("  DW_CFA_restore_extended: r%d\n", reg);
--- 6884,6887 ----
*************** display_debug_frames (section, start, fi
*** 6790,6794 ****
  	    case DW_CFA_undefined:
  	      reg = LEB ();
- 	      frame_need_space (fc, reg);
  #if FDEBUG
  	      printf ("  DW_CFA_undefined: r%d\n", reg);
--- 6893,6896 ----
*************** display_debug_frames (section, start, fi
*** 6800,6804 ****
  	    case DW_CFA_same_value:
  	      reg = LEB ();
- 	      frame_need_space (fc, reg);
  #if FDEBUG
  	      printf ("  DW_CFA_same_value: r%d\n", reg);
--- 6902,6905 ----
*************** display_debug_frames (section, start, fi
*** 6811,6817 ****
  	      reg = LEB ();
  	      roffs = LEB ();
- 	      frame_need_space (fc, reg);
  #if FDEBUG
! 	      printf ("  DW_CFA_ame_value: r%d\n", reg);
  #endif
  	      fc->col_type[reg] = DW_CFA_register;
--- 6912,6917 ----
  	      reg = LEB ();
  	      roffs = LEB ();
  #if FDEBUG
! 	      printf ("  DW_CFA_register: r%d\n", reg);
  #endif
  	      fc->col_type[reg] = DW_CFA_register;
*************** display_debug_frames (section, start, fi
*** 6825,6829 ****
  	      rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
  	      rs->ncols = fc->ncols;
! 	      rs->col_type = (unsigned char *) xmalloc (rs->ncols);
  	      rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
  	      memcpy (rs->col_type, fc->col_type, rs->ncols);
--- 6925,6929 ----
  	      rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
  	      rs->ncols = fc->ncols;
! 	      rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
  	      rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
  	      memcpy (rs->col_type, fc->col_type, rs->ncols);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]