gdb/testsuite: make 'c' default language for get/test compiler info
[binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
index 720418beac294376671032e6085f2936516ff70c..e530ba05a61cb31427a86b57312c085258ee100c 100644 (file)
@@ -834,6 +834,13 @@ proc gdb_internal_error_resync {} {
     return 0
 }
 
+# Fill in the default prompt if PROMPT_REGEXP is empty.
+proc fill_in_default_prompt {prompt_regexp} {
+    if { "$prompt_regexp" == "" } {
+       return "$::gdb_prompt $"
+    }
+    return $prompt_regexp
+}
 
 # gdb_test_multiple COMMAND MESSAGE [ -prompt PROMPT_REGEXP] [ -lbl ]
 #                   EXPECT_ARGUMENTS
@@ -960,9 +967,7 @@ proc gdb_test_multiple { command message args } {
        error "Too few arguments to gdb_test_multiple"
     }
 
-    if { "$prompt_regexp" == "" } {
-       set prompt_regexp "$gdb_prompt $"
-    }
+    set prompt_regexp [fill_in_default_prompt $prompt_regexp]
 
     if { $message == "" } {
        set message $command
@@ -1335,6 +1340,7 @@ proc gdb_test_multiline { name args } {
 # -prompt PROMPT_REGEXP specifies a regexp matching the expected prompt
 #   after the command output.  If empty, defaults to "$gdb_prompt $".
 # -lbl specifies that line-by-line matching will be used.
+# -nopass specifies that a PASS should not be issued.
 #
 # Returns:
 #    1 if the test failed,
@@ -1348,6 +1354,7 @@ proc gdb_test { args } {
     parse_args {
        {prompt ""}
        {lbl}
+       {nopass}
     }
 
     lassign $args command pattern message question response
@@ -1361,21 +1368,17 @@ proc gdb_test { args } {
        set message $command
     }
 
-    if { $prompt == "" } {
-       set prompt "$gdb_prompt $"
-    }
+    set prompt [fill_in_default_prompt $prompt]
 
     set saw_question 0
 
     set user_code {}
     lappend user_code {
        -re "\[\r\n\]*(?:$pattern)\[\r\n\]+$prompt" {
-           if ![string match "" $message] then {
-               if { $question != "" } {
-                   gdb_assert $saw_question "$message"
-               } else {
-                   pass "$message"
-               }
+           if { $question != "" & !$saw_question} {
+               fail $message
+           } elseif {!$nopass} {
+               pass $message
            }
        }
     }
@@ -1393,7 +1396,7 @@ proc gdb_test { args } {
     set user_code [join $user_code]
 
     set opts {}
-    lappend "-prompt $prompt"
+    lappend opts "-prompt" "$prompt"
     if {$lbl} {
        lappend opts "-lbl"
     }
@@ -1439,30 +1442,31 @@ if { [tcl_version_at_least 8 5] == 0 } {
     }
 }
 
-# gdb_test_no_output COMMAND MESSAGE
+# gdb_test_no_output [-prompt PROMPT_REGEXP] [-nopass] COMMAND [MESSAGE]
 # Send a command to GDB and verify that this command generated no output.
 #
-# See gdb_test_multiple for a description of the COMMAND and MESSAGE
-# parameters.  If MESSAGE is ommitted, then COMMAND will be used as
-# the message.  (If MESSAGE is the empty string, then sometimes we do not
-# call pass or fail at all; I don't understand this at all.)
+# See gdb_test for a description of the -prompt, -nopass, COMMAND, and
+# MESSAGE parameters.
 
 proc gdb_test_no_output { args } {
     global gdb_prompt
-    set command [lindex $args 0]
-    if [llength $args]>1 then {
-       set message [lindex $args 1]
-    } else {
-       set message $command
+
+    parse_args {
+       {prompt_re ""}
+       {nopass}
     }
 
+    lassign $args command message
+
+    set prompt_re [fill_in_default_prompt $prompt_re]
+
     set command_regex [string_to_regexp $command]
-    gdb_test_multiple $command $message {
-        -re "^$command_regex\r\n$gdb_prompt $" {
-           if ![string match "" $message] then {
-               pass "$message"
-            }
-        }
+    gdb_test_multiple $command $message -prompt $prompt_re {
+       -re "^$command_regex\r\n$prompt_re" {
+           if {!$nopass} {
+               pass $gdb_test_name
+           }
+       }
     }
 }
 
@@ -2801,11 +2805,11 @@ proc with_target_charset { target_charset body } {
        }
     }
 
-    gdb_test_no_output "set target-charset $target_charset" ""
+    gdb_test_no_output -nopass "set target-charset $target_charset"
 
     set code [catch {uplevel 1 $body} result]
 
-    gdb_test_no_output "set target-charset $saved" ""
+    gdb_test_no_output -nopass "set target-charset $saved"
 
     if {$code == 1} {
        global errorInfo errorCode
@@ -3234,10 +3238,6 @@ gdb_caching_proc skip_altivec_tests {
     }
 
     # Make sure we have a compiler that understands altivec.
-    if [get_compiler_info] {
-       warning "Could not get compiler info"
-       return 1
-    }
     if [test_compiler_info gcc*] {
         set compile_flags "additional_flags=-maltivec"
     } elseif [test_compiler_info xlc*] {
@@ -3353,10 +3353,6 @@ gdb_caching_proc skip_vsx_tests {
     }
 
     # Make sure we have a compiler that understands altivec.
-    if [get_compiler_info] {
-       warning "Could not get compiler info"
-       return 1
-    }
     if [test_compiler_info gcc*] {
         set compile_flags "additional_flags=-mvsx"
     } elseif [test_compiler_info xlc*] {
@@ -4101,15 +4097,15 @@ set gcc_compiled                0
 #
 # -- chastain 2004-01-06
 
-proc get_compiler_info {{arg ""}} {
-    # For compiler.c and compiler.cc
+proc get_compiler_info {{language "c"}} {
+    # For compiler.c, compiler.cc and compiler.F90.
     global srcdir
 
     # I am going to play with the log to keep noise out.
     global outdir
     global tool
 
-    # These come from compiler.c or compiler.cc
+    # These come from compiler.c, compiler.cc or compiler.F90.
     global compiler_info
 
     # Legacy global data symbols.
@@ -4121,9 +4117,15 @@ proc get_compiler_info {{arg ""}} {
     }
 
     # Choose which file to preprocess.
-    set ifile "${srcdir}/lib/compiler.c"
-    if { $arg == "c++" } {
+    if { $language == "c++" } {
        set ifile "${srcdir}/lib/compiler.cc"
+    } elseif { $language == "f90" } {
+       set ifile "${srcdir}/lib/compiler.F90"
+    } elseif { $language == "c" } {
+       set ifile "${srcdir}/lib/compiler.c"
+    } else {
+       perror "Unable to fetch compiler version for language: $language"
+       return -1
     }
 
     # Run $ifile through the right preprocessor.
@@ -4134,12 +4136,12 @@ proc get_compiler_info {{arg ""}} {
        # We have to use -E and -o together, despite the comments
        # above, because of how DejaGnu handles remote host testing.
        set ppout "$outdir/compiler.i"
-       gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet getting_compiler_info]
+       gdb_compile "${ifile}" "$ppout" preprocess [list "$language" quiet getting_compiler_info]
        set file [open $ppout r]
        set cppout [read $file]
        close $file
     } else {
-       set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet getting_compiler_info] ]
+       set cppout [ gdb_compile "${ifile}" "" preprocess [list "$language" quiet getting_compiler_info] ]
     }
     eval log_file $saved_log
 
@@ -4154,6 +4156,10 @@ proc get_compiler_info {{arg ""}} {
            # eval this line
            verbose "get_compiler_info: $cppline" 2
            eval "$cppline"
+       } elseif { [ regexp "flang.*warning.*'-fdiagnostics-color=never'" "$cppline"] } {
+           # Both flang preprocessors (llvm flang and classic flang) print a
+           # warning for the unused -fdiagnostics-color=never, so we skip this
+           # output line here.
        } else {
            # unknown line
            verbose -log "get_compiler_info: $cppline"
@@ -4191,9 +4197,9 @@ proc get_compiler_info {{arg ""}} {
 # Otherwise the argument is a glob-style expression to match against
 # compiler_info.
 
-proc test_compiler_info { {compiler ""} } {
+proc test_compiler_info { {compiler ""} {language "c"} } {
     global compiler_info
-    get_compiler_info
+    get_compiler_info $language
 
     # If no arg, return the compiler_info string.
     if [string match "" $compiler] {
@@ -4208,12 +4214,11 @@ proc test_compiler_info { {compiler ""} } {
 # For gcc 7.5.0, the major version 7.
 
 proc gcc_major_version { } {
-    global compiler_info
     global decimal
     if { ![test_compiler_info "gcc-*"] } {
        return -1
     }
-    set res [regexp gcc-($decimal)-($decimal)- $compiler_info \
+    set res [regexp gcc-($decimal)-($decimal)- [test_compiler_info] \
                 dummy_var major minor]
     if { $res != 1 } {
        return -1
@@ -4393,8 +4398,8 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #   - ldflags=flag: Add FLAG to the linker flags.
 #   - incdir=path: Add PATH to the searched include directories.
 #   - libdir=path: Add PATH to the linker searched directories.
-#   - ada, c++, f77, f90, go, rust: Compile the file as Ada, C++,
-#     Fortran 77, Fortran 90, Go or Rust.
+#   - ada, c++, f90, go, rust: Compile the file as Ada, C++,
+#     Fortran 90, Go or Rust.
 #   - debug: Build with debug information.
 #   - optimize: Build with optimization.
 
@@ -4408,6 +4413,13 @@ proc gdb_compile {source dest type options} {
 
     set outdir [file dirname $dest]
 
+    # If this is set, calling test_compiler_info will cause recursion.
+    if { [lsearch -exact $options getting_compiler_info] == -1 } {
+       set getting_compiler_info false
+    } else {
+       set getting_compiler_info true
+    }
+
     # Add platform-specific options if a shared library was specified using
     # "shlib=librarypath" in OPTIONS.
     set new_options {}
@@ -4424,10 +4436,9 @@ proc gdb_compile {source dest type options} {
     # default, unless you pass -Wno-unknown-warning-option as well.
     # We do that here, so that individual testcases don't have to
     # worry about it.
-    if {[lsearch -exact $options getting_compiler_info] == -1
+    if {!$getting_compiler_info
        && [lsearch -exact $options rust] == -1
        && [lsearch -exact $options ada] == -1
-       && [lsearch -exact $options f77] == -1
        && [lsearch -exact $options f90] == -1
        && [lsearch -exact $options go] == -1
        && [test_compiler_info "clang-*"]} {
@@ -4436,7 +4447,7 @@ proc gdb_compile {source dest type options} {
 
     # Treating .c input files as C++ is deprecated in Clang, so
     # explicitly force C++ language.
-    if { [lsearch -exact $options getting_compiler_info] == -1
+    if { !$getting_compiler_info
         && [lsearch -exact $options c++] != -1
         && [string match *.c $source] != 0 } {
 
@@ -4455,19 +4466,24 @@ proc gdb_compile {source dest type options} {
     }
 
     # Place (and look for) Fortran `.mod` files in the output
-    # directory for this specific test.
-    if {[lsearch -exact $options f77] != -1 \
-           || [lsearch -exact $options f90] != -1 } {
+    # directory for this specific test.  For Intel compilers the -J
+    # option is not supported so instead use the -module flag.
+    # Additionally, Intel compilers need the -debug-parameters flag set to
+    # emit debug info for all parameters in modules.
+    if { !$getting_compiler_info && [lsearch -exact $options f90] != -1 } {
        # Fortran compile.
        set mod_path [standard_output_file ""]
-       if [test_compiler_info "gcc-*"] {
+       if { [test_compiler_info {gfortran-*} f90] } {
            lappend new_options "additional_flags=-J${mod_path}"
+       } elseif { [test_compiler_info {ifort-*} f90]
+                  || [test_compiler_info {ifx-*} f90] } {
+           lappend new_options "additional_flags=-module ${mod_path}"
+           lappend new_options "additional_flags=-debug-parameters all"
        }
     }
 
     set shlib_found 0
     set shlib_load 0
-    set getting_compiler_info 0
     foreach opt $options {
         if {[regexp {^shlib=(.*)} $opt dummy_var shlib_name]
            && $type == "executable"} {
@@ -4499,8 +4515,9 @@ proc gdb_compile {source dest type options} {
        } elseif { $opt == "shlib_load" && $type == "executable" } {
            set shlib_load 1
        } elseif { $opt == "getting_compiler_info" } {
-           # If this is set, calling test_compiler_info will cause recursion.
-           set getting_compiler_info 1
+           # Ignore this setting here as it has been handled earlier in this
+           # procedure.  Do not append it to new_options as this will cause
+           # recursion.
         } elseif {[regexp "^text_segment=(.*)" $opt dummy_var addr]} {
             if { [linker_supports_Ttext_segment_flag] } {
                 # For GNU ld.
@@ -4523,7 +4540,7 @@ proc gdb_compile {source dest type options} {
     # DWARF line numbering.
     # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88432
     # This option defaults to on for Debian/Ubuntu.
-    if { $getting_compiler_info == 0
+    if { !$getting_compiler_info
         && [test_compiler_info {gcc-*-*}]
         && !([test_compiler_info {gcc-[0-3]-*}]
              || [test_compiler_info {gcc-4-0-*}])
@@ -4698,11 +4715,7 @@ proc gdb_compile {source dest type options} {
     }
 
     if {[lsearch $options quiet] < 0} {
-       # We shall update this on a per language basis, to avoid
-       # changing the entire testsuite in one go.
-       if {[lsearch $options f77] >= 0} {
-           gdb_compile_test $source $result
-       } elseif { $result != "" } {
+       if { $result != "" } {
            clone_output "gdb compile failed, $result"
        }
     }
@@ -4758,15 +4771,15 @@ proc gdb_compile_shlib_1 {sources dest options} {
        set ada 1
     }
 
-    set info_options ""
     if { [lsearch -exact $options "c++"] >= 0 } {
        set info_options "c++"
-    }
-    if [get_compiler_info ${info_options}] {
-       return -1
+    } elseif { [lsearch -exact $options "f90"] >= 0 } {
+       set info_options "f90"
+    } else {
+       set info_options "c"
     }
 
-    switch -glob [test_compiler_info] {
+    switch -glob [test_compiler_info "" ${info_options}] {
         "xlc-*" {
             lappend obj_options "additional_flags=-qpic"
         }
@@ -5593,14 +5606,14 @@ proc with_complaints { n body } {
        perror "Did not manage to set complaints"
     } else {
        # Set complaints.
-       gdb_test_no_output "set complaints $n" ""
+       gdb_test_no_output -nopass "set complaints $n"
     }
 
     set code [catch {uplevel 1 $body} result]
 
     # Restore saved setting of complaints.
     if { $save != "" } {
-       gdb_test_no_output "set complaints $save" ""
+       gdb_test_no_output -nopass "set complaints $save"
     }
 
     if {$code == 1} {
@@ -6945,14 +6958,6 @@ proc build_executable_from_specs {testname executable options args} {
 
     set binfile [standard_output_file $executable]
 
-    set info_options ""
-    if { [lsearch -exact $options "c++"] >= 0 } {
-       set info_options "c++"
-    }
-    if [get_compiler_info ${info_options}] {
-        return -1
-    }
-
     set func gdb_compile
     set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads|openmp)$}]
     if {$func_index != -1} {
@@ -8644,5 +8649,60 @@ proc get_set_option_choices {set_cmd} {
     return $values
 }
 
+# Return the compiler that can generate 32-bit ARM executables.  Used
+# when testing biarch support on Aarch64.  If ARM_CC_FOR_TARGET is
+# set, use that.  If not, try a few common compiler names, making sure
+# that the executable they produce can run.
+
+gdb_caching_proc arm_cc_for_target {
+    if {[info exists ARM_CC_FOR_TARGET]} {
+       # If the user specified the compiler explicitly, then don't
+       # check whether the resulting binary runs outside GDB.  Assume
+       # that it does, and if it turns out it doesn't, then the user
+       # should get loud FAILs, instead of UNSUPPORTED.
+       return $ARM_CC_FOR_TARGET
+    }
+
+    # Fallback to a few common compiler names.  Also confirm the
+    # produced binary actually runs on the system before declaring
+    # we've found the right compiler.
+
+    if [istarget "*-linux*-*"] {
+       set compilers {
+           arm-linux-gnueabi-gcc
+           arm-none-linux-gnueabi-gcc
+           arm-linux-gnueabihf-gcc
+       }
+    } else {
+       set compilers {}
+    }
+
+    foreach compiler $compilers {
+       if {![is_remote host] && [which $compiler] == 0} {
+           # Avoid "default_target_compile: Can't find
+           # $compiler." warning issued from gdb_compile.
+           continue
+       }
+
+       set src { int main() { return 0; } }
+       if {[gdb_simple_compile aarch64-32bit \
+                $src \
+                executable [list compiler=$compiler]]} {
+
+           set result [remote_exec target $obj]
+           set status [lindex $result 0]
+           set output [lindex $result 1]
+
+           file delete $obj
+
+           if { $output == "" && $status == 0} {
+               return $compiler
+           }
+       }
+    }
+
+    return ""
+}
+
 # Always load compatibility stuff.
 load_lib future.exp