Get rid of "No such file or directory" in the testsuite's btrace support detection.
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
index 38a8ac674efd1fd045d60e805f22dcd63ccef035..d05257d0f3cbfc29d7104f8b7951d816dfec624e 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1992-2005, 2007-2012 Free Software Foundation, Inc.
+# Copyright 1992-2013 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -123,7 +123,7 @@ proc default_gdb_version {} {
 }
 
 proc gdb_version { } {
-    return [default_gdb_version];
+    return [default_gdb_version]
 }
 
 #
@@ -310,7 +310,7 @@ proc gdb_start_cmd {args} {
            -re "$gdb_prompt $" { }
            default {
                perror "gdb_init_command for target failed";
-               return -1;
+               return -1
            }
        }
     }
@@ -421,7 +421,7 @@ proc gdb_breakpoint { function args } {
     if { $print_pass } {
        pass $test_name
     }
-    return 1;
+    return 1
 }    
 
 # Set breakpoint at function and run gdb until it breaks there.
@@ -466,7 +466,7 @@ proc runto { function args } {
     # elements, and we don't want Tcl to move the remaining elements after
     # the first to $args.  That is why $function is wrapped in {}.
     if ![eval gdb_breakpoint {$function} $args] {
-       return 0;
+       return 0
     }
 
     gdb_run_cmd
@@ -758,7 +758,7 @@ proc gdb_test_multiple { command message user_code } {
                        perror "Couldn't send $command to GDB.";
                    }
                    fail "$message";
-                   return $result;
+                   return $result
                }
                # since we're checking if each line of the multi-line
                # command are 'accepted' by GDB here,
@@ -783,7 +783,7 @@ proc gdb_test_multiple { command message user_code } {
                    perror "Couldn't send $command to GDB.";
                }
                fail "$message";
-               return $result;
+               return $result
            }
        }
     }
@@ -1208,7 +1208,7 @@ proc gdb_reinitialize_dir { subdir } {
     global gdb_prompt
 
     if [is_remote host] {
-       return "";
+       return ""
     }
     send_gdb "dir\n"
     gdb_expect 60 {
@@ -1418,7 +1418,7 @@ proc default_gdb_start { } {
     verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
 
     if [info exists gdb_spawn_id] {
-       return 0;
+       return 0
     }
 
     if ![is_remote host] {
@@ -1430,7 +1430,7 @@ proc default_gdb_start { } {
     set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
     if { $res < 0 || $res == "" } {
        perror "Spawning $GDB failed."
-       return 1;
+       return 1
     }
     gdb_expect 360 {
        -re "\[\r\n\]$gdb_prompt $" {
@@ -1468,7 +1468,7 @@ proc default_gdb_start { } {
            warning "Couldn't set the width to 0."
        }
     }
-    return 0;
+    return 0
 }
 
 # Examine the output of compilation to determine whether compilation
@@ -2097,6 +2097,76 @@ proc skip_vsx_tests {} {
     return $skip_vsx_tests_saved
 }
 
+# Run a test on the target to see if it supports btrace hardware.  Return 0 if so,
+# 1 if it does not.  Based on 'check_vmx_hw_available' from the GCC testsuite.
+
+proc skip_btrace_tests {} {
+    global skip_btrace_tests_saved
+    global srcdir subdir gdb_prompt inferior_exited_re
+
+    # Use the cached value, if it exists.
+    set me "skip_btrace_tests"
+    if [info exists skip_btrace_tests_saved] {
+        verbose "$me:  returning saved $skip_btrace_tests_saved" 2
+        return $skip_btrace_tests_saved
+    }
+
+    if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
+        verbose "$me:  target does not support btrace, returning 1" 2
+        return [set skip_btrace_tests_saved 1]
+    }
+
+    # Set up, compile, and execute a test program.
+    # Include the current process ID in the file names to prevent conflicts
+    # with invocations for multiple testsuites.
+    set src [standard_output_file btrace[pid].c]
+    set exe [standard_output_file btrace[pid].x]
+
+    set f [open $src "w"]
+    puts $f "int main(void) { return 0; }"
+    close $f
+
+    verbose "$me:  compiling testfile $src" 2
+    set compile_flags {debug nowarnings quiet}
+    set lines [gdb_compile $src $exe executable $compile_flags]
+
+    if ![string match "" $lines] then {
+        verbose "$me:  testfile compilation failed, returning 1" 2
+       file delete $src
+        return [set skip_btrace_tests_saved 1]
+    }
+
+    # No error message, compilation succeeded so now run it via gdb.
+
+    clean_restart btrace[pid].x
+    if ![runto_main] {
+       file delete $src
+        return [set skip_btrace_tests_saved 1]
+    }
+    file delete $src
+    # In case of an unexpected output, we return 2 as a fail value.
+    set skip_btrace_tests_saved 2
+    gdb_test_multiple "record btrace" "check btrace support" {
+        -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
+            set skip_btrace_tests_saved 1
+        }
+        -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
+            set skip_btrace_tests_saved 1
+        }
+        -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
+            set skip_btrace_tests_saved 1
+        }
+        -re "^record btrace\r\n$gdb_prompt $" {
+            set skip_btrace_tests_saved 0
+        }
+    }
+    gdb_exit
+    remote_file build delete $exe
+
+    verbose "$me:  returning $skip_btrace_tests_saved" 2
+    return $skip_btrace_tests_saved
+}
+
 # Skip all the tests in the file if you are not on an hppa running
 # hpux target.
 
@@ -2384,7 +2454,7 @@ proc get_compiler_info {{arg ""}} {
       uplevel \#0 { set false false }
     }
 
-    return 0;
+    return 0
 }
 
 proc test_compiler_info { {compiler ""} } {
@@ -2602,7 +2672,7 @@ proc gdb_compile {source dest type options} {
            clone_output "gdb compile failed, $result"
        }
     }
