This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Enhancement to "maint info sections" command



Allow the command "maint info sections" to take a list of arguments.
Arguments can be either section names or bfd section flags such as
LOAD, ALLOC, CODE, DATA etc.  All sections that match any argument
will be listed, eg.

	(gdb) maint info sect .bss .data .text

will list the three named sections, while

	(gdb) maint info sect LOAD ALLOC

will list all sections with either of the flag attributes
SEC_LOAD or SEC_ALLOC.

2001-12-20  Michael Snyder  <msnyder@redhat.com>

	* maint.c (maintenance_info_sections): Pass string argument to
	print_section_table, so that it can be used to select sections.
	(print_section_table): Change PTR to void *.  Look at string arg
	to select sections by name and by flag attributes.
	(match_bfd_flags): New function.
	(print_bfd_flags): New function.

Index: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.16
diff -p -r1.16 maint.c
*** maint.c	2001/09/25 02:31:50	1.16
--- maint.c	2001/12/20 20:58:31
*************** static void maintenance_space_display (c
*** 52,58 ****
  
  static void maintenance_info_command (char *, int);
  
! static void print_section_table (bfd *, asection *, PTR);
  
  static void maintenance_info_sections (char *, int);
  
--- 52,58 ----
  
  static void maintenance_info_command (char *, int);
  
! static void print_section_table (bfd *, asection *, void *);
  
  static void maintenance_info_sections (char *, int);
  
*************** maintenance_info_command (char *arg, int
*** 186,212 ****
    help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout);
  }
  
! static void
! print_section_table (bfd *abfd, asection *asect, PTR ignore)
  {
!   flagword flags;
! 
!   flags = bfd_get_section_flags (abfd, asect);
  
!   /* FIXME-32x64: Need print_address_numeric with field width.  */
!   printf_filtered ("    %s",
! 		   local_hex_string_custom
! 		   ((unsigned long) bfd_section_vma (abfd, asect), "08l"));
!   printf_filtered ("->%s",
! 		   local_hex_string_custom
! 		   ((unsigned long) (bfd_section_vma (abfd, asect)
! 				     + bfd_section_size (abfd, asect)),
! 		    "08l"));
!   printf_filtered (" at %s",
! 		   local_hex_string_custom
! 		   ((unsigned long) asect->filepos, "08l"));
!   printf_filtered (": %s", bfd_section_name (abfd, asect));
  
    if (flags & SEC_ALLOC)
      printf_filtered (" ALLOC");
    if (flags & SEC_LOAD)
--- 186,237 ----
    help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout);
  }
  
! static int 
! match_bfd_flags (char *string, flagword flags)
  {
!   if (flags & SEC_ALLOC)
!     if (strstr (string, "ALLOC"))
!       return 1;
!   if (flags & SEC_LOAD)
!     if (strstr (string, "LOAD"))
!       return 1;
!   if (flags & SEC_RELOC)
!     if (strstr (string, "RELOC"))
!       return 1;
!   if (flags & SEC_READONLY)
!     if (strstr (string, "READONLY"))
!       return 1;
!   if (flags & SEC_CODE)
!     if (strstr (string, "CODE"))
!       return 1;
!   if (flags & SEC_DATA)
!     if (strstr (string, "DATA"))
!       return 1;
!   if (flags & SEC_ROM)
!     if (strstr (string, "ROM"))
!       return 1;
!   if (flags & SEC_CONSTRUCTOR)
!     if (strstr (string, "CONSTRUCTOR"))
!       return 1;
!   if (flags & SEC_HAS_CONTENTS)
!     if (strstr (string, "HAS_CONTENTS"))
!       return 1;
!   if (flags & SEC_NEVER_LOAD)
!     if (strstr (string, "NEVER_LOAD"))
!       return 1;
!   if (flags & SEC_COFF_SHARED_LIBRARY)
!     if (strstr (string, "COFF_SHARED_LIBRARY"))
!       return 1;
!   if (flags & SEC_IS_COMMON)
!     if (strstr (string, "IS_COMMON"))
!       return 1;
  
!   return 0;
! }
  
+ static void
+ print_bfd_flags (flagword flags)
+ {
    if (flags & SEC_ALLOC)
      printf_filtered (" ALLOC");
    if (flags & SEC_LOAD)
*************** print_section_table (bfd *abfd, asection
*** 231,238 ****
      printf_filtered (" COFF_SHARED_LIBRARY");
    if (flags & SEC_IS_COMMON)
      printf_filtered (" IS_COMMON");
  
!   printf_filtered ("\n");
  }
  
  /* ARGSUSED */
--- 256,294 ----
      printf_filtered (" COFF_SHARED_LIBRARY");
    if (flags & SEC_IS_COMMON)
      printf_filtered (" IS_COMMON");
+ }
  
! static void
! print_section_table (bfd *abfd, asection *asect, void *arg)
! {
!   flagword flags;
!   char *string = arg;
! 
!   flags = bfd_get_section_flags (abfd, asect);
! 
!   if (string == NULL || *string == '\0' ||
!       strstr (string, bfd_get_section_name (abfd, asect)) ||
!       match_bfd_flags (string, flags))
!     {
!       /* FIXME-32x64: Need print_address_numeric with field width.  */
!       printf_filtered ("    %s",
! 		       local_hex_string_custom
! 		       ((unsigned long) bfd_section_vma (abfd, asect), 
! 			"08l"));
!       printf_filtered ("->%s",
! 		       local_hex_string_custom
! 		       ((unsigned long) (bfd_section_vma (abfd, asect)
! 					 + bfd_section_size (abfd, asect)),
! 			"08l"));
!       printf_filtered (" at %s",
! 		       local_hex_string_custom
! 		       ((unsigned long) asect->filepos, "08l"));
!       printf_filtered (": %s", bfd_section_name (abfd, asect));
! 
!       print_bfd_flags (flags);
! 
!       printf_filtered ("\n");
!     }
  }
  
  /* ARGSUSED */
*************** maintenance_info_sections (char *arg, in
*** 245,251 ****
        printf_filtered ("    `%s', ", bfd_get_filename (exec_bfd));
        wrap_here ("        ");
        printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
!       bfd_map_over_sections (exec_bfd, print_section_table, 0);
      }
  
    if (core_bfd)
--- 301,307 ----
        printf_filtered ("    `%s', ", bfd_get_filename (exec_bfd));
        wrap_here ("        ");
        printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
!       bfd_map_over_sections (exec_bfd, print_section_table, arg);
      }
  
    if (core_bfd)
*************** maintenance_info_sections (char *arg, in
*** 254,260 ****
        printf_filtered ("    `%s', ", bfd_get_filename (core_bfd));
        wrap_here ("        ");
        printf_filtered ("file type %s.\n", bfd_get_target (core_bfd));
!       bfd_map_over_sections (core_bfd, print_section_table, 0);
      }
  }
  
--- 310,316 ----
        printf_filtered ("    `%s', ", bfd_get_filename (core_bfd));
        wrap_here ("        ");
        printf_filtered ("file type %s.\n", bfd_get_target (core_bfd));
!       bfd_map_over_sections (core_bfd, print_section_table, arg);
      }
  }
  


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