[Ada] Do not cache lookup result if not full_search
authorJoel Brobecker <brobecker@gnat.com>
Wed, 29 Feb 2012 19:35:37 +0000 (19:35 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Wed, 29 Feb 2012 19:35:37 +0000 (19:35 +0000)
commit2ad01556c70780fe89eb7a7cc6e669de34a4b770
tree89d221ccb334c8d663065a203fc632a50430e8b6
parent99b1c762c990c8488c70ad537412f1209b5610bd
[Ada] Do not cache lookup result if not full_search

The ada_lookup_symbol_list function has recently been changed to accept
a "full_search" parameter. When null, this parameter instructs the
function to perform a partial search (global and static symbols are not
searched). When doing a partial search, the result should not be saved
into the lookup cache, as the result might be incomplete.

This manifested itself when trying to perform a function call on AVR
after having inserted a breakpoint inside that function:

    (gdb) b same
    Breakpoint 2 at 0x78: file r.adb, line 5.
    (gdb) call same(42)

    Breakpoint 2, r.same (i=42) at r.adb:5
    5             return I;
    The program being debugged stopped while in a function called from GDB.
    Evaluation of the expression containing the function
    (at 0x0x800068) will be abandoned.
    ^^^^^^^^^^^^^^^
    When the function is done executing, GDB will silently stop.

The expected output for the underlined portion is "(r.same)".

What happens is that the breakpoint command triggers 3 lookups of the
name "same":
  1. full search in LABEL_DOMAIN -> no match, cached;
  2. full search in VAR_DOMAIN -> 1 match, cached;
  3. partial search in VAR_DOMAIN -> no match, cached.

The third lookup therefore causes the results of the partial search
to be cached, thus overriding the result of the full search lookup.

During the following command, the reference to "same" triggers a lookup
of that symbol again. And since GDB CAN find the result of that lookup
in the cache, it returns just that, which is: No match. (wrong!)

As a result, we fallback on the symbol table to resolve the lookup.
And instead of pushing an OP_VAR_VALUE subexpression for symbol "same",
the parser ends up pushing an UNOP_MEMVAL subexpression using the value
of the minimal symbol. This is where being on AVR becomes important:
addresses on AVR are modular types, and if GDB thinks an address is
a data address, it converts it.

This is where one notices the fact that the breakpoint was inserted
at 0x78, and yet GDB says that the function we stopped at is at
0x0x800068...

This patch fixes the problem by making sure we only cache the result
of full searches.

gdb/ChangeLog:

        * ada-lang.c (ada_lookup_symbol_list): Only cache the result of
        full searches.
gdb/ChangeLog
gdb/ada-lang.c