Re: [patch] Speed up find_pc_section

Paul Pluzhnikov
2009-09-10T16:18:37Z

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

On Tue, Sep 8, 2009 at 10:38 PM, Joel Brobecker<brobecker@adacore.com> wrote:

> Otherwise, the patch seems fine. I would love some input from Ulrich,
> though.

Thanks for the review. Attached patch implements your suggestions.
--
Paul Pluzhnikov

2009-09-10 Paul Pluzhnikov <ppluzhnikov@google.com>

*minsyms.c (lookup_minimal_symbol_by_pc_section_1): Assert non-NULL
section.
(lookup_minimal_symbol_by_pc_section): Check for NULL section.
(lookup_minimal_symbol_by_pc): Adjust.

[-- Attachment #2: gdb-overlay-fix-20090910.txt --]
[-- Type: text/plain, Size: 4135 bytes --]

Index: minsyms.c
===================================================================
RCS file: /cvs/src/src/gdb/minsyms.c,v
retrieving revision 1.66
diff -u -p -u -r1.66 minsyms.c
--- minsyms.c 28 Jun 2009 00:20:22 -0000 1.66
+++ minsyms.c 10 Sep 2009 16:17:13 -0000
@@ -434,13 +434,14 @@ lookup_minimal_symbol_solib_trampoline (

/* Search through the minimal symbol table for each objfile and find
the symbol whose address is the largest address that is still less
- than or equal to PC, and matches SECTION (if non-NULL). Returns a
- pointer to the minimal symbol if such a symbol is found, or NULL if
- PC is not in a suitable range. Note that we need to look through
- ALL the minimal symbol tables before deciding on the symbol that
- comes closest to the specified PC. This is because objfiles can
- overlap, for example objfile A has .text at 0x100 and .data at
- 0x40000 and objfile B has .text at 0x234 and .data at 0x40048.
+ than or equal to PC, and matches SECTION (which is not NULL).
+ Returns a pointer to the minimal symbol if such a symbol is found,
+ or NULL if PC is not in a suitable range.
+ Note that we need to look through ALL the minimal symbol tables
+ before deciding on the symbol that comes closest to the specified PC.
+ This is because objfiles can overlap, for example objfile A has .text
+ at 0x100 and .data at 0x40000 and objfile B has .text at 0x234 and
+ .data at 0x40048.

If WANT_TRAMPOLINE is set, prefer mst_solib_trampoline symbols when
there are text and trampoline symbols at the same address.
@@ -457,20 +458,12 @@ lookup_minimal_symbol_by_pc_section_1 (C
struct objfile *objfile;
struct minimal_symbol *msymbol;
struct minimal_symbol *best_symbol = NULL;
- struct obj_section *pc_section;
enum minimal_symbol_type want_type, other_type;

want_type = want_trampoline ? mst_solib_trampoline : mst_text;
other_type = want_trampoline ? mst_text : mst_solib_trampoline;
-
- /* PC has to be in a known section. This ensures that anything
- beyond the end of the last segment doesn't appear to be part of
- the last function in the last segment. */
- pc_section = find_pc_section (pc);
- if (pc_section == NULL)
- return NULL;

- /* We can not require the symbol found to be in pc_section, because
+ /* We can not require the symbol found to be in section, because
e.g. IRIX 6.5 mdebug relies on this code returning an absolute
symbol - but find_pc_section won't return an absolute section and
hence the code below would skip over absolute symbols. We can
@@ -479,7 +472,8 @@ lookup_minimal_symbol_by_pc_section_1 (C
files, search both the file and its separate debug file. There's
no telling which one will have the minimal symbols. */

- objfile = pc_section->objfile;
+ gdb_assert (section != NULL);
+ objfile = section->objfile;
if (objfile->separate_debug_objfile)
objfile = objfile->separate_debug_objfile;

@@ -680,6 +674,15 @@ lookup_minimal_symbol_by_pc_section_1 (C
struct minimal_symbol *
lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, struct obj_section *section)
{
+ if (section == NULL)
+ {
+ /* NOTE: cagney/2004-01-27: This was using find_pc_mapped_section to
+ force the section but that (well unless you're doing overlay
+ debugging) always returns NULL making the call somewhat useless. */
+ section = find_pc_section (pc);
+ if (section == NULL)
+ return NULL;
+ }
return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0);
}

@@ -689,13 +692,7 @@ lookup_minimal_symbol_by_pc_section (COR
struct minimal_symbol *
lookup_minimal_symbol_by_pc (CORE_ADDR pc)
{
- /* NOTE: cagney/2004-01-27: This was using find_pc_mapped_section to
- force the section but that (well unless you're doing overlay
- debugging) always returns NULL making the call somewhat useless. */
- struct obj_section *section = find_pc_section (pc);
- if (section == NULL)
- return NULL;
- return lookup_minimal_symbol_by_pc_section (pc, section);
+ return lookup_minimal_symbol_by_pc_section (pc, NULL);
}
\f