aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
blob: 8910f6d73046419606ef277c1bb60e848b6cc614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright 2016 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 short_type_label
	    declare_labels struct_s_label struct_t_label

	    int_type_label: base_type {
		{name "int"}
		{encoding @DW_ATE_signed}
		{byte_size 4 DW_FORM_sdata}
	    }

	    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}
		}
	    }

	    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}
	    } {
		DW_TAG_variable {
		    {name undef_int}
		    {type :$int_type_label}
		}
		DW_TAG_variable {
		    {name undef_s}
		    {type :$struct_s_label}
		}
		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}
		}
		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}
		}
	    }
	}
    }
}

if { [prepare_for_testing ${testfile}.exp ${testfile} \
	  [list $srcfile $asm_file] {nodebug}] } {
    return -1
}

if ![runto_main] {
    return -1
}

gdb_test "print def_s" " = \\{a = 0, b = -1\\}"
gdb_test "print def_t" " = \\{a = 0, b = -1\\}"
gdb_test "print undef_int" " = <optimized out>"
gdb_test "print undef_s.a" " = <optimized out>"