]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
introduce relative_filename and use it
authorTom Tromey <tromey@redhat.com>
Fri, 23 Aug 2013 18:18:57 +0000 (12:18 -0600)
committerTom Tromey <tromey@redhat.com>
Mon, 4 Nov 2013 18:02:08 +0000 (11:02 -0700)
This introduces a new relative_filename proc to gdb.exp and changes
some tests to use it.  This helps make these tests parallel-safe.

2013-11-04  Tom Tromey  <tromey@redhat.com>

* gdb.base/fullname.exp: Use standard_output_file,
relative_filename.
* gdb.base/hashline1.exp: Use standard_testfile,
standard_output_file, relative_filename, clean_restart.
* gdb.base/hashline2.exp: Use standard_testfile,
standard_output_file.
* gdb.base/hashline3.exp: Use standard_testfile,
standard_output_file, relative_filename.
* lib/gdb.exp (relative_filename): New proc.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/fullname.exp
gdb/testsuite/gdb.base/hashline1.exp
gdb/testsuite/gdb.base/hashline2.exp
gdb/testsuite/gdb.base/hashline3.exp
gdb/testsuite/lib/gdb.exp

index c913cbbb4e7bdc754c76e2cd3203b1f02b2d0e60..b171dc2566637ef750ae2ded50fdeb865fecd168 100644 (file)
@@ -1,3 +1,15 @@
+2013-11-04  Tom Tromey  <tromey@redhat.com>
+
+       * gdb.base/fullname.exp: Use standard_output_file,
+       relative_filename.
+       * gdb.base/hashline1.exp: Use standard_testfile,
+       standard_output_file, relative_filename, clean_restart.
+       * gdb.base/hashline2.exp: Use standard_testfile,
+       standard_output_file.
+       * gdb.base/hashline3.exp: Use standard_testfile,
+       standard_output_file, relative_filename.
+       * lib/gdb.exp (relative_filename): New proc.
+
 2013-11-04  Tom Tromey  <tromey@redhat.com>
 
        * gdb.base/fileio.c (test_open, test_write, test_read)
index 32f6ea455836f6ade403550ce9c678766e401fb5..2754f59f50a631a5fa434c447a1f0803b142425b 100644 (file)
@@ -70,7 +70,8 @@ if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}]
 }
 
 # Build the test executable using a relative path.
-if  { [gdb_compile "${subdir}/tmp-${srcfile}" "${binfile}" executable {debug}] != "" } {
+if  { [gdb_compile [relative_filename [pwd] [standard_output_file tmp-${srcfile}]] \
+          "${binfile}" executable {debug}] != "" } {
     return -1
 }
 
@@ -99,7 +100,7 @@ if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}]
 # we'll run GDB from.
 
 set save_pwd [pwd]
