1 # This testcase is part of GDB, the GNU debugger. 2 3 # Copyright 2022-2024 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 require dwarf2_support 27 28 standard_testfile .c .S 29 30 lassign [function_range main $srcdir/$subdir/$srcfile] \ 31 main_start main_len 32 33 set asm_file [standard_output_file $srcfile2] 34 35 Dwarf::assemble $asm_file { 36 declare_labels L cu_macros 37 38 cu {} { 39 DW_TAG_compile_unit { 40 {DW_AT_producer "clang version 15.0.0"} 41 {DW_AT_language @DW_LANG_C11} 42 {DW_AT_name $::srcfile} 43 {DW_AT_macros $cu_macros DW_FORM_sec_offset} 44 {DW_AT_stmt_list $L DW_FORM_sec_offset} 45 } { 46 declare_labels int_type 47 48 int_type: DW_TAG_base_type { 49 {DW_AT_byte_size 4 DW_FORM_sdata} 50 {DW_AT_encoding @DW_ATE_signed} 51 {DW_AT_name int} 52 } 53 DW_TAG_subprogram { 54 {MACRO_AT_func {main}} 55 {type :$int_type} 56 } 57 } 58 } 59 lines {version 2} L { 60 file_name $::srcfile 1 61 program { 62 DW_LNE_set_address $::main_start 63 line 10 64 DW_LNS_copy 65 DW_LNE_set_address "$::main_start + $::main_len" 66 DW_LNE_end_sequence 67 } 68 } 69 70 # Define the .debug_macro section. 71 macro { 72 cu_macros: unit { 73 "debug-line-offset-label" $L 74 } { 75 start_file 0 1 76 # A macro defined at line 1 of the main file. 77 define 1 "TWO 2" 78 end_file 79 define 0 "ONE 1" 80 } 81 } 82 } 83 84 if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $asm_file] {nodebug}]} { 85 return 86 } 87 88 if {![runto_main]} { 89 return 90 } 91 92 gdb_test "print TWO" "= 2" "print simple macro" 93 gdb_test "print ONE" "= 1" "print defined from CLI" 94