This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFC: solve Ada-specific problem with linespec patches
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 23 Nov 2011 11:52:59 -0700
- Subject: RFC: solve Ada-specific problem with linespec patches
This is the patch I mentioned in the other thread.
It applies on top of the other ambiguous linespec patches, and fixes a
couple of Ada-specific problems.
I added a couple of tests so you can readily see the problems.
The first problem is that we needed a way to find all the Ada symbols
corresponding to the linespec the user gave. I implemented this by
adding a new language method that is called by linespec. This is just a
thin wrapper around ada_lookup_symbol_list.
The other problem was that special Ada quoting (the <name> form) wasn't
handled. I fixed this directly in the new Ada method.
I'm looking for feedback from the Ada-knowledgeable.
Tom
2011-11-22 Tom Tromey <tromey@redhat.com>
* linespec.c (iterate_over_all_matching_symtabs): Call
la_iterate_over_symbols.
(find_function_symbols, decode_variable): Remove Ada special
case.
* language.h (struct language_defn) <la_iterate_over_symbols>: New
field.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Update.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Update.
* d-lang.c (d_language_defn): Update.
* f-lang.c (f_language_defn): Update.
* jv-lang.c (java_language_defn): Update.
* m2-lang.c (m2_language_defn): Update.
* objc-lang.c (objc_language_defn): Update.
* opencl-lang.c (opencl_language_defn): Update.
* p-lang.c (pascal_language_defn): Update.
* ada-lang.c (ada_iterate_over_symbols): New function.
(ada_language_defn): Update.
2011-11-22 Tom Tromey <tromey@redhat.com>
* gdb.ada/homonym.exp: Add two breakpoint tests.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 2edbe7f..18cb954 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5052,6 +5052,35 @@ done:
return ndefns;
}
+/* Implementation of the la_iterate_over_symbols method. */
+
+static void
+ada_iterate_over_symbols (const char *name, domain_enum domain,
+ int (*callback) (struct symbol *, void *),
+ void *data)
+{
+ int ndefs, i;
+ struct ada_symbol_info *results;
+ char *canon;
+ int nlen = strlen (name);
+
+ if (name[0] == '<' && name[nlen - 1] == '>')
+ {
+ canon = alloca (nlen - 1);
+ memcpy (canon, name + 1, nlen - 2);
+ canon[nlen - 2] = '\0';
+ }
+ else
+ canon = ada_encode (ada_fold_name (name));
+
+ ndefs = ada_lookup_symbol_list (canon, NULL, domain, &results);
+ for (i = 0; i < ndefs; ++i)
+ {
+ if (! (*callback) (results[i].sym, data))
+ break;
+ }
+}
+
struct symbol *
ada_lookup_encoded_symbol (const char *name, const struct block *block0,
domain_enum namespace, struct block **block_found)
@@ -12284,6 +12313,7 @@ const struct language_defn ada_language_defn = {
ada_print_array_index,
default_pass_by_reference,
c_get_string,
+ ada_iterate_over_symbols,
LANG_MAGIC
};
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 3a35a78..b9101d3 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -863,6 +863,7 @@ const struct language_defn c_language_defn =
default_print_array_index,
default_pass_by_reference,
c_get_string,
+ NULL,
LANG_MAGIC
};
@@ -984,6 +985,7 @@ const struct language_defn cplus_language_defn =
default_print_array_index,
cp_pass_by_reference,
c_get_string,
+ NULL,
LANG_MAGIC
};
@@ -1023,6 +1025,7 @@ const struct language_defn asm_language_defn =
default_print_array_index,
default_pass_by_reference,
c_get_string,
+ NULL,
LANG_MAGIC
};
@@ -1067,6 +1070,7 @@ const struct language_defn minimal_language_defn =
default_print_array_index,
default_pass_by_reference,
c_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index c0599a5..44ff68a 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -273,6 +273,7 @@ static const struct language_defn d_language_defn =
default_print_array_index,
default_pass_by_reference,
c_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index f538eee..fb48069 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -309,6 +309,7 @@ const struct language_defn f_language_defn =
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index 4eae356..e957255 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -1197,6 +1197,7 @@ const struct language_defn java_language_defn =
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/language.c b/gdb/language.c
index 825c02d..d798c38 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1200,6 +1200,7 @@ const struct language_defn unknown_language_defn =
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
@@ -1241,6 +1242,7 @@ const struct language_defn auto_language_defn =
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
@@ -1280,6 +1282,7 @@ const struct language_defn local_language_defn =
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/language.h b/gdb/language.h
index 1ff575f..ede6a92 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -318,6 +318,19 @@ struct language_defn
void (*la_get_string) (struct value *value, gdb_byte **buffer, int *length,
struct type **chartype, const char **charset);
+ /* Find all symbols in the current program space matching NAME in
+ DOMAIN, according to this language's rules. For each one, call
+ CALLBACK with the symbol and the DATA argument. If CALLBACK
+ returns zero, the iteration ends at that point.
+
+ This field can be NULL, meaning that this language doesn't need
+ any special code aside from ordinary searches of the symbol
+ table. */
+ void (*la_iterate_over_symbols) (const char *name,
+ domain_enum domain,
+ int (*callback) (struct symbol *, void *),
+ void *data);
+
/* Add fields above this point, so the magic number is always last. */
/* Magic number for compat checking. */
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 3e06f09..c07198a 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -376,6 +376,10 @@ iterate_over_all_matching_symtabs (const char *name,
}
}
}
+
+ if (current_language->la_iterate_over_symbols)
+ (*current_language->la_iterate_over_symbols) (name, domain,
+ callback, data);
}
}
@@ -2225,28 +2229,6 @@ find_function_symbols (char **argptr, char *p, int is_quote_enclosed,
iterate_over_all_matching_symtabs (copy, VAR_DOMAIN,
collect_function_symbols, &result, NULL);
- /* If looking up the given name failed, try using the current
- language to look up a symbol. This may augment the search. If a
- symbol is found this way, repeat the iteration, but using the
- discovered name. */
- if (VEC_empty (symbolp, result)
- && current_language->la_language == language_ada)
- {
- struct symbol *function_symbol;
-
- function_symbol = lookup_symbol (copy, get_selected_block (0),
- VAR_DOMAIN, 0);
- if (function_symbol && SYMBOL_CLASS (function_symbol) == LOC_BLOCK)
- {
- xfree (copy);
- copy = xstrdup (SYMBOL_SEARCH_NAME (function_symbol));
- *user_function = copy;
- iterate_over_all_matching_symtabs (copy, VAR_DOMAIN,
- collect_function_symbols,
- &result, NULL);
- }
- }
-
if (VEC_empty (symbolp, result))
VEC_free (symbolp, result);
else
@@ -2781,22 +2763,6 @@ decode_variable (struct linespec_state *self, char *copy)
add_matching_symbols_to_info (lookup_name, &info, NULL);
- /* If looking up the given name failed, try using the current
- language to look up a symbol. This may augment the search. If a
- symbol is found this way, repeat the iteration, but using the
- discovered name. */
- if (info.result.nelts == 0 && current_language->la_language == language_ada)
- {
- struct symbol *sym;
-
- sym = lookup_symbol (lookup_name, get_selected_block (0), VAR_DOMAIN, 0);
- if (sym)
- {
- copy = SYMBOL_SEARCH_NAME (sym);
- add_matching_symbols_to_info (copy, &info, NULL);
- }
- }
-
if (info.result.nelts > 0)
{
if (self->canonical)
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index f83c622..52c592a 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -401,6 +401,7 @@ const struct language_defn m2_language_defn =
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index dcf9459..b5024b6 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -541,6 +541,7 @@ const struct language_defn objc_language_defn = {
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 05955b4..43791ea 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1024,6 +1024,7 @@ const struct language_defn opencl_language_defn =
default_print_array_index,
default_pass_by_reference,
c_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 655279b..76ec4b9 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -459,6 +459,7 @@ const struct language_defn pascal_language_defn =
default_print_array_index,
default_pass_by_reference,
default_get_string,
+ NULL,
LANG_MAGIC
};
diff --git a/gdb/testsuite/gdb.ada/homonym.exp b/gdb/testsuite/gdb.ada/homonym.exp
index b5dff1b..c58657a 100644
--- a/gdb/testsuite/gdb.ada/homonym.exp
+++ b/gdb/testsuite/gdb.ada/homonym.exp
@@ -31,6 +31,20 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" }
clean_restart ${testfile}
+
+# Do these tests before running, so we are operating in a known
+# environment.
+
+gdb_test "break Get_Value" \
+ "Breakpoint \[0-9\]+ at $hex: Get_Value. .2 locations." \
+ "set breakpoint at Get_Value"
+
+gdb_test "break <homonym__get_value>" \
+ "Breakpoint \[0-9\]+ at $hex: <homonym__get_value>. .2 locations." \
+ "set breakpoint at <homonym__get_value>"
+
+delete_breakpoints
+
set bp_location [gdb_get_line_number "BREAK_1" ${testdir}/homonym.adb]
runto "homonym.adb:$bp_location"
@@ -86,6 +100,3 @@ gdb_test "ptype lcl" \
gdb_test "print lcl" \
"= 17" \
"print lcl at BREAK_2"
-
-
-