From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 107103 invoked by alias); 19 Sep 2018 14:36:03 -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 106671 invoked by uid 89); 19 Sep 2018 14:36:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Sep 2018 14:36:01 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 75C6C56018; Wed, 19 Sep 2018 10:36:00 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ULonP7M5zkbK; Wed, 19 Sep 2018 10:36:00 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 416BB56017; Wed, 19 Sep 2018 10:36:00 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 803FF85884; Wed, 19 Sep 2018 07:35:58 -0700 (PDT) Date: Wed, 19 Sep 2018 14:36:00 -0000 From: Joel Brobecker To: Rainer Orth Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Provide pid_to_exec_file on Solaris (PR tdep/17903) Message-ID: <20180919143558.GP19172@adacore.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-SW-Source: 2018-09/txt/msg00688.txt.bz2 Hi Rainer, On Wed, Sep 19, 2018 at 04:17:57PM +0200, Rainer Orth wrote: > While looking through gdb.log, I found that two tests FAIL like this: > > warning: No executable has been specified and target does not support > determining executable automatically. Try using the "file" command. > 0x00400dc4 in ?? () > (gdb) FAIL: gdb.base/attach.exp: attach2, with no file > > The other is gdb.base/quit-live.exp. I've implemented the following > patch that fixes both failures, only then detecting that I'd previously > reported the issue as PR tdep/17903. > > Tested on amd64-pc-solaris2.10 and amd64-pc-solaris2.11, ok for master? > > Rainer > > -- > ----------------------------------------------------------------------------- > Rainer Orth, Center for Biotechnology, Bielefeld University > > > 2018-06-13 Rainer Orth > > PR tdep/17903 > * procfs.c (procfs_target): Declare pid_to_exec_file. > (procfs_target::pid_to_exec_file): New. Nice :). This is OK for me as is; one question: Have you considered the use of an std::string for the variable "name"? I thought about it, and I'm not sure it would make the code all that better, but thought I'd mention it again, in case you or someone else sees something I don't see. > diff --git a/gdb/procfs.c b/gdb/procfs.c > --- a/gdb/procfs.c > +++ b/gdb/procfs.c > @@ -128,6 +128,8 @@ public: > > const char *pid_to_str (ptid_t) override; > > + char *pid_to_exec_file (int pid) override; > + > thread_control_capabilities get_thread_control_capabilities () override > { return tc_schedlock; } > > @@ -3135,6 +3137,35 @@ procfs_target::pid_to_str (ptid_t ptid) > return buf; > } > > +/* Accepts an integer PID; Returns a string representing a file that > + can be opened to get the symbols for the child process. */ > + > +char * > +procfs_target::pid_to_exec_file (int pid) > +{ > + static char buf[PATH_MAX]; > + char name[PATH_MAX]; > + > + /* Solaris 11 introduced /proc//execname. */ > + xsnprintf (name, PATH_MAX, "/proc/%d/execname", pid); > + scoped_fd fd (open (name, O_RDONLY)); > + if (fd.get () < 0 || read (fd.get (), buf, PATH_MAX - 1) < 0) > + { > + /* If that fails, fall back to /proc//path/a.out introduced in > + Solaris 10. */ > + ssize_t len; > + > + xsnprintf (name, PATH_MAX, "/proc/%d/path/a.out", pid); > + len = readlink (name, buf, PATH_MAX - 1); > + if (len <= 0) > + strcpy (buf, name); > + else > + buf[len] = '\0'; > + } > + > + return buf; > +} > + > /* Insert a watchpoint. */ > > static int -- Joel