2003-10-23 Michal Ludvig * symtab.c (choose_better_psymab): New function. (find_pc_sect_psymtab): Instead of returning first matching psymtab choose the most specific one. Index: symtab.c =================================================================== RCS file: /cvs/src/src/gdb/symtab.c,v retrieving revision 1.113.4.1 diff -u -p -r1.113.4.1 symtab.c --- symtab.c 8 Aug 2003 14:06:26 -0000 1.113.4.1 +++ symtab.c 20 Oct 2003 09:56:31 -0000 @@ -673,13 +673,63 @@ init_sal (struct symtab_and_line *sal) } +/* Return psymtab with more specific address range. */ + +static inline struct partial_symtab * +choose_better_psymab (CORE_ADDR pc, struct partial_symtab *pst1, + struct partial_symtab *pst2) +{ + if (pst1 == NULL) + return pst2; + + if (pst2 == NULL) + return pst1; + + if ((pst1->texthigh - pst1->textlow) > (pst2->texthigh - pst2->textlow)) + { + static CORE_ADDR last_pc = 0; + + if (pc != last_pc && info_verbose) + { + char *objname[2]; + struct partial_symtab *pst[2] = { pst1, pst2 }; + int i; + + for (i = 0; i < 2; i++) + { + if (pst[i]->objfile) + objname[i] = strrchr (pst[i]->objfile->name, '/') + ? strrchr (pst[i]->objfile->name, '/') + 1 + : pst[i]->objfile->name; + else + objname[i] = ""; + } + + printf_unfiltered ("More symtabs for PC=0x%lx found:\n" + "\tIgnoring %s (%s) PC=0x%lx...0x%lx\n" + "\tChoosing %s (%s) PC=0x%lx...0x%lx\n", + (unsigned long) pc, + pst1->filename, objname[0], + (unsigned long) pst1->textlow, + (unsigned long) pst1->texthigh, + pst2->filename, objname[1], + (unsigned long) pst2->textlow, + (unsigned long) pst2->texthigh); + + last_pc = pc; + } + return pst2; + } + else + return pst1; +} /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */ struct partial_symtab * find_pc_sect_psymtab (CORE_ADDR pc, asection *section) { - struct partial_symtab *pst; + struct partial_symtab *pst, *result = NULL; struct objfile *objfile; struct minimal_symbol *msymbol; @@ -707,10 +757,16 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec function containing the PC. */ if (!(objfile->flags & OBJF_REORDERED) && section == 0) /* can't validate section this way */ - return (pst); + { + result = choose_better_psymab (pc, result, pst); + continue; + } if (msymbol == NULL) - return (pst); + { + result = choose_better_psymab (pc, result, pst); + continue; + } for (tpst = pst; tpst != NULL; tpst = tpst->next) { @@ -722,13 +778,17 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec if (p != NULL && SYMBOL_VALUE_ADDRESS (p) == SYMBOL_VALUE_ADDRESS (msymbol)) - return (tpst); + { + result = choose_better_psymab (pc, result, tpst); + } } } - return (pst); + + result = choose_better_psymab (pc, result, pst); } } - return (NULL); + + return (result); } /* Find which partial symtab contains PC. Return 0 if none.