From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75461 invoked by alias); 1 Apr 2015 11:22:37 -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 75337 invoked by uid 89); 1 Apr 2015 11:22:36 -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; Wed, 01 Apr 2015 11:22:34 +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 (Postfix) with ESMTPS id 37C50BBF4A for ; Wed, 1 Apr 2015 11:22:33 +0000 (UTC) Received: from blade.nx (ovpn-116-118.ams2.redhat.com [10.36.116.118]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t31BMWim030350 for ; Wed, 1 Apr 2015 07:22:32 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 75D9226410B for ; Wed, 1 Apr 2015 12:22:31 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 1/7] Introduce exec_file_locate_attach Date: Wed, 01 Apr 2015 11:22:00 -0000 Message-Id: <1427887341-31819-2-git-send-email-gbenson@redhat.com> In-Reply-To: <1427887341-31819-1-git-send-email-gbenson@redhat.com> References: <1427887341-31819-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00017.txt.bz2 This commit adds a new function, exec_file_locate_attach, which works like exec_file_attach except that, instead of a filename argument, it takes an integer process ID and attempts to determine the executable filename from that. gdb/ChangeLog: * gdbcore.h (exec_file_locate_attach): New declaration. * exec.c (exec_file_locate_attach): New function, factored out from... * infcmd.c (attach_command_post_wait): ...here. --- gdb/ChangeLog | 7 +++++++ gdb/exec.c | 31 +++++++++++++++++++++++++++++++ gdb/gdbcore.h | 7 +++++++ gdb/infcmd.c | 25 ++----------------------- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 113e869..ab7fcbb 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -134,6 +134,37 @@ exec_file_clear (int from_tty) printf_unfiltered (_("No executable file now.\n")); } +/* See gdbcore.h. */ + +void +exec_file_locate_attach (int pid, int from_tty) +{ + char *exec_file, *full_exec_path = NULL; + + /* Do nothing if we already have an executable filename. */ + exec_file = (char *) get_exec_file (0); + if (exec_file != NULL) + return; + + /* Try to determine a filename from the process itself. */ + exec_file = target_pid_to_exec_file (pid); + if (exec_file == NULL) + return; + + /* 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); + + exec_file_attach (full_exec_path, from_tty); + symbol_file_add_main (full_exec_path, from_tty); +} + /* Set FILENAME as the new exec file. This function is intended to be behave essentially the same diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h index 63a75f0..a437c8a 100644 --- a/gdb/gdbcore.h +++ b/gdb/gdbcore.h @@ -150,6 +150,13 @@ extern void core_file_command (char *filename, int from_tty); extern void exec_file_attach (const char *filename, int from_tty); +/* If the filename of the main executable is unknown, attempt to + determine it. If a filename is determined, proceed as though + it was just specified with the "file" command. Do nothing if + the filename of the main executable is already known. */ + +extern void exec_file_locate_attach (int pid, int from_tty); + extern void exec_file_clear (int from_tty); extern void validate_files (void); diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 1c70675..f028d60 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2489,8 +2489,6 @@ proceed_after_attach (int pid) static void attach_command_post_wait (char *args, int from_tty, int async_exec) { - char *exec_file; - char *full_exec_path = NULL; struct inferior *inferior; inferior = current_inferior (); @@ -2498,27 +2496,8 @@ attach_command_post_wait (char *args, int from_tty, int async_exec) /* If no exec file is yet known, try to determine it from the process itself. */ - exec_file = (char *) get_exec_file (0); - if (!exec_file) - { - 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. - - 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); - - exec_file_attach (full_exec_path, from_tty); - symbol_file_add_main (full_exec_path, from_tty); - } - } + if (get_exec_file (0) == NULL) + exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty); else { reopen_exec_file (); -- 1.7.1