This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gdb script performance


Jean-Marc Saffroy <saffroy@gmail.com> writes:
> Index: gdb-6.5-prof/gdb/symtab.c
> ===================================================================
> --- gdb-6.5-prof.orig/gdb/symtab.c	2006-11-29 03:27:18.000000000 +0100
> +++ gdb-6.5-prof/gdb/symtab.c	2006-11-29 03:27:20.000000000 +0100
> @@ -2022,8 +2022,8 @@
>  /* Find the symtab associated with PC and SECTION.  Look through the
>     psymtabs and read in another symtab if necessary. */
>
> -struct symtab *
> -find_pc_sect_symtab (CORE_ADDR pc, asection *section)
> +static struct symtab *
> +find_pc_sect_symtab_uncached (CORE_ADDR pc, asection *section)
>  {
>    struct block *b;
>    struct blockvector *bv;
> @@ -2123,6 +2123,24 @@
>    return (s);
>  }
>
> +struct symtab *
> +find_pc_sect_symtab (CORE_ADDR pc, asection *section)
> +{
> +  static CORE_ADDR cached_pc;
> +  static asection *cached_section;
> +  static struct symtab *cached_symtab;
> +  static int try_cache = 0;
> +
> +  if (try_cache && (cached_pc == pc) && (cached_section == section))
> +    return cached_symtab;
> +
> +  try_cache = 1;
> +  cached_pc = pc;
> +  cached_section = section;
> +  cached_symtab = find_pc_sect_symtab_uncached (pc, section);
> +  return cached_symtab;
> +}
> +
>  /* Find the symtab associated with PC.  Look through the psymtabs and
>     read in another symtab if necessary.  Backward compatibility, no section */

When the user changes the symbol file (or when GDB notices it has
changed and automatically re-reads it), the section and symtab objects
your static variables are pointing to will be freed.  If you then get
a spurious cache hit, you'll hand out a pointer to garbage.  So you'll
need to invalidate the cache whenever the section or symtab get freed.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]