From patchwork Thu Sep 20 09:27:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 29487 Received: (qmail 21192 invoked by alias); 20 Sep 2018 09:27:25 -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 18970 invoked by uid 89); 20 Sep 2018 09:27:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=Hx-languages-length:1730 X-HELO: smtp.CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE (HELO smtp.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Sep 2018 09:27:19 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 976F8687; Thu, 20 Sep 2018 11:27:17 +0200 (CEST) Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id w8WZ2yzFGzbv; Thu, 20 Sep 2018 11:27:15 +0200 (CEST) Received: from lokon.CeBiTec.Uni-Bielefeld.DE (lokon.CeBiTec.Uni-Bielefeld.DE [129.70.161.152]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id 779A6686; Thu, 20 Sep 2018 11:27:15 +0200 (CEST) Received: (from ro@localhost) by lokon.CeBiTec.Uni-Bielefeld.DE (8.15.2+Sun/8.15.2/Submit) id w8K9REq6021952; Thu, 20 Sep 2018 11:27:14 +0200 (MEST) From: Rainer Orth To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Provide pid_to_exec_file on Solaris (PR tdep/17903) References: <87bm8tr19q.fsf@tromey.com> Date: Thu, 20 Sep 2018 11:27:14 +0200 In-Reply-To: <87bm8tr19q.fsf@tromey.com> (Tom Tromey's message of "Wed, 19 Sep 2018 08:48:49 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes Hi Tom, > Rainer> + scoped_fd fd (open (name, O_RDONLY)); > > You may wish to use gdb_open_cloexec. this worked just as well, so after retesting on amd64-pc-solaris2.11, I've committed the following patch. Thanks. Rainer # HG changeset patch # Parent 020f5ee983bb3daaef32d4d8424e6f60d24111c2 Provide pid_to_exec_file on Solaris 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; } @@ -3138,6 +3140,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 (gdb_open_cloexec (name, O_RDONLY, 0)); + 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