aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-10-12 15:53:16 -0600
committerTom Tromey <tom@tromey.com>2020-10-12 20:18:47 -0600
commit2d128614d4101354d8125449539dc3255c37d345 (patch)
tree4d07bd7567401171c8ea9edd5cee5170b0a0f3b9
parentbb2a67773c5e06545c39a6373be720c7d3d9eeb5 (diff)
downloadgdb-2d128614d4101354d8125449539dc3255c37d345.zip
gdb-2d128614d4101354d8125449539dc3255c37d345.tar.gz
gdb-2d128614d4101354d8125449539dc3255c37d345.tar.bz2
build_section_table cannot fail
I noticed that build_section_table cannot fail. This patch changes it to return a target_section_table and then removes the dead code. gdb/ChangeLog 2020-10-12 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.
-rw-r--r--gdb/ChangeLog10
-rw-r--r--gdb/bfd-target.c4
-rw-r--r--gdb/corelow.c4
-rw-r--r--gdb/exec.c28
-rw-r--r--gdb/exec.h5
-rw-r--r--gdb/record-full.c8
-rw-r--r--gdb/solib.c6
7 files changed, 26 insertions, 39 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4097647..7a66a4d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
2020-10-12 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.
+
+2020-10-12 Tom Tromey <tom@tromey.com>
+
* target.c (target_section_by_addr, memory_xfer_partial_1):
Update.
* target-section.h (struct target_section_table): Use
diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 8a58e92..d5defab9 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 554561d..193dccb 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 e3e515f..d4b9b7b 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, &sections))
- {
- /* 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 &sect = table->sections.back ();
+ table.sections.emplace_back ();
+ target_section &sect = 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 d26eba4..75177dd 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 5dcb42d..40740f2 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 906e178..bd6a27d 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)
{