[PATCH 3/6] build_section_table cannot fail
Tom Tromey
tom@tromey.com
Sat Oct 3 19:37:32 GMT 2020
I noticed that build_section_table cannot fail. This patch changes it
to return a target_section_table and then removes the dead code.
2020-10-03 Tom Tromey <tom@tromey.com>
* solib.c (solib_map_sections): Update.
* record-full.c (record_full_core_open_1): Update.
* exec.h (build_section_table): Return a target_section_table.
* exec.c (exec_file_attach): Update.
(build_section_table): Return a target_section_table.
* corelow.c (core_target::core_target): Update.
* bfd-target.c (target_bfd::target_bfd): Update.
---
gdb/ChangeLog | 10 ++++++++++
gdb/bfd-target.c | 4 ++--
gdb/corelow.c | 4 +---
gdb/exec.c | 28 +++++++++-------------------
gdb/exec.h | 5 ++---
gdb/record-full.c | 8 +-------
gdb/solib.c | 6 +-----
7 files changed, 26 insertions(+), 39 deletions(-)
diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 8a58e92eb1c..d5defab9a80 100644
--- a/gdb/bfd-target.c
+++ b/gdb/bfd-target.c
@@ -89,9 +89,9 @@ target_bfd::get_section_table ()
}
target_bfd::target_bfd (struct bfd *abfd)
- : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
+ : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd)),
+ m_table (build_section_table (abfd))
{
- build_section_table (abfd, &m_table);
}
target_ops *
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 554561dbb36..193dccbeeb5 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -161,9 +161,7 @@ core_target::core_target ()
bfd_get_filename (core_bfd));
/* Find the data section */
- if (build_section_table (core_bfd, &m_core_section_table))
- error (_("\"%s\": Can't find sections: %s"),
- bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
+ m_core_section_table = build_section_table (core_bfd);
build_file_mappings ();
}
diff --git a/gdb/exec.c b/gdb/exec.c
index e3e515fedec..d4b9b7bcf65 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -413,7 +413,6 @@ exec_file_attach (const char *filename, int from_tty)
int load_via_target = 0;
const char *scratch_pathname, *canonical_pathname;
int scratch_chan;
- target_section_table sections;
char **matching;
if (is_target_filename (filename))
@@ -503,15 +502,7 @@ exec_file_attach (const char *filename, int from_tty)
gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
}
- if (build_section_table (exec_bfd, §ions))
- {
- /* Make sure to close exec_bfd, or else "run" might try to use
- it. */
- exec_close ();
- error (_("\"%ps\": can't find the file sections: %s"),
- styled_string (file_name_style.style (), scratch_pathname),
- bfd_errmsg (bfd_get_error ()));
- }
+ target_section_table sections = build_section_table (exec_bfd);
exec_bfd_mtime = bfd_get_mtime (exec_bfd);
@@ -594,13 +585,13 @@ clear_section_table (struct target_section_table *table)
table->sections.clear ();
}
-/* Builds a section table, given args BFD, TABLE.
- Returns 0 if OK, 1 on error. */
+/* Builds a section table, given args BFD, TABLE. */
-int
-build_section_table (struct bfd *some_bfd, target_section_table *table)
+target_section_table
+build_section_table (struct bfd *some_bfd)
{
- table->sections.clear ();
+ target_section_table table;
+
for (asection *asect : gdb_bfd_sections (some_bfd))
{
flagword aflag;
@@ -615,16 +606,15 @@ build_section_table (struct bfd *some_bfd, target_section_table *table)
if (!(aflag & SEC_ALLOC))
continue;
- table->sections.emplace_back ();
- target_section § = table->sections.back ();
+ table.sections.emplace_back ();
+ target_section § = table.sections.back ();
sect.owner = NULL;
sect.the_bfd_section = asect;
sect.addr = bfd_section_vma (asect);
sect.endaddr = sect.addr + bfd_section_size (asect);
}
- /* We could realloc the table, but it probably loses for most files. */
- return 0;
+ return table;
}
/* Add the sections array defined by [SECTIONS..SECTIONS_END[ to the
diff --git a/gdb/exec.h b/gdb/exec.h
index d26eba49236..75177dda96a 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -34,10 +34,9 @@ struct objfile;
#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, SECTABLE_PTR, SECEND_PTR.
- Returns 0 if OK, 1 on error. */
+/* Builds a section table, given args BFD. */
-extern int build_section_table (struct bfd *, struct target_section_table *);
+extern target_section_table build_section_table (struct bfd *);
/* Remove all entries from TABLE. */
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 5dcb42d2f4e..40740f216ce 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -923,13 +923,7 @@ record_full_core_open_1 (const char *name, int from_tty)
for (i = 0; i < regnum; i ++)
record_full_core_regbuf->raw_supply (i, *regcache);
- if (build_section_table (core_bfd, &record_full_core_sections))
- {
- delete record_full_core_regbuf;
- record_full_core_regbuf = NULL;
- error (_("\"%s\": Can't find sections: %s"),
- bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
- }
+ record_full_core_sections = build_section_table (core_bfd);
push_target (&record_full_core_ops);
record_full_restore ();
diff --git a/gdb/solib.c b/gdb/solib.c
index 906e1788c49..bd6a27d8983 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -554,11 +554,7 @@ solib_map_sections (struct so_list *so)
if (so->sections == nullptr)
so->sections = new target_section_table;
- if (build_section_table (so->abfd, so->sections))
- {
- error (_("Can't find the file sections in `%s': %s"),
- bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ()));
- }
+ *so->sections = build_section_table (so->abfd);
for (target_section &p : so->sections->sections)
{
--
2.17.2
More information about the Gdb-patches
mailing list