From: Joel Brobecker Date: Tue, 8 Oct 2013 11:18:58 +0000 (+0000) Subject: [Ada] psymbol search failure due to comparison function discrepancy X-Git-Tag: binutils_latest_snapshot~127 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db230ce3ff2cd460bbd1c9f99bcf92d85fa17773;p=external%2Fbinutils.git [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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0f461ed..de5db77 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2013-10-08 Joel Brobecker + * 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. + +2013-10-08 Joel Brobecker + * ada-lang.c (ada_exception_sal): Remove advance declaration. 2013-10-07 Tom Tromey diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 1429b4f..9ebc851 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4982,23 +4982,37 @@ aux_add_nonlocal_symbols (struct block *block, struct symbol *sym, void *data0) return 0; } -/* Compare STRING1 to STRING2, with results as for strcmp. - Compatible with strcmp_iw in that strcmp_iw (STRING1, STRING2) <= 0 - implies compare_names (STRING1, STRING2) (they may differ as to - what symbols compare equal). */ +/* Implements compare_names, but only applying the comparision using + the given CASING. */ static int -compare_names (const char *string1, const char *string2) +compare_names_with_case (const char *string1, const char *string2, + enum case_sensitivity casing) { while (*string1 != '\0' && *string2 != '\0') { + char c1, c2; + if (isspace (*string1) || isspace (*string2)) return strcmp_iw_ordered (string1, string2); - if (*string1 != *string2) + + if (casing == case_sensitive_off) + { + c1 = tolower (*string1); + c2 = tolower (*string2); + } + else + { + c1 = *string1; + c2 = *string2; + } + if (c1 != c2) break; + string1 += 1; string2 += 1; } + switch (*string1) { case '(': @@ -5016,10 +5030,43 @@ compare_names (const char *string1, const char *string2) if (*string2 == '(') return strcmp_iw_ordered (string1, string2); else - return *string1 - *string2; + { + if (casing == case_sensitive_off) + return tolower (*string1) - tolower (*string2); + else + return *string1 - *string2; + } } } +/* Compare STRING1 to STRING2, with results as for strcmp. + Compatible with strcmp_iw_ordered in that... + + strcmp_iw_ordered (STRING1, STRING2) <= 0 + + ... implies... + + compare_names (STRING1, STRING2) <= 0 + + (they may differ as to what symbols compare equal). */ + +static int +compare_names (const char *string1, const char *string2) +{ + int result; + + /* Similar to what strcmp_iw_ordered does, we need to perform + a case-insensitive comparison first, and only resort to + a second, case-sensitive, comparison if the first one was + not sufficient to differentiate the two strings. */ + + result = compare_names_with_case (string1, string2, case_sensitive_off); + if (result == 0) + result = compare_names_with_case (string1, string2, case_sensitive_on); + + return result; +} + /* Add to OBSTACKP all non-local symbols whose name and domain match NAME and DOMAIN respectively. The search is performed on GLOBAL_BLOCK symbols if GLOBAL is non-zero, or on STATIC_BLOCK symbols otherwise. */