aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLancelot SIX <lancelot.six@amd.com>2023-06-08 15:24:55 +0100
committerLancelot SIX <lancelot.six@amd.com>2023-06-13 09:22:39 +0100
commitbdde90c4cea27aacb0b98b4b1fa7289cb1a96168 (patch)
tree038b09ab45e607ee969d34e7cb4020273ee55cfb
parent1e888ec928b153ffc979f5b34cbc84f74c576c15 (diff)
downloadbinutils-bdde90c4cea27aacb0b98b4b1fa7289cb1a96168.zip
binutils-bdde90c4cea27aacb0b98b4b1fa7289cb1a96168.tar.gz
binutils-bdde90c4cea27aacb0b98b4b1fa7289cb1a96168.tar.bz2
gdb/testsuite: use proper int size for gdb.dwarf2/symbol_needs_eval*.exp
We recently realized that symbol_needs_eval_fail.exp and symbol_needs_eval_timeout.exp invalidly dereference an int (4 bytes on x86_64) by reading 8 bytes (the size of a pointer). Here how it goes: In gdb/testsuite/gdb.dwarf2/symbol_needs_eval.c a global variable is defined: int exec_mask = 1; and later both tests build some DWARF using the assembler doing: set exec_mask_var [gdb_target_symbol exec_mask] ... DW_TAG_variable { {DW_AT_name a} {DW_AT_type :$int_type_label} {DW_AT_location { DW_OP_addr $exec_mask_var DW_OP_deref ... } } The definition of the DW_OP_deref (from Dwarf5 2.5.1.3 Stack Operations) says that "The size of the data retrieved from the dereferenced address is the size of an address on the target machine." On x86_64, the size of an int is 4 while the size of an address is 8. The result is that when evaluating this expression, the debugger reads outside of the `a` variable. Fix this by using `DW_OP_deref_size $int_size` instead. To achieve this, this patch adds the necessary steps so we can figure out what `sizeof(int)` evaluates to for the current target. While at it, also change the definition of the int type in the assembled DWARF information so we use the actual target's size for an int instead of the literal 4. Tested on x86_64 Linux. Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp12
-rw-r--r--gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp12
2 files changed, 18 insertions, 6 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp
index cb9826e..ec3913c 100644
--- a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp
+++ b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp
@@ -47,11 +47,17 @@ if { [is_aarch64_target] } {
standard_testfile symbol_needs_eval.c ${gdb_test_file_name}-dw.S
+if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
+ return
+}
+
+set int_size [get_sizeof "int" -1]
+
# Make some DWARF for the test.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
- global dwarf_regnum regname
+ global dwarf_regnum regname int_size
set exec_mask_var [gdb_target_symbol exec_mask]
@@ -66,7 +72,7 @@ Dwarf::assemble $asm_file {
int_type_label: DW_TAG_base_type {
{DW_AT_name "int"}
{DW_AT_encoding @DW_ATE_signed}
- {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_byte_size $int_size DW_FORM_sdata}
}
# define artificial variable a
@@ -75,7 +81,7 @@ Dwarf::assemble $asm_file {
{DW_AT_type :$int_type_label}
{DW_AT_location {
DW_OP_addr $exec_mask_var
- DW_OP_deref
+ DW_OP_deref_size $int_size
# conditional jump to DW_OP_bregx
DW_OP_bra 4
diff --git a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp
index 0e6ee61..fc0b591 100644
--- a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp
+++ b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp
@@ -47,11 +47,17 @@ if { [is_aarch64_target] } {
standard_testfile symbol_needs_eval.c ${gdb_test_file_name}-dw.S
+if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
+ return
+}
+
+set int_size [get_sizeof "int" -1]
+
# Make some DWARF for the test.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
- global dwarf_regnum regname
+ global dwarf_regnum regname int_size
set exec_mask_var [gdb_target_symbol exec_mask]
@@ -66,7 +72,7 @@ Dwarf::assemble $asm_file {
int_type_label: DW_TAG_base_type {
{DW_AT_name "int"}
{DW_AT_encoding @DW_ATE_signed}
- {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_byte_size $int_size DW_FORM_sdata}
}
# add info for variable exec_mask
@@ -93,7 +99,7 @@ Dwarf::assemble $asm_file {
{DW_AT_location {
DW_OP_lit1
DW_OP_addr $exec_mask_var
- DW_OP_deref
+ DW_OP_deref_size $int_size
# jump to DW_OP_fbreg
DW_OP_skip 4