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