diff --git a/gdb/exec.c b/gdb/exec.c
index 0b8c077..8f19871 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -156,9 +156,16 @@ exec_file_locate_attach (int pid, int from_tty)
/* If gdb_sysroot is not empty and the discovered filename
is absolute then prefix the filename with gdb_sysroot. */
if (*gdb_sysroot != '\0' && IS_ABSOLUTE_PATH (exec_file))
- full_exec_path = exec_file_find (exec_file, NULL);
-
- if (full_exec_path == NULL)
+ {
+ full_exec_path = exec_file_find (exec_file, NULL);
+ if (full_exec_path == NULL)
+ {
+ error (_("%s: in sysroot \"%s\":"
+ " No such file or directory."),
+ exec_file, gdb_sysroot);
+ }
+ }
+ else
{
/* It's possible we don't have a full path, but rather just a
filename. Some targets, such as HP-UX, don't provide the
diff --git a/gdb/testsuite/gdb.base/attach-bad-sysroot.c b/gdb/testsuite/gdb.base/attach-bad-sysroot.c
new file mode 100644
index 0000000..e1c1e70
--- /dev/null
+++ b/gdb/testsuite/gdb.base/attach-bad-sysroot.c
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011-2016 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
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+#include
+
+int
+main (void)
+{
+ sleep (600);
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/attach-bad-sysroot.exp b/gdb/testsuite/gdb.base/attach-bad-sysroot.exp
new file mode 100644
index 0000000..014da65
--- /dev/null
+++ b/gdb/testsuite/gdb.base/attach-bad-sysroot.exp
@@ -0,0 +1,36 @@
+# Copyright (C) 2011-2016 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+if {![can_spawn_for_attach]} {
+ return 0
+}
+
+standard_testfile .c
+if { [build_executable ${testfile}.exp $binfile "${testfile}.c"] == -1 } {
+ untested ${testfile}.exp
+ return -1
+}
+
+set test_spawn_id [spawn_wait_for_attach $binfile]
+set testpid [spawn_id_get_pid $test_spawn_id]
+
+set outdir [make_gdb_parallel_path outputs $subdir $testfile]
+set sysroot ${outdir}/does-not-exist
+
+gdb_start
+gdb_test_no_output "set sysroot $sysroot"
+gdb_test "attach $testpid" "Attaching to process $testpid\r\n.*: No such file or directory\\."
+
+kill_wait_spawned_process $test_spawn_id