From patchwork Wed Apr 10 02:49:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 32241 Received: (qmail 55042 invoked by alias); 10 Apr 2019 02:50:31 -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 54878 invoked by uid 89); 10 Apr 2019 02:50:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=Answer, apparent, 2596, printcmdc X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 10 Apr 2019 02:50:13 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2A7A41E0A9; Tue, 9 Apr 2019 22:49:51 -0400 (EDT) Subject: Re: [PATCH 1/3] Remove some uses of "object_files" To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20190409180945.21621-1-tom@tromey.com> <20190409180945.21621-2-tom@tromey.com> <386c2247-82ff-bb68-92b2-1680d2f0b997@simark.ca> <87k1g2eguv.fsf@tromey.com> From: Simon Marchi Message-ID: <79a6d30f-a4bd-349b-7adc-e001c655fb23@simark.ca> Date: Tue, 9 Apr 2019 22:49:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <87k1g2eguv.fsf@tromey.com> On 2019-04-09 10:25 p.m., Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi writes: > > Simon> LGTM. I would even suggest replacing the remaining few instances > Simon> of object_files with current_program_space->objfiles_head and > Simon> removing the macro completely. > > Yeah, I'll do it, though I think not as part of this patch. Some of the > remaining uses are in objfile destructor, and I was working toward > changing how objfiles are stored (using std::list rather than an > intrusive list) but I haven't finished those patches yet... Here is a patch that does it (goes on top of your patch), we can apply it if it doesn't conflict too much with your other work. From 5866bf2c26900ca78a06ec2bf3c758efc8cf4375 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 9 Apr 2019 21:45:49 -0400 Subject: [PATCH] Remove object_files macro This macro was provided as a compat layer when introducing multiprocess support in GDB, to avoid having to update all usages. There are very few of them left, so I suggest getting rid of it, replacing them with the definition of the macro (current_program_space->objfiles_head). It becomes more apparent that the caller code depends on the current_program_space, which I think is good. At the same time, I changed MULTI_OBJFILE_P to become a function instead of a macro. I noticed that object_files was also referenced in the list-objfiles function defined in gdb.gdb. The function also accesses fields in the objfile structure that no longer exist. I took the opportunity to update them at the same time, since it's a small obvious change. gdb/ChangeLog: * progspace.h (object_files): Remove. * objfiles.h (MULTI_OBJFILE_P): Change this macro... (multi_objfile_p): ... to become this function. * objfiles.c (objfile::objfile): Remove MULTI_OBJFILE_P usages. * maint.c (maintenance_translate_address): Use multi_objfile_p instead of MULTI_OBJFILE_P. * printcmd.c (info_symbol_command): Likewise. * gdb.gdb (list-objfiles): Don't use object_files, fix access to objfile fields. --- gdb/gdb.gdb | 4 ++-- gdb/maint.c | 2 +- gdb/objfiles.c | 12 +++++++----- gdb/objfiles.h | 14 ++++++++++---- gdb/printcmd.c | 2 +- gdb/progspace.h | 4 ---- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/gdb/gdb.gdb b/gdb/gdb.gdb index 437784102c1f..f107178c6353 100644 --- a/gdb/gdb.gdb +++ b/gdb/gdb.gdb @@ -2,11 +2,11 @@ # structures. define list-objfiles - set $obj = object_files + set $obj = current_program_space->objfiles_head printf "objfile bfd msyms name\n" while $obj != 0 printf "0x%-8x 0x%-8x %6d %s\n", $obj, $obj->obfd, \ - $obj->minimal_symbol_count, $obj->name + $obj->per_bfd->minimal_symbol_count, $obj->original_name set var $obj = $obj->next end end diff --git a/gdb/maint.c b/gdb/maint.c index 8fc660eb9394..c907dc806d45 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -483,7 +483,7 @@ maintenance_translate_address (const char *arg, int from_tty) gdb_assert (sect->objfile && objfile_name (sect->objfile)); obj_name = objfile_name (sect->objfile); - if (MULTI_OBJFILE_P ()) + if (multi_objfile_p ()) printf_filtered (_("%s + %s in section %s of %s\n"), symbol_name, symbol_offset, section_name, obj_name); diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 1c95e068842a..d90164433a07 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -393,13 +393,13 @@ objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_) /* Add this file onto the tail of the linked list of other such files. */ - if (object_files == NULL) - object_files = this; + if (current_program_space->objfiles_head == NULL) + current_program_space->objfiles_head = this; else { struct objfile *last_one; - for (last_one = object_files; + for (last_one = current_program_space->objfiles_head; last_one->next; last_one = last_one->next); last_one->next = this; @@ -496,7 +496,8 @@ put_objfile_before (struct objfile *objfile, struct objfile *before_this) unlink_objfile (objfile); - for (objp = &object_files; *objp != NULL; objp = &((*objp)->next)) + for (objp = ¤t_program_space->objfiles_head; *objp != NULL; + objp = &((*objp)->next)) { if (*objp == before_this) { @@ -528,7 +529,8 @@ unlink_objfile (struct objfile *objfile) { struct objfile **objpp; - for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next)) + for (objpp = ¤t_program_space->objfiles_head; + *objpp != NULL; objpp = &((*objpp)->next)) { if (*objpp == objfile) { diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 368d9f3abe25..8d26c039976b 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -398,8 +398,8 @@ struct objfile /* All struct objfile's are chained together by their next pointers. - The program space field "objfiles" (frequently referenced via - the macro "object_files") points to the first link in this chain. */ + The program space field "objfiles_head" points to the first link in this + chain. */ struct objfile *next = nullptr; @@ -679,9 +679,15 @@ extern void default_iterate_over_objfiles_in_search_order uninitialized section index. */ #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss -/* Answer whether there is more than one object file loaded. */ +/* Answer whether there is more than one object file loaded in the current + program space. */ -#define MULTI_OBJFILE_P() (object_files && object_files->next) +static inline +bool multi_objfile_p () +{ + return (current_program_space->objfiles_head != NULL + && current_program_space->objfiles_head->next != NULL); +} /* Reset the per-BFD storage area on OBJ. */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 9e84594fe687..46f0c3400ef7 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1319,7 +1319,7 @@ info_symbol_command (const char *arg, int from_tty) gdb_assert (osect->objfile && objfile_name (osect->objfile)); obj_name = objfile_name (osect->objfile); - if (MULTI_OBJFILE_P ()) + if (multi_objfile_p ()) if (pc_in_unmapped_range (addr, osect)) if (section_is_overlay (osect)) printf_filtered (_("%s in load address range of " diff --git a/gdb/progspace.h b/gdb/progspace.h index 039f55517305..e77e21fdda65 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -259,10 +259,6 @@ struct address_space #define symfile_objfile current_program_space->symfile_object_file -/* All known objfiles are kept in a linked list. This points to the - root of this list. */ -#define object_files current_program_space->objfiles_head - /* The set of target sections matching the sections mapped into the current program space. */ #define current_target_sections (¤t_program_space->target_sections)