From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 97016 invoked by alias); 5 Mar 2015 11:37:48 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 96998 invoked by uid 89); 5 Mar 2015 11:37:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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, 05 Mar 2015 11:37:47 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t25Bbk0a000645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 5 Mar 2015 06:37:46 -0500 Received: from blade.nx (ovpn-116-103.ams2.redhat.com [10.36.116.103]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t25BbjRP021822 for ; Thu, 5 Mar 2015 06:37:45 -0500 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id AF42B26505B for ; Thu, 5 Mar 2015 11:37:44 +0000 (GMT) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Use exec_file_find to locate executable on attach (sometimes) Date: Thu, 05 Mar 2015 11:37:00 -0000 Message-Id: <1425555461-22093-3-git-send-email-gbenson@redhat.com> In-Reply-To: <1425555461-22093-1-git-send-email-gbenson@redhat.com> References: <1425555461-22093-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg00147.txt.bz2 This commit updates attach_command_post_wait to use exec_file_find to compute the full pathname of the main executable if the pathname returned by target_pid_to_exec_file is absolute and if gdb_sysroot is non-empty and not remote. The net effect of this is to prefix the main executable's path with gdb_sysroot if gdb_sysroot is set; this is useful for attaching to processes running in chroot jails or containerized environments. This logic is skipped for remote gdb_sysroots because the subsequent code does not support opening the main executable remotely. gdb/ChangeLog: * infcmd.c (filenames.h): New include. (remote.h): Likewise. (solist.h): Likewise. (attach_command_post_wait): Prefix absolute executable paths with gdb_sysroot if set and not remote. --- gdb/ChangeLog | 8 ++++++++ gdb/infcmd.c | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 3737b8f..23c7a6c 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -54,6 +54,9 @@ #include "continuations.h" #include "linespec.h" #include "cli/cli-utils.h" +#include "filenames.h" +#include "remote.h" +#include "solist.h" /* Local functions: */ @@ -2493,16 +2496,34 @@ attach_command_post_wait (char *args, int from_tty, int async_exec) exec_file = target_pid_to_exec_file (ptid_get_pid (inferior_ptid)); if (exec_file) { - /* 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 - full path, sigh. + /* If there is a gdb_sysroot and exec_file is absolute we + prepend gdb_sysroot to exec_file. This is currently + disabled for remote sysroot as the subsequent code cannot + yet cope with these. */ + if (IS_ABSOLUTE_PATH (exec_file) + && gdb_sysroot != NULL && *gdb_sysroot != '\0' + && !remote_filename_p (gdb_sysroot)) + { + int fd = -1; + + full_exec_path = exec_file_find (exec_file, &fd); + if (fd >= 0) + close (fd); + } - Attempt to qualify the filename against the source path. - (If that fails, we'll just fall back on the original - filename. Not much more we can do...) */ + if (full_exec_path == NULL) + { + /* 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 full path, sigh. + + Attempt to qualify the filename against the source + path. (If that fails, we'll just fall back on the + original filename. Not much more we can do...) */ - if (!source_full_path_of (exec_file, &full_exec_path)) - full_exec_path = xstrdup (exec_file); + if (!source_full_path_of (exec_file, &full_exec_path)) + full_exec_path = xstrdup (exec_file); + } exec_file_attach (full_exec_path, from_tty); symbol_file_add_main (full_exec_path, from_tty); -- 1.7.1