Home | History | Annotate | Line # | Download | only in gdb.dwarf2
loc-sec-offset.exp revision 1.1.1.2
      1  1.1.1.2  christos # Copyright 2021-2024 Free Software Foundation, Inc.
      2      1.1  christos 
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos 
     16      1.1  christos # Test DW_AT_location attribute referencing the .debug_loc section using
     17      1.1  christos # the DW_FORM_sec_offset form.
     18      1.1  christos 
     19      1.1  christos load_lib dwarf.exp
     20      1.1  christos 
     21  1.1.1.2  christos require dwarf2_support
     22      1.1  christos 
     23      1.1  christos # Test with 32-bit and 64-bit DWARF.
     24      1.1  christos foreach_with_prefix is_64 {false true} {
     25      1.1  christos     if { $is_64 } {
     26      1.1  christos 	standard_testfile .c -dw64.S
     27      1.1  christos 	set testfile ${testfile}-dw64
     28      1.1  christos     } else {
     29      1.1  christos 	standard_testfile .c -dw32.S
     30      1.1  christos 	set testfile ${testfile}-dw32
     31      1.1  christos     }
     32      1.1  christos 
     33      1.1  christos     lassign [function_range func1 $srcdir/$subdir/$srcfile] \
     34      1.1  christos 	func1_addr func1_len
     35      1.1  christos     lassign [function_range func2 $srcdir/$subdir/$srcfile] \
     36      1.1  christos 	func2_addr func2_len
     37      1.1  christos 
     38      1.1  christos     set asm_file [standard_output_file $srcfile2]
     39      1.1  christos     Dwarf::assemble $asm_file {
     40      1.1  christos 	global func1_addr func1_len
     41      1.1  christos 	global func2_addr func2_len
     42      1.1  christos 	global is_64
     43      1.1  christos 
     44      1.1  christos 	set cu_version 4
     45      1.1  christos 
     46      1.1  christos 	cu {
     47      1.1  christos 	    version $cu_version
     48      1.1  christos 	    is_64 $is_64
     49      1.1  christos 	} {
     50      1.1  christos 	    declare_labels int_type1
     51      1.1  christos 	    declare_labels foo_location_list
     52      1.1  christos 
     53      1.1  christos 	    DW_TAG_compile_unit {
     54      1.1  christos 	    } {
     55      1.1  christos 		int_type1: DW_TAG_base_type {
     56      1.1  christos 		    {DW_AT_byte_size 4 DW_FORM_data1}
     57      1.1  christos 		    {DW_AT_encoding @DW_ATE_signed}
     58      1.1  christos 		    {DW_AT_name "int"}
     59      1.1  christos 		}
     60      1.1  christos 
     61      1.1  christos 		DW_TAG_variable {
     62      1.1  christos 		    {DW_AT_name "foo"}
     63      1.1  christos 		    {DW_AT_location $foo_location_list DW_FORM_sec_offset}
     64      1.1  christos 		    {DW_AT_type :$int_type1}
     65      1.1  christos 		}
     66      1.1  christos 
     67      1.1  christos 		DW_TAG_subprogram {
     68      1.1  christos 		    {DW_AT_name "func1"}
     69      1.1  christos 		    {DW_AT_low_pc $func1_addr}
     70      1.1  christos 		    {DW_AT_high_pc $func1_len DW_FORM_udata}
     71      1.1  christos 		}
     72      1.1  christos 
     73      1.1  christos 		DW_TAG_subprogram {
     74      1.1  christos 		    {DW_AT_name "func2"}
     75      1.1  christos 		    {DW_AT_low_pc $func2_addr}
     76      1.1  christos 		    {DW_AT_high_pc $func2_len DW_FORM_udata}
     77      1.1  christos 		}
     78      1.1  christos 	    }
     79      1.1  christos 	}
     80      1.1  christos 
     81      1.1  christos 	# Generate a .debug_loc contribution.
     82      1.1  christos 	loc {
     83      1.1  christos 	    cu_is_64 $is_64
     84      1.1  christos 	    cu_version $cu_version
     85      1.1  christos 	} {
     86      1.1  christos 	    foo_location_list:
     87      1.1  christos 	    entry $func1_addr "$func1_addr + $func1_len" {
     88      1.1  christos 		DW_OP_constu 0x123456
     89      1.1  christos 		DW_OP_stack_value
     90      1.1  christos 	    }
     91      1.1  christos 	    entry $func2_addr "$func2_addr + $func2_len" {
     92      1.1  christos 		DW_OP_constu 0x234567
     93      1.1  christos 		DW_OP_stack_value
     94      1.1  christos 	    }
     95      1.1  christos 	}
     96      1.1  christos     }
     97      1.1  christos 
     98      1.1  christos     if { [prepare_for_testing "failed to prepare" ${testfile} \
     99      1.1  christos 	      [list $srcfile $asm_file] {nodebug}] } {
    100      1.1  christos 	return -1
    101      1.1  christos     }
    102      1.1  christos 
    103      1.1  christos     if { ![runto_main] } {
    104      1.1  christos 	return
    105      1.1  christos     }
    106      1.1  christos 
    107      1.1  christos     gdb_breakpoint "func1"
    108      1.1  christos     gdb_breakpoint "func2"
    109      1.1  christos 
    110      1.1  christos     gdb_continue_to_breakpoint "func1"
    111      1.1  christos     with_test_prefix "at func1" {
    112      1.1  christos 	gdb_test "print /x foo" " = 0x123456"
    113      1.1  christos     }
    114      1.1  christos 
    115      1.1  christos     gdb_continue_to_breakpoint "func2"
    116      1.1  christos     with_test_prefix "at func2" {
    117      1.1  christos 	gdb_test "print /x foo" " = 0x234567"
    118      1.1  christos     }
    119      1.1  christos }
    120