Remove ALL_OBJSECTIONS

This removes the ALL_OBJSECTIONS macro, replacing its uses with ranged
for loops.

The special code in this macro for noticing a "break" from the inner
loop was only needed in a single place; so rather than try to
replicate this, I've simply replaced that use with a "goto".

gdb/ChangeLog
2019-01-09  Tom Tromey  <tom@tromey.com>

	* symfile.c (overlay_invalidate_all, find_pc_overlay)
	(find_pc_mapped_section, list_overlays_command)
	(map_overlay_command, unmap_overlay_command)
	(simple_overlay_update): Use all_objfiles.
	* spu-tdep.c (spu_overlay_update): Use all_objfiles.
	* printcmd.c (info_symbol_command): Use all_objfiles.
	* objfiles.h (ALL_OBJSECTIONS): Remove.
	* maint.c (maintenance_translate_address): Use all_objfiles.
	* gcore.c (gcore_create_callback): Use all_objfiles.
	(objfile_find_memory_regions): Likewise.
This commit is contained in:
Tom Tromey 2018-11-24 11:54:26 -07:00
parent 8b31193aa9
commit 3b9d3ac236
7 changed files with 234 additions and 254 deletions

View File

@ -1,3 +1,16 @@
2019-01-09 Tom Tromey <tom@tromey.com>
* symfile.c (overlay_invalidate_all, find_pc_overlay)
(find_pc_mapped_section, list_overlays_command)
(map_overlay_command, unmap_overlay_command)
(simple_overlay_update): Use all_objfiles.
* spu-tdep.c (spu_overlay_update): Use all_objfiles.
* printcmd.c (info_symbol_command): Use all_objfiles.
* objfiles.h (ALL_OBJSECTIONS): Remove.
* maint.c (maintenance_translate_address): Use all_objfiles.
* gcore.c (gcore_create_callback): Use all_objfiles.
(objfile_find_memory_regions): Likewise.
2019-01-09 Tom Tromey <tom@tromey.com>
* symtab.c (find_line_symtab, info_sources_command)

View File

@ -424,34 +424,34 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read,
{
/* See if this region of memory lies inside a known file on disk.
If so, we can avoid copying its contents by clearing SEC_LOAD. */
struct objfile *objfile;
struct obj_section *objsec;
ALL_OBJSECTIONS (objfile, objsec)
{
bfd *abfd = objfile->obfd;
asection *asec = objsec->the_bfd_section;
bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
asec);
bfd_vma start = obj_section_addr (objsec) & -align;
bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, objsec)
{
bfd *abfd = objfile->obfd;
asection *asec = objsec->the_bfd_section;
bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
asec);
bfd_vma start = obj_section_addr (objsec) & -align;
bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
/* Match if either the entire memory region lies inside the
section (i.e. a mapping covering some pages of a large
segment) or the entire section lies inside the memory region
(i.e. a mapping covering multiple small sections).
/* Match if either the entire memory region lies inside the
section (i.e. a mapping covering some pages of a large
segment) or the entire section lies inside the memory region
(i.e. a mapping covering multiple small sections).
This BFD was synthesized from reading target memory,
we don't want to omit that. */
if (objfile->separate_debug_objfile_backlink == NULL
&& ((vaddr >= start && vaddr + size <= end)
|| (start >= vaddr && end <= vaddr + size))
&& !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
{
flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
goto keep; /* Break out of two nested for loops. */
}
}
This BFD was synthesized from reading target memory,
we don't want to omit that. */
if (objfile->separate_debug_objfile_backlink == NULL
&& ((vaddr >= start && vaddr + size <= end)
|| (start >= vaddr && end <= vaddr + size))
&& !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
{
flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
goto keep; /* Break out of two nested for loops. */
}
}
keep:;
}
@ -489,36 +489,36 @@ objfile_find_memory_regions (struct target_ops *self,
find_memory_region_ftype func, void *obfd)
{
/* Use objfile data to create memory sections. */
struct objfile *objfile;
struct obj_section *objsec;
bfd_vma temp_bottom, temp_top;
/* Call callback function for each objfile section. */
ALL_OBJSECTIONS (objfile, objsec)
{
bfd *ibfd = objfile->obfd;
asection *isec = objsec->the_bfd_section;
flagword flags = bfd_get_section_flags (ibfd, isec);
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, objsec)
{
bfd *ibfd = objfile->obfd;
asection *isec = objsec->the_bfd_section;
flagword flags = bfd_get_section_flags (ibfd, isec);
/* Separate debug info files are irrelevant for gcore. */
if (objfile->separate_debug_objfile_backlink != NULL)
continue;
/* Separate debug info files are irrelevant for gcore. */
if (objfile->separate_debug_objfile_backlink != NULL)
continue;
if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
{
int size = bfd_section_size (ibfd, isec);
int ret;
if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
{
int size = bfd_section_size (ibfd, isec);
int ret;
ret = (*func) (obj_section_addr (objsec), size,
1, /* All sections will be readable. */
(flags & SEC_READONLY) == 0, /* Writable. */
(flags & SEC_CODE) != 0, /* Executable. */
1, /* MODIFIED is unknown, pass it as true. */
obfd);
if (ret != 0)
return ret;
}
}
ret = (*func) (obj_section_addr (objsec), size,
1, /* All sections will be readable. */
(flags & SEC_READONLY) == 0, /* Writable. */
(flags & SEC_CODE) != 0, /* Executable. */
1, /* MODIFIED is unknown, pass it as true. */
obfd);
if (ret != 0)
return ret;
}
}
/* Make a stack segment. */
if (derive_stack_segment (&temp_bottom, &temp_top))

