aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2013-11-07 08:35:35 +0400
committerJoel Brobecker <brobecker@adacore.com>2013-12-10 12:16:47 +0100
commit036e93dfdadd23ac73d3bd7f98f1640ded740cc0 (patch)
tree66624c6993134e63a1bd2db73a16142b52db2153
parent72bfa06c56ec662b4262cc264f45462ccda6a5d6 (diff)
downloadgdb-036e93dfdadd23ac73d3bd7f98f1640ded740cc0.zip
gdb-036e93dfdadd23ac73d3bd7f98f1640ded740cc0.tar.gz
gdb-036e93dfdadd23ac73d3bd7f98f1640ded740cc0.tar.bz2
Set language for Ada minimal symbols.
This helps with the following issue: Given an Ada program defining a global variable: package Pck is Watch : Integer := 1974; end Pck; When printing the address of this variable, GDB also tries to print the associated symbol name: (gdb) p watch'address $1 = (access integer) 0x6139d8 <pck__watch> ^^ || The problem is that GDB prints the variable's linkage name, instead of its natural name. This is because the language of the associated minimal symbol never really gets set. This patch adds handling for Ada symbols in symbol_find_demangled_name. After this patch, we now get: (gdb) p watch'address $1 = (access integer) 0x6139d8 <pck.watch> ^ | gdb/ChangeLog: * symtab.c (symbol_find_demangled_name): Add handling of Ada symbols. gdb/testsuite/ChangeLog: * gdb.ada/int_deref.exp: Add test verifying that we print the decoded symbol name when printing the address of Ada symbols.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/symtab.c37
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.ada/int_deref.exp5
4 files changed, 53 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f8790e7..d9e492f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2013-12-10 Joel Brobecker <brobecker@adacore.com>
+ * symtab.c (symbol_find_demangled_name): Add handling of
+ Ada symbols.
+
+2013-12-10 Joel Brobecker <brobecker@adacore.com>
+
* mi/mi-main.c (mi_cmd_list_features): add "exec-run-start-option".
* NEWS: Expand the entry documenting the new -exec-run --start
option to mention the corresponding new entry in the output of
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 8fac0be..aa1e14b 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -60,6 +60,7 @@
#include "solist.h"
#include "macrotab.h"
#include "macroscope.h"
+#include "ada-lang.h"
#include "psymtab.h"
#include "parser-defs.h"
@@ -692,6 +693,42 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
symbols). Just the mangling standard is not standardized across compilers
and there is no DW_AT_producer available for inferiors with only the ELF
symbols to check the mangling kind. */
+
+ /* Check for Ada symbols last. See comment below explaining why. */
+
+ if (gsymbol->language == language_auto)
+ {
+ const char *demangled = ada_decode (mangled);
+
+ if (demangled != mangled && demangled != NULL && demangled[0] != '<')
+ {
+ /* Set the gsymbol language to Ada, but still return NULL.
+ Two reasons for that:
+
+ 1. For Ada, we prefer computing the symbol's decoded name
+ on the fly rather than pre-compute it, in order to save
+ memory (Ada projects are typically very large).
+
+ 2. There are some areas in the definition of the GNAT
+ encoding where, with a bit of bad luck, we might be able
+ to decode a non-Ada symbol, generating an incorrect
+ demangled name (Eg: names ending with "TB" for instance
+ are identified as task bodies and so stripped from
+ the decoded name returned).
+
+ Returning NULL, here, helps us get a little bit of
+ the best of both worlds. Because we're last, we should
+ not affect any of the other languages that were able to
+ demangle the symbol before us; we get to correctly tag
+ Ada symbols as such; and even if we incorrectly tagged
+ a non-Ada symbol, which should be rare, any routing
+ through the Ada language should be transparent (Ada
+ tries to behave much like C/C++ with non-Ada symbols). */
+ gsymbol->language = language_ada;
+ return NULL;
+ }
+ }
+
return NULL;
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 08f6b27..0e1e785 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2013-12-10 Joel Brobecker <brobecker@adacore.com>
+ * gdb.ada/int_deref.exp: Add test verifying that we print
+ the decoded symbol name when printing the address of Ada
+ symbols.
+
+2013-12-10 Joel Brobecker <brobecker@adacore.com>
+
* gdb.mi/mi-start.exp: Add test verifying that -list-features
contains "exec-run-start-option".
diff --git a/gdb/testsuite/gdb.ada/int_deref.exp b/gdb/testsuite/gdb.ada/int_deref.exp
index 7b8f426..ea61d4a 100644
--- a/gdb/testsuite/gdb.ada/int_deref.exp
+++ b/gdb/testsuite/gdb.ada/int_deref.exp
@@ -26,6 +26,11 @@ clean_restart ${testfile}
set bp_location [gdb_get_line_number "Pck.Watch" ${testdir}/foo.adb]
runto "foo.adb:$bp_location"
+# Hijack a bit this testcase, to verify that name decoding works
+# when doing symbolic address printing.
+gdb_test "print watch'address" \
+ " = \\(system\\.address\\) $hex <pck\\.watch>"
+
gdb_test "print *long_integer(watch'address)" \
" = 4874"