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