aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2/dw2-entry-value-2.exp
blob: 55ecf9cece7ed31780d7d1d06d491c9a978345bc (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
# Copyright 2025 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/>.

# Check that we can get DW_OP_entry_value at function entry.

load_lib dwarf.exp

# This test can only be run on targets which support DWARF-2 and use gas.
require dwarf2_support

standard_testfile .c -debug.S

set test "get dwarf regnum for first argument register"
if { [is_x86_64_m64_target] } {
    set dwarf_regnum 5
} elseif { [istarget riscv64*] } {
    set dwarf_regnum 10
} else {
    set reason "architecture-specific setting missing"
    unsupported "$test ($reason)"
    return
}
pass $test

# Set up the DWARF for the test.

set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
    global srcdir subdir srcfile

    get_func_info main
    get_func_info bar

    cu {} {
	DW_TAG_compile_unit {
		{DW_AT_name $srcfile}
	} {
	    declare_labels integer

	    integer: DW_TAG_base_type {
		{DW_AT_byte_size 8 DW_FORM_sdata}
		{DW_AT_encoding @DW_ATE_signed}
		{DW_AT_name integer}
	    }

	    DW_TAG_subprogram {
		{ DW_AT_name main }
		{ DW_AT_low_pc $main_start DW_FORM_addr }
		{ DW_AT_high_pc $main_end DW_FORM_addr }
	    } {
		DW_TAG_variable {
		    { DW_AT_name argc }
		    { DW_AT_type :$integer }
		    { DW_AT_location {
			DW_OP_entry_value {
			    DW_OP_regx $::dwarf_regnum
			}
		    } SPECIAL_expr }
		}
	    }

	    DW_TAG_subprogram {
		{ DW_AT_name bar }
		{ DW_AT_low_pc $bar_start DW_FORM_addr }
		{ DW_AT_high_pc $bar_end DW_FORM_addr }
	    } {
		DW_TAG_variable {
		    { DW_AT_name foo }
		    { DW_AT_type :$integer }
		    { DW_AT_location {
			DW_OP_entry_value {
			    DW_OP_bregx $::dwarf_regnum 0
			    DW_OP_deref_size 4
			}
			DW_OP_stack_value
		    } SPECIAL_expr }
		}
	    }
	}
    }
}

if { [prepare_for_testing "failed to prepare" $testfile \
	  [list $srcfile $asm_file] {nodebug}] } {
    return -1
}

if { ![runto *main] } {
    return
}

with_test_prefix "at main+0" {
    gdb_test "p argc" " = 1"

    gdb_test "stepi"
}

with_test_prefix "at main+1" {
    gdb_test "p argc" " = <optimized out>"
}

gdb_breakpoint "*bar"
gdb_continue_to_breakpoint "bar"

with_test_prefix "at bar+0" {
    gdb_test "p foo" " = 2"

    gdb_test "stepi"
}

with_test_prefix "at bar+1" {
    gdb_test "p foo" " = <optimized out>"
}