mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-30 12:44:10 +08:00
7942e96e43
Recently I fixed a bug that caused a DW_OP_implicit_pointer with non-zero offset into a DW_OP_implicit_value to be handled incorrectly on big-endian targets. GDB ignored the offset and copied the wrong bytes: https://sourceware.org/ml/gdb-patches/2017-01/msg00251.html But there is still a similar issue when a DW_OP_implicit_pointer points into a DW_OP_stack_value instead; and again, the offset is ignored. There is an important difference, though: While implicit values are treated like blocks of data and anchored at the lowest-addressed byte, stack values traditionally contain integer numbers and are anchored at the *least significant* byte. Also, stack values do not come in varying sizes, but are cut down appropriately when used. Thus, on big-endian targets the scenario looks like this (higher addresses shown right): |<- - - - - Stack value - - - - - - ->| | | |<- original object ->| | | offset ->|####| ^^^^ de-referenced implicit pointer (Note how the original object's size influences the position of the de-referenced implicit pointer within the stack value. This is not the case for little-endian targets, where the original object starts at offset zero within the stack value.) This patch implements the logic indicated in the above diagram and adds an appropriate test case. A new function dwarf2_fetch_die_type_sect_off is added; it is used for retrieving the original object's type, so its size can be determined. That type is passed to dwarf2_evaluate_loc_desc_full via a new parameter. gdb/ChangeLog: * dwarf2loc.c (indirect_synthetic_pointer): Get data type of pointed-to DIE and pass it to dwarf2_evaluate_loc_desc_full. (dwarf2_evaluate_loc_desc_full): New parameter subobj_type; rename byte_offset to subobj_byte_offset. Fix the handling of DWARF_VALUE_STACK on big-endian targets when coming via an implicit pointer. (dwarf2_evaluate_loc_desc): Adjust call to dwarf2_evaluate_loc_desc_full. * dwarf2loc.h (dwarf2_fetch_die_type_sect_off): New declaration. * dwarf2read.c (dwarf2_fetch_die_type_sect_off): New function. gdb/testsuite/ChangeLog: * lib/dwarf.exp: Add support for DW_OP_implicit_pointer. * gdb.dwarf2/nonvar-access.exp: Add test for stack value location and implicit pointer into such a location.
233 lines
5.9 KiB
Plaintext
233 lines
5.9 KiB
Plaintext
# Copyright 2016-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/>.
|
|
|
|
# Test accessing "non-variable" variables, i.e., variables which are
|
|
# optimized to a constant DWARF location expression and/or
|
|
# partially/fully optimized out.
|
|
|
|
load_lib dwarf.exp
|
|
|
|
if {![dwarf2_support]} { return 0 }
|
|
|
|
standard_testfile main.c nonvar-access-dw.S
|
|
|
|
# Make some DWARF for the test.
|
|
set asm_file [standard_output_file $srcfile2]
|
|
|
|
Dwarf::assemble $asm_file {
|
|
cu {} {
|
|
compile_unit {
|
|
{DW_AT_name main.c}
|
|
} {
|
|
declare_labels int_type_label char_type_label \
|
|
struct_s_label struct_t_label array_a9_label \
|
|
char_ptr_label implicit_a_label stack_b_label
|
|
|
|
int_type_label: base_type {
|
|
{name "int"}
|
|
{encoding @DW_ATE_signed}
|
|
{byte_size 4 DW_FORM_sdata}
|
|
}
|
|
char_type_label: base_type {
|
|
{name "char"}
|
|
{encoding @DW_ATE_unsigned}
|
|
{byte_size 1 DW_FORM_sdata}
|
|
}
|
|
char_ptr_label: pointer_type {
|
|
{type :$char_type_label}
|
|
}
|
|
|
|
struct_s_label: structure_type {
|
|
{name s}
|
|
{byte_size 4 DW_FORM_sdata}
|
|
} {
|
|
member {
|
|
{name a}
|
|
{type :$int_type_label}
|
|
{data_member_location 0 DW_FORM_udata}
|
|
{bit_size 8 DW_FORM_udata}
|
|
}
|
|
member {
|
|
{name b}
|
|
{type :$int_type_label}
|
|
{data_bit_offset 8 DW_FORM_udata}
|
|
{bit_size 24 DW_FORM_udata}
|
|
}
|
|
}
|
|
|
|
struct_t_label: structure_type {
|
|
{name t}
|
|
{byte_size 4 DW_FORM_sdata}
|
|
} {
|
|
member {
|
|
{name a}
|
|
{type :$int_type_label}
|
|
{data_member_location 0 DW_FORM_udata}
|
|
{bit_size 9 DW_FORM_udata}
|
|
}
|
|
member {
|
|
{name b}
|
|
{type :$int_type_label}
|
|
{data_bit_offset 9 DW_FORM_udata}
|
|
{bit_size 23 DW_FORM_udata}
|
|
}
|
|
}
|
|
|
|
array_a9_label: array_type {
|
|
{type :$char_type_label}
|
|
} {
|
|
subrange_type {
|
|
{type :$int_type_label}
|
|
{upper_bound 8 DW_FORM_udata}
|
|
}
|
|
}
|
|
|
|
DW_TAG_subprogram {
|
|
{name main}
|
|
{DW_AT_external 1 flag}
|
|
{low_pc [gdb_target_symbol main] DW_FORM_addr}
|
|
{high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr}
|
|
} {
|
|
# Simple variable without location.
|
|
DW_TAG_variable {
|
|
{name undef_int}
|
|
{type :$int_type_label}
|
|
}
|
|
# Struct variable without location.
|
|
DW_TAG_variable {
|
|
{name undef_s}
|
|
{type :$struct_s_label}
|
|
}
|
|
# Composite location: byte-aligned pieces.
|
|
DW_TAG_variable {
|
|
{name def_s}
|
|
{type :$struct_s_label}
|
|
{location {
|
|
const1u 0
|
|
stack_value
|
|
bit_piece 8 0
|
|
const1s -1
|
|
stack_value
|
|
bit_piece 24 0
|
|
} SPECIAL_expr}
|
|
}
|
|
# Composite location: non-byte-aligned pieces.
|
|
DW_TAG_variable {
|
|
{name def_t}
|
|
{type :$struct_t_label}
|
|
{location {
|
|
const1u 0
|
|
stack_value
|
|
bit_piece 9 0
|
|
const1s -1
|
|
stack_value
|
|
bit_piece 23 0
|
|
} SPECIAL_expr}
|
|
}
|
|
# Implicit location: immediate value.
|
|
DW_TAG_variable {
|
|
{name def_implicit_s}
|
|
{type :$struct_s_label}
|
|
{location {
|
|
implicit_value 0x12 0x34 0x56 0x78
|
|
} SPECIAL_expr}
|
|
}
|
|
# Implicit location: immediate value for whole array, with
|
|
# excess bytes.
|
|
implicit_a_label: DW_TAG_variable {
|
|
{name def_implicit_a}
|
|
{type :$array_a9_label}
|
|
{location {
|
|
implicit_value 0x1 0x12 0x23 0x34 0x45 \
|
|
0x56 0x67 0x78 0x89 0x9a 0xab
|
|
} SPECIAL_expr}
|
|
}
|
|
# Implicit pointer into immediate value.
|
|
DW_TAG_variable {
|
|
{name implicit_a_ptr}
|
|
{type :$char_ptr_label}
|
|
{location {
|
|
implicit_pointer $implicit_a_label 5
|
|
} SPECIAL_expr}
|
|
}
|
|
# Stack-value location.
|
|
stack_b_label: DW_TAG_variable {
|
|
{name def_stack_b}
|
|
{type :$struct_t_label}
|
|
{location {
|
|
const4u 0x1a2b3c4d
|
|
stack_value
|
|
} SPECIAL_expr}
|
|
}
|
|
# Implicit pointer into stack value.
|
|
DW_TAG_variable {
|
|
{name implicit_b_ptr}
|
|
{type :$char_ptr_label}
|
|
{location {
|
|
implicit_pointer $stack_b_label 1
|
|
} SPECIAL_expr}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if { [prepare_for_testing "failed to prepare" ${testfile} \
|
|
[list $srcfile $asm_file] {nodebug}] } {
|
|
return -1
|
|
}
|
|
|
|
if ![runto_main] {
|
|
return -1
|
|
}
|
|
|
|
# Determine endianness.
|
|
set endian "little"
|
|
gdb_test_multiple "show endian" "determine endianness" {
|
|
-re ".* (big|little) endian.*$gdb_prompt $" {
|
|
set endian $expect_out(1,string)
|
|
pass "endianness: $endian"
|
|
}
|
|
}
|
|
|
|
# Byte-aligned objects with simple location descriptions.
|
|
switch $endian { big {set val 0x345678} little {set val 0x785634} }
|
|
gdb_test "print/x def_implicit_s" " = \\{a = 0x12, b = $val\\}"
|
|
gdb_test "print/x def_implicit_s.b" " = $val"
|
|
gdb_test "print/x def_implicit_a" \
|
|
" = \\{0x1, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89\\}"
|
|
gdb_test "print/x def_implicit_a\[5\]" " = 0x56"
|
|
gdb_test "print/x *(char (*)\[5\]) implicit_a_ptr" \
|
|
" = \\{0x56, 0x67, 0x78, 0x89, 0x9a\\}"
|
|
switch $endian {
|
|
big {set val "a = 52, b = 2833485"}
|
|
little {set val "a = 77, b = 857502"}
|
|
}
|
|
gdb_test "print def_stack_b" " = \\{$val\\}"
|
|
switch $endian {big {set val 0x2b} little {set val 0x3c}}
|
|
gdb_test "print/x *implicit_b_ptr" " = $val"
|
|
|
|
# Byte-aligned fields, pieced together from DWARF stack values.
|
|
gdb_test "print def_s" " = \\{a = 0, b = -1\\}"
|
|
|
|
# Non-byte-aligned fields, pieced together from DWARF stack values.
|
|
gdb_test "print def_t" " = \\{a = 0, b = -1\\}"
|
|
|
|
# Simple variable without location.
|
|
gdb_test "print undef_int" " = <optimized out>"
|
|
|
|
# Member of a structure without location.
|
|
gdb_test "print undef_s.a" " = <optimized out>"
|