This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Pascal and case sensitivity
- From: Joost van der Sluis <joost at cnoc dot nl>
- To: gdb at sourceware dot org
- Date: Mon, 10 Jan 2011 21:00:25 +0100
- Subject: Pascal and case sensitivity
Hi all,
Attached is patch to fix case-sensitivity issues with Pascal. It first
searches case-sensitive an if an identifier isn't found, a
case-insensitive search is performed.
But this path is quite messy it can be cleaned up somewhat, but it will
never win the 'most beautiful patch' contest. ;)
Would it be acceptable to make the hash (msymbol_hash_iw or dict_hash)
case insensitive by adding a to_lower, and to change strcmp_iw so that
it does a case-insensitive compare when some case-insensitivity setting
is set?
Regards,
Joost.
diff --git a/gdb/dictionary.c b/gdb/dictionary.c
index 9d53ff0..8a04921 100644
--- a/gdb/dictionary.c
+++ b/gdb/dictionary.c
@@ -27,6 +27,7 @@
#include "buildsym.h"
#include "gdb_assert.h"
#include "dictionary.h"
+#include "language.h"
/* This file implements dictionaries, which are tables that associate
symbols to names. They are represented by an opaque type 'struct
@@ -665,11 +666,20 @@ iter_match_first_hashed (const struct dictionary *dict,
sym = sym->hash_next)
{
/* Warning: the order of arguments to compare matters! */
- if (compare (SYMBOL_SEARCH_NAME (sym), name) == 0)
- {
- break;
- }
-
+ if ((current_language->la_language == language_pascal) && (performing_case_sensitive_search == 1) && (original_search_name))
+ {
+ if (compare (SYMBOL_NATURAL_NAME (sym), original_search_name) == 0)
+ {
+ break;
+ }
+ }
+ else
+ {
+ if (compare (SYMBOL_SEARCH_NAME (sym), name) == 0)
+ {
+ break;
+ }
+ }
}
DICT_ITERATOR_CURRENT (iterator) = sym;
diff --git a/gdb/dictionary.h b/gdb/dictionary.h
index f7d3035..3476a41 100644
--- a/gdb/dictionary.h
+++ b/gdb/dictionary.h
@@ -177,3 +177,7 @@ extern int dict_size (const struct dictionary *dict);
(sym) = dict_iterator_next (&(iter)))
#endif /* DICTIONARY_H */
+
+int performing_case_sensitive_search;
+char *original_search_name;
+
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 19f5ceb..706205f 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -52,6 +52,7 @@
#include "parser-defs.h"
#include "language.h"
#include "p-lang.h"
+#include "dictionary.h"
#include "bfd.h" /* Required by objfiles.h. */
#include "symfile.h" /* Required by objfiles.h. */
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
@@ -1445,8 +1446,23 @@ yylex ()
if (is_a_field)
sym = NULL;
else
- sym = lookup_symbol (tmp, expression_context_block,
- VAR_DOMAIN, &is_a_field_of_this);
+ {
+ original_search_name = malloc(100);
+ strcpy (original_search_name,tmp);
+ for (i = 0; i <= namelen; i++)
+ tmp[i] = tolower (tmp[i]);
+
+ performing_case_sensitive_search = 1;
+ sym = lookup_symbol (tmp, expression_context_block,
+ VAR_DOMAIN, &is_a_field_of_this);
+ free(original_search_name);
+ performing_case_sensitive_search = 0;
+ if (!sym)
+ {
+ sym = lookup_symbol (tmp, expression_context_block,
+ VAR_DOMAIN, &is_a_field_of_this);
+ }
+ }
/* second chance uppercased (as Free Pascal does). */
if (!sym && !is_a_field_of_this && !is_a_field)
{
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 9d577b0..135269f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -372,6 +372,10 @@ symbol_set_demangled_name (struct general_symbol_info *gsymbol,
gsymbol->language_specific.cplus_specific->demangled_name = name;
}
+ else if (gsymbol->language == language_pascal)
+ {
+ gsymbol->language_specific.pascal_specific.lowercase_name = NULL;
+ }
else
gsymbol->language_specific.mangled_lang.demangled_name = name;
}
@@ -594,6 +598,28 @@ symbol_set_names (struct general_symbol_info *gsymbol,
return;
}
+ if (gsymbol->language == language_pascal)
+ {
+ int i;
+ char *lc_name;
+ /* In pascal, we do the symbol lookups using the lowercase name. */
+ if (!copy_name)
+ gsymbol->name = (char *) linkage_name;
+ else
+ {
+ gsymbol->name = obstack_alloc (&objfile->objfile_obstack, len + 1);
+ memcpy (gsymbol->name, linkage_name, len);
+ gsymbol->name[len] = '\0';
+ }
+ lc_name = obstack_alloc (&objfile->objfile_obstack, len + 1);
+ for (i = 0; i < len; i++)
+ lc_name[i] = tolower (linkage_name[i]);
+ lc_name[len] = '\0';
+ gsymbol->language_specific.pascal_specific.lowercase_name = lc_name;
+ return;
+ }
+
+
if (objfile->demangled_names_hash == NULL)
create_demangled_names_hash (objfile);
@@ -752,10 +778,19 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
char *
symbol_search_name (const struct general_symbol_info *gsymbol)
{
- if (gsymbol->language == language_ada)
- return gsymbol->name;
- else
- return symbol_natural_name (gsymbol);
+ switch (gsymbol->language)
+ {
+ case language_ada:
+ return gsymbol->name;
+ break;
+ case language_pascal:
+ if (gsymbol->language_specific.pascal_specific.lowercase_name != NULL)
+ return gsymbol->language_specific.pascal_specific.lowercase_name;
+ break;
+ default:
+ break;
+ }
+ return symbol_natural_name (gsymbol);
}
/* Initialize the structure fields to zero values. */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 944dd33..e371a43 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -138,6 +138,12 @@ struct general_symbol_info
mangled_lang;
struct cplus_specific *cplus_specific;
+ struct pascal_specific
+ {
+ /* This is used for case insensitive searching. */
+ char *lowercase_name;
+ }
+ pascal_specific;
}
language_specific;