Re: [patch] Speed up find_pc_section

Paul Pluzhnikov
2009-08-20T20:40:26Z

[-- Attachment #1: Type: text/plain, Size: 1450 bytes --]

On Thu, Aug 20, 2009 at 11:22 AM, Ulrich Weigand<uweigand@de.ibm.com> wrote:

> Unfortunately, this doesn't help. ...
> If you want to remove *all* overlay sections, mapped or not, you

Yes.

> could attempt to use "section_is_overlay" instead.  But that won't
> work either -- all the overlay routines have a shortcut that says
> "no" to all such questions before the user actually enabled overlay
> support.  This means that when loading a binary with overlays,
> you still crash at the assertion before the user even has the
> chance to give the "overlay auto" command.

Right. Here is an updated patch ...

> It used to be the case that you could debug -to some extent- binaries
> with overlays even in "overlay off" mode, e.g. because GDB does not
> support the particular overlay manager.  I think this should be preserved;
> at least GDB should not run into assertion failures just because section
> addresses overlap ...

I believe the crash at load should be gone now, and some debugging will
be possible, though find_pc_section will fail to find any overlay section
which find_pc_mapped_section doesn't find. I think that's still better
than what GDB was doing before under these conditions: finding a "random"
overlapping overlay section.

Thanks,
--
Paul Pluzhnikov

2009-08-20 Paul Pluzhnikov <ppluzhnikov@google.com>

*objfiles.c (insert_section_p): New function.
(update_section_map): Call it.

[-- Attachment #2: gdb-find_pc_section-20090820-2.txt --]
[-- Type: text/plain, Size: 1692 bytes --]

Index: objfiles.c
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.c,v
retrieving revision 1.92
diff -u -p -u -r1.92 objfiles.c
--- objfiles.c 17 Aug 2009 11:16:13 -0000 1.92
+++ objfiles.c 20 Aug 2009 20:37:22 -0000
@@ -823,6 +823,24 @@ preferred_obj_section (struct obj_sectio
return b;
}

+/* Return 1 if SECTION should be inserted into the section map.
+ We want to insert only non-overlay and non-TLS section. */
+
+static int
+insert_section_p (const struct bfd *abfd,
+ const struct bfd_section *section)
+{
+ const bfd_vma lma = bfd_section_lma (abfd, section);
+
+ if (lma != 0 && lma != bfd_section_vma (abfd, section))
+ /* This is an overlay section. */
+ return 0;
+ if ((bfd_get_section_flags (abfd, section) & SEC_THREAD_LOCAL) != 0)
+ return 0;
+
+ return 1;
+}
+
/* Update PMAP, PMAP_SIZE with non-TLS sections from all objfiles. */

static void
@@ -837,24 +855,18 @@ update_section_map (struct obj_section *
map = *pmap;
xfree (map);

-#define insert_p(objf, sec) \
- ((bfd_get_section_flags ((objf)->obfd, (sec)->the_bfd_section) \
- & SEC_THREAD_LOCAL) == 0)
-
map_size = 0;
ALL_OBJSECTIONS (objfile, s)
- if (insert_p (objfile, s))
+ if (insert_section_p (objfile->obfd, s->the_bfd_section))
map_size += 1;

map = xmalloc (map_size * sizeof (*map));

i = 0;
ALL_OBJSECTIONS (objfile, s)
- if (insert_p (objfile, s))
+ if (insert_section_p (objfile->obfd, s->the_bfd_section))
map[i++] = s;

-#undef insert_p
-
qsort (map, map_size, sizeof (*map), qsort_cmp);

/* With separate debuginfo files, we may have up to two (almost)