Bug 17854 - Nothing sets pspace_data->sym_cache?
Summary: Nothing sets pspace_data->sym_cache?
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: ada (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 17853 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-01-18 04:44 UTC by Doug Evans
Modified: 2015-02-02 04:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Evans 2015-01-18 04:44:55 UTC
I think there's a bug in cache invalidation, but my testcase isn't exposing it.
That got me digging into the implementation of ada-lang.c's symbol lookup cache.

It looks like nothing sets pspace_data->sym_cache.

Presumably, it should be set here.

static struct ada_symbol_cache *
ada_get_symbol_cache (struct program_space *pspace)
{
  struct ada_pspace_data *pspace_data = get_ada_pspace_data (pspace);
  struct ada_symbol_cache *sym_cache = pspace_data->sym_cache;

  if (sym_cache == NULL)
    {
      sym_cache = XCNEW (struct ada_symbol_cache);
      ada_init_symbol_cache (sym_cache);
    }

  return sym_cache;
}

Could be missing something though.
Comment 1 Doug Evans 2015-01-18 04:53:58 UTC
PR 17855 describes the cache invalidation bug.
Comment 2 Doug Evans 2015-01-18 05:04:16 UTC
While we're fixing this,
ada_clear_symbol_cache could first check whether there is a cache.
This would save creating one when debugging non-ada programs.
Plus, after fixing this bug I see ada_clear_symbol_cache create
the cache only to free it and recreate it.
Comment 3 Doug Evans 2015-01-18 07:25:46 UTC
*** Bug 17853 has been marked as a duplicate of this bug. ***
Comment 4 cvs-commit@gcc.gnu.org 2015-02-02 03:32:15 UTC
The master branch has been updated by Joel Brobecker <brobecke@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=66c168ae56fa2d67f821ccae774fd25c695fd9ce

commit 66c168ae56fa2d67f821ccae774fd25c695fd9ce
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Mon Feb 2 07:20:58 2015 +0400

    [Ada] pspace_data->sym_cache is always NULL
    
    The Ada symbol cache has been designed to have one instance of that
    of that cache per program space, and for each instance to be created
    on-demand. ada_get_symbol_cache is the function responsible for both
    lookup and creation on demand.
    
    Unfortunately, ada_get_symbol_cache forgot to store the reference
    to newly created caches, thus causing it to:
      - Leak old caches;
      - Allocate a new cache each time the cache is being searched or
        a new entry is to be inserted.
    
    This patch fixes the issue by avoiding the use of the local variable,
    which indirectly allowed the bug to happen. We manipulate the reference
    in the program-space data instead.
    
    gdb/ChangeLog:
    
            PR gdb/17854:
            * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache
            when allocating a new one.
Comment 5 cvs-commit@gcc.gnu.org 2015-02-02 03:40:40 UTC
The gdb-7.9-branch branch has been updated by Joel Brobecker <brobecke@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=19a5737950b966d0ff3e50c01bb43742a870bb9e

commit 19a5737950b966d0ff3e50c01bb43742a870bb9e
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Mon Feb 2 07:20:58 2015 +0400

    [Ada] pspace_data->sym_cache is always NULL
    
    The Ada symbol cache has been designed to have one instance of that
    of that cache per program space, and for each instance to be created
    on-demand. ada_get_symbol_cache is the function responsible for both
    lookup and creation on demand.
    
    Unfortunately, ada_get_symbol_cache forgot to store the reference
    to newly created caches, thus causing it to:
      - Leak old caches;
      - Allocate a new cache each time the cache is being searched or
        a new entry is to be inserted.
    
    This patch fixes the issue by avoiding the use of the local variable,
    which indirectly allowed the bug to happen. We manipulate the reference
    in the program-space data instead.
    
    gdb/ChangeLog:
    
            PR gdb/17854:
            * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache
            when allocating a new one.
Comment 6 Joel Brobecker 2015-02-02 04:22:08 UTC
Fixed.