* [PATCH v2 00/16] Remove some macros from exec.h and progspace.h
@ 2020-10-19 21:44 Tom Tromey
2020-10-19 21:44 ` [PATCH v2 01/16] Add target_section constructor Tom Tromey
` (16 more replies)
0 siblings, 17 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches
This is version 2 of the series to remove the remaining object-like
macros from exec.h and progspace.h.
Version 1 of the series is here
https://sourceware.org/pipermail/gdb-patches/2020-July/170704.html
This version corrects the review comments, and adds a few more patches
to do so. Now some "target section"-related functions are methods on
program_space, removing uses of current_program_space and making the
code simpler (IMO) to reason about
Regression tested on x86-64 Fedora 28.
Let me know what you think.
Tom
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 01/16] Add target_section constructor
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 02/16] Remove exec_filename macro Tom Tromey
` (15 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This adds a constructor to target_section, simplifying the code that
creates instances of this.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* target-section.h (struct target_section): Add constructor.
* exec.c (build_section_table, add_target_sections_of_objfile):
Update.
* corelow.c (core_target::build_file_mappings): Update.
---
gdb/ChangeLog | 7 +++++++
gdb/corelow.c | 7 +------
gdb/exec.c | 18 ++++++------------
gdb/target-section.h | 9 +++++++++
4 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/gdb/corelow.c b/gdb/corelow.c
index d557475e06f..d73cc5b4b14 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -266,12 +266,7 @@ core_target::build_file_mappings ()
bfd_set_section_alignment (sec, 2);
/* Set target_section fields. */
- m_core_file_mappings.emplace_back ();
- target_section &ts = m_core_file_mappings.back ();
- ts.addr = start;
- ts.endaddr = end;
- ts.owner = nullptr;
- ts.the_bfd_section = sec;
+ m_core_file_mappings.emplace_back (start, end, sec);
});
normalize_mem_ranges (&m_core_unavailable_mappings);
diff --git a/gdb/exec.c b/gdb/exec.c
index dd322129139..0646a4df89b 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -598,12 +598,9 @@ build_section_table (struct bfd *some_bfd)
if (!(aflag & SEC_ALLOC))
continue;
- table.emplace_back ();
- target_section § = table.back ();
- sect.owner = NULL;
- sect.the_bfd_section = asect;
- sect.addr = bfd_section_vma (asect);
- sect.endaddr = sect.addr + bfd_section_size (asect);
+ table.emplace_back (bfd_section_vma (asect),
+ bfd_section_vma (asect) + bfd_section_size (asect),
+ asect);
}
return table;
@@ -662,12 +659,9 @@ add_target_sections_of_objfile (struct objfile *objfile)
if (bfd_section_size (osect->the_bfd_section) == 0)
continue;
- table->emplace_back ();
- target_section &ts = table->back ();
- ts.addr = obj_section_addr (osect);
- ts.endaddr = obj_section_endaddr (osect);
- ts.the_bfd_section = osect->the_bfd_section;
- ts.owner = (void *) objfile;
+ table->emplace_back (obj_section_addr (osect),
+ obj_section_endaddr (osect),
+ osect->the_bfd_section, (void *) objfile);
}
}
diff --git a/gdb/target-section.h b/gdb/target-section.h
index ec6932da0a6..b19bcf9e997 100644
--- a/gdb/target-section.h
+++ b/gdb/target-section.h
@@ -26,6 +26,15 @@
struct target_section
{
+ target_section (CORE_ADDR addr_, CORE_ADDR end_, struct bfd_section *sect_,
+ void *owner_ = nullptr)
+ : addr (addr_),
+ endaddr (end_),
+ the_bfd_section (sect_),
+ owner (owner_)
+ {
+ }
+
/* Lowest address in section. */
CORE_ADDR addr;
/* Highest address in section, plus 1. */
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 02/16] Remove exec_filename macro
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
2020-10-19 21:44 ` [PATCH v2 01/16] Add target_section constructor Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 03/16] Change exec_close to be a method on program_space Tom Tromey
` (14 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes the exec_filename macro, replacing it with uses of the
member of current_program_space. This also renames that member, and
changes it to be a unique pointer.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* progspace.h (struct program_space) <exec_filename>: Rename from
pspace_exec_filename. Now a unique_xmalloc_ptr.
* inferior.c (print_selected_inferior): Update.
(print_inferior): Update.
* mi/mi-main.c (print_one_inferior): Update.
* exec.h (exec_filename): Remove macro.
* corefile.c (get_exec_file): Update.
* exec.c (exec_close): Update.
(exec_file_attach): Update.
* progspace.c (clone_program_space): Update.
(print_program_space): Update.
---
gdb/ChangeLog | 14 ++++++++++++++
gdb/corefile.c | 4 ++--
gdb/exec.c | 11 ++++++-----
gdb/exec.h | 1 -
gdb/inferior.c | 6 +++---
gdb/mi/mi-main.c | 4 ++--
gdb/progspace.c | 8 ++++----
gdb/progspace.h | 6 +++---
8 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/gdb/corefile.c b/gdb/corefile.c
index fed0e4fe8ad..c1eec199342 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -144,8 +144,8 @@ validate_files (void)
const char *
get_exec_file (int err)
{
- if (exec_filename)
- return exec_filename;
+ if (current_program_space->exec_filename != nullptr)
+ return current_program_space->exec_filename.get ();
if (!err)
return NULL;
diff --git a/gdb/exec.c b/gdb/exec.c
index 0646a4df89b..98b7fbbe5a4 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -167,8 +167,7 @@ exec_close (void)
remove_target_sections (&exec_bfd);
- xfree (exec_filename);
- exec_filename = NULL;
+ current_program_space->exec_filename.reset (nullptr);
}
}
@@ -486,11 +485,13 @@ exec_file_attach (const char *filename, int from_tty)
/* gdb_realpath_keepfile resolves symlinks on the local
filesystem and so cannot be used for "target:" files. */
- gdb_assert (exec_filename == NULL);
+ gdb_assert (current_program_space->exec_filename == nullptr);
if (load_via_target)
- exec_filename = xstrdup (bfd_get_filename (exec_bfd));
+ current_program_space->exec_filename
+ = make_unique_xstrdup (bfd_get_filename (exec_bfd));
else
- exec_filename = gdb_realpath_keepfile (scratch_pathname).release ();
+ current_program_space->exec_filename
+ = gdb_realpath_keepfile (scratch_pathname);
if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
{
diff --git a/gdb/exec.h b/gdb/exec.h
index 24489654ddc..b2f51509bcf 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -32,7 +32,6 @@ struct objfile;
#define exec_bfd current_program_space->ebfd
#define exec_bfd_mtime current_program_space->ebfd_mtime
-#define exec_filename current_program_space->pspace_exec_filename
/* Builds a section table, given args BFD. */
diff --git a/gdb/inferior.c b/gdb/inferior.c
index f775938721d..5c63dfa0bf1 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -415,7 +415,7 @@ void
print_selected_inferior (struct ui_out *uiout)
{
struct inferior *inf = current_inferior ();
- const char *filename = inf->pspace->pspace_exec_filename;
+ const char *filename = inf->pspace->exec_filename.get ();
if (filename == NULL)
filename = _("<noexec>");
@@ -518,8 +518,8 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
std::string conn = uiout_field_connection (inf->process_target ());
uiout->field_string ("connection-id", conn.c_str ());
- if (inf->pspace->pspace_exec_filename != NULL)
- uiout->field_string ("exec", inf->pspace->pspace_exec_filename);
+ if (inf->pspace->exec_filename != nullptr)
+ uiout->field_string ("exec", inf->pspace->exec_filename.get ());
else
uiout->field_skip ("exec");
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index c5c7be7246a..41bafd2f70d 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -649,10 +649,10 @@ print_one_inferior (struct inferior *inferior, bool recurse,
if (inferior->pid != 0)
uiout->field_signed ("pid", inferior->pid);
- if (inferior->pspace->pspace_exec_filename != NULL)
+ if (inferior->pspace->exec_filename != nullptr)
{
uiout->field_string ("executable",
- inferior->pspace->pspace_exec_filename);
+ inferior->pspace->exec_filename.get ());
}
if (inferior->pid != 0)
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 67ea8bdb9e9..76001234255 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -233,8 +233,8 @@ clone_program_space (struct program_space *dest, struct program_space *src)
set_current_program_space (dest);
- if (src->pspace_exec_filename != NULL)
- exec_file_attach (src->pspace_exec_filename, 0);
+ if (src->exec_filename != NULL)
+ exec_file_attach (src->exec_filename.get (), 0);
if (src->symfile_object_file != NULL)
symbol_file_add_main (objfile_name (src->symfile_object_file),
@@ -315,8 +315,8 @@ print_program_space (struct ui_out *uiout, int requested)
uiout->field_signed ("id", pspace->num);
- if (pspace->pspace_exec_filename)
- uiout->field_string ("exec", pspace->pspace_exec_filename);
+ if (pspace->exec_filename != nullptr)
+ uiout->field_string ("exec", pspace->exec_filename.get ());
else
uiout->field_skip ("exec");
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 6a0e9036399..3acce50b32f 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -284,9 +284,9 @@ struct program_space
/* The last-modified time, from when the exec was brought in. */
long ebfd_mtime = 0;
/* Similar to bfd_get_filename (exec_bfd) but in original form given
- by user, without symbolic links and pathname resolved.
- It needs to be freed by xfree. It is not NULL iff EBFD is not NULL. */
- char *pspace_exec_filename = NULL;
+ by user, without symbolic links and pathname resolved. It is not
+ NULL iff EBFD is not NULL. */
+ gdb::unique_xmalloc_ptr<char> exec_filename;
/* Binary file diddling handle for the core file. */
gdb_bfd_ref_ptr cbfd;
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 03/16] Change exec_close to be a method on program_space
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
2020-10-19 21:44 ` [PATCH v2 01/16] Add target_section constructor Tom Tromey
2020-10-19 21:44 ` [PATCH v2 02/16] Remove exec_filename macro Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 04/16] Remove commented-out code from gcore.c Tom Tromey
` (13 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
exec_close uses the current program space, so it seemed cleaner to
change it to be a method on program_space. This patch makes this
change.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::exec_close): New method, from
exec_close in exec.c.
* exec.c (exec_close): Move to progspace.c.
(exec_target::close, exec_file_attach): Update.
* progspace.h (struct program_space) <exec_close>: Declare
method.
---
gdb/ChangeLog | 9 +++++++++
gdb/exec.c | 29 +++--------------------------
gdb/exec.h | 2 --
gdb/progspace.c | 20 ++++++++++++++++++++
gdb/progspace.h | 3 +++
5 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index 98b7fbbe5a4..96164ddfd02 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -148,29 +148,6 @@ exec_target_open (const char *args, int from_tty)
exec_file_attach (args, from_tty);
}
-/* Close and clear exec_bfd. If we end up with no target sections to
- read memory from, this unpushes the exec_ops target. */
-
-void
-exec_close (void)
-{
- if (exec_bfd)
- {
- bfd *abfd = exec_bfd;
-
- gdb_bfd_unref (abfd);
-
- /* Removing target sections may close the exec_ops target.
- Clear exec_bfd before doing so to prevent recursion. */
- exec_bfd = NULL;
- exec_bfd_mtime = 0;
-
- remove_target_sections (&exec_bfd);
-
- current_program_space->exec_filename.reset (nullptr);
- }
-}
-
/* This is the target_close implementation. Clears all target
sections and closes all executable bfds from all program spaces. */
@@ -183,7 +160,7 @@ exec_target::close ()
{
set_current_program_space (ss);
current_target_sections->clear ();
- exec_close ();
+ ss->exec_close ();
}
}
@@ -396,7 +373,7 @@ exec_file_attach (const char *filename, int from_tty)
gdb_bfd_ref_ptr exec_bfd_holder = gdb_bfd_ref_ptr::new_reference (exec_bfd);
/* Remove any previous exec file. */
- exec_close ();
+ current_program_space->exec_close ();
/* Now open and digest the file the user requested, if any. */
@@ -497,7 +474,7 @@ exec_file_attach (const char *filename, int from_tty)
{
/* Make sure to close exec_bfd, or else "run" might try to use
it. */
- exec_close ();
+ current_program_space->exec_close ();
error (_("\"%ps\": not in executable format: %s"),
styled_string (file_name_style.style (), scratch_pathname),
gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
diff --git a/gdb/exec.h b/gdb/exec.h
index b2f51509bcf..f98dd83da21 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -117,8 +117,6 @@ extern void add_target_sections_of_objfile (struct objfile *objfile);
extern void print_section_info (target_section_table *table,
bfd *abfd);
-extern void exec_close (void);
-
/* Helper function that attempts to open the symbol file at EXEC_FILE_HOST.
If successful, it proceeds to add the symbol file as the main symbol file.
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 76001234255..8a15c402c28 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -223,6 +223,26 @@ program_space::solibs () const
return next_adapter<struct so_list> (this->so_list);
}
+/* See progspace.h. */
+
+void
+program_space::exec_close ()
+{
+ if (ebfd)
+ {
+ gdb_bfd_unref (ebfd);
+
+ /* Removing target sections may close the exec_ops target.
+ Clear exec_bfd before doing so to prevent recursion. */
+ ebfd = NULL;
+ ebfd_mtime = 0;
+
+ remove_target_sections (&ebfd);
+
+ exec_filename.reset (nullptr);
+ }
+}
+
/* Copies program space SRC to DEST. Copies the main executable file,
and the main symbol file. Returns DEST. */
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 3acce50b32f..6dcec9c96f7 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -272,6 +272,9 @@ struct program_space
for (so_list *so : pspace->solibs ()) { ... } */
next_adapter<struct so_list> solibs () const;
+ /* Close and clear exec_bfd. If we end up with no target sections
+ to read memory from, this unpushes the exec_ops target. */
+ void exec_close ();
/* Unique ID number. */
int num = 0;
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 04/16] Remove commented-out code from gcore.c
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (2 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 03/16] Change exec_close to be a method on program_space Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-20 14:01 ` [PP?] " Simon Marchi
2020-10-19 21:44 ` [PATCH v2 05/16] Remove exec_bfd_mtime define Tom Tromey
` (12 subsequent siblings)
16 siblings, 1 reply; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I found some code in gcore.c that has been commented out since
d3420b2fce5e (Mark Kettenis 2003-09-04 166) #if 1 /* See if this even matters... */
This patch deletes this code.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* gcore.c (default_gcore_mach): Remove commented-out code.
---
gdb/ChangeLog | 4 ++++
gdb/gcore.c | 12 ------------
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/gdb/gcore.c b/gdb/gcore.c
index db82eaac3dd..c1ea7a6c481 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -168,19 +168,7 @@ gcore_command (const char *args, int from_tty)
static unsigned long
default_gcore_mach (void)
{
-#if 1 /* See if this even matters... */
return 0;
-#else
-
- const struct bfd_arch_info *bfdarch = gdbarch_bfd_arch_info (target_gdbarch ());
-
- if (bfdarch != NULL)
- return bfdarch->mach;
- if (exec_bfd == NULL)
- error (_("Can't find default bfd machine type (need execfile)."));
-
- return bfd_get_mach (exec_bfd);
-#endif /* 1 */
}
static enum bfd_architecture
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 05/16] Remove exec_bfd_mtime define
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (3 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 04/16] Remove commented-out code from gcore.c Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 06/16] Remove current_target_sections macro Tom Tromey
` (11 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes the exec_bfd_mtime define, in favor of directly using the
appropriate member of the current program space.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* source-cache.c (source_cache::get_plain_source_lines): Use
current_program_space.
* corefile.c (reopen_exec_file): Use current_program_space.
* exec.c (exec_file_attach): Use current_program_space.
* exec.h (exec_bfd_mtime): Remove.
---
gdb/ChangeLog | 8 ++++++++
gdb/corefile.c | 4 +++-
gdb/exec.c | 2 +-
gdb/exec.h | 1 -
gdb/source-cache.c | 2 +-
5 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/gdb/corefile.c b/gdb/corefile.c
index c1eec199342..1586e9f175a 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -115,7 +115,9 @@ reopen_exec_file (void)
std::string filename = bfd_get_filename (exec_bfd);
res = stat (filename.c_str (), &st);
- if (res == 0 && exec_bfd_mtime && exec_bfd_mtime != st.st_mtime)
+ if (res == 0
+ && current_program_space->ebfd_mtime
+ && current_program_space->ebfd_mtime != st.st_mtime)
exec_file_attach (filename.c_str (), 0);
else
/* If we accessed the file since last opening it, close it now;
diff --git a/gdb/exec.c b/gdb/exec.c
index 96164ddfd02..22be006a9c0 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -482,7 +482,7 @@ exec_file_attach (const char *filename, int from_tty)
target_section_table sections = build_section_table (exec_bfd);
- exec_bfd_mtime = bfd_get_mtime (exec_bfd);
+ current_program_space->ebfd_mtime = bfd_get_mtime (exec_bfd);
validate_files ();
diff --git a/gdb/exec.h b/gdb/exec.h
index f98dd83da21..658112a0f28 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -31,7 +31,6 @@ struct bfd;
struct objfile;
#define exec_bfd current_program_space->ebfd
-#define exec_bfd_mtime current_program_space->ebfd_mtime
/* Builds a section table, given args BFD. */
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 9196e3a19e3..c67d087c76d 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -69,7 +69,7 @@ source_cache::get_plain_source_lines (struct symtab *s,
if (SYMTAB_OBJFILE (s) != NULL && SYMTAB_OBJFILE (s)->obfd != NULL)
mtime = SYMTAB_OBJFILE (s)->mtime;
else if (exec_bfd)
- mtime = exec_bfd_mtime;
+ mtime = current_program_space->ebfd_mtime;
if (mtime && mtime < st.st_mtime)
warning (_("Source file is more recent than executable."));
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 06/16] Remove current_target_sections macro
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (4 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 05/16] Remove exec_bfd_mtime define Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 07/16] Remove the exec_bfd macro Tom Tromey
` (10 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes the current_target_sections macro, replacing it with uses
of the appropriate member from current_program_space.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* progspace.h (current_target_sections): Remove macro.
* solib-svr4.c (scan_dyntag): Update.
* solib-dsbt.c (scan_dyntag): Update.
* exec.c (exec_target::close): Update.
(add_target_sections, add_target_sections_of_objfile)
(remove_target_sections, exec_target::get_section_table)
(exec_target::files_info, set_section_command)
(exec_set_section_address, exec_target::has_memory)
(exec_target::has_memory): Update.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/exec.c | 18 +++++++++---------
gdb/progspace.h | 4 ----
gdb/solib-dsbt.c | 2 +-
gdb/solib-svr4.c | 2 +-
5 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index 22be006a9c0..013fcfc1356 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -159,7 +159,7 @@ exec_target::close ()
for (struct program_space *ss : program_spaces)
{
set_current_program_space (ss);
- current_target_sections->clear ();
+ ss->target_sections.clear ();
ss->exec_close ();
}
}
@@ -591,7 +591,7 @@ void
add_target_sections (void *owner,
const target_section_table §ions)
{
- target_section_table *table = current_target_sections;
+ target_section_table *table = ¤t_program_space->target_sections;
if (!sections.empty ())
{
@@ -626,7 +626,7 @@ add_target_sections (void *owner,
void
add_target_sections_of_objfile (struct objfile *objfile)
{
- target_section_table *table = current_target_sections;
+ target_section_table *table = ¤t_program_space->target_sections;
struct obj_section *osect;
gdb_assert (objfile != nullptr);
@@ -649,7 +649,7 @@ add_target_sections_of_objfile (struct objfile *objfile)
void
remove_target_sections (void *owner)
{
- target_section_table *table = current_target_sections;
+ target_section_table *table = ¤t_program_space->target_sections;
gdb_assert (owner != NULL);
@@ -893,7 +893,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
target_section_table *
exec_target::get_section_table ()
{
- return current_target_sections;
+ return ¤t_program_space->target_sections;
}
enum target_xfer_status
@@ -991,7 +991,7 @@ void
exec_target::files_info ()
{
if (exec_bfd)
- print_section_info (current_target_sections, exec_bfd);
+ print_section_info (¤t_program_space->target_sections, exec_bfd);
else
puts_filtered (_("\t<no file loaded>\n"));
}
@@ -1015,7 +1015,7 @@ set_section_command (const char *args, int from_tty)
/* Parse out new virtual address. */
secaddr = parse_and_eval_address (args);
- for (target_section &p : *current_target_sections)
+ for (target_section &p : current_program_space->target_sections)
{
if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
&& bfd_section_name (p.the_bfd_section)[seclen] == '\0')
@@ -1041,7 +1041,7 @@ set_section_command (const char *args, int from_tty)
void
exec_set_section_address (const char *filename, int index, CORE_ADDR address)
{
- for (target_section &p : *current_target_sections)
+ for (target_section &p : current_program_space->target_sections)
{
if (filename_cmp (filename,
bfd_get_filename (p.the_bfd_section->owner)) == 0
@@ -1058,7 +1058,7 @@ exec_target::has_memory ()
{
/* We can provide memory if we have any file/target sections to read
from. */
- return !current_target_sections->empty ();
+ return !current_program_space->target_sections.empty ();
}
char *
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 6dcec9c96f7..03634034ba0 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -365,10 +365,6 @@ struct address_space
#define symfile_objfile current_program_space->symfile_object_file
-/* The set of target sections matching the sections mapped into the
- current program space. */
-#define current_target_sections (¤t_program_space->target_sections)
-
/* The list of all program spaces. There's always at least one. */
extern std::vector<struct program_space *>program_spaces;
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 57c7ab18430..6f610c511e0 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -424,7 +424,7 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
return 0;
bool found = false;
- for (target_section &target_section : *current_target_sections)
+ for (target_section &target_section : current_program_space->target_sections)
if (sect == target_section.the_bfd_section)
{
dyn_addr = target_section.addr;
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index a780f8d3467..faaba471a19 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -608,7 +608,7 @@ scan_dyntag (const int desired_dyntag, bfd *abfd, CORE_ADDR *ptr,
return 0;
bool found = false;
- for (target_section &target_section : *current_target_sections)
+ for (target_section &target_section : current_program_space->target_sections)
if (sect == target_section.the_bfd_section)
{
dyn_addr = target_section.addr;
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 07/16] Remove the exec_bfd macro
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (5 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 06/16] Remove current_target_sections macro Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-20 14:24 ` Simon Marchi
2020-10-19 21:44 ` [PATCH v2 08/16] Change program_space::ebfd to a gdb_bfd_ref_ptr Tom Tromey
` (9 subsequent siblings)
16 siblings, 1 reply; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes the exec_bfd macro, in favor of new accessors on
program_space. In one spot the accessor can't be used; but this is
still a big improvement over the macro, IMO.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* windows-tdep.c (windows_solib_create_inferior_hook): Update.
* symfile.c (reread_symbols): Update.
* symfile-mem.c (add_symbol_file_from_memory_command)
(add_vsyscall_page): Update.
* source-cache.c (source_cache::get_plain_source_lines): Update.
* solib-svr4.c (find_program_interpreter, elf_locate_base)
(svr4_current_sos_direct, svr4_exec_displacement)
(svr4_relocate_main_executable): Update.
(svr4_iterate_over_objfiles_in_search_order): Update.
* solib-frv.c (enable_break2, enable_break): Update.
* solib-dsbt.c (lm_base, enable_break): Update.
* solib-darwin.c (find_program_interpreter)
(darwin_solib_create_inferior_hook): Update.
* sol-thread.c (rw_common, ps_pdmodel): Update.
* rs6000-nat.c (rs6000_nat_target::create_inferior): Update.
* remote.c (compare_sections_command)
(remote_target::trace_set_readonly_regions): Update.
* remote-sim.c (get_sim_inferior_data)
(gdbsim_target::create_inferior, gdbsim_target::create_inferior): Update.
(gdbsim_target_open, gdbsim_target::files_info): Update.
* exec.h (exec_bfd): Remove macro.
* progspace.c (initialize_progspace): Update.
* proc-service.c (ps_addr_to_core_addr, core_addr_to_ps_addr):
Update.
* nto-procfs.c (nto_procfs_target::post_attach)
(nto_procfs_target::create_inferior): Update.
* maint.c (maintenance_info_sections): Update.
* linux-thread-db.c (thread_db_target::get_thread_local_address):
Update.
* infcmd.c (post_create_inferior): Update.
* gcore.c (default_gcore_arch, default_gcore_target): Update.
(objfile_find_memory_regions): Update.
* exec.c (validate_exec_file, exec_file_attach)
(exec_read_partial_read_only, print_section_info): Update.
* corelow.c (core_target_open): Update.
* corefile.c (reopen_exec_file, validate_files): Update.
* arm-tdep.c (gdb_print_insn_arm): Update.
* arch-utils.c (gdbarch_update_p, default_print_insn): Update.
* progspace.h (struct program_space) <exec_bfd, set_exec_bfd>: New
methods.
---
gdb/ChangeLog | 43 +++++++++++++++++++++++++++
gdb/arch-utils.c | 4 +--
gdb/arm-tdep.c | 4 +--
gdb/corefile.c | 10 +++----
gdb/corelow.c | 4 +--
gdb/exec.c | 38 +++++++++++++-----------
gdb/exec.h | 2 --
gdb/gcore.c | 12 ++++----
gdb/infcmd.c | 2 +-
gdb/linux-thread-db.c | 4 +--
gdb/maint.c | 8 ++---
gdb/nto-procfs.c | 4 +--
gdb/proc-service.c | 6 ++--
gdb/progspace.c | 6 ++--
gdb/progspace.h | 12 ++++++++
gdb/remote-sim.c | 17 ++++++-----
gdb/remote.c | 12 ++++----
gdb/rs6000-nat.c | 6 ++--
gdb/sol-thread.c | 6 ++--
gdb/solib-darwin.c | 10 +++----
gdb/solib-dsbt.c | 11 +++----
gdb/solib-frv.c | 10 ++++---
gdb/solib-svr4.c | 68 ++++++++++++++++++++++++++-----------------
gdb/source-cache.c | 2 +-
gdb/symfile-mem.c | 6 ++--
gdb/symfile.c | 4 +--
gdb/tracefile-tfile.c | 2 +-
gdb/windows-tdep.c | 3 +-
28 files changed, 198 insertions(+), 118 deletions(-)
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 12e3b8dbbb9..51cc068dac3 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -527,7 +527,7 @@ gdbarch_update_p (struct gdbarch_info info)
/* Check for the current file. */
if (info.abfd == NULL)
- info.abfd = exec_bfd;
+ info.abfd = current_program_space->exec_bfd ();
if (info.abfd == NULL)
info.abfd = core_bfd;
@@ -989,7 +989,7 @@ default_print_insn (bfd_vma memaddr, disassemble_info *info)
disassembler_ftype disassemble_fn;
disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
- info->mach, exec_bfd);
+ info->mach, current_program_space->exec_bfd ());
gdb_assert (disassemble_fn != NULL);
return (*disassemble_fn) (memaddr, info);
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index a214f22d7ad..2a8a0003d78 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -7756,9 +7756,9 @@ gdb_print_insn_arm (bfd_vma memaddr, disassemble_info *info)
/* GDB is able to get bfd_mach from the exe_bfd, info->mach is
accurate, so mark USER_SPECIFIED_MACHINE_TYPE bit. Otherwise,
opcodes/arm-dis.c:print_insn reset info->mach, and it will trigger
- the assert on the mismatch of info->mach and bfd_get_mach (exec_bfd)
+ the assert on the mismatch of info->mach and bfd_get_mach (current_program_space->exec_bfd ())
in default_print_insn. */
- if (exec_bfd != NULL)
+ if (current_program_space->exec_bfd () != NULL)
info->flags |= USER_SPECIFIED_MACHINE_TYPE;
return default_print_insn (memaddr, info);
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 1586e9f175a..09fec24c4cd 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -108,11 +108,11 @@ reopen_exec_file (void)
struct stat st;
/* Don't do anything if there isn't an exec file. */
- if (exec_bfd == NULL)
+ if (current_program_space->exec_bfd () == NULL)
return;
/* If the timestamp of the exec file has changed, reopen it. */
- std::string filename = bfd_get_filename (exec_bfd);
+ std::string filename = bfd_get_filename (current_program_space->exec_bfd ());
res = stat (filename.c_str (), &st);
if (res == 0
@@ -132,11 +132,11 @@ reopen_exec_file (void)
void
validate_files (void)
{
- if (exec_bfd && core_bfd)
+ if (current_program_space->exec_bfd () && core_bfd)
{
- if (!core_file_matches_executable_p (core_bfd, exec_bfd))
+ if (!core_file_matches_executable_p (core_bfd, current_program_space->exec_bfd ()))
warning (_("core file may not match specified executable file."));
- else if (bfd_get_mtime (exec_bfd) > bfd_get_mtime (core_bfd))
+ else if (bfd_get_mtime (current_program_space->exec_bfd ()) > bfd_get_mtime (core_bfd))
warning (_("exec file is newer than core file."));
}
}
diff --git a/gdb/corelow.c b/gdb/corelow.c
index d73cc5b4b14..d3e1a84342f 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -454,7 +454,7 @@ core_target_open (const char *arg, int from_tty)
core file. We don't do this unconditionally since an exec file
typically contains more information that helps us determine the
architecture than a core file. */
- if (!exec_bfd)
+ if (!current_program_space->exec_bfd ())
set_gdbarch_from_file (core_bfd);
push_target (std::move (target_holder));
@@ -495,7 +495,7 @@ core_target_open (const char *arg, int from_tty)
switch_to_thread (thread);
}
- if (exec_bfd == nullptr)
+ if (current_program_space->exec_bfd () == nullptr)
locate_exec_from_corefile_build_id (core_bfd, from_tty);
post_create_inferior (from_tty);
diff --git a/gdb/exec.c b/gdb/exec.c
index 013fcfc1356..85ad1aa49cb 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -240,7 +240,8 @@ validate_exec_file (int from_tty)
reopen_exec_file ();
current_exec_file = get_exec_file (0);
- const bfd_build_id *exec_file_build_id = build_id_bfd_get (exec_bfd);
+ const bfd_build_id *exec_file_build_id
+ = build_id_bfd_get (current_program_space->exec_bfd ());
if (exec_file_build_id != nullptr)
{
/* Prepend the target prefix, to force gdb_bfd_open to open the
@@ -367,10 +368,11 @@ exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
void
exec_file_attach (const char *filename, int from_tty)
{
- /* First, acquire a reference to the current exec_bfd. We release
+ /* First, acquire a reference to the exec_bfd. We release
this at the end of the function; but acquiring it now lets the
BFD cache return it if this call refers to the same file. */
- gdb_bfd_ref_ptr exec_bfd_holder = gdb_bfd_ref_ptr::new_reference (exec_bfd);
+ gdb_bfd_ref_ptr exec_bfd_holder
+ = gdb_bfd_ref_ptr::new_reference (current_program_space->exec_bfd ());
/* Remove any previous exec file. */
current_program_space->exec_close ();
@@ -451,9 +453,9 @@ exec_file_attach (const char *filename, int from_tty)
FOPEN_RUB, scratch_chan);
else
temp = gdb_bfd_open (canonical_pathname, gnutarget, scratch_chan);
- exec_bfd = temp.release ();
+ current_program_space->set_exec_bfd (temp.release ());
- if (!exec_bfd)
+ if (!current_program_space->exec_bfd ())
{
error (_("\"%ps\": could not open as an executable file: %s."),
styled_string (file_name_style.style (), scratch_pathname),
@@ -465,12 +467,12 @@ exec_file_attach (const char *filename, int from_tty)
gdb_assert (current_program_space->exec_filename == nullptr);
if (load_via_target)
current_program_space->exec_filename
- = make_unique_xstrdup (bfd_get_filename (exec_bfd));
+ = make_unique_xstrdup (bfd_get_filename (current_program_space->exec_bfd ()));
else
current_program_space->exec_filename
= gdb_realpath_keepfile (scratch_pathname);
- if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
+ if (!bfd_check_format_matches (current_program_space->exec_bfd (), bfd_object, &matching))
{
/* Make sure to close exec_bfd, or else "run" might try to use
it. */
@@ -480,18 +482,20 @@ exec_file_attach (const char *filename, int from_tty)
gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
}
- target_section_table sections = build_section_table (exec_bfd);
+ target_section_table sections
+ = build_section_table (current_program_space->exec_bfd ());
- current_program_space->ebfd_mtime = bfd_get_mtime (exec_bfd);
+ current_program_space->ebfd_mtime
+ = bfd_get_mtime (current_program_space->exec_bfd ());
validate_files ();
- set_gdbarch_from_file (exec_bfd);
+ set_gdbarch_from_file (current_program_space->exec_bfd ());
/* Add the executable's sections to the current address spaces'
list of sections. This possibly pushes the exec_ops
target. */
- add_target_sections (&exec_bfd, sections);
+ add_target_sections (¤t_program_space->ebfd, sections);
/* Tell display code (if any) about the changed file name. */
if (deprecated_exec_file_display_hook)
@@ -701,13 +705,13 @@ exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
/* It's unduly pedantic to refuse to look at the executable for
read-only pieces; so do the equivalent of readonly regions aka
QTro packet. */
- if (exec_bfd != NULL)
+ if (current_program_space->exec_bfd () != NULL)
{
asection *s;
bfd_size_type size;
bfd_vma vma;
- for (s = exec_bfd->sections; s; s = s->next)
+ for (s = current_program_space->exec_bfd ()->sections; s; s = s->next)
{
if ((s->flags & SEC_LOAD) == 0
|| (s->flags & SEC_READONLY) == 0)
@@ -723,7 +727,7 @@ exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
if (amt > len)
amt = len;
- amt = bfd_get_section_contents (exec_bfd, s,
+ amt = bfd_get_section_contents (current_program_space->exec_bfd (), s,
readbuf, offset - vma, amt);
if (amt == 0)
@@ -925,7 +929,7 @@ print_section_info (target_section_table *t, bfd *abfd)
bfd_get_filename (abfd)));
wrap_here (" ");
printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
- if (abfd == exec_bfd)
+ if (abfd == current_program_space->exec_bfd ())
{
/* gcc-3.4 does not like the initialization in
<p == t->sections_end>. */
@@ -990,8 +994,8 @@ print_section_info (target_section_table *t, bfd *abfd)
void
exec_target::files_info ()
{
- if (exec_bfd)
- print_section_info (¤t_program_space->target_sections, exec_bfd);
+ if (current_program_space->exec_bfd ())
+ print_section_info (¤t_program_space->target_sections, current_program_space->exec_bfd ());
else
puts_filtered (_("\t<no file loaded>\n"));
}
diff --git a/gdb/exec.h b/gdb/exec.h
index 658112a0f28..8590e78710a 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -30,8 +30,6 @@ struct target_ops;
struct bfd;
struct objfile;
-#define exec_bfd current_program_space->ebfd
-
/* Builds a section table, given args BFD. */
extern target_section_table build_section_table (struct bfd *);
diff --git a/gdb/gcore.c b/gdb/gcore.c
index c1ea7a6c481..7e5f17d3df4 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -178,10 +178,10 @@ default_gcore_arch (void)
if (bfdarch != NULL)
return bfdarch->arch;
- if (exec_bfd == NULL)
+ if (current_program_space->exec_bfd () == NULL)
error (_("Can't find bfd architecture for corefile (need execfile)."));
- return bfd_get_arch (exec_bfd);
+ return bfd_get_arch (current_program_space->exec_bfd ());
}
static const char *
@@ -191,12 +191,12 @@ default_gcore_target (void)
if (gdbarch_gcore_bfd_target_p (target_gdbarch ()))
return gdbarch_gcore_bfd_target (target_gdbarch ());
- /* Otherwise, try to fall back to the exec_bfd target. This will probably
+ /* Otherwise, try to fall back to the exec target. This will probably
not work for non-ELF targets. */
- if (exec_bfd == NULL)
+ if (current_program_space->exec_bfd () == NULL)
return NULL;
else
- return bfd_get_target (exec_bfd);
+ return bfd_get_target (current_program_space->exec_bfd ());
}
/* Derive a reasonable stack segment by unwinding the target stack,
@@ -507,7 +507,7 @@ objfile_find_memory_regions (struct target_ops *self,
obfd);
/* Make a heap segment. */
- if (derive_heap_segment (exec_bfd, &temp_bottom, &temp_top))
+ if (derive_heap_segment (current_program_space->exec_bfd (), &temp_bottom, &temp_top))
(*func) (temp_bottom, temp_top - temp_bottom,
1, /* Heap section will be readable. */
1, /* Heap section will be writable. */
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 498089fdb52..a2665e8fafb 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -308,7 +308,7 @@ post_create_inferior (int from_tty)
throw;
}
- if (exec_bfd)
+ if (current_program_space->exec_bfd ())
{
const unsigned solib_add_generation
= current_program_space->solib_add_generation;
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index c625cefead2..eb6588b7540 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1800,8 +1800,8 @@ thread_db_target::get_thread_local_address (ptid_t ptid,
/* Cast assuming host == target. Joy. */
/* Do proper sign extension for the target. */
- gdb_assert (exec_bfd);
- return (bfd_get_sign_extend_vma (exec_bfd) > 0
+ gdb_assert (current_program_space->exec_bfd ());
+ return (bfd_get_sign_extend_vma (current_program_space->exec_bfd ()) > 0
? (CORE_ADDR) (intptr_t) address
: (CORE_ADDR) (uintptr_t) address);
}
diff --git a/gdb/maint.c b/gdb/maint.c
index 46dd99f6ccf..aae6e79ae69 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -380,14 +380,14 @@ print_bfd_section_info_maybe_relocated (bfd *abfd, asection *asect,
static void
maintenance_info_sections (const char *arg, int from_tty)
{
- if (exec_bfd)
+ if (current_program_space->exec_bfd ())
{
bool allobj = false;
printf_filtered (_("Exec file:\n"));
- printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
+ printf_filtered (" `%s', ", bfd_get_filename (current_program_space->exec_bfd ()));
wrap_here (" ");
- printf_filtered (_("file type %s.\n"), bfd_get_target (exec_bfd));
+ printf_filtered (_("file type %s.\n"), bfd_get_target (current_program_space->exec_bfd ()));
/* Only this function cares about the 'ALLOBJ' argument;
if 'ALLOBJ' is the only argument, discard it rather than
@@ -404,7 +404,7 @@ maintenance_info_sections (const char *arg, int from_tty)
if (allobj)
printf_filtered (_(" Object file: %s\n"),
bfd_get_filename (ofile->obfd));
- else if (ofile->obfd != exec_bfd)
+ else if (ofile->obfd != current_program_space->exec_bfd ())
continue;
int section_count = gdb_bfd_count_sections (ofile->obfd);
diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c
index ef1615df3e2..5ecf9b52c34 100644
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -728,7 +728,7 @@ nto_procfs_target::attach (const char *args, int from_tty)
void
nto_procfs_target::post_attach (pid_t pid)
{
- if (exec_bfd)
+ if (current_program_space->exec_bfd ())
solib_create_inferior_hook (0);
}
@@ -1322,7 +1322,7 @@ nto_procfs_target::create_inferior (const char *exec_file,
push_target (ops);
target_terminal::init ();
- if (exec_bfd != NULL
+ if (current_program_space->exec_bfd () != NULL
|| (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
solib_create_inferior_hook (0);
}
diff --git a/gdb/proc-service.c b/gdb/proc-service.c
index e0383700a1d..2025f3a66c5 100644
--- a/gdb/proc-service.c
+++ b/gdb/proc-service.c
@@ -42,7 +42,8 @@
static CORE_ADDR
ps_addr_to_core_addr (psaddr_t addr)
{
- if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
+ if (current_program_space->exec_bfd ()
+ && bfd_get_sign_extend_vma (current_program_space->exec_bfd ()))
return (intptr_t) addr;
else
return (uintptr_t) addr;
@@ -53,7 +54,8 @@ ps_addr_to_core_addr (psaddr_t addr)
static psaddr_t
core_addr_to_ps_addr (CORE_ADDR addr)
{
- if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
+ if (current_program_space->exec_bfd ()
+ && bfd_get_sign_extend_vma (current_program_space->exec_bfd ()))
return (psaddr_t) (intptr_t) addr;
else
return (psaddr_t) (uintptr_t) addr;
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 8a15c402c28..57edc298da7 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -233,7 +233,7 @@ program_space::exec_close ()
gdb_bfd_unref (ebfd);
/* Removing target sections may close the exec_ops target.
- Clear exec_bfd before doing so to prevent recursion. */
+ Clear ebfd before doing so to prevent recursion. */
ebfd = NULL;
ebfd_mtime = 0;
@@ -471,7 +471,7 @@ initialize_progspace (void)
_initialize_foo routines may need to install their per-pspace
data keys. We can only allocate a progspace when all those
modules have done that. Do this before
- initialize_current_architecture, because that accesses exec_bfd,
- which in turn dereferences current_program_space. */
+ initialize_current_architecture, because that accesses the ebfd
+ of current_program_space. */
current_program_space = new program_space (new_address_space ());
}
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 03634034ba0..5e49083884a 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -276,6 +276,18 @@ struct program_space
to read memory from, this unpushes the exec_ops target. */
void exec_close ();
+ /* Return the exec BFD for this program space. */
+ bfd *exec_bfd () const
+ {
+ return ebfd;
+ }
+
+ /* Set the exec BFD for this program space to ABFD. */
+ void set_exec_bfd (bfd *abfd)
+ {
+ ebfd = abfd;
+ }
+
/* Unique ID number. */
int num = 0;
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 9e1c2b151c8..d0e19b0e061 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -211,7 +211,8 @@ get_sim_inferior_data (struct inferior *inf, int sim_instance_needed)
if (sim_instance_needed == SIM_INSTANCE_NEEDED
&& (sim_data == NULL || sim_data->gdbsim_desc == NULL))
{
- sim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
+ sim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback,
+ current_program_space->exec_bfd (), sim_argv);
if (sim_desc == NULL)
error (_("Unable to create simulator instance for inferior %d."),
inf->num);
@@ -620,7 +621,7 @@ gdbsim_target::create_inferior (const char *exec_file,
char *arg_buf;
const char *args = allargs.c_str ();
- if (exec_file == 0 || exec_bfd == 0)
+ if (exec_file == 0 || current_program_space->exec_bfd () == 0)
warning (_("No executable file specified."));
if (!sim_data->program_loaded)
warning (_("No program loaded."));
@@ -648,7 +649,8 @@ gdbsim_target::create_inferior (const char *exec_file,
built_argv.reset (arg_buf);
}
- if (sim_create_inferior (sim_data->gdbsim_desc, exec_bfd,
+ if (sim_create_inferior (sim_data->gdbsim_desc,
+ current_program_space->exec_bfd (),
built_argv.get (), env)
!= SIM_RC_OK)
error (_("Unable to create sim inferior."));
@@ -738,7 +740,8 @@ gdbsim_target_open (const char *args, int from_tty)
sim_argv = argv.release ();
init_callbacks ();
- gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
+ gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback,
+ current_program_space->exec_bfd (), sim_argv);
if (gdbsim_desc == 0)
{
@@ -1104,13 +1107,13 @@ gdbsim_target::files_info ()
= get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
const char *file = "nothing";
- if (exec_bfd)
- file = bfd_get_filename (exec_bfd);
+ if (current_program_space->exec_bfd ())
+ file = bfd_get_filename (current_program_space->exec_bfd ());
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "gdbsim_files_info: file \"%s\"\n", file);
- if (exec_bfd)
+ if (current_program_space->exec_bfd ())
{
fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
target_shortname, file);
diff --git a/gdb/remote.c b/gdb/remote.c
index 9ee1e8cbcf9..7eb8fcf5604 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -56,7 +56,7 @@
#include <signal.h>
#include "serial.h"
-#include "gdbcore.h" /* for exec_bfd */
+#include "gdbcore.h"
#include "remote-fileio.h"
#include "gdb/fileio.h"
@@ -10770,7 +10770,7 @@ compare_sections_command (const char *args, int from_tty)
int res;
int read_only = 0;
- if (!exec_bfd)
+ if (!current_program_space->exec_bfd ())
error (_("command cannot be used without an exec file"));
if (args != NULL && strcmp (args, "-r") == 0)
@@ -10779,7 +10779,7 @@ compare_sections_command (const char *args, int from_tty)
args = NULL;
}
- for (s = exec_bfd->sections; s; s = s->next)
+ for (s = current_program_space->exec_bfd ()->sections; s; s = s->next)
{
if (!(s->flags & SEC_LOAD))
continue; /* Skip non-loadable section. */
@@ -10799,7 +10799,7 @@ compare_sections_command (const char *args, int from_tty)
lma = s->lma;
gdb::byte_vector sectdata (size);
- bfd_get_section_contents (exec_bfd, s, sectdata.data (), 0, size);
+ bfd_get_section_contents (current_program_space->exec_bfd (), s, sectdata.data (), 0, size);
res = target_verify_memory (sectdata.data (), lma, size);
@@ -13180,14 +13180,14 @@ remote_target::trace_set_readonly_regions ()
int anysecs = 0;
int offset = 0;
- if (!exec_bfd)
+ if (!current_program_space->exec_bfd ())
return; /* No information to give. */
struct remote_state *rs = get_remote_state ();
strcpy (rs->buf.data (), "QTro");
offset = strlen (rs->buf.data ());
- for (s = exec_bfd->sections; s; s = s->next)
+ for (s = current_program_space->exec_bfd ()->sections; s; s = s->next)
{
char tmp1[40], tmp2[40];
int sec_length;
diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c
index c49e64b5a62..e366807485a 100644
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -581,11 +581,11 @@ rs6000_nat_target::create_inferior (const char *exec_file,
Blindly calling rs6000_gdbarch_init used to work in older versions of
GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
determine the wordsize. */
- if (exec_bfd)
+ if (current_program_space->exec_bfd ())
{
const struct bfd_arch_info *exec_bfd_arch_info;
- exec_bfd_arch_info = bfd_get_arch_info (exec_bfd);
+ exec_bfd_arch_info = bfd_get_arch_info (current_program_space->exec_bfd ());
if (arch == exec_bfd_arch_info->arch)
return;
}
@@ -594,7 +594,7 @@ rs6000_nat_target::create_inferior (const char *exec_file,
gdbarch_info_init (&info);
info.bfd_arch_info = bfd_get_arch_info (&abfd);
- info.abfd = exec_bfd;
+ info.abfd = current_program_space->exec_bfd ();
if (!gdbarch_update_p (info))
internal_error (__FILE__, __LINE__,
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index bb33a20ea52..69a3ac11394 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -794,7 +794,7 @@ rw_common (int dowrite, const struct ps_prochandle *ph, psaddr_t addr,
#if defined (__sparcv9)
/* For Sparc64 cross Sparc32, make sure the address has not been
accidentally sign-extended (or whatever) to beyond 32 bits. */
- if (bfd_get_arch_size (exec_bfd) == 32)
+ if (bfd_get_arch_size (current_program_space->exec_bfd ()) == 32)
addr &= 0xffffffff;
#endif
@@ -950,9 +950,9 @@ ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
ps_err_e
ps_pdmodel (struct ps_prochandle *ph, int *data_model)
{
- if (exec_bfd == 0)
+ if (current_program_space->exec_bfd () == 0)
*data_model = PR_MODEL_UNKNOWN;
- else if (bfd_get_arch_size (exec_bfd) == 32)
+ else if (bfd_get_arch_size (current_program_space->exec_bfd ()) == 32)
*data_model = PR_MODEL_ILP32;
else
*data_model = PR_MODEL_LP64;
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 3806c7e48cc..e55b2082949 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -192,12 +192,12 @@ find_program_interpreter (void)
{
char *buf = NULL;
- /* If we have an exec_bfd, get the interpreter from the load commands. */
- if (exec_bfd)
+ /* If we have an current_program_space->exec_bfd (), get the interpreter from the load commands. */
+ if (current_program_space->exec_bfd ())
{
bfd_mach_o_load_command *cmd;
- if (bfd_mach_o_lookup_command (exec_bfd,
+ if (bfd_mach_o_lookup_command (current_program_space->exec_bfd (),
BFD_MACH_O_LC_LOAD_DYLINKER, &cmd) == 1)
return cmd->command.dylinker.name_str;
}
@@ -543,7 +543,7 @@ darwin_solib_create_inferior_hook (int from_tty)
CORE_ADDR vmaddr;
/* Find the base address of the executable. */
- vmaddr = bfd_mach_o_get_base_address (exec_bfd);
+ vmaddr = bfd_mach_o_get_base_address (current_program_space->exec_bfd ());
/* Relocate. */
if (vmaddr != load_addr)
@@ -557,7 +557,7 @@ darwin_solib_create_inferior_hook (int from_tty)
{
/* Dyld hasn't yet relocated itself, so the notifier address may
be incorrect (as it has to be relocated). */
- CORE_ADDR start = bfd_get_start_address (exec_bfd);
+ CORE_ADDR start = bfd_get_start_address (current_program_space->exec_bfd ());
if (start == 0)
notifier = 0;
else
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 6f610c511e0..8e1da5dd73d 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -562,7 +562,7 @@ lm_base (void)
"lm_base: get addr %x by _GLOBAL_OFFSET_TABLE_.\n",
(unsigned int) addr);
}
- else if (scan_dyntag (DT_PLTGOT, exec_bfd, &addr))
+ else if (scan_dyntag (DT_PLTGOT, current_program_space->exec_bfd (), &addr))
{
struct int_elf32_dsbt_loadmap *ldm;
@@ -778,7 +778,7 @@ enable_break (void)
asection *interp_sect;
struct dsbt_info *info;
- if (exec_bfd == NULL)
+ if (current_program_space->exec_bfd () == NULL)
return 0;
if (!target_has_execution ())
@@ -793,7 +793,8 @@ enable_break (void)
/* Find the .interp section; if not found, warn the user and drop
into the old breakpoint at symbol code. */
- interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+ interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+ ".interp");
if (interp_sect)
{
unsigned int interp_sect_size;
@@ -806,8 +807,8 @@ enable_break (void)
the contents specify the dynamic linker this program uses. */
interp_sect_size = bfd_section_size (interp_sect);
buf = (char *) alloca (interp_sect_size);
- bfd_get_section_contents (exec_bfd, interp_sect,
- buf, 0, interp_sect_size);
+ bfd_get_section_contents (current_program_space->exec_bfd (),
+ interp_sect, buf, 0, interp_sect_size);
/* Now we need to figure out where the dynamic linker was
loaded so that we can load its symbols and place a breakpoint
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index bce33a3e4d6..08c9cf7ca5c 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -531,7 +531,8 @@ enable_break2 (void)
/* Find the .interp section; if not found, warn the user and drop
into the old breakpoint at symbol code. */
- interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+ interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+ ".interp");
if (interp_sect)
{
unsigned int interp_sect_size;
@@ -545,8 +546,8 @@ enable_break2 (void)
the contents specify the dynamic linker this program uses. */
interp_sect_size = bfd_section_size (interp_sect);
buf = (char *) alloca (interp_sect_size);
- bfd_get_section_contents (exec_bfd, interp_sect,
- buf, 0, interp_sect_size);
+ bfd_get_section_contents (current_program_space->exec_bfd (),
+ interp_sect, buf, 0, interp_sect_size);
/* Now we need to figure out where the dynamic linker was
loaded so that we can load its symbols and place a breakpoint
@@ -735,7 +736,8 @@ enable_break (void)
/* Check for the presence of a .interp section. If there is no
such section, the executable is statically linked. */
- interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+ interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+ ".interp");
if (interp_sect == NULL)
{
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index faaba471a19..ef1d78c1c83 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -554,20 +554,22 @@ read_program_header (int type, int *p_arch_size, CORE_ADDR *base_addr)
static gdb::optional<gdb::byte_vector>
find_program_interpreter (void)
{
- /* If we have an exec_bfd, use its section table. */
- if (exec_bfd
- && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
+ /* If we have an current_program_space->exec_bfd (), use its section table. */
+ if (current_program_space->exec_bfd ()
+ && (bfd_get_flavour (current_program_space->exec_bfd ())
+ == bfd_target_elf_flavour))
{
struct bfd_section *interp_sect;
- interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+ interp_sect = bfd_get_section_by_name (current_program_space->exec_bfd (),
+ ".interp");
if (interp_sect != NULL)
{
int sect_size = bfd_section_size (interp_sect);
gdb::byte_vector buf (sect_size);
- bfd_get_section_contents (exec_bfd, interp_sect, buf.data (), 0,
- sect_size);
+ bfd_get_section_contents (current_program_space->exec_bfd (),
+ interp_sect, buf.data (), 0, sect_size);
return buf;
}
}
@@ -762,7 +764,8 @@ elf_locate_base (void)
/* Look for DT_MIPS_RLD_MAP first. MIPS executables use this
instead of DT_DEBUG, although they sometimes contain an unused
DT_DEBUG. */
- if (scan_dyntag (DT_MIPS_RLD_MAP, exec_bfd, &dyn_ptr, NULL)
+ if (scan_dyntag (DT_MIPS_RLD_MAP, current_program_space->exec_bfd (),
+ &dyn_ptr, NULL)
|| scan_dyntag_auxv (DT_MIPS_RLD_MAP, &dyn_ptr, NULL))
{
struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
@@ -780,7 +783,8 @@ elf_locate_base (void)
/* Then check DT_MIPS_RLD_MAP_REL. MIPS executables now use this form
because of needing to support PIE. DT_MIPS_RLD_MAP will also exist
in non-PIE. */
- if (scan_dyntag (DT_MIPS_RLD_MAP_REL, exec_bfd, &dyn_ptr, &dyn_ptr_addr)
+ if (scan_dyntag (DT_MIPS_RLD_MAP_REL, current_program_space->exec_bfd (),
+ &dyn_ptr, &dyn_ptr_addr)
|| scan_dyntag_auxv (DT_MIPS_RLD_MAP_REL, &dyn_ptr, &dyn_ptr_addr))
{
struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
@@ -796,7 +800,7 @@ elf_locate_base (void)
}
/* Find DT_DEBUG. */
- if (scan_dyntag (DT_DEBUG, exec_bfd, &dyn_ptr, NULL)
+ if (scan_dyntag (DT_DEBUG, current_program_space->exec_bfd (), &dyn_ptr, NULL)
|| scan_dyntag_auxv (DT_DEBUG, &dyn_ptr, NULL))
return dyn_ptr;
@@ -1399,7 +1403,9 @@ svr4_current_sos_direct (struct svr4_info *info)
/* Assume that everything is a library if the dynamic loader was loaded
late by a static executable. */
- if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
+ if (current_program_space->exec_bfd ()
+ && bfd_get_section_by_name (current_program_space->exec_bfd (),
+ ".dynamic") == NULL)
ignore_first = 0;
else
ignore_first = 1;
@@ -2564,27 +2570,30 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
a call to gdbarch_convert_from_func_ptr_addr. */
CORE_ADDR entry_point, exec_displacement;
- if (exec_bfd == NULL)
+ if (current_program_space->exec_bfd () == NULL)
return 0;
/* Therefore for ELF it is ET_EXEC and not ET_DYN. Both shared libraries
being executed themselves and PIE (Position Independent Executable)
executables are ET_DYN. */
- if ((bfd_get_file_flags (exec_bfd) & DYNAMIC) == 0)
+ if ((bfd_get_file_flags (current_program_space->exec_bfd ()) & DYNAMIC) == 0)
return 0;
if (target_auxv_search (current_top_target (), AT_ENTRY, &entry_point) <= 0)
return 0;
- exec_displacement = entry_point - bfd_get_start_address (exec_bfd);
+ exec_displacement
+ = entry_point - bfd_get_start_address (current_program_space->exec_bfd ());
/* Verify the EXEC_DISPLACEMENT candidate complies with the required page
alignment. It is cheaper than the program headers comparison below. */
- if (bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
+ if (bfd_get_flavour (current_program_space->exec_bfd ())
+ == bfd_target_elf_flavour)
{
- const struct elf_backend_data *elf = get_elf_backend_data (exec_bfd);
+ const struct elf_backend_data *elf
+ = get_elf_backend_data (current_program_space->exec_bfd ());
/* p_align of PT_LOAD segments does not specify any alignment but
only congruency of addresses:
@@ -2601,7 +2610,8 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
looking at a different file than the one used by the kernel - for
instance, "gdb program" connected to "gdbserver :PORT ld.so program". */
- if (bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
+ if (bfd_get_flavour (current_program_space->exec_bfd ())
+ == bfd_target_elf_flavour)
{
/* Be optimistic and return 0 only if GDB was able to verify the headers
really do not match. */
@@ -2610,7 +2620,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
gdb::optional<gdb::byte_vector> phdrs_target
= read_program_header (-1, &arch_size, NULL);
gdb::optional<gdb::byte_vector> phdrs_binary
- = read_program_headers_from_bfd (exec_bfd);
+ = read_program_headers_from_bfd (current_program_space->exec_bfd ());
if (phdrs_target && phdrs_binary)
{
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
@@ -2629,14 +2639,16 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
content offset for the verification purpose. */
if (phdrs_target->size () != phdrs_binary->size ()
- || bfd_get_arch_size (exec_bfd) != arch_size)
+ || bfd_get_arch_size (current_program_space->exec_bfd ()) != arch_size)
return 0;
else if (arch_size == 32
&& phdrs_target->size () >= sizeof (Elf32_External_Phdr)
&& phdrs_target->size () % sizeof (Elf32_External_Phdr) == 0)
{
- Elf_Internal_Ehdr *ehdr2 = elf_tdata (exec_bfd)->elf_header;
- Elf_Internal_Phdr *phdr2 = elf_tdata (exec_bfd)->phdr;
+ Elf_Internal_Ehdr *ehdr2
+ = elf_tdata (current_program_space->exec_bfd ())->elf_header;
+ Elf_Internal_Phdr *phdr2
+ = elf_tdata (current_program_space->exec_bfd ())->phdr;
CORE_ADDR displacement = 0;
int i;
@@ -2736,6 +2748,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
}
/* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS. */
+ bfd *exec_bfd = current_program_space->exec_bfd ();
plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt");
if (plt2_asect)
{
@@ -2770,8 +2783,8 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
&& phdrs_target->size () >= sizeof (Elf64_External_Phdr)
&& phdrs_target->size () % sizeof (Elf64_External_Phdr) == 0)
{
- Elf_Internal_Ehdr *ehdr2 = elf_tdata (exec_bfd)->elf_header;
- Elf_Internal_Phdr *phdr2 = elf_tdata (exec_bfd)->phdr;
+ Elf_Internal_Ehdr *ehdr2 = elf_tdata (current_program_space->exec_bfd ())->elf_header;
+ Elf_Internal_Phdr *phdr2 = elf_tdata (current_program_space->exec_bfd ())->phdr;
CORE_ADDR displacement = 0;
int i;
@@ -2870,7 +2883,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
}
/* prelink can convert .plt SHT_NOBITS to SHT_PROGBITS. */
- plt2_asect = bfd_get_section_by_name (exec_bfd, ".plt");
+ plt2_asect = bfd_get_section_by_name (current_program_space->exec_bfd (), ".plt");
if (plt2_asect)
{
int content2;
@@ -2883,7 +2896,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
filesz = extract_unsigned_integer (buf_filesz_p, 8,
byte_order);
- /* PLT2_ASECT is from on-disk file (exec_bfd) while
+ /* PLT2_ASECT is from on-disk file (current_program_space->exec_bfd ()) while
FILESZ is from the in-memory image. */
if (content2)
filesz += bfd_section_size (plt2_asect);
@@ -2914,7 +2927,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
printf_unfiltered (_("Using PIE (Position Independent Executable) "
"displacement %s for \"%s\".\n"),
paddress (target_gdbarch (), exec_displacement),
- bfd_get_filename (exec_bfd));
+ bfd_get_filename (current_program_space->exec_bfd ()));
}
*displacementp = exec_displacement;
@@ -2969,10 +2982,11 @@ svr4_relocate_main_executable (void)
displacement);
objfile_relocate (symfile_objfile, new_offsets);
}
- else if (exec_bfd)
+ else if (current_program_space->exec_bfd ())
{
asection *asect;
+ bfd *exec_bfd = current_program_space->exec_bfd ();
for (asect = exec_bfd->sections; asect != NULL; asect = asect->next)
exec_set_section_address (bfd_get_filename (exec_bfd), asect->index,
bfd_section_vma (asect) + displacement);
@@ -3228,7 +3242,7 @@ svr4_iterate_over_objfiles_in_search_order
current_objfile = current_objfile->separate_debug_objfile_backlink;
if (current_objfile == symfile_objfile)
- abfd = exec_bfd;
+ abfd = current_program_space->exec_bfd ();
else
abfd = current_objfile->obfd;
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index c67d087c76d..098fcf72e4e 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -68,7 +68,7 @@ source_cache::get_plain_source_lines (struct symtab *s,
time_t mtime = 0;
if (SYMTAB_OBJFILE (s) != NULL && SYMTAB_OBJFILE (s)->obfd != NULL)
mtime = SYMTAB_OBJFILE (s)->mtime;
- else if (exec_bfd)
+ else if (current_program_space->exec_bfd ())
mtime = current_program_space->ebfd_mtime;
if (mtime && mtime < st.st_mtime)
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 5f212e10323..275588cb814 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -145,7 +145,7 @@ add_symbol_file_from_memory_command (const char *args, int from_tty)
if (symfile_objfile != NULL)
templ = symfile_objfile->obfd;
else
- templ = exec_bfd;
+ templ = current_program_space->exec_bfd ();
if (templ == NULL)
error (_("Must use symbol-file or exec-file "
"before add-symbol-file-from-memory."));
@@ -167,8 +167,8 @@ add_vsyscall_page ()
if (core_bfd != NULL)
bfd = core_bfd;
- else if (exec_bfd != NULL)
- bfd = exec_bfd;
+ else if (current_program_space->exec_bfd () != NULL)
+ bfd = current_program_space->exec_bfd ();
else
/* FIXME: cagney/2004-05-06: Should not require an existing
BFD when trying to create a run-time BFD of the VSYSCALL
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 3332e7f69ff..434ecb9a667 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2460,9 +2460,9 @@ reread_symbols (void)
/* We need to do this whenever any symbols go away. */
clear_symtab_users_cleanup defer_clear_users (0);
- if (exec_bfd != NULL
+ if (current_program_space->exec_bfd () != NULL
&& filename_cmp (bfd_get_filename (objfile->obfd),
- bfd_get_filename (exec_bfd)) == 0)
+ bfd_get_filename (current_program_space->exec_bfd ())) == 0)
{
/* Reload EXEC_BFD without asking anything. */
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 9cf68c5cb6e..c26d99a2765 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -25,7 +25,7 @@
#include "regcache.h"
#include "inferior.h"
#include "gdbthread.h"
-#include "exec.h" /* exec_bfd */
+#include "exec.h"
#include "completer.h"
#include "filenames.h"
#include "remote.h"
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 984f13941ce..5f2b10a8e04 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -914,7 +914,8 @@ windows_solib_create_inferior_hook (int from_tty)
/* Rebase executable if the base address changed because of ASLR. */
if (symfile_objfile != nullptr && exec_base != 0)
{
- CORE_ADDR vmaddr = pe_data (exec_bfd)->pe_opthdr.ImageBase;
+ CORE_ADDR vmaddr
+ = pe_data (current_program_space->exec_bfd ())->pe_opthdr.ImageBase;
if (vmaddr != exec_base)
objfile_rebase (symfile_objfile, exec_base - vmaddr);
}
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 08/16] Change program_space::ebfd to a gdb_bfd_ref_ptr
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (6 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 07/16] Remove the exec_bfd macro Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 09/16] Remove symfile_objfile macro Tom Tromey
` (8 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes program_space::ebfd to a gdb_bfd_ref_ptr, removing some
manual management.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* exec.c (exec_file_attach): Update.
* progspace.c (program_space::exec_close): Update.
* progspace.h (struct program_space) <ebfd>: Now a
gdb_bfd_ref_ptr.
<set_exec_bfd>: Change argument type.
<exec_bfd>: Update.
---
gdb/ChangeLog | 9 +++++++++
gdb/exec.c | 2 +-
gdb/progspace.c | 6 ++----
gdb/progspace.h | 8 ++++----
4 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index 85ad1aa49cb..4a82b38ea41 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -453,7 +453,7 @@ exec_file_attach (const char *filename, int from_tty)
FOPEN_RUB, scratch_chan);
else
temp = gdb_bfd_open (canonical_pathname, gnutarget, scratch_chan);
- current_program_space->set_exec_bfd (temp.release ());
+ current_program_space->set_exec_bfd (std::move (temp));
if (!current_program_space->exec_bfd ())
{
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 57edc298da7..52482ca8f64 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -228,13 +228,11 @@ program_space::solibs () const
void
program_space::exec_close ()
{
- if (ebfd)
+ if (ebfd != nullptr)
{
- gdb_bfd_unref (ebfd);
-
/* Removing target sections may close the exec_ops target.
Clear ebfd before doing so to prevent recursion. */
- ebfd = NULL;
+ ebfd.reset (nullptr);
ebfd_mtime = 0;
remove_target_sections (&ebfd);
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 5e49083884a..8150d8a2a62 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -279,13 +279,13 @@ struct program_space
/* Return the exec BFD for this program space. */
bfd *exec_bfd () const
{
- return ebfd;
+ return ebfd.get ();
}
/* Set the exec BFD for this program space to ABFD. */
- void set_exec_bfd (bfd *abfd)
+ void set_exec_bfd (gdb_bfd_ref_ptr &&abfd)
{
- ebfd = abfd;
+ ebfd = std::move (abfd);
}
/* Unique ID number. */
@@ -295,7 +295,7 @@ struct program_space
managed by the exec target. */
/* The BFD handle for the main executable. */
- bfd *ebfd = NULL;
+ gdb_bfd_ref_ptr ebfd;
/* The last-modified time, from when the exec was brought in. */
long ebfd_mtime = 0;
/* Similar to bfd_get_filename (exec_bfd) but in original form given
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 09/16] Remove symfile_objfile macro
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (7 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 08/16] Change program_space::ebfd to a gdb_bfd_ref_ptr Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 10/16] Change clear_program_space_solib_cache to method on program_space Tom Tromey
` (7 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes the symfile_objfile macro, in favor of just spelling out
the member access.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* windows-tdep.c (windows_solib_create_inferior_hook): Update.
* target.c (info_target_command): Update.
* symfile.c (syms_from_objfile_1, finish_new_objfile)
(symbol_file_clear, reread_symbols): Update.
* symfile-mem.c (add_symbol_file_from_memory_command): Update.
* stabsread.c (scan_file_globals): Update.
* solib.c (update_solib_list): Update.
* solib-svr4.c (elf_locate_base, open_symbol_file_object)
(svr4_fetch_objfile_link_map, enable_break)
(svr4_relocate_main_executable)
(svr4_iterate_over_objfiles_in_search_order): Update.
* solib-frv.c (lm_base, enable_break)
(frv_relocate_main_executable): Update.
(main_got, frv_fdpic_find_canonical_descriptor): Update.
(frv_fetch_objfile_link_map): Update.
* solib-dsbt.c (lm_base, dsbt_relocate_main_executable): Update.
* solib-darwin.c (darwin_solib_create_inferior_hook): Update.
* solib-aix.c (solib_aix_solib_create_inferior_hook): Update.
* remote.c (remote_target::get_offsets): Update.
(remote_target::start_remote)
(extended_remote_target::post_attach): Update.
* objfiles.c (entry_point_address_query): Update.
* nto-procfs.c (nto_procfs_target::create_inferior): Update.
* minsyms.c (get_symbol_leading_char): Update.
* frame.c (inside_main_func): Update.
* progspace.h (symfile_objfile): Remove macro.
---
gdb/ChangeLog | 29 +++++++++++++++++++++++++++++
gdb/frame.c | 5 +++--
gdb/minsyms.c | 8 ++++++--
gdb/nto-procfs.c | 3 ++-
gdb/objfiles.c | 8 ++++----
gdb/progspace.h | 5 -----
gdb/remote.c | 23 ++++++++++++-----------
gdb/solib-aix.c | 9 +++++----
gdb/solib-darwin.c | 5 +++--
gdb/solib-dsbt.c | 17 +++++++++--------
gdb/solib-frv.c | 28 +++++++++++++++-------------
gdb/solib-svr4.c | 21 ++++++++++++---------
gdb/solib.c | 3 ++-
gdb/stabsread.c | 5 +++--
gdb/symfile-mem.c | 4 ++--
gdb/symfile.c | 16 ++++++++--------
gdb/target.c | 9 ++++++---
gdb/windows-tdep.c | 5 +++--
18 files changed, 124 insertions(+), 79 deletions(-)
diff --git a/gdb/frame.c b/gdb/frame.c
index 6bfa31e630e..15168fb4315 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2292,13 +2292,14 @@ frame_debug_got_null_frame (struct frame_info *this_frame,
static bool
inside_main_func (frame_info *this_frame)
{
- if (symfile_objfile == nullptr)
+ if (current_program_space->symfile_object_file == nullptr)
return false;
CORE_ADDR sym_addr;
const char *name = main_name ();
bound_minimal_symbol msymbol
- = lookup_minimal_symbol (name, NULL, symfile_objfile);
+ = lookup_minimal_symbol (name, NULL,
+ current_program_space->symfile_object_file);
if (msymbol.minsym == nullptr)
{
/* In some language (for example Fortran) there will be no minimal
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index f4a2544eb19..0dec18d21ab 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1008,8 +1008,12 @@ get_symbol_leading_char (bfd *abfd)
{
if (abfd != NULL)
return bfd_get_symbol_leading_char (abfd);
- if (symfile_objfile != NULL && symfile_objfile->obfd != NULL)
- return bfd_get_symbol_leading_char (symfile_objfile->obfd);
+ if (current_program_space->symfile_object_file != NULL)
+ {
+ objfile *objf = current_program_space->symfile_object_file;
+ if (objf->obfd != NULL)
+ return bfd_get_symbol_leading_char (objf->obfd);
+ }
return 0;
}
diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c
index 5ecf9b52c34..366ef38fdd9 100644
--- a/gdb/nto-procfs.c
+++ b/gdb/nto-procfs.c
@@ -1323,7 +1323,8 @@ nto_procfs_target::create_inferior (const char *exec_file,
target_terminal::init ();
if (current_program_space->exec_bfd () != NULL
- || (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
+ || (current_program_space->symfile_object_file != NULL
+ && current_program_space->symfile_object_file->obfd != NULL))
solib_create_inferior_hook (0);
}
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 471a5c4c393..b322c6b2b9a 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -373,12 +373,12 @@ objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_)
int
entry_point_address_query (CORE_ADDR *entry_p)
{
- if (symfile_objfile == NULL || !symfile_objfile->per_bfd->ei.entry_point_p)
+ objfile *objf = current_program_space->symfile_object_file;
+ if (objf == NULL || !objf->per_bfd->ei.entry_point_p)
return 0;
- int idx = symfile_objfile->per_bfd->ei.the_bfd_section_index;
- *entry_p = (symfile_objfile->per_bfd->ei.entry_point
- + symfile_objfile->section_offsets[idx]);
+ int idx = objf->per_bfd->ei.the_bfd_section_index;
+ *entry_p = objf->per_bfd->ei.entry_point + objf->section_offsets[idx];
return 1;
}
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 8150d8a2a62..e719cee57d0 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -372,11 +372,6 @@ struct address_space
REGISTRY_FIELDS;
};
-/* The object file that the main symbol table was loaded from (e.g. the
- argument to the "symbol-file" or "file" command). */
-
-#define symfile_objfile current_program_space->symfile_object_file
-
/* The list of all program spaces. There's always at least one. */
extern std::vector<struct program_space *>program_spaces;
diff --git a/gdb/remote.c b/gdb/remote.c
index 7eb8fcf5604..f10fe52db2a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4107,7 +4107,7 @@ remote_target::get_offsets ()
int lose, num_segments = 0, do_sections, do_segments;
CORE_ADDR text_addr, data_addr, bss_addr, segments[2];
- if (symfile_objfile == NULL)
+ if (current_program_space->symfile_object_file == NULL)
return;
putpkt ("qOffsets");
@@ -4183,10 +4183,10 @@ remote_target::get_offsets ()
else if (*ptr != '\0')
warning (_("Target reported unsupported offsets: %s"), buf);
- section_offsets offs = symfile_objfile->section_offsets;
+ objfile *objf = current_program_space->symfile_object_file;
+ section_offsets offs = objf->section_offsets;
- symfile_segment_data_up data
- = get_symfile_segment_data (symfile_objfile->obfd);
+ symfile_segment_data_up data = get_symfile_segment_data (objf->obfd);
do_segments = (data != NULL);
do_sections = num_segments == 0;
@@ -4221,7 +4221,7 @@ remote_target::get_offsets ()
if (do_segments)
{
- int ret = symfile_map_offsets_to_segments (symfile_objfile->obfd,
+ int ret = symfile_map_offsets_to_segments (objf->obfd,
data.get (), offs,
num_segments, segments);
@@ -4235,18 +4235,18 @@ remote_target::get_offsets ()
if (do_sections)
{
- offs[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
+ offs[SECT_OFF_TEXT (objf)] = text_addr;
/* This is a temporary kludge to force data and bss to use the
same offsets because that's what nlmconv does now. The real
solution requires changes to the stub and remote.c that I
don't have time to do right now. */
- offs[SECT_OFF_DATA (symfile_objfile)] = data_addr;
- offs[SECT_OFF_BSS (symfile_objfile)] = data_addr;
+ offs[SECT_OFF_DATA (objf)] = data_addr;
+ offs[SECT_OFF_BSS (objf)] = data_addr;
}
- objfile_relocate (symfile_objfile, offs);
+ objfile_relocate (objf, offs);
}
/* Send interrupt_sequence to remote target. */
@@ -4846,7 +4846,8 @@ remote_target::start_remote (int from_tty, int extended_p)
/* If we connected to a live target, do some additional setup. */
if (target_has_execution ())
{
- if (symfile_objfile) /* No use without a symbol-file. */
+ /* No use without a symbol-file. */
+ if (current_program_space->symfile_object_file)
remote_check_symbols ();
}
@@ -5983,7 +5984,7 @@ extended_remote_target::post_attach (int pid)
binary is not using shared libraries, the vsyscall page is not
present (on Linux) and the binary itself hadn't changed since the
debugging process was started. */
- if (symfile_objfile != NULL)
+ if (current_program_space->symfile_object_file != NULL)
remote_check_symbols();
}
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index 344c1f57600..0897d067c40 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -462,12 +462,13 @@ solib_aix_solib_create_inferior_hook (int from_tty)
}
lm_info_aix &exec_info = (*library_list)[0];
- if (symfile_objfile != NULL)
+ if (current_program_space->symfile_object_file != NULL)
{
- section_offsets offsets
- = solib_aix_get_section_offsets (symfile_objfile, &exec_info);
+ objfile *objf = current_program_space->symfile_object_file;
+ section_offsets offsets = solib_aix_get_section_offsets (objf,
+ &exec_info);
- objfile_relocate (symfile_objfile, offsets);
+ objfile_relocate (objf, offsets);
}
}
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index e55b2082949..90d2be534c0 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -538,7 +538,7 @@ darwin_solib_create_inferior_hook (int from_tty)
load_addr = darwin_read_exec_load_addr_at_init (info);
}
- if (load_addr != 0 && symfile_objfile != NULL)
+ if (load_addr != 0 && current_program_space->symfile_object_file != NULL)
{
CORE_ADDR vmaddr;
@@ -547,7 +547,8 @@ darwin_solib_create_inferior_hook (int from_tty)
/* Relocate. */
if (vmaddr != load_addr)
- objfile_rebase (symfile_objfile, load_addr - vmaddr);
+ objfile_rebase (current_program_space->symfile_object_file,
+ load_addr - vmaddr);
}
/* Set solib notifier (to reload list of shared libraries). */
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 8e1da5dd73d..c3ce167d617 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -552,7 +552,7 @@ lm_base (void)
return info->lm_base_cache;
got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_", NULL,
- symfile_objfile);
+ current_program_space->symfile_object_file);
if (got_sym.minsym != 0)
{
@@ -909,21 +909,22 @@ dsbt_relocate_main_executable (void)
info->main_executable_lm_info = new lm_info_dsbt;
info->main_executable_lm_info->map = ldm;
- section_offsets new_offsets (symfile_objfile->section_offsets.size ());
+ objfile *objf = current_program_space->symfile_object_file;
+ section_offsets new_offsets (objf->section_offsets.size ());
changed = 0;
- ALL_OBJFILE_OSECTIONS (symfile_objfile, osect)
+ ALL_OBJFILE_OSECTIONS (objf, osect)
{
CORE_ADDR orig_addr, addr, offset;
int osect_idx;
int seg;
- osect_idx = osect - symfile_objfile->sections;
+ osect_idx = osect - objf->sections;
/* Current address of section. */
addr = obj_section_addr (osect);
/* Offset from where this section started. */
- offset = symfile_objfile->section_offsets[osect_idx];
+ offset = objf->section_offsets[osect_idx];
/* Original address prior to any past relocations. */
orig_addr = addr - offset;
@@ -943,10 +944,10 @@ dsbt_relocate_main_executable (void)
}
if (changed)
- objfile_relocate (symfile_objfile, new_offsets);
+ objfile_relocate (objf, new_offsets);
- /* Now that symfile_objfile has been relocated, we can compute the
- GOT value and stash it away. */
+ /* Now that OBJF has been relocated, we can compute the GOT value
+ and stash it away. */
}
/* When gdb starts up the inferior, it nurses it along (through the
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 08c9cf7ca5c..6c9ab1757b2 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -287,7 +287,7 @@ lm_base (void)
return lm_base_cache;
got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_", NULL,
- symfile_objfile);
+ current_program_space->symfile_object_file);
if (got_sym.minsym == 0)
{
if (solib_frv_debug)
@@ -717,7 +717,7 @@ enable_break (void)
asection *interp_sect;
CORE_ADDR entry_point;
- if (symfile_objfile == NULL)
+ if (current_program_space->symfile_object_file == NULL)
{
if (solib_frv_debug)
fprintf_unfiltered (gdb_stdlog,
@@ -784,21 +784,22 @@ frv_relocate_main_executable (void)
main_executable_lm_info = new lm_info_frv;
main_executable_lm_info->map = ldm;
- section_offsets new_offsets (symfile_objfile->section_offsets.size ());
+ objfile *objf = current_program_space->symfile_object_file;
+ section_offsets new_offsets (objf->section_offsets.size ());
changed = 0;
- ALL_OBJFILE_OSECTIONS (symfile_objfile, osect)
+ ALL_OBJFILE_OSECTIONS (objf, osect)
{
CORE_ADDR orig_addr, addr, offset;
int osect_idx;
int seg;
- osect_idx = osect - symfile_objfile->sections;
+ osect_idx = osect - objf->sections;
/* Current address of section. */
addr = obj_section_addr (osect);
/* Offset from where this section started. */
- offset = symfile_objfile->section_offsets[osect_idx];
+ offset = objf->section_offsets[osect_idx];
/* Original address prior to any past relocations. */
orig_addr = addr - offset;
@@ -818,10 +819,10 @@ frv_relocate_main_executable (void)
}
if (changed)
- objfile_relocate (symfile_objfile, new_offsets);
+ objfile_relocate (objf, new_offsets);
- /* Now that symfile_objfile has been relocated, we can compute the
- GOT value and stash it away. */
+ /* Now that OBJF has been relocated, we can compute the GOT value
+ and stash it away. */
main_executable_lm_info->got_value = main_got ();
}
@@ -894,8 +895,8 @@ main_got (void)
{
struct bound_minimal_symbol got_sym;
- got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_",
- NULL, symfile_objfile);
+ objfile *objf = current_program_space->symfile_object_file;
+ got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_", NULL, objf);
if (got_sym.minsym == 0)
return 0;
@@ -955,8 +956,9 @@ frv_fdpic_find_canonical_descriptor (CORE_ADDR entry_point)
name = sym->linkage_name ();
/* Check the main executable. */
+ objfile *objf = current_program_space->symfile_object_file;
addr = find_canonical_descriptor_in_load_object
- (entry_point, got_value, name, symfile_objfile->obfd,
+ (entry_point, got_value, name, objf->obfd,
main_executable_lm_info);
/* If descriptor not found via main executable, check each load object
@@ -1110,7 +1112,7 @@ frv_fetch_objfile_link_map (struct objfile *objfile)
solib_add (0, 0, 1);
/* frv_current_sos() will set main_lm_addr for the main executable. */
- if (objfile == symfile_objfile)
+ if (objfile == current_program_space->symfile_object_file)
return main_lm_addr;
/* The other link map addresses may be found by examining the list
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index ef1d78c1c83..981ff88e413 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -806,7 +806,8 @@ elf_locate_base (void)
/* This may be a static executable. Look for the symbol
conventionally named _r_debug, as a last resort. */
- msymbol = lookup_minimal_symbol ("_r_debug", NULL, symfile_objfile);
+ msymbol = lookup_minimal_symbol ("_r_debug", NULL,
+ current_program_space->symfile_object_file);
if (msymbol.minsym != NULL)
return BMSYMBOL_VALUE_ADDRESS (msymbol);
@@ -971,7 +972,7 @@ open_symbol_file_object (int from_tty)
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
- if (symfile_objfile)
+ if (current_program_space->symfile_object_file)
if (!query (_("Attempt to reload symbols from process? ")))
return 0;
@@ -1544,7 +1545,7 @@ svr4_fetch_objfile_link_map (struct objfile *objfile)
solib_add (NULL, 0, auto_solib_add);
/* svr4_current_sos() will set main_lm_addr for the main executable. */
- if (objfile == symfile_objfile)
+ if (objfile == current_program_space->symfile_object_file)
return info->main_lm_addr;
/* If OBJFILE is a separate debug object file, look for the
@@ -2465,9 +2466,10 @@ enable_break (struct svr4_info *info, int from_tty)
/* Scan through the lists of symbols, trying to look up the symbol and
set a breakpoint there. Terminate loop when we/if we succeed. */
+ objfile *objf = current_program_space->symfile_object_file;
for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
{
- msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
+ msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, objf);
if ((msymbol.minsym != NULL)
&& (BMSYMBOL_VALUE_ADDRESS (msymbol) != 0))
{
@@ -2485,7 +2487,7 @@ enable_break (struct svr4_info *info, int from_tty)
{
for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
{
- msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
+ msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, objf);
if ((msymbol.minsym != NULL)
&& (BMSYMBOL_VALUE_ADDRESS (msymbol) != 0))
{
@@ -2976,11 +2978,12 @@ svr4_relocate_main_executable (void)
/* Even DISPLACEMENT 0 is a valid new difference of in-memory vs. in-file
addresses. */
- if (symfile_objfile)
+ objfile *objf = current_program_space->symfile_object_file;
+ if (objf)
{
- section_offsets new_offsets (symfile_objfile->section_offsets.size (),
+ section_offsets new_offsets (objf->section_offsets.size (),
displacement);
- objfile_relocate (symfile_objfile, new_offsets);
+ objfile_relocate (objf, new_offsets);
}
else if (current_program_space->exec_bfd ())
{
@@ -3241,7 +3244,7 @@ svr4_iterate_over_objfiles_in_search_order
if (current_objfile->separate_debug_objfile_backlink != nullptr)
current_objfile = current_objfile->separate_debug_objfile_backlink;
- if (current_objfile == symfile_objfile)
+ if (current_objfile == current_program_space->symfile_object_file)
abfd = current_program_space->exec_bfd ();
else
abfd = current_objfile->obfd;
diff --git a/gdb/solib.c b/gdb/solib.c
index 28f6a4ecbfb..9df4eca888a 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -729,7 +729,8 @@ update_solib_list (int from_tty)
/* If we are attaching to a running process for which we
have not opened a symbol file, we may be able to get its
symbols now! */
- if (inf->attach_flag && symfile_objfile == NULL)
+ if (inf->attach_flag
+ && current_program_space->symfile_object_file == NULL)
{
try
{
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 4b1e3b2857a..17248aa4b62 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -4521,8 +4521,9 @@ scan_file_globals (struct objfile *objfile)
If we are scanning the symbols for a shared library, try to resolve
them from the minimal symbols of the main executable first. */
- if (symfile_objfile && objfile != symfile_objfile)
- resolve_objfile = symfile_objfile;
+ if (current_program_space->symfile_object_file
+ && objfile != current_program_space->symfile_object_file)
+ resolve_objfile = current_program_space->symfile_object_file;
else
resolve_objfile = objfile;
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 275588cb814..6621bba7138 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -142,8 +142,8 @@ add_symbol_file_from_memory_command (const char *args, int from_tty)
addr = parse_and_eval_address (args);
/* We need some representative bfd to know the target we are looking at. */
- if (symfile_objfile != NULL)
- templ = symfile_objfile->obfd;
+ if (current_program_space->symfile_object_file != NULL)
+ templ = current_program_space->symfile_object_file->obfd;
else
templ = current_program_space->exec_bfd ();
if (templ == NULL)
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 434ecb9a667..493411fa417 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -929,10 +929,10 @@ syms_from_objfile_1 (struct objfile *objfile,
/* Since no error yet, throw away the old symbol table. */
- if (symfile_objfile != NULL)
+ if (current_program_space->symfile_object_file != NULL)
{
- symfile_objfile->unlink ();
- gdb_assert (symfile_objfile == NULL);
+ current_program_space->symfile_object_file->unlink ();
+ gdb_assert (current_program_space->symfile_object_file == NULL);
}
/* Currently we keep symbols from the add-symbol-file command.
@@ -995,7 +995,7 @@ finish_new_objfile (struct objfile *objfile, symfile_add_flags add_flags)
if (add_flags & SYMFILE_MAINLINE)
{
/* OK, make it the "real" symbol file. */
- symfile_objfile = objfile;
+ current_program_space->symfile_object_file = objfile;
clear_symtab_users (add_flags);
}
@@ -1216,9 +1216,9 @@ symbol_file_clear (int from_tty)
{
if ((have_full_symbols () || have_partial_symbols ())
&& from_tty
- && (symfile_objfile
+ && (current_program_space->symfile_object_file
? !query (_("Discard symbol table from `%s'? "),
- objfile_name (symfile_objfile))
+ objfile_name (current_program_space->symfile_object_file))
: !query (_("Discard symbol table? "))))
error (_("Not confirmed."));
@@ -1230,7 +1230,7 @@ symbol_file_clear (int from_tty)
clear_symtab_users (0);
- gdb_assert (symfile_objfile == NULL);
+ gdb_assert (current_program_space->symfile_object_file == NULL);
if (from_tty)
printf_filtered (_("No symbol file now.\n"));
}
@@ -2555,7 +2555,7 @@ reread_symbols (void)
/* What the hell is sym_new_init for, anyway? The concept of
distinguishing between the main file and additional files
in this way seems rather dubious. */
- if (objfile == symfile_objfile)
+ if (objfile == current_program_space->symfile_object_file)
{
(*objfile->sf->sym_new_init) (objfile);
}
diff --git a/gdb/target.c b/gdb/target.c
index a111ea3c333..1b6e37e2806 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1828,9 +1828,12 @@ info_target_command (const char *args, int from_tty)
{
int has_all_mem = 0;
- if (symfile_objfile != NULL)
- printf_unfiltered (_("Symbols from \"%s\".\n"),
- objfile_name (symfile_objfile));
+ if (current_program_space->symfile_object_file != NULL)
+ {
+ objfile *objf = current_program_space->symfile_object_file;
+ printf_unfiltered (_("Symbols from \"%s\".\n"),
+ objfile_name (objf));
+ }
for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
{
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 5f2b10a8e04..50858f5c65a 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -912,12 +912,13 @@ windows_solib_create_inferior_hook (int from_tty)
}
/* Rebase executable if the base address changed because of ASLR. */
- if (symfile_objfile != nullptr && exec_base != 0)
+ if (current_program_space->symfile_object_file != nullptr && exec_base != 0)
{
CORE_ADDR vmaddr
= pe_data (current_program_space->exec_bfd ())->pe_opthdr.ImageBase;
if (vmaddr != exec_base)
- objfile_rebase (symfile_objfile, exec_base - vmaddr);
+ objfile_rebase (current_program_space->symfile_object_file,
+ exec_base - vmaddr);
}
}
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 10/16] Change clear_program_space_solib_cache to method on program_space
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (8 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 09/16] Remove symfile_objfile macro Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 11/16] Change program_space_empty_p " Tom Tromey
` (6 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes clear_program_space_solib_cache to be a method on
program_space. Also, it removes a call to this function from the
program_space destructor, as that is not necessary.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::~program_space): Don't call
clear_program_space_solib_cache.
(program_space::clear_solib_cache): Rename from
clear_solib_cache.
* solib.c (handle_solib_event): Update.
* progspace.h (struct program_space) <clear_solib_cache>: New
method.
(clear_program_space_solib_cache): Don't declare.
---
gdb/ChangeLog | 11 +++++++++++
gdb/progspace.c | 7 +++----
gdb/progspace.h | 10 +++++-----
gdb/solib.c | 2 +-
4 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 52482ca8f64..84baaeab292 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -154,7 +154,6 @@ program_space::~program_space ()
clear_symtab_users (SYMFILE_DEFER_BP_RESET);
if (!gdbarch_has_shared_address_space (target_gdbarch ()))
free_address_space (this->aspace);
- clear_program_space_solib_cache (this);
/* Discard any data modules have associated with the PSPACE. */
program_space_free_data (this);
}
@@ -448,10 +447,10 @@ update_address_spaces (void)
/* See progspace.h. */
void
-clear_program_space_solib_cache (struct program_space *pspace)
+program_space::clear_solib_cache ()
{
- pspace->added_solibs.clear ();
- pspace->deleted_solibs.clear ();
+ added_solibs.clear ();
+ deleted_solibs.clear ();
}
\f
diff --git a/gdb/progspace.h b/gdb/progspace.h
index e719cee57d0..22805d74f37 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -288,6 +288,11 @@ struct program_space
ebfd = std::move (abfd);
}
+ /* Reset saved solib data at the start of an solib event. This lets
+ us properly collect the data when calling solib_add, so it can then
+ later be printed. */
+ void clear_solib_cache ();
+
/* Unique ID number. */
int num = 0;
@@ -435,11 +440,6 @@ extern int address_space_num (struct address_space *aspace);
mappings. */
extern void update_address_spaces (void);
-/* Reset saved solib data at the start of an solib event. This lets
- us properly collect the data when calling solib_add, so it can then
- later be printed. */
-extern void clear_program_space_solib_cache (struct program_space *);
-
/* Keep a registry of per-pspace data-pointers required by other GDB
modules. */
diff --git a/gdb/solib.c b/gdb/solib.c
index 9df4eca888a..baa1801635b 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1252,7 +1252,7 @@ handle_solib_event (void)
if (ops->handle_event != NULL)
ops->handle_event ();
- clear_program_space_solib_cache (current_inferior ()->pspace);
+ current_inferior ()->pspace->clear_solib_cache ();
/* Check for any newly added shared libraries if we're supposed to
be adding them automatically. Switch terminal for any messages
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 11/16] Change program_space_empty_p to method on program_space
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (9 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 10/16] Change clear_program_space_solib_cache to method on program_space Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 12/16] Change remove_target_sections " Tom Tromey
` (5 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes program_space_empty_p to be a method on program_space.
It also changes it to return bool. I removed the "_p" suffix because
"empty" is a "well-known" C++ method name.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* inferior.c (delete_inferior): Update.
* progspace.c (program_space::empty): Rename from
program_space_empty_p. Return bool.
* progspace.h (struct program_space) <empty>: New method.
(program_space_empty_p): Don't declare.
---
gdb/ChangeLog | 8 ++++++++
gdb/inferior.c | 2 +-
gdb/progspace.c | 9 +++------
gdb/progspace.h | 7 ++++---
4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 5c63dfa0bf1..6ca0c28d7f0 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -175,7 +175,7 @@ delete_inferior (struct inferior *todel)
gdb::observers::inferior_removed.notify (inf);
/* If this program space is rendered useless, remove it. */
- if (program_space_empty_p (inf->pspace))
+ if (inf->pspace->empty ())
delete inf->pspace;
delete inf;
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 84baaeab292..70c0f7ec2a2 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -280,13 +280,10 @@ set_current_program_space (struct program_space *pspace)
/* Returns true iff there's no inferior bound to PSPACE. */
-int
-program_space_empty_p (struct program_space *pspace)
+bool
+program_space::empty ()
{
- if (find_inferior_for_program_space (pspace) != NULL)
- return 0;
-
- return 1;
+ return find_inferior_for_program_space (this) == nullptr;
}
/* Prints the list of program spaces and their details on UIOUT. If
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 22805d74f37..fa5247f8ac2 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -293,6 +293,10 @@ struct program_space
later be printed. */
void clear_solib_cache ();
+ /* Returns true iff there's no inferior bound to this program
+ space. */
+ bool empty ();
+
/* Unique ID number. */
int num = 0;
@@ -383,9 +387,6 @@ extern std::vector<struct program_space *>program_spaces;
/* The current program space. This is always non-null. */
extern struct program_space *current_program_space;
-/* Returns true iff there's no inferior bound to PSPACE. */
-extern int program_space_empty_p (struct program_space *pspace);
-
/* Copies program space SRC to DEST. Copies the main executable file,
and the main symbol file. Returns DEST. */
extern struct program_space *clone_program_space (struct program_space *dest,
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 12/16] Change remove_target_sections to method on program_space
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (10 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 11/16] Change program_space_empty_p " Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-20 14:40 ` [PP?] " Simon Marchi
2020-10-19 21:44 ` [PATCH v2 13/16] Change add_target_sections " Tom Tromey
` (4 subsequent siblings)
16 siblings, 1 reply; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes remove_target_sections to be a method on program_space.
This makes sense because this function manipulates data that is
attached to the program space.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* progspace.h (struct program_space) <remove_target_sections>:
Declare.
* exec.c (program_space::remove_target_sections): Now a method.
* exec.h (remove_target_sections): Don't declare.
---
gdb/ChangeLog | 7 +++++++
gdb/exec.c | 15 ++++++---------
gdb/exec.h | 4 ----
gdb/progspace.h | 3 +++
gdb/solib.c | 6 +++---
gdb/symfile.c | 2 +-
6 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index 4a82b38ea41..8952a99bf1a 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -651,31 +651,28 @@ add_target_sections_of_objfile (struct objfile *objfile)
OWNER must be the same value passed to add_target_sections. */
void
-remove_target_sections (void *owner)
+program_space::remove_target_sections (void *owner)
{
- target_section_table *table = ¤t_program_space->target_sections;
-
gdb_assert (owner != NULL);
- auto it = std::remove_if (table->begin (),
- table->end (),
+ auto it = std::remove_if (target_sections.begin (),
+ target_sections.end (),
[&] (target_section §)
{
return sect.owner == owner;
});
- table->erase (it, table->end ());
+ target_sections.erase (it, target_sections.end ());
/* If we don't have any more sections to read memory from,
remove the file_stratum target from the stack of each
inferior sharing the program space. */
- if (table->empty ())
+ if (target_sections.empty ())
{
scoped_restore_current_pspace_and_thread restore_pspace_thread;
- program_space *curr_pspace = current_program_space;
for (inferior *inf : all_inferiors ())
{
- if (inf->pspace != curr_pspace)
+ if (inf->pspace != this)
continue;
if (!inf->pspace->target_sections.empty ())
diff --git a/gdb/exec.h b/gdb/exec.h
index 8590e78710a..d5b3cff3855 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -92,10 +92,6 @@ extern enum target_xfer_status
/* Set the loaded address of a section. */
extern void exec_set_section_address (const char *, int, CORE_ADDR);
-/* Remove all target sections owned by OWNER. */
-
-extern void remove_target_sections (void *owner);
-
/* Add the sections array defined by [SECTIONS..SECTIONS_END[ to the
current set of target sections. */
diff --git a/gdb/progspace.h b/gdb/progspace.h
index fa5247f8ac2..f4e1107c6ec 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -297,6 +297,9 @@ struct program_space
space. */
bool empty ();
+ /* Remove all target sections owned by OWNER. */
+ void remove_target_sections (void *owner);
+
/* Unique ID number. */
int num = 0;
diff --git a/gdb/solib.c b/gdb/solib.c
index baa1801635b..64b2035cd89 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -824,7 +824,7 @@ update_solib_list (int from_tty)
/* Some targets' section tables might be referring to
sections from so->abfd; remove them. */
- remove_target_sections (gdb);
+ current_program_space->remove_target_sections (gdb);
free_so (gdb);
gdb = *gdb_link;
@@ -1175,7 +1175,7 @@ clear_solib (void)
current_program_space->so_list = so->next;
gdb::observers::solib_unloaded.notify (so);
- remove_target_sections (so);
+ current_program_space->remove_target_sections (so);
free_so (so);
}
@@ -1295,7 +1295,7 @@ reload_shared_libraries_1 (int from_tty)
if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED)
&& !solib_used (so))
so->objfile->unlink ();
- remove_target_sections (so);
+ current_program_space->remove_target_sections (so);
clear_so (so);
}
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 493411fa417..504132754b0 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3709,7 +3709,7 @@ symfile_free_objfile (struct objfile *objfile)
{
/* Remove the target sections owned by this objfile. */
if (objfile != NULL)
- remove_target_sections ((void *) objfile);
+ current_program_space->remove_target_sections ((void *) objfile);
}
/* Wrapper around the quick_symbol_functions expand_symtabs_matching "method".
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 13/16] Change add_target_sections to method on program_space
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (11 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 12/16] Change remove_target_sections " Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 14/16] Change add_target_sections_of_objfile " Tom Tromey
` (3 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes add_target_sections to be a method on program_space.
Like the earlier change to remove_target_sections, this makes sense
because this function is manipulating data that is stored on the
program space.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* solib.c (solib_map_sections): Update.
* exec.c (program_space::add_target_sections): Now a method.
(exec_file_attach): Update.
* exec.h (add_target_sections): Don't declare.
* progspace.h (struct program_space) <add_target_sections>:
Declare.
---
gdb/ChangeLog | 9 +++++++++
gdb/exec.c | 16 +++++++---------
gdb/exec.h | 6 ------
gdb/progspace.h | 5 +++++
gdb/solib.c | 2 +-
5 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index 8952a99bf1a..552730b4336 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -495,7 +495,8 @@ exec_file_attach (const char *filename, int from_tty)
/* Add the executable's sections to the current address spaces'
list of sections. This possibly pushes the exec_ops
target. */
- add_target_sections (¤t_program_space->ebfd, sections);
+ current_program_space->add_target_sections (¤t_program_space->ebfd,
+ sections);
/* Tell display code (if any) about the changed file name. */
if (deprecated_exec_file_display_hook)
@@ -592,28 +593,25 @@ build_section_table (struct bfd *some_bfd)
current set of target sections. */
void
-add_target_sections (void *owner,
- const target_section_table §ions)
+program_space::add_target_sections (void *owner,
+ const target_section_table §ions)
{
- target_section_table *table = ¤t_program_space->target_sections;
-
if (!sections.empty ())
{
for (const target_section &s : sections)
{
- table->push_back (s);
- table->back ().owner = owner;
+ target_sections.push_back (s);
+ target_sections.back ().owner = owner;
}
scoped_restore_current_pspace_and_thread restore_pspace_thread;
- program_space *curr_pspace = current_program_space;
/* If these are the first file sections we can provide memory
from, push the file_stratum target. Must do this in all
inferiors sharing the program space. */
for (inferior *inf : all_inferiors ())
{
- if (inf->pspace != curr_pspace)
+ if (inf->pspace != this)
continue;
if (inf->target_is_pushed (&exec_ops))
diff --git a/gdb/exec.h b/gdb/exec.h
index d5b3cff3855..3aa248527c9 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -92,12 +92,6 @@ extern enum target_xfer_status
/* Set the loaded address of a section. */
extern void exec_set_section_address (const char *, int, CORE_ADDR);
-/* Add the sections array defined by [SECTIONS..SECTIONS_END[ to the
- current set of target sections. */
-
-extern void add_target_sections (void *owner,
- const target_section_table §ions);
-
/* Add the sections of OBJFILE to the current set of target sections.
* OBJFILE owns the new target sections. */
diff --git a/gdb/progspace.h b/gdb/progspace.h
index f4e1107c6ec..92a7942c560 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -300,6 +300,11 @@ struct program_space
/* Remove all target sections owned by OWNER. */
void remove_target_sections (void *owner);
+ /* Add the sections array defined by SECTIONS to the
+ current set of target sections. */
+ void add_target_sections (void *owner,
+ const target_section_table §ions);
+
/* Unique ID number. */
int num = 0;
diff --git a/gdb/solib.c b/gdb/solib.c
index 64b2035cd89..e7dbde6a7f6 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -578,7 +578,7 @@ solib_map_sections (struct so_list *so)
section tables. Do this immediately after mapping the object so
that later nodes in the list can query this object, as is needed
in solib-osf.c. */
- add_target_sections (so, *so->sections);
+ current_program_space->add_target_sections (so, *so->sections);
return 1;
}
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 14/16] Change add_target_sections_of_objfile to method on program_space
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (12 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 13/16] Change add_target_sections " Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 15/16] Don't change current program space in exec_target::close Tom Tromey
` (2 subsequent siblings)
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes add_target_sections_of_objfile to be a method on
program_space. It is renamed to be another overload of
add_target_sections, because they are semantically equivalent in a
sense.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* symfile.c (add_symbol_file_command): Update.
* exec.c (program_space::add_target_sections): Rename.
* symfile-mem.c (symbol_file_add_from_memory): Update.
* progspace.h (struct program_space) <add_target_sections>:
Declare new overload.
* exec.h (add_target_sections_of_objfile): Don't declare.
---
gdb/ChangeLog | 9 +++++++++
gdb/exec.c | 9 ++++-----
gdb/exec.h | 5 -----
gdb/progspace.h | 4 ++++
gdb/symfile-mem.c | 2 +-
gdb/symfile.c | 2 +-
6 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index 552730b4336..3736c3c9e67 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -626,9 +626,8 @@ program_space::add_target_sections (void *owner,
/* Add the sections of OBJFILE to the current set of target sections. */
void
-add_target_sections_of_objfile (struct objfile *objfile)
+program_space::add_target_sections (struct objfile *objfile)
{
- target_section_table *table = ¤t_program_space->target_sections;
struct obj_section *osect;
gdb_assert (objfile != nullptr);
@@ -639,9 +638,9 @@ add_target_sections_of_objfile (struct objfile *objfile)
if (bfd_section_size (osect->the_bfd_section) == 0)
continue;
- table->emplace_back (obj_section_addr (osect),
- obj_section_endaddr (osect),
- osect->the_bfd_section, (void *) objfile);
+ target_sections.emplace_back (obj_section_addr (osect),
+ obj_section_endaddr (osect),
+ osect->the_bfd_section, (void *) objfile);
}
}
diff --git a/gdb/exec.h b/gdb/exec.h
index 3aa248527c9..4ddc6850be1 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -92,11 +92,6 @@ extern enum target_xfer_status
/* Set the loaded address of a section. */
extern void exec_set_section_address (const char *, int, CORE_ADDR);
-/* Add the sections of OBJFILE to the current set of target sections.
- * OBJFILE owns the new target sections. */
-
-extern void add_target_sections_of_objfile (struct objfile *objfile);
-
/* Prints info about all sections defined in the TABLE. ABFD is
special cased --- it's filename is omitted; if it is the executable
file, its entry point is printed. */
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 92a7942c560..c141731fa94 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -305,6 +305,10 @@ struct program_space
void add_target_sections (void *owner,
const target_section_table §ions);
+ /* Add the sections of OBJFILE to the current set of target
+ sections. They are given OBJFILE as the "owner". */
+ void add_target_sections (struct objfile *objfile);
+
/* Unique ID number. */
int num = 0;
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 6621bba7138..7e110173ad2 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -121,7 +121,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr,
objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd),
add_flags, &sai, OBJF_SHARED, NULL);
- add_target_sections_of_objfile (objf);
+ current_program_space->add_target_sections (objf);
/* This might change our ideas about frames already looked at. */
reinit_frame_cache ();
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 504132754b0..58ed660e52a 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2323,7 +2323,7 @@ add_symbol_file_command (const char *args, int from_tty)
if (seen_offset)
set_objfile_default_section_offset (objf, section_addrs, offset);
- add_target_sections_of_objfile (objf);
+ current_program_space->add_target_sections (objf);
/* Getting new symbols may change our opinion about what is
frameless. */
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 15/16] Don't change current program space in exec_target::close
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (13 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 14/16] Change add_target_sections_of_objfile " Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 16/16] Remove call to exec_close Tom Tromey
2020-10-20 14:46 ` [PP?] [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Simon Marchi
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
Now that we've removed the macros and moved various functions to be
methods on program_space (removing uses of current_program_space),
it's clear that exec_target::close can operate on program spaces
without changing the current program space.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* exec.c (exec_target::close): Don't change current program
space.
---
gdb/ChangeLog | 5 +++++
gdb/exec.c | 3 ---
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/gdb/exec.c b/gdb/exec.c
index 3736c3c9e67..3092e8fc3a6 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -154,11 +154,8 @@ exec_target_open (const char *args, int from_tty)
void
exec_target::close ()
{
- scoped_restore_current_program_space restore_pspace;
-
for (struct program_space *ss : program_spaces)
{
- set_current_program_space (ss);
ss->target_sections.clear ();
ss->exec_close ();
}
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 16/16] Remove call to exec_close
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (14 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 15/16] Don't change current program space in exec_target::close Tom Tromey
@ 2020-10-19 21:44 ` Tom Tromey
2020-10-20 14:46 ` [PP?] [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Simon Marchi
16 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-19 21:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
There's no need to call exec_close from ~progspace, because that
method just does some cleanup that's already going to be done during
destruction. This patch removes the call.
gdb/ChangeLog
2020-10-19 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::~program_space): Don't call
exec_close.
---
gdb/ChangeLog | 5 +++++
gdb/progspace.c | 1 -
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 70c0f7ec2a2..0e7c8d2428e 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -147,7 +147,6 @@ program_space::~program_space ()
breakpoint_program_space_exit (this);
no_shared_libraries (NULL, 0);
- exec_close ();
free_all_objfiles ();
/* Defer breakpoint re-set because we don't want to create new
locations for this pspace which we're tearing down. */
--
2.17.2
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PP?] [PATCH v2 04/16] Remove commented-out code from gcore.c
2020-10-19 21:44 ` [PATCH v2 04/16] Remove commented-out code from gcore.c Tom Tromey
@ 2020-10-20 14:01 ` Simon Marchi
2020-10-29 1:19 ` Tom Tromey
0 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2020-10-20 14:01 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2020-10-19 5:44 p.m., Tom Tromey wrote:
> I found some code in gcore.c that has been commented out since
>
> d3420b2fce5e (Mark Kettenis 2003-09-04 166) #if 1 /* See if this even matters... */
>
> This patch deletes this code.
>
> gdb/ChangeLog
> 2020-10-19 Tom Tromey <tom@tromey.com>
>
> * gcore.c (default_gcore_mach): Remove commented-out code.
> ---
> gdb/ChangeLog | 4 ++++
> gdb/gcore.c | 12 ------------
> 2 files changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/gdb/gcore.c b/gdb/gcore.c
> index db82eaac3dd..c1ea7a6c481 100644
> --- a/gdb/gcore.c
> +++ b/gdb/gcore.c
> @@ -168,19 +168,7 @@ gcore_command (const char *args, int from_tty)
> static unsigned long
> default_gcore_mach (void)
> {
> -#if 1 /* See if this even matters... */
> return 0;
> -#else
> -
> - const struct bfd_arch_info *bfdarch = gdbarch_bfd_arch_info (target_gdbarch ());
> -
> - if (bfdarch != NULL)
> - return bfdarch->mach;
> - if (exec_bfd == NULL)
> - error (_("Can't find default bfd machine type (need execfile)."));
> -
> - return bfd_get_mach (exec_bfd);
> -#endif /* 1 */
> }
The default_gcore_mach function is not needed then, you can remove it
too (replace where it is called with just "0").
Simon
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/16] Remove the exec_bfd macro
2020-10-19 21:44 ` [PATCH v2 07/16] Remove the exec_bfd macro Tom Tromey
@ 2020-10-20 14:24 ` Simon Marchi
2020-10-20 21:20 ` Tom Tromey
0 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2020-10-20 14:24 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2020-10-19 5:44 p.m., Tom Tromey wrote:
> This removes the exec_bfd macro, in favor of new accessors on
> program_space. In one spot the accessor can't be used; but this is
> still a big improvement over the macro, IMO.
Maybe just check for lines that are too long after the replacement.
A quick way I use is:
$ git show | sed 's|\t| |' | less
And when in less, I search for:
^\+.{81}
That highlights the lines that are added that are too long.
> @@ -480,18 +482,20 @@ exec_file_attach (const char *filename, int from_tty)
> gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
> }
>
> - target_section_table sections = build_section_table (exec_bfd);
> + target_section_table sections
> + = build_section_table (current_program_space->exec_bfd ());
>
> - current_program_space->ebfd_mtime = bfd_get_mtime (exec_bfd);
> + current_program_space->ebfd_mtime
> + = bfd_get_mtime (current_program_space->exec_bfd ());
>
> validate_files ();
>
> - set_gdbarch_from_file (exec_bfd);
> + set_gdbarch_from_file (current_program_space->exec_bfd ());
>
> /* Add the executable's sections to the current address spaces'
> list of sections. This possibly pushes the exec_ops
> target. */
> - add_target_sections (&exec_bfd, sections);
> + add_target_sections (¤t_program_space->ebfd, sections);
It's odd that the owner of these sections is the address of the ebfd
field in the program_space structure, and not the bfd pointer itself.
Do you know if this is done on purpose?
The only reason I would see is if we wanted a stable "owner" value even
when the exec bfd changes. But I don't see any comment to that effect.
Looking at the code, it looks like adding and removing the target
sections is tied to setting and unsetting the exec bfd.
- exec_file_attach sets the exec bfd and adds the corresponding target
sections
- program_space::close unsets the exec bfd and removes the
corresponding target sections
I don't see anything that could change the value of exec bfd in the mean
time, that would make the "owner" value of these sections stale. So I
believe it would be safe to use `current_program_space->exec_bfd ()` as
the owner.
Otherwise, this patch LGTM.
Simon
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PP?] [PATCH v2 12/16] Change remove_target_sections to method on program_space
2020-10-19 21:44 ` [PATCH v2 12/16] Change remove_target_sections " Tom Tromey
@ 2020-10-20 14:40 ` Simon Marchi
2020-10-29 1:24 ` Tom Tromey
0 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2020-10-20 14:40 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2020-10-19 5:44 p.m., Tom Tromey wrote:
> This changes remove_target_sections to be a method on program_space.
> This makes sense because this function manipulates data that is
> attached to the program space.
>
> gdb/ChangeLog
> 2020-10-19 Tom Tromey <tom@tromey.com>
>
> * progspace.h (struct program_space) <remove_target_sections>:
> Declare.
> * exec.c (program_space::remove_target_sections): Now a method.
> * exec.h (remove_target_sections): Don't declare.
> ---
> gdb/ChangeLog | 7 +++++++
> gdb/exec.c | 15 ++++++---------
> gdb/exec.h | 4 ----
> gdb/progspace.h | 3 +++
> gdb/solib.c | 6 +++---
> gdb/symfile.c | 2 +-
> 6 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/gdb/exec.c b/gdb/exec.c
> index 4a82b38ea41..8952a99bf1a 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -651,31 +651,28 @@ add_target_sections_of_objfile (struct objfile *objfile)
> OWNER must be the same value passed to add_target_sections. */
>
> void
> -remove_target_sections (void *owner)
> +program_space::remove_target_sections (void *owner)
Would it make sense to make a subsequent patch that just moves this
method to progspace.c? I think it's ok to leave it in exec.c in this
patch, so we can more easily see the diff, but I think in the end it
belongs to progspace.c.
The only thing that doesn't belong to progspace.c in this method is:
unpush_target (&exec_ops);
But I think it just means that we need better decoupling. We could have
a "program_space_target_sections_changed" observer, which exec.c would
attach to, and push/unpush as necessary.
> {
> - target_section_table *table = ¤t_program_space->target_sections;
> -
> gdb_assert (owner != NULL);
>
> - auto it = std::remove_if (table->begin (),
> - table->end (),
> + auto it = std::remove_if (target_sections.begin (),
> + target_sections.end (),
> [&] (target_section §)
> {
> return sect.owner == owner;
> });
> - table->erase (it, table->end ());
> + target_sections.erase (it, target_sections.end ());
>
> /* If we don't have any more sections to read memory from,
> remove the file_stratum target from the stack of each
> inferior sharing the program space. */
> - if (table->empty ())
> + if (target_sections.empty ())
> {
> scoped_restore_current_pspace_and_thread restore_pspace_thread;
> - program_space *curr_pspace = current_program_space;
>
> for (inferior *inf : all_inferiors ())
> {
> - if (inf->pspace != curr_pspace)
> + if (inf->pspace != this)
> continue;
>
> if (!inf->pspace->target_sections.empty ())
This line can be simplified, I believe:
if (!this->target_sections.empty ())
(you can omit `this` to be consistent with the rest of the code, I just
happen to like using `this` to access fields that aren't prefixed with
`m_`, for clarity)
Simon
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PP?] [PATCH v2 00/16] Remove some macros from exec.h and progspace.h
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
` (15 preceding siblings ...)
2020-10-19 21:44 ` [PATCH v2 16/16] Remove call to exec_close Tom Tromey
@ 2020-10-20 14:46 ` Simon Marchi
2020-10-29 21:06 ` Tom Tromey
16 siblings, 1 reply; 26+ messages in thread
From: Simon Marchi @ 2020-10-20 14:46 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2020-10-19 5:44 p.m., Tom Tromey wrote:
> This is version 2 of the series to remove the remaining object-like
> macros from exec.h and progspace.h.
>
> Version 1 of the series is here
>
> https://sourceware.org/pipermail/gdb-patches/2020-July/170704.html
>
> This version corrects the review comments, and adds a few more patches
> to do so. Now some "target section"-related functions are methods on
> program_space, removing uses of current_program_space and making the
> code simpler (IMO) to reason about
>
> Regression tested on x86-64 Fedora 28.
>
> Let me know what you think.
>
> Tom
I sent a few minor comments, other than that it all LGTM. Thanks a lot
for doing this, I think it really helps untangle this code.
Simon
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/16] Remove the exec_bfd macro
2020-10-20 14:24 ` Simon Marchi
@ 2020-10-20 21:20 ` Tom Tromey
2020-10-20 21:34 ` Simon Marchi
0 siblings, 1 reply; 26+ messages in thread
From: Tom Tromey @ 2020-10-20 21:20 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
Simon> Maybe just check for lines that are too long after the replacement.
Will do.
>> - add_target_sections (&exec_bfd, sections);
>> + add_target_sections (¤t_program_space->ebfd, sections);
Simon> It's odd that the owner of these sections is the address of the ebfd
Simon> field in the program_space structure, and not the bfd pointer itself.
Simon> Do you know if this is done on purpose?
There's probably no good reason for it, though I'm not completely sure.
Simon> I don't see anything that could change the value of exec bfd in the mean
Simon> time, that would make the "owner" value of these sections stale. So I
Simon> believe it would be safe to use `current_program_space->exec_bfd ()` as
Simon> the owner.
Or even just the program space itself.
The value is really just a cookie to make sure that different callers
don't accidentally clash.
Tom
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/16] Remove the exec_bfd macro
2020-10-20 21:20 ` Tom Tromey
@ 2020-10-20 21:34 ` Simon Marchi
0 siblings, 0 replies; 26+ messages in thread
From: Simon Marchi @ 2020-10-20 21:34 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2020-10-20 5:20 p.m., Tom Tromey wrote:
> Simon> Maybe just check for lines that are too long after the replacement.
>
> Will do.
>
>>> - add_target_sections (&exec_bfd, sections);
>>> + add_target_sections (¤t_program_space->ebfd, sections);
>
> Simon> It's odd that the owner of these sections is the address of the ebfd
> Simon> field in the program_space structure, and not the bfd pointer itself.
> Simon> Do you know if this is done on purpose?
>
> There's probably no good reason for it, though I'm not completely sure.
>
> Simon> I don't see anything that could change the value of exec bfd in the mean
> Simon> time, that would make the "owner" value of these sections stale. So I
> Simon> believe it would be safe to use `current_program_space->exec_bfd ()` as
> Simon> the owner.
>
> Or even just the program space itself.
> The value is really just a cookie to make sure that different callers
> don't accidentally clash.
True, but I think it would be more confusing, since the target sections
are derived from the exec bfd.
Simon
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PP?] [PATCH v2 04/16] Remove commented-out code from gcore.c
2020-10-20 14:01 ` [PP?] " Simon Marchi
@ 2020-10-29 1:19 ` Tom Tromey
0 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-29 1:19 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
>> static unsigned long
>> default_gcore_mach (void)
>> {
>> -#if 1 /* See if this even matters... */
>> return 0;
>> -#else
Simon> The default_gcore_mach function is not needed then, you can remove it
Simon> too (replace where it is called with just "0").
Thanks for noticing. I did this.
Tom
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PP?] [PATCH v2 12/16] Change remove_target_sections to method on program_space
2020-10-20 14:40 ` [PP?] " Simon Marchi
@ 2020-10-29 1:24 ` Tom Tromey
0 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-29 1:24 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
>> void
>> -remove_target_sections (void *owner)
>> +program_space::remove_target_sections (void *owner)
Simon> Would it make sense to make a subsequent patch that just moves this
Simon> method to progspace.c? I think it's ok to leave it in exec.c in this
Simon> patch, so we can more easily see the diff, but I think in the end it
Simon> belongs to progspace.c.
Yeah, makes sense to me.
Simon> The only thing that doesn't belong to progspace.c in this method is:
Simon> unpush_target (&exec_ops);
Simon> But I think it just means that we need better decoupling. We could have
Simon> a "program_space_target_sections_changed" observer, which exec.c would
Simon> attach to, and push/unpush as necessary.
I am not totally sure. Sometimes observers make the code more obscure.
>> - if (inf->pspace != curr_pspace)
>> + if (inf->pspace != this)
>> continue;
>>
>> if (!inf->pspace->target_sections.empty ())
Simon> This line can be simplified, I believe:
Simon> if (!this->target_sections.empty ())
Simon> (you can omit `this` to be consistent with the rest of the code, I just
Simon> happen to like using `this` to access fields that aren't prefixed with
Simon> `m_`, for clarity)
Thanks for pointing this out. I think the entire 'if' can be removed,
because we already know from an outer 'if' that target_sections is
empty.
Tom
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PP?] [PATCH v2 00/16] Remove some macros from exec.h and progspace.h
2020-10-20 14:46 ` [PP?] [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Simon Marchi
@ 2020-10-29 21:06 ` Tom Tromey
0 siblings, 0 replies; 26+ messages in thread
From: Tom Tromey @ 2020-10-29 21:06 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
Simon> I sent a few minor comments, other than that it all LGTM. Thanks a lot
Simon> for doing this, I think it really helps untangle this code.
I'm checking this in now.
I think I fixed all the comments and I re-regression tested it on
x86-64 Fedora 28.
I made a note to write a follow-up patch to move the method
implementations to progspace.c.
Tom
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2020-10-29 21:06 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-19 21:44 [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Tom Tromey
2020-10-19 21:44 ` [PATCH v2 01/16] Add target_section constructor Tom Tromey
2020-10-19 21:44 ` [PATCH v2 02/16] Remove exec_filename macro Tom Tromey
2020-10-19 21:44 ` [PATCH v2 03/16] Change exec_close to be a method on program_space Tom Tromey
2020-10-19 21:44 ` [PATCH v2 04/16] Remove commented-out code from gcore.c Tom Tromey
2020-10-20 14:01 ` [PP?] " Simon Marchi
2020-10-29 1:19 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 05/16] Remove exec_bfd_mtime define Tom Tromey
2020-10-19 21:44 ` [PATCH v2 06/16] Remove current_target_sections macro Tom Tromey
2020-10-19 21:44 ` [PATCH v2 07/16] Remove the exec_bfd macro Tom Tromey
2020-10-20 14:24 ` Simon Marchi
2020-10-20 21:20 ` Tom Tromey
2020-10-20 21:34 ` Simon Marchi
2020-10-19 21:44 ` [PATCH v2 08/16] Change program_space::ebfd to a gdb_bfd_ref_ptr Tom Tromey
2020-10-19 21:44 ` [PATCH v2 09/16] Remove symfile_objfile macro Tom Tromey
2020-10-19 21:44 ` [PATCH v2 10/16] Change clear_program_space_solib_cache to method on program_space Tom Tromey
2020-10-19 21:44 ` [PATCH v2 11/16] Change program_space_empty_p " Tom Tromey
2020-10-19 21:44 ` [PATCH v2 12/16] Change remove_target_sections " Tom Tromey
2020-10-20 14:40 ` [PP?] " Simon Marchi
2020-10-29 1:24 ` Tom Tromey
2020-10-19 21:44 ` [PATCH v2 13/16] Change add_target_sections " Tom Tromey
2020-10-19 21:44 ` [PATCH v2 14/16] Change add_target_sections_of_objfile " Tom Tromey
2020-10-19 21:44 ` [PATCH v2 15/16] Don't change current program space in exec_target::close Tom Tromey
2020-10-19 21:44 ` [PATCH v2 16/16] Remove call to exec_close Tom Tromey
2020-10-20 14:46 ` [PP?] [PATCH v2 00/16] Remove some macros from exec.h and progspace.h Simon Marchi
2020-10-29 21:06 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).