[PATCH] gdb script performance
Jim Blandy
jimb@codesourcery.com
Thu Nov 30 01:04:00 GMT 2006
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.
More information about the Gdb-patches
mailing list