-cd ${subdir}
+cd [standard_output_file {}]
 if  { [gdb_compile [standard_output_file tmp-${srcfile}] "${testfile}" \
           executable {debug}] != "" } {
     cd $save_pwd
index 950d67efb1f7ed36e3332fa4f52a7844a45876cb..2330daf7f0021670d2eabdf7bb8e2b96be102241 100644 (file)
 # srcfile is in objdir because we need to machine generate it in order
 # to get the correct path in the #line directive.
 
-set testfile "hashline1"
-set srcfile "${testfile}.c"
-set binfile "${objdir}/${subdir}/${testfile}"
+standard_testfile .c
 
-set fd [open ${objdir}/${subdir}/${srcfile} w]
-puts $fd "#line 2 \"[pwd]/${subdir}/${srcfile}\""
+set new_srcfile [standard_output_file $srcfile]
+set fd [open $new_srcfile w]
+puts $fd "#line 2 \"$new_srcfile\""
 puts $fd "int main () { return 0; } /* set breakpoint here */"
 close $fd
 
 # The choice of path name for the source file is important in order to trigger
-# the bug.  Using ${objdir}/${subdir}/${srcfile} here won't trigger the bug.
-if { [gdb_compile "./${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+# the bug.  Using $new_srcfile here won't trigger the bug.
+set compile_name [relative_filename $objdir $new_srcfile]
+if { [gdb_compile $compile_name "${binfile}" executable {debug}] != "" } {
     untested hashline1.exp
     return -1
 }
 
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
+clean_restart ${binfile}
 
-set bp_location [gdb_get_line_number "set breakpoint here" ${objdir}/${subdir}/${srcfile}]
+set bp_location [gdb_get_line_number "set breakpoint here" $new_srcfile]
 
 # Try to set a breakpoint on the specified file location.
 
index d7ee4a75dfc78b7e4334455a1ad75c498e37f83e..cd748ca7b5adb1dd770997909cb239b39e2c5ccd 100644 (file)
 # srcfile is in objdir because we need to machine generate it in order
 # to get the correct path in the #line directive.
 
-set testfile "hashline2"
-set srcfile "${testfile}.c"
-set binfile "${objdir}/${subdir}/${testfile}"
+standard_testfile .c
 
-set fd [open ${objdir}/${subdir}/${srcfile} w]
-puts $fd "#line 2 \"///[pwd]/${subdir}/${srcfile}\""
+set new_srcfile [standard_output_file $srcfile]
+set fd [open $new_srcfile w]
+puts $fd "#line 2 \"///${new_srcfile}\""
 puts $fd "int main () { return 0; } /* set breakpoint here */"
 close $fd
 
-if { [gdb_compile "${objdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if { [gdb_compile $new_srcfile "${binfile}" executable {debug}] != "" } {
     untested hashline2.exp
     return -1
 }
@@ -40,7 +39,7 @@ gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
-set bp_location [gdb_get_line_number "set breakpoint here" ${objdir}/${subdir}/${srcfile}]
+set bp_location [gdb_get_line_number "set breakpoint here" ${new_srcfile}]
 
 # Try to set a breakpoint on the specified file location.
 
index 2496b3ccd5afe77575ba047403578e7cff3a79a3..eba5f778be51885f95adf08944c7eac83aca007c 100644 (file)
 # srcfile is in objdir because we need to machine generate it in order
 # to get the correct path in the #line directive.
 
-set testfile "hashline3"
-set srcfile "${testfile}.c"
-set binfile "${objdir}/${subdir}/${testfile}"
+standard_testfile
 
-set fd [open ${objdir}/${subdir}/${srcfile} w]
-puts $fd "#line 2 \"./${subdir}/${srcfile}\""
+set new_srcfile [standard_output_file $srcfile]
+set fd [open $new_srcfile w]
+set relative [relative_filename $objdir $new_srcfile]
+puts $fd "#line 2 \"./$relative\""
 puts $fd "int main () { return 0; } /* set breakpoint here */"
 close $fd
 
-if { [gdb_compile "${objdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if { [gdb_compile $new_srcfile "${binfile}" executable {debug}] != "" } {
     untested hashline3.exp
     return -1
 }
@@ -40,7 +40,7 @@ gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
-set bp_location [gdb_get_line_number "set breakpoint here" ${objdir}/${subdir}/${srcfile}]
+set bp_location [gdb_get_line_number "set breakpoint here" $new_srcfile]
 
 # Try to set a breakpoint on the specified file location.
 
index 21a44af3767e7b62950fcc623f9dc3c2b34e6b0a..76137613c39a1de5ffebc3c3fef351eb9bb1cf14 100644 (file)
@@ -4372,6 +4372,25 @@ proc set_remotetimeout { timeout } {
     }
 }
 
+# ROOT and FULL are file names.  Returns the relative path from ROOT
+# to FULL.  Note that FULL must be in a subdirectory of ROOT.
+# For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
+# will return "ls".
+
+proc relative_filename {root full} {
+    set root_split [file split $root]
+    set full_split [file split $full]
+
+    set len [llength $root_split]
+
+    if {[eval file join $root_split]
+       != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
+       error "$full not a subdir of $root"
+    }
+
+    return [eval file join [lrange $full_split $len end]]
+}
+
 # Log gdb command line and script if requested.
 if {[info exists TRANSCRIPT]} {
   rename send_gdb real_send_gdb