View File

@ -430,7 +430,6 @@ maintenance_translate_address (const char *arg, int from_tty)
struct obj_section *sect;
const char *p;
struct bound_minimal_symbol sym;
struct objfile *objfile;
if (arg == NULL || *arg == 0)
error (_("requires argument (address or section + address)"));
@ -448,14 +447,15 @@ maintenance_translate_address (const char *arg, int from_tty)
int arg_len = p - arg;
p = skip_spaces (p + 1);
ALL_OBJSECTIONS (objfile, sect)
{
if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0)
break;
}
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, sect)
{
if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0)
goto found;
}
if (!objfile)
error (_("Unknown section %s."), arg);
error (_("Unknown section %s."), arg);
found: ;
}
address = parse_and_eval_address (p);

View File

@ -705,42 +705,6 @@ private:
} \
else
/* Traverse all obj_sections in all objfiles in the current program
space.
Note that this detects a "break" in the inner loop, and exits
immediately from the outer loop as well, thus, client code doesn't
need to know that this is implemented with a double for. The extra
hair is to make sure that a "break;" stops the outer loop iterating
as well, and both OBJFILE and OSECT are left unmodified:
- The outer loop learns about the inner loop's end condition, and
stops iterating if it detects the inner loop didn't reach its
end. In other words, the outer loop keeps going only if the
inner loop reached its end cleanly [(osect) ==
(objfile)->sections_end].
- OSECT is initialized in the outer loop initialization
expressions, such as if the inner loop has reached its end, so
the check mentioned above succeeds the first time.
- The trick to not clearing OBJFILE on a "break;" is, in the outer
loop's loop expression, advance OBJFILE, but iff the inner loop
reached its end. If not, there was a "break;", so leave OBJFILE
as is; the outer loop's conditional will break immediately as
well (as OSECT will be different from OBJFILE->sections_end). */
#define ALL_OBJSECTIONS(objfile, osect) \
for ((objfile) = current_program_space->objfiles, \
(objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0; \
(objfile) != NULL \
&& (osect) == (objfile)->sections_end; \
((osect) == (objfile)->sections_end \
? ((objfile) = (objfile)->next, \
(objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \
: 0)) \
ALL_OBJFILE_OSECTIONS (objfile, osect)
#define SECT_OFF_DATA(objfile) \
((objfile->sect_index_data == -1) \
? (internal_error (__FILE__, __LINE__, \

View File

@ -1273,7 +1273,6 @@ static void
info_symbol_command (const char *arg, int from_tty)
{
struct minimal_symbol *msymbol;
struct objfile *objfile;
struct obj_section *osect;
CORE_ADDR addr, sect_addr;
int matches = 0;
@ -1283,78 +1282,81 @@ info_symbol_command (const char *arg, int from_tty)
error_no_arg (_("address"));
addr = parse_and_eval_address (arg);
ALL_OBJSECTIONS (objfile, osect)
{
/* Only process each object file once, even if there's a separate
debug file. */
if (objfile->separate_debug_objfile_backlink)
continue;
sect_addr = overlay_mapped_address (addr, osect);
if (obj_section_addr (osect) <= sect_addr
&& sect_addr < obj_section_endaddr (osect)
&& (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr, osect).minsym))
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, osect)
{
const char *obj_name, *mapped, *sec_name, *msym_name;
const char *loc_string;
/* Only process each object file once, even if there's a separate
debug file. */
if (objfile->separate_debug_objfile_backlink)
continue;
matches = 1;
offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
sec_name = osect->the_bfd_section->name;
msym_name = MSYMBOL_PRINT_NAME (msymbol);
sect_addr = overlay_mapped_address (addr, osect);
/* Don't print the offset if it is zero.
We assume there's no need to handle i18n of "sym + offset". */
std::string string_holder;
if (offset)
if (obj_section_addr (osect) <= sect_addr
&& sect_addr < obj_section_endaddr (osect)
&& (msymbol
= lookup_minimal_symbol_by_pc_section (sect_addr,
osect).minsym))
{
string_holder = string_printf ("%s + %u", msym_name, offset);
loc_string = string_holder.c_str ();
const char *obj_name, *mapped, *sec_name, *msym_name;
const char *loc_string;
matches = 1;
offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
sec_name = osect->the_bfd_section->name;
msym_name = MSYMBOL_PRINT_NAME (msymbol);
/* Don't print the offset if it is zero.
We assume there's no need to handle i18n of "sym + offset". */
std::string string_holder;
if (offset)
{
string_holder = string_printf ("%s + %u", msym_name, offset);
loc_string = string_holder.c_str ();
}
else
loc_string = msym_name;
gdb_assert (osect->objfile && objfile_name (osect->objfile));
obj_name = objfile_name (osect->objfile);
if (MULTI_OBJFILE_P ())
if (pc_in_unmapped_range (addr, osect))
if (section_is_overlay (osect))
printf_filtered (_("%s in load address range of "
"%s overlay section %s of %s\n"),
loc_string, mapped, sec_name, obj_name);
else
printf_filtered (_("%s in load address range of "
"section %s of %s\n"),
loc_string, sec_name, obj_name);
else
if (section_is_overlay (osect))
printf_filtered (_("%s in %s overlay section %s of %s\n"),
loc_string, mapped, sec_name, obj_name);
else
printf_filtered (_("%s in section %s of %s\n"),
loc_string, sec_name, obj_name);
else
if (pc_in_unmapped_range (addr, osect))
if (section_is_overlay (osect))
printf_filtered (_("%s in load address range of %s overlay "
"section %s\n"),
loc_string, mapped, sec_name);
else
printf_filtered
(_("%s in load address range of section %s\n"),
loc_string, sec_name);
else
if (section_is_overlay (osect))
printf_filtered (_("%s in %s overlay section %s\n"),
loc_string, mapped, sec_name);
else
printf_filtered (_("%s in section %s\n"),
loc_string, sec_name);
}
else
loc_string = msym_name;
gdb_assert (osect->objfile && objfile_name (osect->objfile));
obj_name = objfile_name (osect->objfile);
if (MULTI_OBJFILE_P ())
if (pc_in_unmapped_range (addr, osect))
if (section_is_overlay (osect))
printf_filtered (_("%s in load address range of "
"%s overlay section %s of %s\n"),
loc_string, mapped, sec_name, obj_name);
else
printf_filtered (_("%s in load address range of "
"section %s of %s\n"),
loc_string, sec_name, obj_name);
else
if (section_is_overlay (osect))
printf_filtered (_("%s in %s overlay section %s of %s\n"),
loc_string, mapped, sec_name, obj_name);
else
printf_filtered (_("%s in section %s of %s\n"),
loc_string, sec_name, obj_name);
else
if (pc_in_unmapped_range (addr, osect))
if (section_is_overlay (osect))
printf_filtered (_("%s in load address range of %s overlay "
"section %s\n"),
loc_string, mapped, sec_name);
else
printf_filtered (_("%s in load address range of section %s\n"),
loc_string, sec_name);
else
if (section_is_overlay (osect))
printf_filtered (_("%s in %s overlay section %s\n"),
loc_string, mapped, sec_name);
else
printf_filtered (_("%s in section %s\n"),
loc_string, sec_name);
}
}
if (matches == 0)
printf_filtered (_("No symbol matches %s.\n"), arg);
}

View File

@ -1883,11 +1883,10 @@ spu_overlay_update (struct obj_section *osect)
/* All sections. */
else
{
struct objfile *objfile;
ALL_OBJSECTIONS (objfile, osect)
if (section_is_overlay (osect))
spu_overlay_update_osect (osect);
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (section_is_overlay (osect))
spu_overlay_update_osect (osect);
}
}

View File

@ -2988,12 +2988,12 @@ section_is_overlay (struct obj_section *section)
static void
overlay_invalidate_all (void)
{
struct objfile *objfile;
struct obj_section *sect;
ALL_OBJSECTIONS (objfile, sect)
if (section_is_overlay (sect))
sect->ovly_mapped = -1;
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, sect)
if (section_is_overlay (sect))
sect->ovly_mapped = -1;
}
/* Function: section_is_mapped (SECTION)
@ -3164,24 +3164,24 @@ symbol_overlayed_address (CORE_ADDR address, struct obj_section *section)
struct obj_section *
find_pc_overlay (CORE_ADDR pc)
{
struct objfile *objfile;
struct obj_section *osect, *best_match = NULL;
if (overlay_debugging)
{
ALL_OBJSECTIONS (objfile, osect)
if (section_is_overlay (osect))
{
if (pc_in_mapped_range (pc, osect))
{
if (section_is_mapped (osect))
return osect;
else
best_match = osect;
}
else if (pc_in_unmapped_range (pc, osect))
best_match = osect;
}
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (section_is_overlay (osect))
{
if (pc_in_mapped_range (pc, osect))
{
if (section_is_mapped (osect))
return osect;
else
best_match = osect;
}
else if (pc_in_unmapped_range (pc, osect))
best_match = osect;
}
}
return best_match;
}
@ -3193,14 +3193,14 @@ find_pc_overlay (CORE_ADDR pc)
struct obj_section *
find_pc_mapped_section (CORE_ADDR pc)
{
struct objfile *objfile;
struct obj_section *osect;
if (overlay_debugging)
{
ALL_OBJSECTIONS (objfile, osect)
if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
return osect;
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
return osect;
}
return NULL;
@ -3213,36 +3213,36 @@ static void
list_overlays_command (const char *args, int from_tty)
{
int nmapped = 0;
struct objfile *objfile;
struct obj_section *osect;
if (overlay_debugging)
{
ALL_OBJSECTIONS (objfile, osect)
if (section_is_mapped (osect))
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const char *name;
bfd_vma lma, vma;
int size;
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (section_is_mapped (osect))
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const char *name;
bfd_vma lma, vma;
int size;
vma = bfd_section_vma (objfile->obfd, osect->the_bfd_section);
lma = bfd_section_lma (objfile->obfd, osect->the_bfd_section);
size = bfd_get_section_size (osect->the_bfd_section);
name = bfd_section_name (objfile->obfd, osect->the_bfd_section);
vma = bfd_section_vma (objfile->obfd, osect->the_bfd_section);
lma = bfd_section_lma (objfile->obfd, osect->the_bfd_section);
size = bfd_get_section_size (osect->the_bfd_section);
name = bfd_section_name (objfile->obfd, osect->the_bfd_section);
printf_filtered ("Section %s, loaded at ", name);
fputs_filtered (paddress (gdbarch, lma), gdb_stdout);
puts_filtered (" - ");
fputs_filtered (paddress (gdbarch, lma + size), gdb_stdout);
printf_filtered (", mapped at ");
fputs_filtered (paddress (gdbarch, vma), gdb_stdout);
puts_filtered (" - ");
fputs_filtered (paddress (gdbarch, vma + size), gdb_stdout);
puts_filtered ("\n");
printf_filtered ("Section %s, loaded at ", name);
fputs_filtered (paddress (gdbarch, lma), gdb_stdout);
puts_filtered (" - ");
fputs_filtered (paddress (gdbarch, lma + size), gdb_stdout);
printf_filtered (", mapped at ");
fputs_filtered (paddress (gdbarch, vma), gdb_stdout);
puts_filtered (" - ");
fputs_filtered (paddress (gdbarch, vma + size), gdb_stdout);
puts_filtered ("\n");
nmapped++;
}
nmapped++;
}
}
if (nmapped == 0)
printf_filtered (_("No sections are mapped.\n"));
@ -3254,7 +3254,6 @@ list_overlays_command (const char *args, int from_tty)
static void
map_overlay_command (const char *args, int from_tty)
{
struct objfile *objfile, *objfile2;
struct obj_section *sec, *sec2;
if (!overlay_debugging)
@ -3266,29 +3265,33 @@ map_overlay_command (const char *args, int from_tty)
error (_("Argument required: name of an overlay section"));
/* First, find a section matching the user supplied argument. */
ALL_OBJSECTIONS (objfile, sec)
if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
{
/* Now, check to see if the section is an overlay. */
if (!section_is_overlay (sec))
continue; /* not an overlay section */
/* Mark the overlay as "mapped". */
sec->ovly_mapped = 1;
/* Next, make a pass and unmap any sections that are
overlapped by this new section: */
ALL_OBJSECTIONS (objfile2, sec2)
if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec, sec2))
for (objfile *obj_file : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (obj_file, sec)
if (!strcmp (bfd_section_name (obj_file->obfd, sec->the_bfd_section),
args))
{
if (info_verbose)
printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
bfd_section_name (objfile->obfd,
sec2->the_bfd_section));
sec2->ovly_mapped = 0; /* sec2 overlaps sec: unmap sec2. */
/* Now, check to see if the section is an overlay. */
if (!section_is_overlay (sec))
continue; /* not an overlay section */
/* Mark the overlay as "mapped". */
sec->ovly_mapped = 1;
/* Next, make a pass and unmap any sections that are
overlapped by this new section: */
for (objfile *objfile2 : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile2, sec2)
if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec,
sec2))
{
if (info_verbose)
printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
bfd_section_name (obj_file->obfd,
sec2->the_bfd_section));
sec2->ovly_mapped = 0; /* sec2 overlaps sec: unmap sec2. */
}
return;
}
return;
}
error (_("No overlay section called %s"), args);
}
@ -3299,7 +3302,6 @@ map_overlay_command (const char *args, int from_tty)
static void
unmap_overlay_command (const char *args, int from_tty)
{
struct objfile *objfile;
struct obj_section *sec = NULL;
if (!overlay_debugging)
@ -3311,14 +3313,15 @@ unmap_overlay_command (const char *args, int from_tty)
error (_("Argument required: name of an overlay section"));
/* First, find a section matching the user supplied argument. */
ALL_OBJSECTIONS (objfile, sec)
if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
{
if (!sec->ovly_mapped)
error (_("Section %s is not mapped"), args);
sec->ovly_mapped = 0;
return;
}
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, sec)
if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
{
if (!sec->ovly_mapped)
error (_("Section %s is not mapped"), args);
sec->ovly_mapped = 0;
return;
}
error (_("No overlay section called %s"), args);
}
@ -3550,8 +3553,6 @@ simple_overlay_update_1 (struct obj_section *osect)
void
simple_overlay_update (struct obj_section *osect)
{
struct objfile *objfile;
/* Were we given an osect to look up? NULL means do all of them. */
if (osect)
/* Have we got a cached copy of the target's overlay table? */
@ -3583,20 +3584,21 @@ simple_overlay_update (struct obj_section *osect)
return;
/* Now may as well update all sections, even if only one was requested. */
ALL_OBJSECTIONS (objfile, osect)
if (section_is_overlay (osect))
{
int i;
asection *bsect = osect->the_bfd_section;
for (objfile *objfile : all_objfiles (current_program_space))
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (section_is_overlay (osect))
{
int i;
asection *bsect = osect->the_bfd_section;
for (i = 0; i < cache_novlys; i++)
if (cache_ovly_table[i][VMA] == bfd_section_vma (obfd, bsect)
&& cache_ovly_table[i][LMA] == bfd_section_lma (obfd, bsect))
{ /* obj_section matches i'th entry in ovly_table. */
osect->ovly_mapped = cache_ovly_table[i][MAPPED];
break; /* finished with inner for loop: break out. */
}
}
for (i = 0; i < cache_novlys; i++)
if (cache_ovly_table[i][VMA] == bfd_section_vma (obfd, bsect)
&& cache_ovly_table[i][LMA] == bfd_section_lma (obfd, bsect))
{ /* obj_section matches i'th entry in ovly_table. */
osect->ovly_mapped = cache_ovly_table[i][MAPPED];
break; /* finished with inner for loop: break out. */
}
}
}
/* Set the output sections and output offsets for section SECTP in