1# Copyright 2012-2015 Free Software Foundation, Inc. 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15load_lib dwarf.exp 16 17# This test can only be run on targets which support DWARF-2 and use gas. 18if {![dwarf2_support]} { 19 return 0 20} 21 22# Find length of addresses in bytes. 23if {[is_64_target]} { 24 set addr_len 8 25} else { 26 set addr_len 4 27} 28 29standard_testfile 30set asmsrcfile [standard_output_file ${testfile}asm.S] 31set asmobjfile [standard_output_file ${testfile}asm.o] 32set srcabsdir [standard_output_file ${testfile}.d] 33set srctmpfile tmp-${testfile}.c 34 35# $srcdir may be relative. 36if {[file pathtype $srcabsdir] != "absolute"} { 37 untested "objdir pathtype is not absolute" 38 return -1 39} 40 41set f [open $asmsrcfile "w"] 42puts $f "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */" 43 44proc out_cu { name cu_dir cu_name line_dir line_name } { 45 global f 46 global addr_len 47 48 puts -nonewline $f "\ 49.L${name}_begin: 50 .4byte .L${name}_end - .L${name}_start /* Length of Compilation Unit */ 51.L${name}_start: 52 .2byte 2 /* DWARF Version */ 53 .4byte .Labbrev1_begin /* Offset into abbrev section */ 54 .byte ${addr_len} /* Pointer size */ 55" 56 if { $cu_dir != "" } { 57 puts $f " .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev: DW_TAG_compile_unit */" 58 } else { 59 puts $f " .uleb128 ABBREV_NAME /* Abbrev: DW_TAG_compile_unit */" 60 } 61 puts -nonewline $f "\ 62 .ascii \"GNU C\\0\" /* DW_AT_producer */ 63 .byte 2 /* DW_AT_language (DW_LANG_C) */ 64 .4byte .Lline_${name}_begin /* DW_AT_stmt_list */ 65 .${addr_len}byte ${name}_start /* DW_AT_low_pc */ 66 .${addr_len}byte ${name}_end /* DW_AT_high_pc */ 67" 68 if { $cu_dir != "" } { 69 puts $f " .ascii $cu_dir /* DW_AT_comp_dir */" 70 } 71 puts -nonewline $f "\ 72 .ascii $cu_name /* DW_AT_name */ 73 74 .uleb128 3 /* Abbrev: DW_TAG_subprogram */ 75 .asciz \"${name}\" /* DW_AT_name */ 76 .${addr_len}byte ${name}_start /* DW_AT_low_pc */ 77 .${addr_len}byte ${name}_end /* DW_AT_high_pc */ 78 79 .byte 0 /* End of children of CU */ 80.L${name}_end: 81" 82} 83 84proc out_line { name cu_dir cu_name line_dir line_name } { 85 global f 86 global addr_len 87 88 puts -nonewline $f "\ 89.Lline_${name}_begin: 90 .4byte .Lline_${name}_end - .Lline_${name}_start /* Initial length */ 91.Lline_${name}_start: 92 .2byte 2 /* Version */ 93 .4byte .Lline_${name}_lines - .Lline_${name}_hdr /* header_length */ 94.Lline_${name}_hdr: 95 .byte 1 /* Minimum insn length */ 96 .byte 1 /* default_is_stmt */ 97 .byte 1 /* line_base */ 98 .byte 1 /* line_range */ 99 .byte 4 /* opcode_base */ 100 101 /* Standard lengths */ 102 .byte 0 103 .byte 1 104 .byte 1 105 106 /* Include directories */ 107" 108 if { $line_dir != "" } { 109 puts $f " .ascii $line_dir" 110 } 111 puts -nonewline $f "\ 112 .byte 0 113 114 /* File names */ 115 .ascii $line_name 116" 117 if { $line_dir != "" } { 118 puts $f " .uleb128 1" 119 } else { 120 puts $f " .uleb128 0" 121 } 122 puts -nonewline $f "\ 123 .uleb128 0 124 .uleb128 0 125 126 .byte 0 127 128.Lline_${name}_lines: 129 .byte 3 /* DW_LNS_advance_line */ 130 .sleb128 998 /* ... to 999 */ 131 .byte 0 /* DW_LNE_set_address */ 132 .uleb128 ${addr_len}+1 133 .byte 2 134 .${addr_len}byte ${name}_start 135 .byte 1 /* DW_LNS_copy */ 136 .byte 3 /* DW_LNS_advance_line */ 137 .sleb128 1 /* ... to 1000 */ 138 .byte 0 /* DW_LNE_set_address */ 139 .uleb128 ${addr_len}+1 140 .byte 2 141 .${addr_len}byte ${name}_end 142 .byte 1 /* DW_LNS_copy */ 143 .byte 0 /* DW_LNE_end_of_sequence */ 144 .uleb128 1 145 .byte 1 146.Lline_${name}_end: 147" 148} 149 150# IFSOME can be optionally _same or _different if >= 2 absolute directories are 151# provided. Then in the _different case the overriden directories have invalid 152# XDIR value. 153 154proc out_unit { func compdir ldir file ifsame } { 155 set name "compdir_${compdir}_ldir_${ldir}_file_${file}${ifsame}" 156 157 if { $compdir == "missing_" } { 158 set cu_dir {} 159 } elseif { $compdir == "relative" } { 160 set cu_dir {COMPDIR "\0"} 161 } elseif { $compdir == "absolute" } { 162 set cu_dir {BDIR "/" COMPDIR "\0"} 163 } else { 164 error "compdir $compdir" 165 } 166 167 if { $ldir == "missing_" } { 168 set line_dir {} 169 } elseif { $ldir == "relative" } { 170 set line_dir {LDIR "\0"} 171 } elseif { $ldir == "absolute" } { 172 set line_dir {BDIR "/" LDIR "\0"} 173 } else { 174 error "ldir $ldir" 175 } 176 177 if { $file == "basename" } { 178 set cu_name {FILE "\0"} 179 } elseif { $file == "relative" } { 180 set cu_name {FDIR "/" FILE "\0"} 181 } elseif { $file == "absolute" } { 182 set cu_name {BDIR "/" FILE "\0"} 183 } else { 184 error "file $file" 185 } 186 set line_name $cu_name 187 188 if { "$ifsame" == "_different" } { 189 if { $file == "absolute" } { 190 if { $ldir == "absolute" } { 191 set line_dir {XDIR "\0"} 192 } 193 if { $compdir == "absolute" } { 194 set cu_dir {XDIR "\0"} 195 } 196 } elseif { $ldir == "absolute" } { 197 if { $compdir == "absolute" } { 198 set cu_dir {XDIR "\0"} 199 } 200 } else { 201 error "not enough absolutes" 202 } 203 } 204 205 $func $name $cu_dir $cu_name $line_dir $line_name 206} 207 208proc out_diff { func compdir ldir file } { 209 set abscount 0 210 if { $compdir == "absolute" } { 211 incr abscount 212 } 213 if { $ldir == "absolute" } { 214 incr abscount 215 } 216 if { $file == "absolute" } { 217 incr abscount 218 } 219 if { $abscount <= 1 } { 220 out_unit $func $compdir $ldir $file "" 221 } else { 222 out_unit $func $compdir $ldir $file "_same" 223 out_unit $func $compdir $ldir $file "_different" 224 } 225} 226 227proc out_file { func compdir ldir } { 228 out_diff $func $compdir $ldir "basename" 229 out_diff $func $compdir $ldir "relative" 230 out_diff $func $compdir $ldir "absolute" 231} 232 233proc out_ldir { func compdir } { 234 out_file $func $compdir "missing_" 235 out_file $func $compdir "relative" 236 out_file $func $compdir "absolute" 237} 238 239proc out_compdir { func } { 240 out_ldir $func "missing_" 241 out_ldir $func "relative" 242 out_ldir $func "absolute" 243} 244 245puts -nonewline $f "\ 246#define ABBREV_NAME 1 247#define ABBREV_COMP_DIR_NAME 2 248 .section .debug_info 249" 250out_compdir out_cu 251 252puts $f " .section .debug_line" 253out_compdir out_line 254 255puts -nonewline $f "\ 256 .section .debug_abbrev 257.Labbrev1_begin: 258 259 .uleb128 ABBREV_NAME /* Abbrev code */ 260 .uleb128 0x11 /* DW_TAG_compile_unit */ 261 .byte 1 /* has_children */ 262 .uleb128 0x25 /* DW_AT_producer */ 263 .uleb128 0x8 /* DW_FORM_string */ 264 .uleb128 0x13 /* DW_AT_language */ 265 .uleb128 0xb /* DW_FORM_data1 */ 266 .uleb128 0x10 /* DW_AT_stmt_list */ 267 .uleb128 0x6 /* DW_FORM_data4 */ 268 .uleb128 0x11 /* DW_AT_low_pc */ 269 .uleb128 0x1 /* DW_FORM_addr */ 270 .uleb128 0x12 /* DW_AT_high_pc */ 271 .uleb128 0x1 /* DW_FORM_addr */ 272 .uleb128 0x3 /* DW_AT_name */ 273 .uleb128 0x8 /* DW_FORM_string */ 274 .byte 0x0 /* Terminator */ 275 .byte 0x0 /* Terminator */ 276 277 .uleb128 ABBREV_COMP_DIR_NAME /* Abbrev code */ 278 .uleb128 0x11 /* DW_TAG_compile_unit */ 279 .byte 1 /* has_children */ 280 .uleb128 0x25 /* DW_AT_producer */ 281 .uleb128 0x8 /* DW_FORM_string */ 282 .uleb128 0x13 /* DW_AT_language */ 283 .uleb128 0xb /* DW_FORM_data1 */ 284 .uleb128 0x10 /* DW_AT_stmt_list */ 285 .uleb128 0x6 /* DW_FORM_data4 */ 286 .uleb128 0x11 /* DW_AT_low_pc */ 287 .uleb128 0x1 /* DW_FORM_addr */ 288 .uleb128 0x12 /* DW_AT_high_pc */ 289 .uleb128 0x1 /* DW_FORM_addr */ 290 .uleb128 0x1b /* DW_AT_comp_dir */ 291 .uleb128 0x8 /* DW_FORM_string */ 292 .uleb128 0x3 /* DW_AT_name */ 293 .uleb128 0x8 /* DW_FORM_string */ 294 .byte 0x0 /* Terminator */ 295 .byte 0x0 /* Terminator */ 296 297 .uleb128 3 /* Abbrev code */ 298 .uleb128 0x2e /* DW_TAG_subprogram */ 299 .byte 0 /* has_children */ 300 .uleb128 0x3 /* DW_AT_name */ 301 .uleb128 0x8 /* DW_FORM_string */ 302 .uleb128 0x11 /* DW_AT_low_pc */ 303 .uleb128 0x1 /* DW_FORM_addr */ 304 .uleb128 0x12 /* DW_AT_high_pc */ 305 .uleb128 0x1 /* DW_FORM_addr */ 306 .byte 0x0 /* Terminator */ 307 .byte 0x0 /* Terminator */ 308 309 .byte 0x0 /* Terminator */ 310 .byte 0x0 /* Terminator */ 311" 312 313close $f 314 315set opts {} 316# Base directory. 317lappend opts "additional_flags=-DBDIR=\"${srcabsdir}\"" 318# Incorrect directory which should never be visible from GDB. 319lappend opts "additional_flags=-DXDIR=\"${srcabsdir}/xdir\"" 320# CU's DW_AT_comp_dir. 321lappend opts "additional_flags=-DCOMPDIR=\"compdir\"" 322# .debug_line's directory. 323lappend opts "additional_flags=-DLDIR=\"ldir\"" 324# CU's DW_AT_name and .debug_line's filename relative directory, if needed. 325lappend opts "additional_flags=-DFDIR=\"fdir\"" 326# CU's DW_AT_name and .debug_line's filename. 327lappend opts "additional_flags=-DFILE=\"${srctmpfile}\"" 328 329if { [gdb_compile "${asmsrcfile} ${srcdir}/${subdir}/$srcfile" "${binfile}" executable $opts] != "" } { 330 untested "Cannot compile ${asmsrcfile} or $srcfile" 331 return -1 332} 333 334set dirs {} 335foreach r {"" /rdir} { 336 foreach x {"" /xdir} { 337 foreach comp {"" /compdir} { 338 foreach l {"" /ldir} { 339 foreach f {"" /fdir} { 340 lappend dirs $r$x$comp$l$f 341 } 342 } 343 } 344 } 345} 346 347proc pathexpand {prefix dirlst suffix} { 348 set retlst {} 349 foreach dir $dirlst { 350 lappend retlst "$prefix$dir$suffix" 351 } 352 return $retlst 353} 354 355set filelist [pathexpand $srcabsdir $dirs "/$srctmpfile"] 356set dircreatelist [pathexpand $srcabsdir $dirs ""] 357set dirremovelist [pathexpand $srcabsdir [lreverse $dirs] ""] 358 359remote_exec host "sh -c \"rm -f $filelist\"" 360remote_exec host "sh -c \"rmdir $dirremovelist\"" 361remote_exec host "sh -c \"mkdir $dircreatelist\"" 362remote_exec host "sh -c \"for d in $dircreatelist; do cp ${srcdir}/${subdir}/${srcfile} \\\$d/${srctmpfile}; done\"" 363 364clean_restart ${testfile} 365 366if ![runto_main] { 367 return -1 368} 369 370gdb_test "cd ${srcabsdir}/rdir" "Working directory [string_to_regexp ${srcabsdir}]/rdir\\." "cd .../rdir" 371 372proc test { func compdir filename } { 373 with_test_prefix "$func" { 374 # Clear the GDB cache. 375 gdb_test_no_output "set directories" "" 376 377 if {$compdir == ""} { 378 set absolute "$filename" 379 } else { 380 set absolute "$compdir/$filename" 381 } 382 if {[string index $absolute 0] != "/"} { 383 error "not absolute" 384 } 385 386 gdb_breakpoint $func 387 gdb_continue_to_breakpoint $func "$func \\(\\) at .*" 388 389 gdb_test_no_output "set filename-display absolute" 390 verbose -log "expect: ${absolute}" 391 gdb_test "frame" " in $func \\(\\) at [string_to_regexp ${absolute}]:999" "absolute" 392 393 gdb_test_no_output "set filename-display basename" 394 verbose -log "expect: [file tail $filename]" 395 gdb_test "frame" " in $func \\(\\) at [string_to_regexp [file tail $filename]]:999" "basename" 396 397 gdb_test_no_output "set filename-display relative" 398 verbose -log "expect: $filename" 399 gdb_test "frame" " in $func \\(\\) at [string_to_regexp $filename]:999" "relative" 400 } 401} 402 403set bdir "${srcabsdir}" 404set file "${srctmpfile}" 405test "compdir_missing__ldir_missing__file_basename" "$bdir/rdir" "$file" 406test "compdir_missing__ldir_missing__file_relative" "$bdir/rdir" "fdir/$file" 407test "compdir_missing__ldir_missing__file_absolute" "" "$bdir/$file" 408test "compdir_missing__ldir_relative_file_basename" "$bdir/rdir" "ldir/$file" 409test "compdir_missing__ldir_relative_file_relative" "$bdir/rdir" "ldir/fdir/$file" 410test "compdir_missing__ldir_relative_file_absolute" "" "$bdir/$file" 411test "compdir_missing__ldir_absolute_file_basename" "" "$bdir/ldir/$file" 412test "compdir_missing__ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file" 413test "compdir_missing__ldir_absolute_file_absolute_same" "" "$bdir/$file" 414test "compdir_missing__ldir_absolute_file_absolute_different" "" "$bdir/$file" 415test "compdir_relative_ldir_missing__file_basename" "$bdir/rdir/compdir" "$file" 416test "compdir_relative_ldir_missing__file_relative" "$bdir/rdir/compdir" "fdir/$file" 417test "compdir_relative_ldir_missing__file_absolute" "" "$bdir/$file" 418test "compdir_relative_ldir_relative_file_basename" "$bdir/rdir/compdir" "ldir/$file" 419test "compdir_relative_ldir_relative_file_relative" "$bdir/rdir/compdir" "ldir/fdir/$file" 420test "compdir_relative_ldir_relative_file_absolute" "" "$bdir/$file" 421test "compdir_relative_ldir_absolute_file_basename" "" "$bdir/ldir/$file" 422test "compdir_relative_ldir_absolute_file_relative" "" "$bdir/ldir/fdir/$file" 423test "compdir_relative_ldir_absolute_file_absolute_same" "" "$bdir/$file" 424test "compdir_relative_ldir_absolute_file_absolute_different" "" "$bdir/$file" 425test "compdir_absolute_ldir_missing__file_basename" "$bdir/compdir" "$file" 426test "compdir_absolute_ldir_missing__file_relative" "$bdir/compdir" "fdir/$file" 427test "compdir_absolute_ldir_missing__file_absolute_same" "" "$bdir/$file" 428test "compdir_absolute_ldir_missing__file_absolute_different" "" "$bdir/$file" 429test "compdir_absolute_ldir_relative_file_basename" "$bdir/compdir" "ldir/$file" 430test "compdir_absolute_ldir_relative_file_relative" "$bdir/compdir" "ldir/fdir/$file" 431test "compdir_absolute_ldir_relative_file_absolute_same" "" "$bdir/$file" 432test "compdir_absolute_ldir_relative_file_absolute_different" "" "$bdir/$file" 433test "compdir_absolute_ldir_absolute_file_basename_same" "" "$bdir/ldir/$file" 434test "compdir_absolute_ldir_absolute_file_relative_different" "" "$bdir/ldir/fdir/$file" 435test "compdir_absolute_ldir_absolute_file_absolute_same" "" "$bdir/$file" 436test "compdir_absolute_ldir_absolute_file_absolute_different" "" "$bdir/$file" 437