From patchwork Tue Oct 20 14:28:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Ristovski X-Patchwork-Id: 9244 Received: (qmail 86027 invoked by alias); 20 Oct 2015 14:29:02 -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 85942 invoked by uid 89); 20 Oct 2015 14:29:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: smtp-a02.blackberry.com Received: from smtp-a02.blackberry.com (HELO smtp-a02.blackberry.com) (208.65.78.91) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Oct 2015 14:28:51 +0000 Received: from mhs101cnc.rim.net ([10.65.141.79]) by mhs215cnc-app.rim.net with ESMTP; 20 Oct 2015 10:28:28 -0400 Received: from unknown (HELO qnxws9580.ott.qnx.com) ([10.65.140.253]) by mhs101cnc.rim.net with ESMTP; 20 Oct 2015 14:28:28 +0000 From: Aleksandar Ristovski To: gdb-patches@sourceware.org Cc: palves@redhat.com, Aleksandar Ristovski Subject: [PATCH 3/3] (patch 2/4, v2) [nto] Implement procfs_pid_to_exec_file. Date: Tue, 20 Oct 2015 10:28:14 -0400 Message-Id: <1445351294-18179-4-git-send-email-aristovski@qnx.com> In-Reply-To: <1445351294-18179-1-git-send-email-aristovski@qnx.com> References: <56263FED.3050602@redhat.com> <1445351294-18179-1-git-send-email-aristovski@qnx.com> gdb/ChangeLog: * gdb/nto-procfs.c (procfs_pid_to_exec_file): New function. (init_procfs_targets): Wire new function. --- gdb/nto-procfs.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index ac54c32..e7882ba 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -617,6 +617,33 @@ procfs_files_info (struct target_ops *ignore) (nodestr != NULL) ? nodestr : "local node"); } +/* Read executable file name for the given PID. */ + +static char * +procfs_pid_to_exec_file (struct target_ops *ops, const int pid) +{ + int proc_fd; + static char proc_path[PATH_MAX]; + ssize_t rd; + + /* Read exe file name. */ + snprintf (proc_path, sizeof (proc_path), "%s/proc/%d/exefile", + (nodestr != NULL) ? nodestr : "", pid); + proc_fd = open (proc_path, O_RDONLY); + if (proc_fd == -1) + return NULL; + + rd = read (proc_fd, proc_path, sizeof (proc_path) - 1); + close (proc_fd); + if (rd <= 0) + { + proc_path[0] = '\0'; + return NULL; + } + proc_path[rd] = '\0'; + return proc_path; +} + /* Attach to process PID, then initialize for debugging it. */ static void procfs_attach (struct target_ops *ops, const char *args, int from_tty) @@ -1493,6 +1520,7 @@ init_procfs_targets (void) t->to_interrupt = procfs_interrupt; t->to_have_continuable_watchpoint = 1; t->to_extra_thread_info = nto_extra_thread_info; + t->to_pid_to_exec_file = procfs_pid_to_exec_file; nto_native_ops = t;