public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Cc: Pedro Alves <palves@redhat.com>,
	Luis Machado <lgustavo@codesourcery.com>
Subject: [PATCH v2] Fix logic in exec_file_locate_attach
Date: Fri, 19 Feb 2016 11:21:00 -0000	[thread overview]
Message-ID: <1455880879-310-1-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <20160219102447.GA29870@blade.nx>

Hi all,

This is an updated version of the patch I posted yesterday.
It fails silently rather than throwing if the executable is
not in the sysroot, which both fixes the sysroot-escape issue
and results in a better GDB session for the user.

Built and regtested on RHEL 6.6 x86_64.

Luis, I think this patch will fix your connection drop without
any further changes.  Could you test it please?

Thanks,
Gary

---
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.

gdb/ChangeLog:

	* exec.c (exec_file_locate_attach): Do not attempt to
	locate main executable locally if not found in sysroot.

gdb/testsuite/ChangeLog:

	* gdb.base/attach-pie-noexec.exp: Do not expect an error
	message on attach.
---
 gdb/ChangeLog                                |    5 +++++
 gdb/exec.c                                   |    9 ++++++---
 gdb/testsuite/ChangeLog                      |    5 +++++
 gdb/testsuite/gdb.base/attach-pie-noexec.exp |    2 +-
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index 0b8c077..90811c0 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -156,9 +156,12 @@ 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)
+	return;
+    }
+  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-pie-noexec.exp b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
index f3e693a..1a51049 100644
--- a/gdb/testsuite/gdb.base/attach-pie-noexec.exp
+++ b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
@@ -60,7 +60,7 @@ set testpid [spawn_id_get_pid $test_spawn_id]
 
 gdb_start
 file delete -- $binfile
-gdb_test "attach $testpid" "Attaching to process $testpid\r\n.*: No such file or directory\\." "attach"
+gdb_test "attach $testpid" "Attaching to process $testpid\r\n.*" "attach"
 gdb_test "set architecture $arch" "The target architecture is assumed to be $arch"
 gdb_test "info shared" "From\[ \t\]+To\[ \t\]+Syms Read\[ \t\]+Shared Object Library\r\n0x.*"
 
-- 
1.7.1

  parent reply	other threads:[~2016-02-19 11:21 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 14:19 [PATCH] Remote debugging without a binary (regression) Luis Machado
2016-02-11 16:35 ` Gary Benson
2016-02-11 17:06   ` Luis Machado
2016-02-11 17:31     ` Pedro Alves
2016-02-11 17:42       ` Luis Machado
2016-02-12 10:31     ` Gary Benson
2016-02-12 10:59       ` Luis Machado
2016-02-12 15:24       ` Pedro Alves
2016-02-17 13:53         ` Gary Benson
2016-02-17 14:40           ` Pedro Alves
2016-02-17 17:02           ` [OB PATCH] Add missing cleanup in exec_file_locate_attach Gary Benson
2016-02-17 17:05             ` Gary Benson
2016-02-17 18:11             ` Luis Machado
2016-02-18  9:54               ` Gary Benson
2016-02-18 17:05         ` [PATCH] Fix logic " Gary Benson
2016-02-18 17:28           ` Pedro Alves
2016-02-19 10:24             ` Gary Benson
2016-02-19 10:33               ` Luis Machado
2016-02-19 11:21               ` Gary Benson [this message]
2016-02-19 15:38                 ` [PATCH v2] " Luis Machado
2016-02-22 10:40                   ` Gary Benson
2016-02-22 11:37                     ` Luis Machado
2016-02-22 13:51                       ` Gary Benson
2016-02-22 22:00                         ` Luis Machado
2016-02-22 22:50                           ` Luis Machado
2016-02-22 23:00                             ` Pedro Alves
2016-02-23  0:04                               ` Luis Machado
2016-02-23  0:13                                 ` Pedro Alves
2016-02-23  0:16                                   ` Luis Machado
2016-02-23 11:27                                     ` Gary Benson
2016-02-23 11:43                                       ` Pedro Alves
2016-02-23 12:15                                         ` Gary Benson
2016-02-23 12:20                                           ` Pedro Alves
2016-02-23 11:55                 ` Pedro Alves
2016-02-24 11:56                   ` Gary Benson
2016-02-12 15:29 ` [PATCH] Remote debugging without a binary (regression) Pedro Alves
2016-02-12 16:08   ` Luis Machado
2016-02-12 16:36     ` Pedro Alves
2016-02-12 17:31       ` Luis Machado
2016-02-17 11:46         ` Pedro Alves
2016-02-18 12:30 ` Gary Benson
2016-02-18 12:40   ` Luis Machado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455880879-310-1-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lgustavo@codesourcery.com \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).