Add target_section constructor

This adds a constructor to target_section, simplifying the code that
creates instances of this.

gdb/ChangeLog
2020-10-29  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.
This commit is contained in:
Tom Tromey 2020-10-29 15:04:33 -06:00
parent 8ee54925b4
commit 6be2a9ab1f
4 changed files with 23 additions and 18 deletions

View File

@ -1,3 +1,10 @@
2020-10-29 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.
2020-10-29 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> 2020-10-29 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
PR gdb/19318 PR gdb/19318

View File

@ -266,12 +266,7 @@ core_target::build_file_mappings ()
bfd_set_section_alignment (sec, 2); bfd_set_section_alignment (sec, 2);
/* Set target_section fields. */ /* Set target_section fields. */
m_core_file_mappings.emplace_back (); m_core_file_mappings.emplace_back (start, end, sec);
target_section &ts = m_core_file_mappings.back ();
ts.addr = start;
ts.endaddr = end;
ts.owner = nullptr;
ts.the_bfd_section = sec;
}); });
normalize_mem_ranges (&m_core_unavailable_mappings); normalize_mem_ranges (&m_core_unavailable_mappings);

View File

@ -598,12 +598,9 @@ build_section_table (struct bfd *some_bfd)
if (!(aflag & SEC_ALLOC)) if (!(aflag & SEC_ALLOC))
continue; continue;
table.emplace_back (); table.emplace_back (bfd_section_vma (asect),
target_section &sect = table.back (); bfd_section_vma (asect) + bfd_section_size (asect),
sect.owner = NULL; asect);
sect.the_bfd_section = asect;
sect.addr = bfd_section_vma (asect);
sect.endaddr = sect.addr + bfd_section_size (asect);
} }
return table; return table;
@ -662,12 +659,9 @@ add_target_sections_of_objfile (struct objfile *objfile)
if (bfd_section_size (osect->the_bfd_section) == 0) if (bfd_section_size (osect->the_bfd_section) == 0)
continue; continue;
table->emplace_back (); table->emplace_back (obj_section_addr (osect),
target_section &ts = table->back (); obj_section_endaddr (osect),
ts.addr = obj_section_addr (osect); osect->the_bfd_section, (void *) objfile);
ts.endaddr = obj_section_endaddr (osect);
ts.the_bfd_section = osect->the_bfd_section;
ts.owner = (void *) objfile;
} }
} }

View File

@ -26,6 +26,15 @@
struct target_section 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. */ /* Lowest address in section. */
CORE_ADDR addr; CORE_ADDR addr;
/* Highest address in section, plus 1. */ /* Highest address in section, plus 1. */