From patchwork Wed Sep 4 09:00:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 34384 Received: (qmail 64055 invoked by alias); 4 Sep 2019 09:10:09 -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 64037 invoked by uid 89); 4 Sep 2019 09:10:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=day 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; Wed, 04 Sep 2019 09:10:07 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 9DD1F397 for ; Wed, 4 Sep 2019 11:10:04 +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 eQP-84Egb-eP for ; Wed, 4 Sep 2019 11:10:02 +0200 (CEST) Received: from itzacchiuatl.CeBiTec.Uni-Bielefeld.DE (itzacchiuatl.CeBiTec.Uni-Bielefeld.DE [129.70.161.157]) (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 6A13C318 for ; Wed, 4 Sep 2019 11:00:49 +0200 (CEST) Received: (from ro@localhost) by itzacchiuatl.CeBiTec.Uni-Bielefeld.DE (8.15.2+Sun/8.15.2/Submit) id x8490mnd020741; Wed, 4 Sep 2019 11:00:48 +0200 (CEST) From: Rainer Orth To: gdb-patches@sourceware.org Subject: [PATCH] Fix signals reported for faults on Solaris Date: Wed, 04 Sep 2019 11:00:48 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes It's been a long-standing nuisance that gdb reported unaligned accesses on Solaris/SPARC as SIGSEGV, contrary to the shells and truss which correctly report SIGBUS instead. I could trace this down to the fault handling code in procfs.c (procfs_target::wait): when pr_why is set to PR_FAULTED, the current code sets the signal based on the fault number. For one, the code gets this wrong for FLTACCESS (the unaligned access case) where it uses SIGSEGV. What's worse, it's completely unnecessary to make up the signal number inside gdb. Instead, it should just take what procfs reports to avoid mismatches, which is what this patch does. I've completely removed the explicit handling of the various fault codes: for one, the list has already been incomplete, lacking FLTCPCOVF which existed since at least Solaris 8. Besides, there's no reason to error out on unknown fault codes: either the fault causes a signal which can then be reported from procfs, or it doesn't (as for FLTPAGE) and no reporting is necessary. Tested on sparcv9-sun-solaris2.11 and x86_64-pc-solaris2.11. Also spot-checked manually for a couple of cases (unaligned access, division by 0, NULL pointer dereference). I thought about adding a testcase, but that's going to be difficult because both the existance of faults (as in the unaligned access case which only happens on SPARC) or the mapping from fault to signal is target and OS specific. Thus, unless someone objects, I'm going to install the patch in a day or two. Rainer # HG changeset patch # Parent 0dae8fb1c51501778a95bad44ddbc511c49b50fb Fix signals reported for faults on Solaris diff --git a/gdb/procfs.c b/gdb/procfs.c --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -2476,40 +2476,12 @@ wait_again: wstat = (what << 8) | 0177; break; case PR_FAULTED: - switch (what) { - case FLTWATCH: - wstat = (SIGTRAP << 8) | 0177; - break; - /* FIXME: use si_signo where possible. */ - case FLTPRIV: - case FLTILL: - wstat = (SIGILL << 8) | 0177; - break; - case FLTBPT: - case FLTTRACE: - wstat = (SIGTRAP << 8) | 0177; - break; - case FLTSTACK: - case FLTACCESS: - case FLTBOUNDS: - wstat = (SIGSEGV << 8) | 0177; - break; - case FLTIOVF: - case FLTIZDIV: - case FLTFPE: - wstat = (SIGFPE << 8) | 0177; - break; - case FLTPAGE: /* Recoverable page fault */ - default: /* FIXME: use si_signo if possible for - fault. */ - retval = ptid_t (-1); - printf_filtered ("procfs:%d -- ", __LINE__); - printf_filtered (_("child stopped for unknown reason:\n")); - proc_prettyprint_why (why, what, 1); - error (_("... giving up...")); - break; + { + int signo = pi->prstatus.pr_lwp.pr_info.si_signo; + if (signo != 0) + wstat = (signo << 8) | 0177; } - break; /* case PR_FAULTED: */ + break; default: /* switch (why) unmatched */ printf_filtered ("procfs:%d -- ", __LINE__); printf_filtered (_("child stopped for unknown reason:\n"));