From patchwork Wed Aug 14 15:15:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 34088 Received: (qmail 29019 invoked by alias); 14 Aug 2019 15:15:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 28882 invoked by uid 89); 14 Aug 2019 15:15:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=states X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Aug 2019 15:15:03 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C1D08AC47 for ; Wed, 14 Aug 2019 15:15:01 +0000 (UTC) Date: Wed, 14 Aug 2019 17:15:00 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb] Make maint info sections print relocated addresses Message-ID: <20190814151458.GA22847@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi, 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. OK for trunk? Thanks, - Tom [gdb] Make maint info sections print relocated addresses gdb/ChangeLog: 2019-08-14 Tom de Vries * maint.c (maintenance_info_sections): Also handle !ALLOBJ case using print_objfile_section_info. --- gdb/maint.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gdb/maint.c b/gdb/maint.c index f7485dc3ab..12262b14e5 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)