Add "info connections" command, "info inferiors" connection number/string
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.linespec / linespec.exp
index 3698ea2215ec2b420d0609afcb54376ac6e2179f..be1b9189e2039cabda0eae30882fd962d18984bb 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011-2012 Free Software Foundation, Inc.
+# Copyright 2011-2020 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
@@ -23,11 +23,11 @@ set baseone base/one/thefile.cc
 set basetwo base/two/thefile.cc
 
 if {[skip_cplus_tests]} {
-    unsupported linespec.exp
+    unsupported "skipping c++ tests"
     return
 }
 
-if {[prepare_for_testing ${testfile}.exp $exefile \
+if {[prepare_for_testing "failed to prepare" $exefile \
         [list $srcfile $baseone $basetwo] \
         {debug nowarnings c++}]} {
     return -1
@@ -43,13 +43,109 @@ if {$l1 != $l2} {
     error "somebody incompatibly modified the source files needed by linespec.exp"
 }
 
-gdb_test "break one/thefile.cc:$l1" \
-    "Breakpoint $decimal at $hex: file .*thefile.cc, line $l1." \
-    "single-location break using dir/file:line"
+gdb_test_no_output "set breakpoint pending off" \
+    "disable pending breakpoints for linespec tests"
 
-gdb_test "clear one/thefile.cc:$l1" \
-    "Deleted breakpoint $decimal *" \
-    "clear breakpoint using dir/file:line"
+# Copying files to a remote host loses the directory prefix during
+# compilation.
+if { [is_remote host] } {
+    untested "breakpoints using dir/file:line"
+} else {
+    gdb_test "break one/thefile.cc:$l1" \
+        "Breakpoint $decimal at $hex: file .*thefile.cc, line $l1." \
+        "single-location break using dir/file:line"
+
+    gdb_test "clear one/thefile.cc:$l1" \
+        "Deleted breakpoint $decimal *" \
+        "clear breakpoint using dir/file:line"
+
+    if { [readline_is_used] } {
+       # There are functions named 'twodup' in both source files.
+       # Both should be found if we restrict the linespec to the
+       # ambiguous "thefile.cc" source filename.  Check both
+       # completion and setting the breakpoint.
+       set tst "complete unique function name in two source files"
+       send_gdb "break thefile.cc:t\t"
+       gdb_test_multiple "" $tst {
+           -re "break thefile.cc:twodup\\(\\) " {
+               pass $tst
+
+               send_gdb "\n"
+               gdb_test "" \
+                   "Breakpoint $decimal at $hex: thefile.cc:twodup\\(\\). \[(\]2 locations\[)\]" \
+                   "set break at unique function name in two source files"
+           }
+       }
+
+       # Check both completing and setting a breakpoint on a linespec
+       # with a source component, where there's more than one source
+       # file with the same basename.  We should find the functions
+       # in all matching sources -- one/thefile.cc and
+       # two/thefile.cc.  The "one" file has "z1()", while the "two"
+       # file has "z2()".
+       set tst "complete non-unique function name in two source files"
+       send_gdb "break thefile.cc:z\t"
+       gdb_test_multiple "" $tst {
+           -re "break thefile.cc:z\\\x07" {
+               send_gdb "\t"
+               gdb_test_multiple "" $tst {
+                   -re "\r\nz1\\(\\)\[ \t\]+z2\\(\\)\[ \t\]+\r\n$gdb_prompt " {
+                       pass $tst
+
+                       send_gdb "\n"
+                       gdb_test "" \
+                           "Function \"z\" not defined in \"thefile.cc\"." \
+                           "set break at non-unique function name in two source files"
+                   }
+               }
+           }
+       }
+
+       # Now check that disambiguating the source path makes GDB only
+       # match the symbols in that file.  "z" should now have a
+       # unique completion to "z1()", and setting the breakpoint
+       # should find only one location.
+       set tst "complete unique function name in disambiguated source file"
+       send_gdb "break one/thefile.cc:z\t"
+       gdb_test_multiple "" $tst {
+           -re "break one/thefile.cc:z1\\(\\) " {
+               pass $tst
+
+               send_gdb "\n"
+               gdb_test "" \
+                   "Breakpoint $decimal at $hex: file .*thefile.cc, line \[^\r\n\]*" \
+                   "set break at unique function name in disambiguated source file"
+               }
+       }
+
+       # Check that using a non-existing source path does not confuse
+       # GDB.  It should not match any symbol.
+       set dir_file "one/thefile.cc"
+       set non_existing "/some/non-existing/absolute/path/prefix/$dir_file"
+       set non_existing_re [string_to_regexp $non_existing]
+
+       set tst "complete functions in non-existing absolute path"
+       send_gdb "break $non_existing:\t"
+       gdb_test_multiple "" $tst {
+           -re "break $non_existing_re:\\\x07" {
+               send_gdb "\t\t"
+               gdb_test_multiple "" $tst {
+                   -re "^\\\x07\\\x07" {
+                       pass $tst
+
+                       # There's a function called 'twodup' in each
+                       # of the thefile.cc files.  Make sure none is
+                       # picked.
+                       send_gdb "twodup\n"
+                       gdb_test "" \
+                           "No source file named $non_existing_re." \
+                           "set break in function in non-existing absolute path"
+                   }
+               }
+           }
+       }
+    }
+}
 
 gdb_test "break thefile.cc:$l1" \
     "Breakpoint $decimal at $hex: thefile.cc:$l1. \[(\]2 locations\[)\]" \
@@ -63,8 +159,9 @@ gdb_test "break dupname:label" \
     "Breakpoint $decimal at $hex: dupname:label. \[(\]2 locations\[)\]" \
     "multi-location break using duplicate function name and label"
 
-gdb_test_no_output "set breakpoint pending off" \
-    "disable pending breakpoints for linespec tests"
+# Testing if the "condition" command completes only the breakpoints,
+# not the locations.
+gdb_test "complete condition " "condition $decimal\r\ncondition $decimal\r\ncondition $decimal"
 
 # This is PR breakpoints/12856.
 gdb_test "break lspec.cc:nosuchfunction" \
@@ -104,7 +201,7 @@ gdb_test "break lspec.h:$line" \
 # Multi-inferior tests.
 #
 
-gdb_test "add-inferior" "Added inferior 2" \
+gdb_test "add-inferior" "Added inferior 2.*" \
     "add inferior for linespec tests"
 
 gdb_test "inferior 2" "Switching to inferior 2 .*" \
@@ -113,7 +210,7 @@ gdb_test "inferior 2" "Switching to inferior 2 .*" \
 # Note that in particular this should not cause errors when re-setting
 # breakpoints.
 gdb_test "file $binfile" \
-    "Reading symbols from .*done." \
+    "Reading symbols from .*" \
     "set the new inferior file for linespec tests"
 
 gdb_test "break main" \
This page took 0.026869 seconds and 4 git commands to generate.