[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / symbol-alias.exp
blob30599c726ae1efa2976e7ab0aed28d7f5cc31744
1 # Test for printing alias symbols.
2 # Copyright 2017-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 standard_testfile symbol-alias.c symbol-alias2.c
18 # Clang versions prior to v15 do not emit debug info for aliases.
19 set old_clang [expr [test_compiler_info {clang-1[0-4]-*-*}] \
20                  || [test_compiler_info {clang-[1-9]-*}]]
22 if { [prepare_for_testing "failed to prepare" ${testfile} [list $srcfile $srcfile2]] } {
23     return -1
26 if {![runto_main]} {
27     return
30 # Functions.
31 foreach f {"func" "func_alias"} {
32     gdb_test "p $f" " = {(struct )?S \\*\\(void\\)} $hex <func(\\(\\))?>"
33     gdb_test "p *${f}()" "= {field1 = 1, field2 = 2}"
36 # Extern global variable.
37 gdb_test "p g_var_s" "= {field1 = 1, field2 = 2}"
38 foreach v {"g_var_s_alias" "g_var_s_alias2"} {
39     gdb_test_multiple "p $v" "print alias variable $v" {
40         -re -wrap " = {field1 = 1, field2 = 2}" {
41             pass $gdb_test_name
42         }
43         -re -wrap "has unknown type; cast it to its declared type" {
44             if { $old_clang } {
45                 xfail $gdb_test_name
46             } else {
47                 fail $gdb_test_name
48             }
49         }
50     }
53 # Static global variable.
54 gdb_test "p g_var" " = 1"
55 gdb_test_multiple "p g_var_alias" "print alias of static variable" {
56     -re -wrap " = 1" {
57         pass $gdb_test_name
58     }
59     -re -wrap "has unknown type; cast it to its declared type" {
60         if { $old_clang } {
61           xfail $gdb_test_name
62         } else {
63           fail $gdb_test_name
64         }
65     }
68 # Alias of a variable that is declared later in the scope.
69 gdb_test "p g_def_var" " = 2"
70 gdb_test_multiple "p g_def_var_alias" "print g_def_var_alias" {
71     -re -wrap " = 2" {
72         pass $gdb_test_name
73     }
74     -re -wrap "has unknown type; cast it to its declared type" {
75         if { $old_clang } {
76           xfail $gdb_test_name
77         } else {
78           fail $gdb_test_name
79         }
80     }
82 gdb_test_multiple "p g_def_var_alias2" "print g_def_var_alias2" {
83     -re -wrap " = 2" {
84         pass $gdb_test_name
85     }
86     -re -wrap "has unknown type; cast it to its declared type" {
87         if { $old_clang } {
88           xfail $gdb_test_name
89         } else {
90           fail $gdb_test_name
91         }
92     }