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