gdb: Fix issue with Clang CLI macros
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / clang-cli-macro.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2022 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # Clang has this bug where it puts the macros defined on the command-line
19 # after the main file portion (see PR 29034 and
20 # https://github.com/llvm/llvm-project/issues/54506 )
21 # Test that GDB is still able to print macros in clang versions that
22 # have this bug.
23
24 load_lib dwarf.exp
25
26 if {![dwarf2_support]} {
27 return 0
28 }
29 if {![test_compiler_info gcc-*-*]} {
30 untested "dwarf assembler needs GCC"
31 }
32
33 standard_testfile .c .S
34
35 lassign [function_range main $srcdir/$subdir/$srcfile] \
36 main_start main_len
37
38 set asm_file [standard_output_file $srcfile2]
39
40 Dwarf::assemble $asm_file {
41 declare_labels L cu_macros
42
43 cu {} {
44 DW_TAG_compile_unit {
45 {DW_AT_producer "clang version 15.0.0"}
46 {DW_AT_language @DW_LANG_C11}
47 {DW_AT_name $::srcfile}
48 {DW_AT_macros $cu_macros DW_FORM_sec_offset}
49 {DW_AT_stmt_list $L DW_FORM_sec_offset}
50 } {
51 declare_labels int_type
52
53 int_type: DW_TAG_base_type {
54 {DW_AT_byte_size 4 DW_FORM_sdata}
55 {DW_AT_encoding @DW_ATE_signed}
56 {DW_AT_name int}
57 }
58 DW_TAG_subprogram {
59 {MACRO_AT_func {main}}
60 {type :$int_type}
61 }
62 }
63 }
64 lines {version 2} L {
65 file_name $::srcfile 1
66 program {
67 DW_LNE_set_address $::main_start
68 line 10
69 DW_LNS_copy
70 DW_LNE_set_address "$::main_start + $::main_len"
71 DW_LNE_end_sequence
72 }
73 }
74
75 # Define the .debug_macro section.
76 macro {
77 cu_macros: unit {
78 "debug-line-offset-label" $L
79 } {
80 start_file 0 1
81 # A macro defined at line 1 of the main file.
82 define 1 "TWO 2"
83 end_file
84 define 0 "ONE 1"
85 }
86 }
87 }
88
89 if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $asm_file] {nodebug}]} {
90 return
91 }
92
93 if {![runto_main]} {
94 return
95 }
96
97 gdb_test "print TWO" "= 2" "print simple macro"
98 gdb_test "print ONE" "= 1" "print defined from CLI"