From patchwork Tue Aug 7 19:45:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Vandenberg X-Patchwork-Id: 28774 Received: (qmail 68916 invoked by alias); 7 Aug 2018 19:45:44 -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 68678 invoked by uid 89); 7 Aug 2018 19:45:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Included, his X-HELO: mail-yw1-f47.google.com Received: from mail-yw1-f47.google.com (HELO mail-yw1-f47.google.com) (209.85.161.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Aug 2018 19:45:30 +0000 Received: by mail-yw1-f47.google.com with SMTP id v197-v6so5397197ywg.3 for ; Tue, 07 Aug 2018 12:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=iSMM0BOxRbZ4ppQajRKfGehF5b1RLWYpNgPiau1akks=; b=lUwG3kJxQTNtpAy6B8BUEvJzwLGd7XGUbCpTmQaHNn7eC3WcVUvzaq8D7ELkUtWG73 pE9xvvxiz4jnsrw6t3k6y/kUkjH4lYuhJyVdY6SsENveGZrdoiyFb7ueEIpv+FGJFaoU QwpiR+J0HfZK547tDmrj/3ON7SEs2sRQAmgMEl/PJnlT8w7GG3l8vzxQnESmYLJFUKEi 2iLLllaIK3ZPApJ1FfRyf+FL8S8lsYrI5qyiPYYHSBLDDBuQsKAvKwNol+KoDHKchjhL JaLxh5plANQ740f4ekUClAlNal/Uv2bpQlVegKxY7Dio9daKg6MDvB0bJOD17QzQ20Fk CqzQ== MIME-Version: 1.0 Received: by 2002:a25:57c2:0:0:0:0:0 with HTTP; Tue, 7 Aug 2018 12:45:27 -0700 (PDT) From: Brian Vandenberg Date: Tue, 7 Aug 2018 13:45:27 -0600 Message-ID: Subject: [PATCH V3][PR gdb/17903] Implement to_pid_to_exec_file for solaris To: gdb-patches@sourceware.org This patch is to address an issue in Solaris, bug 17903. This is my third submission for this issue with changes requested by Pedro Alvez / Joel Brobecker. Problem: 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. Pedro indicated Solaris is likely the only OS affected by this code & still needs support; at his suggestion I tailored this change for Solaris I cannot easily run the test suite against these changes right now. If this gets rejected based on that, I'll see about getting something setup at home to run the tests when I have time. ---- note: this patch was tested against 8.1.1. In its current form this patch cannot be used against 8.2 / master, however it looks like it won't take much to apply the same change against the new C++ procfs interface. -brian ps, my assignment/release forms were completed/received 10/30/2017 gdb/Changelog: 2018-08-07 Brian Vandenberg PR gdb/17903 * procfs.c (inclusions): Included ansidecl.h for ARG_UNUSED (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 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -46,6 +46,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 @@ -95,6 +96,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); @@ -169,6 +171,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; @@ -2175,6 +2178,29 @@ 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/%u/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; +} + static int syscall_is_lwp_exit (procinfo *pi, int scall) {