-    return $result;
+    return $result
 }
 
 
@@ -2795,9 +2865,9 @@ proc gdb_compile_objc {source dest type options} {
 proc send_gdb { string } {
     global suppress_flag;
     if { $suppress_flag } {
-       return "suppressed";
+       return "suppressed"
     }
-    return [remote_send host "$string"];
+    return [remote_send host "$string"]
 }
 
 #
@@ -3195,7 +3265,7 @@ proc gdb_reload { } {
 proc gdb_continue { function } {
     global decimal
 
-    return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
+    return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
 }
 
 proc default_gdb_init { args } {
@@ -3402,7 +3472,7 @@ proc gdb_init { args } {
     set gdbserver_reconnect_p 1
     unset gdbserver_reconnect_p
 
-    return [eval default_gdb_init $args];
+    return [eval default_gdb_init $args]
 }
 
 proc gdb_finish { } {
@@ -3452,19 +3522,19 @@ proc get_debug_format { } {
        -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
            set debug_format $expect_out(1,string)
            verbose "debug format is $debug_format"
-           return 1;
+           return 1
        }
        -re "No current source file.\r\n$gdb_prompt $" {
            perror "get_debug_format used when no current source file"
-           return 0;
+           return 0
        }
        -re "$gdb_prompt $" {
            warning "couldn't check debug format (no valid response)."
-           return 1;
+           return 1
        }
        timeout {
            warning "couldn't check debug format (timeout)."
-           return 1;
+           return 1
        }
     }
 }
@@ -3493,7 +3563,7 @@ proc setup_xfail_format { format } {
     if {$ret} then {
        setup_xfail "*-*-*"
     }
-    return $ret;
+    return $ret
 }
 
 # gdb_get_line_number TEXT [FILE]
@@ -3677,9 +3747,9 @@ proc rerun_to_main {} {
 proc gdb_skip_float_test { msg } {
     if [target_info exists gdb,skip_float_tests] {
        verbose "Skipping test '$msg': no float tests.";
-       return 1;
+       return 1
     }
-    return 0;
+    return 0
 }
 
 # Print a message and return true if a test should be skipped
@@ -3688,13 +3758,13 @@ proc gdb_skip_float_test { msg } {
 proc gdb_skip_stdio_test { msg } {
     if [target_info exists gdb,noinferiorio] {
        verbose "Skipping test '$msg': no inferior i/o.";
-       return 1;
+       return 1
     }
-    return 0;
+    return 0
 }
 
 proc gdb_skip_bogus_test { msg } {
-    return 0;
+    return 0
 }
 
 # Return true if a test should be skipped due to lack of XML support
@@ -3764,7 +3834,7 @@ proc build_id_debug_filename_get { exec } {
     # Convert it to hex.
     binary scan $data H* data
     regsub {^..} $data {\0/} data
-    return ".build-id/${data}.debug";
+    return ".build-id/${data}.debug"
 }
 
 # Create stripped files for DEST, replacing it.  If ARGS is passed, it is a
@@ -4068,7 +4138,7 @@ proc get_remotetimeout { } {
 
     gdb_test_multiple "show remotetimeout" "" {
        -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
-           return $expect_out(1,string);
+           return $expect_out(1,string)
        }
     }
 
This page took 0.027704 seconds and 4 git commands to generate.