gdb: Introduce 'print max-depth' feature
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / gdb.exp
index 2d197d9b5c8a05bd7832ace35f24ec75eb1d2fa7..25d370ebb52832af97287a3b9e1d807d35960bd4 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1992-2018 Free Software Foundation, Inc.
+# Copyright 1992-2019 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
@@ -906,10 +906,13 @@ proc gdb_test_multiple { command message user_code } {
        }
     }
     append code $processed_code
+
+    # Reset the spawn id, in case the processed code used -i.
     append code {
-       # Reset the spawn id, in case the processed code used -i.
        -i "$gdb_spawn_id"
+    }
 
+    append code {
        -re "Ending remote debugging.*$gdb_prompt $" {
            if ![isnative] then {
                warning "Can`t communicate to remote target."
@@ -980,7 +983,20 @@ proc gdb_test_multiple { command message user_code } {
            set result -1
        }
 
-       # Patterns below apply to any spawn id specified.
+       -i $gdb_spawn_id
+       eof {
+           perror "GDB process no longer exists"
+           set wait_status [wait -i $gdb_spawn_id]
+           verbose -log "GDB process exited with wait status $wait_status"
+           if { $message != "" } {
+               fail "$message"
+           }
+           return -1
+       }
+    }
+
+    # Now patterns that apply to any spawn id specified.
+    append code {
        -i $any_spawn_id
        eof {
            perror "Process no longer exists"
@@ -1002,6 +1018,20 @@ proc gdb_test_multiple { command message user_code } {
        }
     }
 
+    # remote_expect calls the eof section if there is an error on the
+    # expect call.  We already have eof sections above, and we don't
+    # want them to get called in that situation.  Since the last eof
+    # section becomes the error section, here we define another eof
+    # section, but with an empty spawn_id list, so that it won't ever
+    # match.
+    append code {
+       -i "" eof {
+           # This comment is here because the eof section must not be
+           # the empty string, otherwise remote_expect won't realize
+           # it exists.
+       }
+    }
+
     set result 0
     set code [catch {gdb_expect $code} string]
     if {$code == 1} {
@@ -1360,6 +1390,36 @@ proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} {
     return $res
 }
 
+# get_print_expr_at_depths EXP OUTPUTS
+#
+# Used for testing 'set print max-depth'.  Prints the expression EXP
+# with 'set print max-depth' set to various depths.  OUTPUTS is a list
+# of `n` different patterns to match at each of the depths from 0 to
+# (`n` - 1).
+#
+# This proc does one final check with the max-depth set to 'unlimited'
+# which is tested against the last pattern in the OUTPUTS list.  The
+# OUTPUTS list is therefore required to match every depth from 0 to a
+# depth where the whole of EXP is printed with no ellipsis.
+#
+# This proc leaves the 'set print max-depth' set to 'unlimited'.
+proc gdb_print_expr_at_depths {exp outputs} {
+    for { set depth 0 } { $depth <= [llength $outputs] } { incr depth } {
+       if { $depth == [llength $outputs] } {
+           set expected_result [lindex $outputs [expr [llength $outputs] - 1]]
+           set depth_string "unlimited"
+       } else {
+           set expected_result [lindex $outputs $depth]
+           set depth_string $depth
+       }
+
+       with_test_prefix "exp='$exp': depth=${depth_string}" {
+           gdb_test_no_output "set print max-depth ${depth_string}"
+           gdb_test "p $exp" "$expected_result"
+       }
+    }
+}
+
 \f
 
 # Issue a PASS and return true if evaluating CONDITION in the caller's
@@ -1627,7 +1687,7 @@ proc default_gdb_spawn { } {
 # Default gdb_start procedure.
 
 proc default_gdb_start { } {
-    global gdb_prompt pagination_prompt
+    global gdb_prompt
     global gdb_spawn_id
     global inferior_spawn_id
 
@@ -1648,29 +1708,20 @@ proc default_gdb_start { } {
     # When running over NFS, particularly if running many simultaneous
     # tests on different hosts all using the same server, things can
     # get really slow.  Give gdb at least 3 minutes to start up.
-    set loop_again 1
-    while { $loop_again } {
-       set loop_again 0
-       gdb_expect 360 {
-           -re "$pagination_prompt" {
-               verbose "Hit pagination during startup. Pressing enter to continue."
-               send_gdb "\n"
-               set loop_again 1
-           }
-           -re "\[\r\n\]$gdb_prompt $" {
-               verbose "GDB initialized."
-           }
-           -re "$gdb_prompt $" {
-               perror "GDB never initialized."
-               unset gdb_spawn_id
-               return -1
-           }
-           timeout     {
-               perror "(timeout) GDB never initialized after 10 seconds."
-               remote_close host
-               unset gdb_spawn_id
-               return -1
-           }
+    gdb_expect 360 {
+       -re "\[\r\n\]$gdb_prompt $" {
+           verbose "GDB initialized."
+       }
+       -re "$gdb_prompt $"     {
+           perror "GDB never initialized."
+           unset gdb_spawn_id
+           return -1
+       }
+       timeout {
+           perror "(timeout) GDB never initialized after 10 seconds."
+           remote_close host
+           unset gdb_spawn_id
+           return -1
        }
     }
 
@@ -1801,7 +1852,6 @@ proc skip_rust_tests {} {
 
 proc skip_python_tests_prompt { prompt_regexp } {
     global gdb_py_is_py3k
-    global gdb_py_is_py24
 
     gdb_test_multiple "python print ('test')" "verify python support" {
        -re "not supported.*$prompt_regexp" {
@@ -1811,7 +1861,6 @@ proc skip_python_tests_prompt { prompt_regexp } {
        -re "$prompt_regexp" {}
     }
 
-    set gdb_py_is_py24 0
     gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" {
        -re "3.*$prompt_regexp" {
             set gdb_py_is_py3k 1
@@ -1820,16 +1869,6 @@ proc skip_python_tests_prompt { prompt_regexp } {
             set gdb_py_is_py3k 0
         }
     }
-    if { $gdb_py_is_py3k == 0 } {
-        gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" {
-           -re "\[45\].*$prompt_regexp" {
-                set gdb_py_is_py24 1
-            }
-           -re ".*$prompt_regexp" {
-                set gdb_py_is_py24 0
-            }
-        }
-    }
 
     return 0
 }
@@ -3265,12 +3304,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]
+       gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" 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] ]
+       set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet getting_compiler_info] ]
     }
     eval log_file $saved_log
 
@@ -3471,6 +3510,8 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #     dynamically load libraries at runtime.  For example, on Linux, this adds
 #     -ldl so that the test can use dlopen.
 #   - nowarnings:  Inhibit all compiler warnings.
+#   - pie: Force creation of PIE executables.
+#   - nopie: Prevent creation of PIE executables.
 #
 # And here are some of the not too obscure options understood by DejaGnu that
 # influence the compilation:
@@ -3507,6 +3548,7 @@ proc gdb_compile {source dest type options} {
     }
     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"} {
@@ -3537,11 +3579,27 @@ 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
         } else {
             lappend new_options $opt
         }
     }
 
+    # Ensure stack protector is disabled for GCC, as this causes problems with
+    # 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
+        && [test_compiler_info {gcc-*-*}]
+        && !([test_compiler_info {gcc-[0-3]-*}]
+             || [test_compiler_info {gcc-4-0-*}])
+        && [lsearch -exact $options rust] == -1} {
+        # Put it at the front to not override any user-provided value.
+        lappend new_options "early_flags=-fno-stack-protector"
+    }
+
     # Because we link with libraries using their basename, we may need
     # (depending on the platform) to set a special rpath value, to allow
     # the executable to find the libraries it depends on.
@@ -3592,6 +3650,43 @@ proc gdb_compile {source dest type options} {
        set options [lreplace $options $nowarnings $nowarnings $flag]
     }
 
+    # Replace the "pie" option with the appropriate compiler and linker flags
+    # to enable PIE executables.
+    set pie [lsearch -exact $options pie]
+    if {$pie != -1} {
+       if [target_info exists gdb,pie_flag] {
+           set flag "additional_flags=[target_info gdb,pie_flag]"
+       } else {
+           # For safety, use fPIE rather than fpie. On AArch64, m68k, PowerPC
+           # and SPARC, fpie can cause compile errors due to the GOT exceeding
+           # a maximum size.  On other architectures the two flags are
+           # identical (see the GCC manual). Note Debian9 and Ubuntu16.10
+           # onwards default GCC to using fPIE.  If you do require fpie, then
+           # it can be set using the pie_flag.
+           set flag "additional_flags=-fPIE"
+       }
+       set options [lreplace $options $pie $pie $flag]
+
+       if [target_info exists gdb,pie_ldflag] {
+           set flag "ldflags=[target_info gdb,pie_ldflag]"
+       } else {
+           set flag "ldflags=-pie"
+       }
+       lappend options "$flag"
+    }
+
+    # Replace the "nopie" option with the appropriate linker flag to disable
+    # PIE executables.  There are no compiler flags for this option.
+    set nopie [lsearch -exact $options nopie]
+    if {$nopie != -1} {
+       if [target_info exists gdb,nopie_flag] {
+           set flag "ldflags=[target_info gdb,nopie_flag]"
+       } else {
+           set flag "ldflags=-no-pie"
+       }
+       set options [lreplace $options $nopie $nopie $flag]
+    }
+
     if { $type == "executable" } {
        if { ([istarget "*-*-mingw*"]
              || [istarget "*-*-*djgpp"]
@@ -4708,10 +4803,14 @@ proc gdb_init { test_file_name } {
     # read from this file.
     setenv INPUTRC "/dev/null"
 
-    # The gdb.base/readline.exp arrow key test relies on the standard VT100
-    # bindings, so make sure that an appropriate terminal is selected.
-    # The same bug doesn't show up if we use ^P / ^N instead.
-    setenv TERM "vt100"
+    # This disables style output, which would interfere with many
+    # tests.
+    setenv TERM "dumb"
+
+    # Initialize GDB's pty with a fixed size, to make sure we avoid pagination
+    # during startup.  See "man expect" for details about stty_init.
+    global stty_init
+    set stty_init "rows 25 cols 80"
 
     # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
     # grep.  Clear GREP_OPTIONS to make the behavior predictable,
@@ -5625,7 +5724,7 @@ proc get_valueof { fmt exp default {test ""} } {
     gdb_test_multiple "print${fmt} ${exp}" "$test" {
        -re "\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
            set val $expect_out(1,string)
-           pass "$test ($val)"
+           pass "$test"
        }
        timeout {
            fail "$test (timeout)"
@@ -6249,5 +6348,56 @@ proc gdb_define_cmd {command command_list} {
     }
 }
 
+# Override the 'cd' builtin with a version that ensures that the
+# log file keeps pointing at the same file.  We need this because
+# unfortunately the path to the log file is recorded using an
+# relative path name, and, we sometimes need to close/reopen the log
+# after changing the current directory.  See get_compiler_info.
+
+rename cd builtin_cd
+
+proc cd { dir } {
+
+    # Get the existing log file flags.
+    set log_file_info [log_file -info]
+
+    # Split the flags into args and file name.
+    set log_file_flags ""
+    set log_file_file ""
+    foreach arg [ split "$log_file_info" " "] {
+       if [string match "-*" $arg] {
+           lappend log_file_flags $arg
+       } else {
+           lappend log_file_file $arg
+       }
+    }
+
+    # If there was an existing file, ensure it is an absolute path, and then
+    # reset logging.
+    if { $log_file_file != "" } {
+       set log_file_file [file normalize $log_file_file]
+       log_file
+       log_file $log_file_flags "$log_file_file"
+    }
+
+    # Call the builtin version of cd.
+    builtin_cd $dir
+}
+
+# Return a list of all languages supported by GDB, suitable for use in
+# 'set language NAME'.  This doesn't include either the 'local' or
+# 'auto' keywords.
+proc gdb_supported_languages {} {
+    return [list c objective-c c++ d go fortran modula-2 asm pascal \
+               opencl rust minimal ada]
+}
+
+# Check if debugging is enabled for gdbserver.
+
+proc gdbserver_debug_enabled { } {
+    # Always disabled for GDB only setups.
+    return 0
+}
+
 # Always load compatibility stuff.
 load_lib future.exp
This page took 0.02969 seconds and 4 git commands to generate.