From patchwork Tue May 15 15:27:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 27272 Received: (qmail 118302 invoked by alias); 15 May 2018 15:28:04 -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 117426 invoked by uid 89); 15 May 2018 15:28:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: 9pmail.ess.barracuda.com Received: from 9pmail.ess.barracuda.com (HELO 9pmail.ess.barracuda.com) (64.235.154.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 May 2018 15:28:02 +0000 Received: from mipsdag02.mipstec.com (mail2.mips.com [12.201.5.32]) by mx1402.ess.rzc.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Tue, 15 May 2018 15:27:49 +0000 Received: from [10.20.78.107] (10.20.78.107) by mipsdag02.mipstec.com (10.20.40.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1415.2; Tue, 15 May 2018 08:27:44 -0700 Date: Tue, 15 May 2018 16:27:07 +0100 From: "Maciej W. Rozycki" To: Subject: [committed] MIPS/Linux/native: Supply $zero for the !PTRACE_GETREGS case Message-ID: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-ClientProxiedBy: mipsdag02.mipstec.com (10.20.40.47) To mipsdag02.mipstec.com (10.20.40.47) X-BESS-ID: 1526398067-321458-2553-48181-1 X-BESS-VER: 2018.6-r1805102334 X-BESS-Apparent-Source-IP: 12.201.5.32 X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.193012 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 With native MIPS/Linux targets the $zero register is inaccessible, with its supposed context slot provided by the OS occupied by the $restart register. The PTRACE_GETREGS path takes care of it by artificially supplying the hardwired contents of $zero in `mips_supply_gregset' or `mips64_supply_gregset', as applicable, however the PTRACE_PEEKUSER fallback does not, making the register unavailable, e.g.: (gdb) info registers zero at v0 v1 a0 a1 a2 a3 R0 00000001 00000001 d2f1a9fc 00000000 00000000 00417158 00417150 t0 t1 t2 t3 t4 t5 t6 t7 R8 00000004 00000000 fffffff8 00000000 00000000 00000000 00000001 00000007 s0 s1 s2 s3 s4 s5 s6 s7 R16 00000000 00405e30 00000000 00500000 00000000 0052ec08 00000000 00000000 t8 t9 k0 k1 gp sp s8 ra R24 00000000 00417008 00000000 00000000 0041e220 7fff4ce0 7fff4ce0 00405d0c status lo hi badvaddr cause pc 00441cf1 00000017 00417004 00800024 00405d10 fcsr fir restart 00800000 00f30000 00000000 (gdb) or (under certain circumstances): (gdb) stepi Register 0 is not available (gdb) This is specifically because `mips_linux_register_addr' and `mips64_linux_register_addr', both correctly return -1 for MIPS_ZERO_REGNUM, and therefore `linux_nat_trad_target::fetch_registers' faithfully marks this register as unavailable. Supply this register artificially then in the PTRACE_PEEKUSER case as well, correcting this issue. gdb/ * mips-linux-nat.c (mips_linux_nat_target::fetch_registers): Supply the MIPS_ZERO_REGNUM register. --- gdb/mips-linux-nat.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) gdb-mips-linux-nat-zero-regno.diff Index: binutils/gdb/mips-linux-nat.c =================================================================== --- binutils.orig/gdb/mips-linux-nat.c 2018-05-12 06:56:28.000000000 +0100 +++ binutils/gdb/mips-linux-nat.c 2018-05-12 07:00:04.545527001 +0100 @@ -416,7 +416,13 @@ mips_linux_nat_target::fetch_registers ( /* If we know, or just found out, that PTRACE_GETREGS does not work, fall back to PTRACE_PEEKUSER. */ if (!have_ptrace_regsets) - linux_nat_trad_target::fetch_registers (regcache, regnum); + { + linux_nat_trad_target::fetch_registers (regcache, regnum); + + /* Fill the inaccessible zero register with zero. */ + if (regnum == MIPS_ZERO_REGNUM || regnum == -1) + regcache->raw_supply_zeroed (MIPS_ZERO_REGNUM); + } } /* Store REGNO (or all registers if REGNO == -1) to the target