| 1 | # Copyright 2016 Free Software Foundation, Inc. |
| 2 | |
| 3 | # This program is free software; you can redistribute it and/or modify |
| 4 | # it under the terms of the GNU General Public License as published by |
| 5 | # the Free Software Foundation; either version 3 of the License, or |
| 6 | # (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | # GNU General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public License |
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | # Test accessing "non-variable" variables, i.e., variables which are |
| 17 | # optimized to a constant DWARF location expression and/or |
| 18 | # partially/fully optimized out. |
| 19 | |
| 20 | load_lib dwarf.exp |
| 21 | |
| 22 | if {![dwarf2_support]} { return 0 } |
| 23 | |
| 24 | standard_testfile main.c nonvar-access-dw.S |
| 25 | |
| 26 | # Make some DWARF for the test. |
| 27 | set asm_file [standard_output_file $srcfile2] |
| 28 | |
| 29 | Dwarf::assemble $asm_file { |
| 30 | cu {} { |
| 31 | compile_unit { |
| 32 | {DW_AT_name main.c} |
| 33 | } { |
| 34 | declare_labels int_type_label short_type_label |
| 35 | declare_labels struct_s_label struct_t_label |
| 36 | |
| 37 | int_type_label: base_type { |
| 38 | {name "int"} |
| 39 | {encoding @DW_ATE_signed} |
| 40 | {byte_size 4 DW_FORM_sdata} |
| 41 | } |
| 42 | |
| 43 | struct_s_label: structure_type { |
| 44 | {name s} |
| 45 | {byte_size 4 DW_FORM_sdata} |
| 46 | } { |
| 47 | member { |
| 48 | {name a} |
| 49 | {type :$int_type_label} |
| 50 | {data_member_location 0 DW_FORM_udata} |
| 51 | {bit_size 8 DW_FORM_udata} |
| 52 | } |
| 53 | member { |
| 54 | {name b} |
| 55 | {type :$int_type_label} |
| 56 | {data_bit_offset 8 DW_FORM_udata} |
| 57 | {bit_size 24 DW_FORM_udata} |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | struct_t_label: structure_type { |
| 62 | {name t} |
| 63 | {byte_size 4 DW_FORM_sdata} |
| 64 | } { |
| 65 | member { |
| 66 | {name a} |
| 67 | {type :$int_type_label} |
| 68 | {data_member_location 0 DW_FORM_udata} |
| 69 | {bit_size 9 DW_FORM_udata} |
| 70 | } |
| 71 | member { |
| 72 | {name b} |
| 73 | {type :$int_type_label} |
| 74 | {data_bit_offset 9 DW_FORM_udata} |
| 75 | {bit_size 23 DW_FORM_udata} |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | DW_TAG_subprogram { |
| 80 | {name main} |
| 81 | {DW_AT_external 1 flag} |
| 82 | {low_pc [gdb_target_symbol main] DW_FORM_addr} |
| 83 | {high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr} |
| 84 | } { |
| 85 | DW_TAG_variable { |
| 86 | {name undef_int} |
| 87 | {type :$int_type_label} |
| 88 | } |
| 89 | DW_TAG_variable { |
| 90 | {name undef_s} |
| 91 | {type :$struct_s_label} |
| 92 | } |
| 93 | DW_TAG_variable { |
| 94 | {name def_s} |
| 95 | {type :$struct_s_label} |
| 96 | {location { |
| 97 | const1u 0 |
| 98 | stack_value |
| 99 | bit_piece 8 0 |
| 100 | const1s -1 |
| 101 | stack_value |
| 102 | bit_piece 24 0 |
| 103 | } SPECIAL_expr} |
| 104 | } |
| 105 | DW_TAG_variable { |
| 106 | {name def_t} |
| 107 | {type :$struct_t_label} |
| 108 | {location { |
| 109 | const1u 0 |
| 110 | stack_value |
| 111 | bit_piece 9 0 |
| 112 | const1s -1 |
| 113 | stack_value |
| 114 | bit_piece 23 0 |
| 115 | } SPECIAL_expr} |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if { [prepare_for_testing ${testfile}.exp ${testfile} \ |
| 123 | [list $srcfile $asm_file] {nodebug}] } { |
| 124 | return -1 |
| 125 | } |
| 126 | |
| 127 | if ![runto_main] { |
| 128 | return -1 |
| 129 | } |
| 130 | |
| 131 | gdb_test "print def_s" " = \\{a = 0, b = -1\\}" |
| 132 | gdb_test "print def_t" " = \\{a = 0, b = -1\\}" |
| 133 | gdb_test "print undef_int" " = <optimized out>" |
| 134 | gdb_test "print undef_s.a" " = <optimized out>" |