This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 1/3] Remove some uses of "object_files"
On 2019-04-09 10:25 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> 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 <simon.marchi@polymtl.ca>
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)
--
2.21.0