From patchwork Tue Apr 22 13:09:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Zhu X-Patchwork-Id: 637 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id 7CDF53606C6 for ; Tue, 22 Apr 2014 06:09:59 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id 21B0C13F6FBB; Tue, 22 Apr 2014 06:09:58 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id CA22F1458F42 for ; Tue, 22 Apr 2014 06:09:58 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=f83vukYn9xeOPan3 M4qIjMlfMVyKnHbPfWtGMNIOJlp+pWjsIcOu+Qs9HUmeBSOgjxwjJ6dkfTwVAYDA izGfKsHUq26kbHIr1ft2yhUy2uZxl2pSbt9mr+Qu6GgFqVo/fkkYfkMhyWcq0zTU +2tlonkhgbAMhw0qAMuHymMQ0EU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; s=default; bh=X3NXlJRBlkO5+Iv6aQ1I4z k6CCk=; b=Z56LIGRvLh+Tr01i0cgTeLmVf6s/WqdKqJptUuiUKWgL53wnGp0iDm 7uSiGBlHHAaCtkwY0hw4GXMqTLBrjc7dLqTBp2p2pRP3owWfjc36A0Ms/Gq++iEX SIKWLeC2jwpVHrRKMfLJUU+4dDaJIfvTo5HkWyoJr/lh2lGceSGSs= Received: (qmail 6930 invoked by alias); 22 Apr 2014 13:09:56 -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 6918 invoked by uid 89); 22 Apr 2014 13:09:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Apr 2014 13:09:50 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1WcaSI-0000Uz-9G from Hui_Zhu@mentor.com ; Tue, 22 Apr 2014 06:09:46 -0700 Received: from SVR-ORW-FEM-06.mgc.mentorg.com ([147.34.97.120]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 22 Apr 2014 06:09:46 -0700 Received: from localhost.localdomain (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.2.247.3; Tue, 22 Apr 2014 06:09:45 -0700 Message-ID: <53566A17.4060109@mentor.com> Date: Tue, 22 Apr 2014 21:09:43 +0800 From: Hui Zhu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: CC: gdb-patches ml Subject: Re: [PATCH] Fix interrupt.exp fails with m32 in x86_64 References: <53554475.3010201@mentor.com> <201404211827.s3LIRL6a007871@glazunov.sibelius.xs4all.nl> In-Reply-To: <201404211827.s3LIRL6a007871@glazunov.sibelius.xs4all.nl> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in On 04/22/14 02:27, Mark Kettenis wrote: >> Date: Tue, 22 Apr 2014 00:16:53 +0800 >> From: Hui Zhu >> >> I make a patch that let eax sign-extend in function >> amd64_collect_native_gregset >> that can handle this issue. >> It can handle the issue and pass the regression test. >> Please help me review it. > I don't think the generic amd64 target code is the proper place to > work around Linux kernel bugs. If you really want to work around this > bug in GDB, it should probably be done in the Linux-specific > i386/amd64 native code. > > Mark Hi Mark, Thanks for your review. I will keep work on the patch for Linux kernel to Linux can handle it. But I worried about even if this issue is fixed in Linux kernel. A lot of GDB will still work with the old Linux kernel. So I make this patch. I make a new patch the move %eax sign-extend code to amd64-linux-nat.c. Thanks, Hui 2014-04-22 Hui Zhu * amd64-linux-nat.c (fill_gregset): Make %eax sign-extended. (amd64_linux_store_inferior_registers): Change amd64_collect_native_gregset to fill_gregset. * amd64-nat.c (amd64_native_gregset_reg_offset): Remove static. * amd64-nat.h (amd64_native_gregset_reg_offset): Add extern. --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -126,7 +126,27 @@ void fill_gregset (const struct regcache *regcache, elf_gregset_t *gregsetp, int regnum) { + struct gdbarch *gdbarch = get_regcache_arch (regcache); + amd64_collect_native_gregset (regcache, gregsetp, regnum); + + if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32 + && (regnum == I386_EAX_REGNUM || regnum == -1)) + { + /* Make %eax get sign-extended to 64 bits. */ + LONGEST val; + char *regs = (char *) gregsetp; + int offset = amd64_native_gregset_reg_offset (gdbarch, + I386_EAX_REGNUM); + + regcache_raw_collect (regcache, I386_EAX_REGNUM, + regs + offset); + val = extract_signed_integer ((gdb_byte *)(regs + offset), + 4, + gdbarch_byte_order (gdbarch)); + store_signed_integer ((gdb_byte *)(regs + offset), 8, + gdbarch_byte_order (gdbarch), val); + } } /* Transfering floating-point registers between GDB, inferiors and cores. */ @@ -232,7 +252,7 @@ amd64_linux_store_inferior_registers (st if (ptrace (PTRACE_GETREGS, tid, 0, (long) ®s) < 0) perror_with_name (_("Couldn't get registers")); - amd64_collect_native_gregset (regcache, ®s, regnum); + fill_gregset (regcache, ®s, regnum); if (ptrace (PTRACE_SETREGS, tid, 0, (long) ®s) < 0) perror_with_name (_("Couldn't write registers")); --- a/gdb/amd64-nat.c +++ b/gdb/amd64-nat.c @@ -51,7 +51,7 @@ int amd64_native_gregset64_num_regs = AM /* Return the offset of REGNUM within the appropriate native general-purpose register set. */ -static int +int amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, int regnum) { int *reg_offset = amd64_native_gregset64_reg_offset; --- a/gdb/amd64-nat.h +++ b/gdb/amd64-nat.h @@ -30,6 +30,12 @@ extern int amd64_native_gregset32_num_re extern int *amd64_native_gregset64_reg_offset; extern int amd64_native_gregset64_num_regs; +/* Return the offset of REGNUM within the appropriate native + general-purpose register set. */ + +extern int amd64_native_gregset_reg_offset (struct gdbarch *gdbarch, + int regnum); + /* Return whether the native general-purpose register set supplies register REGNUM. */