From patchwork Thu Feb 18 17:05:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 10894 Received: (qmail 20440 invoked by alias); 18 Feb 2016 17:05:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 20431 invoked by uid 89); 18 Feb 2016 17:05:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=6.6, 1569, sk:attach, sk:attach- X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 18 Feb 2016 17:05:33 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 203971E22; Thu, 18 Feb 2016 17:05:32 +0000 (UTC) Received: from blade.nx (ovpn-116-96.ams2.redhat.com [10.36.116.96]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1IH5UAi032108; Thu, 18 Feb 2016 12:05:31 -0500 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 4BC4826441A; Thu, 18 Feb 2016 17:05:30 +0000 (GMT) From: Gary Benson To: gdb-patches@sourceware.org Cc: Pedro Alves , Luis Machado Subject: [PATCH] Fix logic in exec_file_locate_attach Date: Thu, 18 Feb 2016 17:05:29 +0000 Message-Id: <1455815129-14795-1-git-send-email-gbenson@redhat.com> In-Reply-To: <56BDF92B.50107@redhat.com> References: <56BDF92B.50107@redhat.com> X-IsSubscribed: yes Hi all, This commit fixes an error in exec_file_locate_attach where the main executable could be loaded from outside the sysroot if a nonempty, non-"target:" sysroot was set but the discovered executable filename did not exist in that sysroot and did exist on the main filesystem. Before: gdb -q \ -ex "set sysroot /whatever" \ -ex "target remote | gdbserver - /bin/ls" ... Reading symbols from /bin/ls...(no debugging symbols found)...done. After: gdb -q \ -ex "set sysroot /whatever" \ -ex "target remote | gdbserver - /bin/ls" ... /bin/ls: in sysroot "/whatever": No such file or directory. Built and regtested on RHEL 6.6 x86_64. Ok to commit? Cheers, Gary --- gdb/ChangeLog: * exec.c (exec_file_locate_attach): Throw error if exec_file_find fails to locate the main executable. gdb/testsuite/ChangeLog: * gdb.base/attach-bad-sysroot.exp: New file. * gdb.base/attach-bad-sysroot.c: Likewise. --- gdb/ChangeLog | 5 +++ gdb/exec.c | 13 +++++++-- gdb/testsuite/ChangeLog | 5 +++ gdb/testsuite/gdb.base/attach-bad-sysroot.c | 25 +++++++++++++++++ gdb/testsuite/gdb.base/attach-bad-sysroot.exp | 36 +++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.base/attach-bad-sysroot.c create mode 100644 gdb/testsuite/gdb.base/attach-bad-sysroot.exp 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