]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/ada-lang.c
[Ada] psymbol search failure due to comparison function discrepancy
authorJoel Brobecker <brobecker@gnat.com>
Tue, 8 Oct 2013 11:18:58 +0000 (11:18 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Tue, 8 Oct 2013 11:18:58 +0000 (11:18 +0000)
commitdb230ce3ff2cd460bbd1c9f99bcf92d85fa17773
treee925228601a69dccee9db530e81439cec1e765e2
parent6501c98a131de1dca595314ace78d79e50aee4d3
[Ada] psymbol search failure due to comparison function discrepancy

Upon trying to print the value of a variant record, a user noticed
the following problem:

        (gdb) print rt
        warning: Unknown upper bound, using 1.
        warning: Unknown upper bound, using 1.
        $1 = (a => ((a1 => (4), a2 => (4)), (a1 => (8), a2 => (8))))

The expected output is:

        (gdb) print rt
        $1 = (a => ((a1 => (4, 4), a2 => (8, 8)), (a1 => (4, 4),
              a2 => (8, 8))))

The problems comes from the fact that components "a1" and "a2" are
defined as arrays whose upper bound is dynamic.  To determine the value
of that upper bound, GDB relies on the GNAT encoding and searches
for the parallel ___U variable.  Unfortunately, the search fails
while doing a binary search inside the partial symtab of the unit
where the array and its bound (and therefore the parallel ___U variable)
are defined.

It fails because partial symbols are sorted using strcmp_iw_ordered,
while Ada symbol lookups are performed using a different comparison
function (ada-lang.c:compare_names). The two functions are supposed
to be compatible, but a change performed in April 2011 modified
strcmp_iw_ordered, introducing case-sensitivity issues. As a result,
the two functions would now disagree when passed the following
two arguments:

  string1="common__inner_arr___SIZE_A_UNIT"
  string2="common__inner_arr__T4s___U"

The difference starts at "_SIZE_A_UNIT" vs "T4s___U". So, it's mostly
a matter of comparing '_' with 'T'.

On the one hand, strcmp_iw_ordered would return -1, while compare_names
returned 11. The change that made all the difference is that
strcmp_iw_ordered now performs a case-insensitive comparison,
and only resorts to case-sentitive comparison if the first comparison
finds an equality. This changes everything, because while 'T' (84)
and 't' (116) are on opposite sides of '_' (95).

This patch aims at restoring the compatibility between the two
functions, by adding case-sensitivity handling in the Ada comparison
function.

gdb/ChangeLog:

        * ada-lang.c (compare_names_with_case): Renamed from
        compare_names, adding a new parameter "casing" and its handling.
        New function documentation.
        (compare_names): New function, implemented using
        compare_names_with_case.
gdb/ChangeLog
gdb/ada-lang.c