aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/lib
diff options
context:
space:
mode:
authorKevin Buettner <kevinb@redhat.com>2015-10-28 11:36:06 -0700
committerKevin Buettner <kevinb@redhat.com>2015-11-05 15:22:51 -0700
commit2223449a47a8908db2a1992379f54294128a7ee4 (patch)
treefbad66c4188b834d57bcd20af8cff505973c8e31 /gdb/testsuite/lib
parent96f9814df23564e16909bb5ba00de4a202c63417 (diff)
downloadgdb-2223449a47a8908db2a1992379f54294128a7ee4.zip
gdb-2223449a47a8908db2a1992379f54294128a7ee4.tar.gz
gdb-2223449a47a8908db2a1992379f54294128a7ee4.tar.bz2
gdb.dwarf2: Define and use gdb_target_symbol for symbol prefixes
Some of the tests in gdb.dwarf2 which use Dwarf::assemble refer to (minimal/linker) symbols created in the course of building a small test program. Some targets use a prefix such as underscore ("_") on these symbols. Many of the tests in gdb.dwarf2 do not take this into account. As a consequence, these tests fail to build, resulting either in failures or untested testcases. Here is an example from gdb.dwarf2/dw2-regno-invalid.exp: Dwarf::assemble $asm_file { cu {} { compile_unit { {low_pc main DW_FORM_addr} {high_pc main+0x10000 DW_FORM_addr} } { ... } For targets which require an underscore prefix on linker symbols, the two occurrences of "main" would have to have a prepended underscore, i.e. _main instead of main. For the above case, a call to the new proc gdb_target_symbol is used prepend the correct prefix to the symbol. I.e. the above code is rewritten (as shown in the patch) as follows: Dwarf::assemble $asm_file { cu {} { compile_unit { {low_pc [gdb_target_symbol main] DW_FORM_addr} {high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr} } { ... } I also found it necessary to make an adjustment to lib/dwarf.exp so that expressions of more than just one list element can be used in DW_TAG_... constructs. Both atomic-type.exp and dw2-bad-mips-linkage-name.exp require this new functionality. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_target_symbol_prefix, gdb_target_symbol): New procs. * lib/dwarf.exp (_handle_DW_TAG): Handle attribute values, representing expressions, of more than one list element. * gdb.dwarf2/atomic-type.exp (Dwarf::assemble): Use gdb_target_symbol to prepend linker symbol prefix to f. * gdb.dwarf2/data-loc.exp (Dwarf::assemble): Likewise, for table_1 and table_2. * gdb.dwarf2/dw2-bad-mips-linkage-name.exp (Dwarf::assemble): Likewise, for f and g. * gdb.dwarf2/dw2-ifort-parameter.exp (Dwarf::assemble): Likewise, for ptr. * gdb.dwarf2/dw2-regno-invalid.exp (Dwarf::assemble): Likewise, for main. * gdb.dwarf2/dynarr-ptr.exp (Dwarf::assemble): Likewise, for table_1_ptr and table_2_ptr.
Diffstat (limited to 'gdb/testsuite/lib')
-rw-r--r--gdb/testsuite/lib/dwarf.exp15
-rw-r--r--gdb/testsuite/lib/gdb.exp48
2 files changed, 61 insertions, 2 deletions
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 5dc7ea8..9716795 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -621,7 +621,18 @@ namespace eval Dwarf {
foreach attr $attrs {
set attr_name [_map_name [lindex $attr 0] _AT]
- set attr_value [uplevel 2 [list subst [lindex $attr 1]]]
+
+ # When the length of ATTR is greater than 2, the last
+ # element of the list must be a form. The second through
+ # the penultimate elements are joined together and
+ # evaluated using subst. This allows constructs such as
+ # [gdb_target_symbol foo] to be used.
+
+ if {[llength $attr] > 2} {
+ set attr_value [uplevel 2 [list subst [join [lrange $attr 1 end-1]]]]
+ } else {
+ set attr_value [uplevel 2 [list subst [lindex $attr 1]]]
+ }
if { [string equal "MACRO_AT_func" $attr_name] } {
_handle_macro_at_func $attr_value
@@ -629,7 +640,7 @@ namespace eval Dwarf {
_handle_macro_at_range $attr_value
} else {
if {[llength $attr] > 2} {
- set attr_form [lindex $attr 2]
+ set attr_form [lindex $attr end]
} else {
# If the value looks like an integer, a form is required.
if [string is integer $attr_value] {
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 6681a49..83dd0a2 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5523,6 +5523,54 @@ proc core_find {binfile {deletefiles {}} {arg ""}} {
return $destcore
}
+# gdb_target_symbol_prefix compiles a test program and then examines
+# the output from objdump to determine the prefix (such as underscore)
+# for linker symbol prefixes.
+
+gdb_caching_proc gdb_target_symbol_prefix {
+ # Set up and compile a simple test program...
+ set src [standard_temp_file main[pid].c]
+ set exe [standard_temp_file main[pid].x]
+
+ gdb_produce_source $src {
+ int main() {
+ return 0;
+ }
+ }
+
+ verbose "compiling testfile $src" 2
+ set compile_flags {debug nowarnings quiet}
+ set lines [gdb_compile $src $exe executable $compile_flags]
+
+ set prefix ""
+
+ if ![string match "" $lines] then {
+ verbose "gdb_target_symbol_prefix: testfile compilation failed, returning null prefix" 2
+ } else {
+ set objdump_program [gdb_find_objdump]
+ set result [catch "exec $objdump_program --syms $exe" output]
+
+ if { $result == 0 \
+ && ![regexp -lineanchor \
+ { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } {
+ verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2
+ }
+ }
+
+ file delete $src
+ file delete $exe
+
+ return $prefix
+}
+
+# gdb_target_symbol returns the provided symbol with the correct prefix
+# prepended. (See gdb_target_symbol_prefix, above.)
+
+proc gdb_target_symbol { symbol } {
+ set prefix [gdb_target_symbol_prefix]
+ return "${prefix}${symbol}"
+}
+
# gdb_target_symbol_prefix_flags returns a string that can be added
# to gdb_compile options to define SYMBOL_PREFIX macro value
# symbol_prefix_flags returns a string that can be added