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