binutils-gdb/gdb/testsuite/gdb.dwarf2/dw2-op-stack-value.exp

55 lines
1.6 KiB
Plaintext
Raw Normal View History

# Copyright 2011-2017 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
if {![dwarf2_support]} {
return 0
}
testsuite: Define and use gdb_target_symbol_prefix_flags_asm. Some of the source code for the test cases in the GDB testsuite reside in .S files containing assembly code. These files typically define a symbol - such as main - which may, depending on the target, require a prefix such as underscore. For example, gdb.dwarf2/dw-compdir-oldgcc.S defines the symbol main: main: .globl main Some targets, such as rx-elf, require main to have an underscore prefix. (If it doesn't, a linker error results due to not being able to find _main required by crt0.o.) So, instead, the above should look like this for rx-elf and other targets with this same requirement: _main: .globl _main This patch defines a new tcl proc in lib/gdb named gdb_target_symbol_prefix_flags_asm. This proc returns a string which will - assuming everything else is wired up correctly - cause -DSYMBOL_PREFIX=_ to be passed on the command line to the compiler. The test cases are augmented with a macro definition for SYMBOL as follows: #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a ## b #ifdef SYMBOL_PREFIX # define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str) #else # define SYMBOL(str) str #endif Symbols, such as main shown in the example earlier are then wrapped with SYMBOL like this: SYMBOL(main): .globl SYMBOL(main) The net effect will be to add a prefix for those targets which need it and add no prefix for those targets which do not. It should be noted that there was already a proc in lib/gdb.exp called gdb_target_symbol_prefix_flags. It still exists, but has been significantly rewritten. (There is only one small difference between the two versions.) That proc used to explicitly list targets which were known to require an underscore prefix. This is no longer done; the recently added proc, gdb_target_symbol_prefix, is now invoked to dynamically discover whether or not a prefix is required for that particular target. The difference between gdb_target_symbol_prefix_flags_asm and gdb_target_symbol_prefix_flags is that the former returns a bare prefix while the latter returns the prefix enclosed in double quotes. I.e. assuming that the discovered prefix is underscore, gdb_target_symbol_prefix_flags_asm returns: additional_flags=-DSYMBOL_PREFIX=_ while gdb_target_symbol_prefix_flags returns: additional_flags=-DSYMBOL_PREFIX="_" The double-quoted version is not suitable for using with .S files containing assembly code; there is no way to strip the double quotes using C preprocessor constructs. It would be possible to use the bare (non double quoted) version in C source code. However, the supporting macros become more complicated and therefore more difficult to maintain. gdb/testsuite/ChangeLog: * lib/gdb (gdb_target_symbol_prefix_flags_asm): New proc. (gdb_target_symbol_prefix_flags): Define in terms of _asm version. * gdb.arch/i386-float.exp, gdb.arch/i386-permbkpt.exp, gdb.dwarf2/dw2-canonicalize-type.exp, gdb.dwarf2/dw2-compdir-oldgcc.exp, gdb.dwarf2/dw2-minsym-in-cu.exp, gdb.dwarf2/dw2-op-stack-value.exp, gdb.dwarf2/dw2-unresolved.exp, gdb.dwarf2/fission-reread.exp, gdb.dwarf2/pr13961.exp: Use flags provided by gdb_target_symbol_prefix_flags_asm. * gdb.dwarf2/dw2-canonicalize-type.S, gdb.dwarf2/dw2-compdir-oldgcc.S, testsuite/gdb.dwarf2/dw2-minsym-in-cu.S, testsuite/gdb.dwarf2/dw2-unresolved-main.c, testsuite/gdb.dwarf2/dw2-unresolved.S, gdb.dwarf2/fission-reread.S, gdb.dwarf2/pr13961.S: Define and use SYMBOL macro (and supporting macros where needed). Use this macro for symbols which require the prefix provided by SYMBOL_PREFIX.
2015-11-06 05:40:53 +01:00
# Some targets have leading underscores on assembly symbols.
set additional_flags [gdb_target_symbol_prefix_flags_asm]
* gdb.dwarf2/pr10770.exp: Use standard_testfile. * gdb.dwarf2/dw2-var-zero-addr.exp: Use standard_testfile. * gdb.dwarf2/dw2-param-error.exp: Use standard_testfile. * gdb.dwarf2/dw2-op-call.exp: Use standard_testfile. * gdb.dwarf2/dw2-inline-param.exp: Use standard_testfile, prepare_for_testing. * gdb.dwarf2/dw2-inline-break.exp: Use standard_testfile. * gdb.dwarf2/dw2-ifort-parameter.exp: Use standard_testfile. * gdb.dwarf2/dw2-cp-infcall-ref-static.exp: Use standard_testfile. * gdb.dwarf2/dw2-case-insensitive.exp: Use standard_testfile. * gdb.dwarf2/dw4-sig-types.exp: Use standard_testfile. * gdb.dwarf2/dw2-objfile-overlap.exp: Use standard_testfile. * gdb.dwarf2/callframecfa.exp: Use standard_testfile, prepare_for_testing. * gdb.dwarf2/dup-psym.exp: Use standard_testfile. * gdb.dwarf2/dw2-ada-ffffffff.exp: Use standard_testfile. * gdb.dwarf2/dw2-anonymous-func.exp: Use standard_testfile. * gdb.dwarf2/dw2-bad-parameter-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-basic.exp: Use standard_testfile. * gdb.dwarf2/dw2-compressed.exp: Use standard_testfile. * gdb.dwarf2/dw2-const.exp: Use standard_testfile. * gdb.dwarf2/dw2-cu-size.exp: Use standard_testfile. * gdb.dwarf2/dw2-double-set-die-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-empty-namespace.exp: Use standard_testfile. * gdb.dwarf2/dw2-empty-pc-range.exp: Use standard_testfile. * gdb.dwarf2/dw2-filename.exp: Use standard_testfile. * gdb.dwarf2/dw2-icc-opaque.exp: Use standard_testfile. * gdb.dwarf2/dw2-inheritance.exp: Use standard_testfile. * gdb.dwarf2/dw2-intercu.exp: Use standard_testfile. * gdb.dwarf2/dw2-intermix.exp: Use standard_testfile. * gdb.dwarf2/dw2-linkage-name-trust.exp: Use standard_testfile. * gdb.dwarf2/dw2-modula2-self-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-namespaceless-anonymous.exp: Use standard_testfile. * gdb.dwarf2/dw2-op-stack-value.exp: Use standard_testfile. * gdb.dwarf2/dw2-producer.exp: Use standard_testfile. * gdb.dwarf2/dw2-ranges.exp: Use standard_testfile, standard_output_file. * gdb.dwarf2/dw2-ref-missing-frame.exp: Use standard_testfile, standard_output_file. * gdb.dwarf2/dw2-restore.exp: Use standard_testfile. * gdb.dwarf2/dw2-simple-locdesc.exp: Use standard_testfile. * gdb.dwarf2/dw2-skip-prologue.exp: Use standard_testfile. * gdb.dwarf2/dw2-stack-boundary.exp: Use standard_testfile. * gdb.dwarf2/dw2-strp.exp: Use standard_testfile. * gdb.dwarf2/dw4-sig-type-unused.exp: Use standard_testfile. * gdb.dwarf2/implptr-64bit.exp: Use standard_testfile. * gdb.dwarf2/implptr-optimized-out.exp: Use standard_testfile. * gdb.dwarf2/implptr.exp: Use standard_testfile. * gdb.dwarf2/mac-fileno.exp: Use standard_testfile. * gdb.dwarf2/member-ptr-forwardref.exp: Use standard_testfile. * gdb.dwarf2/pieces.exp: Use standard_testfile. * gdb.dwarf2/pr11465.exp: Use standard_testfile. * gdb.dwarf2/pr13961.exp: Use standard_testfile. * gdb.dwarf2/valop.exp: Use standard_testfile, prepare_for_testing.
2012-06-27 19:00:09 +02:00
standard_testfile .S
* gdb.dwarf2/pr10770.exp: Use standard_testfile. * gdb.dwarf2/dw2-var-zero-addr.exp: Use standard_testfile. * gdb.dwarf2/dw2-param-error.exp: Use standard_testfile. * gdb.dwarf2/dw2-op-call.exp: Use standard_testfile. * gdb.dwarf2/dw2-inline-param.exp: Use standard_testfile, prepare_for_testing. * gdb.dwarf2/dw2-inline-break.exp: Use standard_testfile. * gdb.dwarf2/dw2-ifort-parameter.exp: Use standard_testfile. * gdb.dwarf2/dw2-cp-infcall-ref-static.exp: Use standard_testfile. * gdb.dwarf2/dw2-case-insensitive.exp: Use standard_testfile. * gdb.dwarf2/dw4-sig-types.exp: Use standard_testfile. * gdb.dwarf2/dw2-objfile-overlap.exp: Use standard_testfile. * gdb.dwarf2/callframecfa.exp: Use standard_testfile, prepare_for_testing. * gdb.dwarf2/dup-psym.exp: Use standard_testfile. * gdb.dwarf2/dw2-ada-ffffffff.exp: Use standard_testfile. * gdb.dwarf2/dw2-anonymous-func.exp: Use standard_testfile. * gdb.dwarf2/dw2-bad-parameter-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-basic.exp: Use standard_testfile. * gdb.dwarf2/dw2-compressed.exp: Use standard_testfile. * gdb.dwarf2/dw2-const.exp: Use standard_testfile. * gdb.dwarf2/dw2-cu-size.exp: Use standard_testfile. * gdb.dwarf2/dw2-double-set-die-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-empty-namespace.exp: Use standard_testfile. * gdb.dwarf2/dw2-empty-pc-range.exp: Use standard_testfile. * gdb.dwarf2/dw2-filename.exp: Use standard_testfile. * gdb.dwarf2/dw2-icc-opaque.exp: Use standard_testfile. * gdb.dwarf2/dw2-inheritance.exp: Use standard_testfile. * gdb.dwarf2/dw2-intercu.exp: Use standard_testfile. * gdb.dwarf2/dw2-intermix.exp: Use standard_testfile. * gdb.dwarf2/dw2-linkage-name-trust.exp: Use standard_testfile. * gdb.dwarf2/dw2-modula2-self-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-namespaceless-anonymous.exp: Use standard_testfile. * gdb.dwarf2/dw2-op-stack-value.exp: Use standard_testfile. * gdb.dwarf2/dw2-producer.exp: Use standard_testfile. * gdb.dwarf2/dw2-ranges.exp: Use standard_testfile, standard_output_file. * gdb.dwarf2/dw2-ref-missing-frame.exp: Use standard_testfile, standard_output_file. * gdb.dwarf2/dw2-restore.exp: Use standard_testfile. * gdb.dwarf2/dw2-simple-locdesc.exp: Use standard_testfile. * gdb.dwarf2/dw2-skip-prologue.exp: Use standard_testfile. * gdb.dwarf2/dw2-stack-boundary.exp: Use standard_testfile. * gdb.dwarf2/dw2-strp.exp: Use standard_testfile. * gdb.dwarf2/dw4-sig-type-unused.exp: Use standard_testfile. * gdb.dwarf2/implptr-64bit.exp: Use standard_testfile. * gdb.dwarf2/implptr-optimized-out.exp: Use standard_testfile. * gdb.dwarf2/implptr.exp: Use standard_testfile. * gdb.dwarf2/mac-fileno.exp: Use standard_testfile. * gdb.dwarf2/member-ptr-forwardref.exp: Use standard_testfile. * gdb.dwarf2/pieces.exp: Use standard_testfile. * gdb.dwarf2/pr11465.exp: Use standard_testfile. * gdb.dwarf2/pr13961.exp: Use standard_testfile. * gdb.dwarf2/valop.exp: Use standard_testfile, prepare_for_testing.
2012-06-27 19:00:09 +02:00
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" $binfile \
object {nodebug}] != "" } {
return -1
}
* gdb.dwarf2/pr10770.exp: Use standard_testfile. * gdb.dwarf2/dw2-var-zero-addr.exp: Use standard_testfile. * gdb.dwarf2/dw2-param-error.exp: Use standard_testfile. * gdb.dwarf2/dw2-op-call.exp: Use standard_testfile. * gdb.dwarf2/dw2-inline-param.exp: Use standard_testfile, prepare_for_testing. * gdb.dwarf2/dw2-inline-break.exp: Use standard_testfile. * gdb.dwarf2/dw2-ifort-parameter.exp: Use standard_testfile. * gdb.dwarf2/dw2-cp-infcall-ref-static.exp: Use standard_testfile. * gdb.dwarf2/dw2-case-insensitive.exp: Use standard_testfile. * gdb.dwarf2/dw4-sig-types.exp: Use standard_testfile. * gdb.dwarf2/dw2-objfile-overlap.exp: Use standard_testfile. * gdb.dwarf2/callframecfa.exp: Use standard_testfile, prepare_for_testing. * gdb.dwarf2/dup-psym.exp: Use standard_testfile. * gdb.dwarf2/dw2-ada-ffffffff.exp: Use standard_testfile. * gdb.dwarf2/dw2-anonymous-func.exp: Use standard_testfile. * gdb.dwarf2/dw2-bad-parameter-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-basic.exp: Use standard_testfile. * gdb.dwarf2/dw2-compressed.exp: Use standard_testfile. * gdb.dwarf2/dw2-const.exp: Use standard_testfile. * gdb.dwarf2/dw2-cu-size.exp: Use standard_testfile. * gdb.dwarf2/dw2-double-set-die-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-empty-namespace.exp: Use standard_testfile. * gdb.dwarf2/dw2-empty-pc-range.exp: Use standard_testfile. * gdb.dwarf2/dw2-filename.exp: Use standard_testfile. * gdb.dwarf2/dw2-icc-opaque.exp: Use standard_testfile. * gdb.dwarf2/dw2-inheritance.exp: Use standard_testfile. * gdb.dwarf2/dw2-intercu.exp: Use standard_testfile. * gdb.dwarf2/dw2-intermix.exp: Use standard_testfile. * gdb.dwarf2/dw2-linkage-name-trust.exp: Use standard_testfile. * gdb.dwarf2/dw2-modula2-self-type.exp: Use standard_testfile. * gdb.dwarf2/dw2-namespaceless-anonymous.exp: Use standard_testfile. * gdb.dwarf2/dw2-op-stack-value.exp: Use standard_testfile. * gdb.dwarf2/dw2-producer.exp: Use standard_testfile. * gdb.dwarf2/dw2-ranges.exp: Use standard_testfile, standard_output_file. * gdb.dwarf2/dw2-ref-missing-frame.exp: Use standard_testfile, standard_output_file. * gdb.dwarf2/dw2-restore.exp: Use standard_testfile. * gdb.dwarf2/dw2-simple-locdesc.exp: Use standard_testfile. * gdb.dwarf2/dw2-skip-prologue.exp: Use standard_testfile. * gdb.dwarf2/dw2-stack-boundary.exp: Use standard_testfile. * gdb.dwarf2/dw2-strp.exp: Use standard_testfile. * gdb.dwarf2/dw4-sig-type-unused.exp: Use standard_testfile. * gdb.dwarf2/implptr-64bit.exp: Use standard_testfile. * gdb.dwarf2/implptr-optimized-out.exp: Use standard_testfile. * gdb.dwarf2/implptr.exp: Use standard_testfile. * gdb.dwarf2/mac-fileno.exp: Use standard_testfile. * gdb.dwarf2/member-ptr-forwardref.exp: Use standard_testfile. * gdb.dwarf2/pieces.exp: Use standard_testfile. * gdb.dwarf2/pr11465.exp: Use standard_testfile. * gdb.dwarf2/pr13961.exp: Use standard_testfile. * gdb.dwarf2/valop.exp: Use standard_testfile, prepare_for_testing.
2012-06-27 19:00:09 +02:00
clean_restart $testfile
gdb_test "p/x stack2" " = 0x1"
gdb_test "p/x stack8" " = 0x1"
set test "x/wx &aa551234"
gdb_test_multiple $test $test {
-re ":\[ \t\]*0x341255aa\r\n$gdb_prompt $" {
# little endian
pass $test
gdb_test "p/x implicit4to2" " = 0x2211"
gdb_test "p/x implicit4to4" " = 0x44332211"
}
-re ":\[ \t\]*0xaa551234\r\n$gdb_prompt $" {
# big endian
pass $test
Big-endian targets: Don't ignore offset into DW_OP_implicit_value When a variable's location is expressed as DW_OP_implicit_value, but the given value is longer than needed, which bytes should be used? GDB's current logic was introduced with a patch from 2011 and uses the "least significant" bytes: https://sourceware.org/ml/gdb-patches/2011-08/msg00123.html Now consider a sub-value from such a location at a given offset, accessed through DW_OP_implicit_pointer. Which bytes should be used for that? The patch above *always* uses the last bytes on big-endian targets, ignoring the offset. E.g., given the code snippet const char foo[] = "Hello, world!"; const char *a = &foo[0]; const char *b = &foo[7]; assume that `foo' is described as DW_OP_implicit_value and `a' and `b' each as DW_OP_implicit_pointer into that value. Then with current GDB `*a' and `*b' yield the same result -- the string's zero terminator. This patch basically reverts the portion of the patch above that deals with DW_OP_implicit_value. This fixes the offset handling and also goes back to dropping the last instead of the first bytes on big-endian targets if the implicit value is longer than needed. The latter aspect of the change probably doesn't matter for actual programs, but simplifies the logic. The patch also cleans up the original code a bit and adds appropriate test cases. gdb/testsuite/ChangeLog: * gdb.dwarf2/dw2-op-stack-value.exp: Adjust expected result of taking a 2-byte value out of a 4-byte DWARF implicit value on big-endian targets. * gdb.dwarf2/nonvar-access.exp: Add more comments to existing logic. Add test cases for DW_OP_implicit. gdb/ChangeLog: * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): For DWARF_VALUE_LITERAL, no longer ignore the offset on big-endian targets. And if the implicit value is longer than needed, extract the first bytes instead of the "least significant" ones.
2017-02-01 16:59:00 +01:00
gdb_test "p/x implicit4to2" " = 0x1122"
gdb_test "p/x implicit4to4" " = 0x11223344"
}
-re ":\[ \t\]*0x\[0-9a-f\]{8}\r\n$gdb_prompt $" {
unsupported $test
}
}