This is the mail archive of the gdb-cvs@sourceware.org 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]

[binutils-gdb] [gdb] Make maint info sections print relocated addresses


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6eac171f0624303d944ff1a1ae4d0e3b0a63c800

commit 6eac171f0624303d944ff1a1ae4d0e3b0a63c800
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Aug 16 00:25:14 2019 +0200

    [gdb] Make maint info sections print relocated addresses
    
    When running gdb.base/compare-sections.exp with -fPIE/-pie, we get:
    ...
    print /u *(unsigned char *) 0x00000238^M
    Cannot access memory at address 0x238^M
    (gdb) FAIL: gdb.base/compare-sections.exp: read-only: get value of read-only section
    ...
    
    The problem is that that "maint info sections" prints an unrelocated address:
    ...
     [0]     0x00000238->0x00000254 at 0x00000238: .interp ALLOC LOAD READONLY \
                                                           DATA HAS_CONTENTS
    ...
    while the test expects a relocated address.
    
    Given that the documentation states that the command displays "the section
    information displayed by info files", and that info files shows relocated
    addresses:
    ...
            0x0000555555554238 - 0x0000555555554254 is .interp
    ...
    fix this by showing relocated addresses for maint info sections as
    well.
    
    Build and tested on x86_64-linux.
    
    gdb/ChangeLog:
    
    2019-08-16  Tom de Vries  <tdevries@suse.de>
    
    	* maint.c (maintenance_info_sections): Also handle !ALLOBJ case using
    	print_objfile_section_info.

Diff:
---
 gdb/ChangeLog |  5 +++++
 gdb/maint.c   | 39 +++++++++++++++++++++------------------
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8512e9e..151f78f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-08-16  Tom de Vries  <tdevries@suse.de>
+
+	* maint.c (maintenance_info_sections): Also handle !ALLOBJ case using
+	print_objfile_section_info.
+
 2019-08-15  Tom Tromey  <tom@tromey.com>
 
 	* tui/tui-io.c (tui_puts_internal): Check TUI_CMD_WIN before
diff --git a/gdb/maint.c b/gdb/maint.c
index f7485dc..837ed23 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -329,33 +329,36 @@ maintenance_info_sections (const char *arg, int from_tty)
 {
   if (exec_bfd)
     {
+      struct obj_section *osect;
+      bool allobj = false;
+
       printf_filtered (_("Exec file:\n"));
       printf_filtered ("    `%s', ", bfd_get_filename (exec_bfd));
       wrap_here ("        ");
       printf_filtered (_("file type %s.\n"), bfd_get_target (exec_bfd));
-      if (arg && *arg && match_substring (arg, "ALLOBJ"))
-	{
-	  struct obj_section *osect;
 
-	  /* Only this function cares about the 'ALLOBJ' argument; 
-	     if 'ALLOBJ' is the only argument, discard it rather than
-	     passing it down to print_objfile_section_info (which 
-	     wouldn't know how to handle it).  */
-	  if (strcmp (arg, "ALLOBJ") == 0)
-	    arg = NULL;
+      /* Only this function cares about the 'ALLOBJ' argument;
+	 if 'ALLOBJ' is the only argument, discard it rather than
+	 passing it down to print_objfile_section_info (which
+	 wouldn't know how to handle it).  */
+      if (arg && strcmp (arg, "ALLOBJ") == 0)
+	{
+	  arg = NULL;
+	  allobj = true;
+	}
 
-	  for (objfile *ofile : current_program_space->objfiles ())
+      for (objfile *ofile : current_program_space->objfiles ())
+	{
+	  if (allobj)
+	    printf_filtered (_("  Object file: %s\n"),
+			     bfd_get_filename (ofile->obfd));
+	  ALL_OBJFILE_OSECTIONS (ofile, osect)
 	    {
-	      printf_filtered (_("  Object file: %s\n"), 
-			       bfd_get_filename (ofile->obfd));
-	      ALL_OBJFILE_OSECTIONS (ofile, osect)
-		{
-		  print_objfile_section_info (ofile->obfd, osect, arg);
-		}
+	      if (!allobj && ofile->obfd != exec_bfd)
+		continue;
+	      print_objfile_section_info (ofile->obfd, osect, arg);
 	    }
 	}
-      else 
-	bfd_map_over_sections (exec_bfd, print_bfd_section_info, (void *) arg);
     }
 
   if (core_bfd)


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