From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9679 invoked by alias); 31 Oct 2006 18:22:34 -0000 Received: (qmail 9669 invoked by uid 22791); 31 Oct 2006 18:22:33 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Tue, 31 Oct 2006 18:22:13 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1GeyFV-0007jr-6m; Tue, 31 Oct 2006 13:22:09 -0500 Date: Tue, 31 Oct 2006 18:22:00 -0000 From: Daniel Jacobowitz To: Datoda , Andi Kleen Cc: gdb-patches@sourceware.org Subject: Re: [rfa] Handle amd64-linux %orig_rax Message-ID: <20061031182209.GA29639@nevyn.them.org> Mail-Followup-To: Datoda , Andi Kleen , gdb-patches@sourceware.org References: <20061031181702.73135.qmail@web53714.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20061031181702.73135.qmail@web53714.mail.yahoo.com> User-Agent: Mutt/1.5.13 (2006-08-11) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-10/txt/msg00314.txt.bz2 Andi, have you got any opinion on this? The problem arises when GDB sets %orig_rax to -1 to indicate that the interrupted syscall should not be resumed, and then sets %rip to some other address; the kernel is still changing %rcx on the way out to userspace. I think this sounds like a kernel bug. On Tue, Oct 31, 2006 at 10:17:01AM -0800, Datoda wrote: > Here's my explanation of the cause of this problem: According to the > AMD64 ABI, Section A.2, Item 2., the kernel destroys %rcx in a > syscall. Meanwhile, the calling convention uses %rcx to pass in the > fourth argument to the function being called. Therefore, the kernel > may trash the fourth argument to an inferior call even when it's not > restarting the interrupted system call (i.e., when %orig_rax is set > to a negative value) because the kernel is still in the "syscall > mode". > > A repeat inferior call returns the correct value because the kernel > has left that syscall mode when doing the first inferior call. > > It appears to me that instead of telling the kernel not to restart a > syscall by setting %orig_rax to -1, gdb should be telling the kernel > to forget about the syscall all together when initiating an inferior > call, and restoring the kernel's memory about the interrupted syscall > when the inferior call finishes. I don't know how that can be > achieved, though. We don't need to restore it; we can just restart the syscall from scratch. > Alternatively, the kernel can be made to suppress trashing %rcx when > the process is being debugged and %orig_rax is -1. But I don't know > the ramification/implication of this change. > > Or perhaps it's just a kernel bug that needs to be fixed.... > > Any other insight on this? -- Daniel Jacobowitz CodeSourcery