From patchwork Tue Jan 5 19:27:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Vandenberg X-Patchwork-Id: 10230 Received: (qmail 28198 invoked by alias); 5 Jan 2016 19:27:41 -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 28182 invoked by uid 89); 5 Jan 2016 19:27:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=meat, Unix, resembles, Included X-HELO: mail-yk0-f170.google.com Received: from mail-yk0-f170.google.com (HELO mail-yk0-f170.google.com) (209.85.160.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 05 Jan 2016 19:27:39 +0000 Received: by mail-yk0-f170.google.com with SMTP id x67so292226701ykd.2 for ; Tue, 05 Jan 2016 11:27:38 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.129.145.143 with SMTP id i137mr36401624ywg.268.1452022057141; Tue, 05 Jan 2016 11:27:37 -0800 (PST) Received: by 10.37.118.130 with HTTP; Tue, 5 Jan 2016 11:27:37 -0800 (PST) Date: Tue, 5 Jan 2016 12:27:37 -0700 Message-ID: Subject: [PATCH V2][PR gdb/17903] Implement to_pid_to_exec_file for solaris From: Brian Vandenberg To: gdb-patches@sourceware.org This patch is to address an issue in Solaris, bug 17903. This is my second submission for this issue with changes made as requested by Pedro Alvez in December, as well as adjustments to the changelog formatting as suggested by Joel Brobecker. The meat of the differences between the two patches: this change only resolves the problem in Solaris 10+ and any other OS using procfs that uses the same path convention. In any other OS currently affected it will remain broken -- though Pedro indicated in an earlier message that Solaris is the only OS of concern w/regard to gdb/procfs.c. When attaching to a process by PID the current implementation in gdb/procfs.c leaves "to_pid_to_exec_file" at the default -- a stub function that returns NULL. This causes symbols not to load when attaching, forcing the user to either attach by specifying the path on the command line or inside gdb. After specifying the file inside gdb it's also necessary to manually load symbolic information. The proposed change resembles the implementation in gdb/linux-nat.c. I don't have DejaGNU installed on my development machines at work and I don't have one [that functions] at home, so I was unable to run the test suite (otherwise I would have). Lastly: I made these changes on a machine that doesn't have network access. I had to hand-type the following diff. My apologies if there are typos; I did my best. Obviously I won't be able to push this myself. -brian gdb/Changelog: 2015-12-16 Brian Vandenberg PR gdb/17903 * procfs.c (inclusions): Included ansidecl.h for UNUSED_ARG (procfs_target): added procfs_child_pid_to_exec_file to target_ops (procfs_child_pid_to_exec_file): solaris implementation of to_pid_to_exec_file diff --git a/gdb/procfs.c b/gdb/procfs.c index 7b7ff45..a663223 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -51,6 +51,7 @@ #include "auxv.h" #include "procfs.h" #include "observer.h" +#include "ansidecl.h" /* This module provides the interface between GDB and the /proc file system, which is used on many versions of Unix @@ -118,6 +119,7 @@ static void procfs_fetch_registers (struct target_ops *, struct regcache *, int); static void procfs_store_registers (struct target_ops *, struct regcache *, int); +static char* procfs_child_pid_to_exec_file( struct target_ops*, int ); static void procfs_pass_signals (struct target_ops *self, int, unsigned char *); static void procfs_kill_inferior (struct target_ops *ops); @@ -192,6 +194,7 @@procfs_target (void) t->to_resume = procfs_resume; t->to_fetch_registers = procfs_fetch_registers; t->to_store_registers = procfs_store_registers; + t->to_pid_to_exec_file = procfs_child_pid_to_exec_file; t->to_xfer_partial = procfs_xfer_partial; t->to_pass_signals = procfs_pass_signals; t->to_files_info = procfs_files_info; @@ -3301,6 +3304,41 @@ procfs_store_registers (struct target_ops *ops, } } +/* Get a fully qualified path to the debugged process */ +static char* procfs_child_pid_to_exec_file( struct target_ops *ARG_UNUSED(self), + int pid ) +{ + static char buf[PATH_MAX]; + char name[PATH_MAX]; + ssize_t sz = -1; + + xsnprintf( name, sizeof(name), "/proc/%d/path/a.out", pid ); + sz = readlink( name, buf, sizeof( name ) ); + + if( 0 < sz ) + { + buf[sz] = '\0'; + return buf; + } + + /* This is the default behavior as defined in target.h + * and implemented in inf_child_pid_to_exec_file() */ + return NULL; +} +