From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8910 invoked by alias); 11 Apr 2012 20:36:19 -0000 Received: (qmail 8632 invoked by uid 22791); 11 Apr 2012 20:36:17 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Apr 2012 20:36:00 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3BKZupB003664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Apr 2012 16:35:56 -0400 Received: from host2.jankratochvil.net (ovpn-116-17.ams2.redhat.com [10.36.116.17]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q3BKZoug024430 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 11 Apr 2012 16:35:53 -0400 Date: Wed, 11 Apr 2012 21:33:00 -0000 From: Jan Kratochvil To: Hui Zhu Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] breakpoint remove fail handle bug fix Message-ID: <20120411203549.GA4715@host2.jankratochvil.net> References: <4F8549BC.3050003@mentor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4F8549BC.3050003@mentor.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-04/txt/msg00263.txt.bz2 On Wed, 11 Apr 2012 11:07:08 +0200, Hui Zhu wrote: > (gdb) d > Delete all breakpoints? (y or n) y > warning: Error removing breakpoint 2 I would propose the attached patch instead. It needs a testcase, would you write one? Not sure if gdbserver also needs a fix or not. No regressions on {x86_64,x86_64-m32,i686}-fedora17-linux-gnu. Thanks, Jan gdb/ 2012-04-11 Jan Kratochvil * linux-nat.c (linux_proc_xfer_partial): Do not check for LEN size and support also WRITEBUF. (linux_xfer_partial): Move here the LEN check from linux_proc_xfer_partial but also call linux_proc_xfer_partial as a last resort if super_xfer_partial fails. --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4494,9 +4494,9 @@ linux_nat_make_corefile_notes (bfd *obfd, int *note_size) } /* Implement the to_xfer_partial interface for memory reads using the /proc - filesystem. Because we can use a single read() call for /proc, this - can be much more efficient than banging away at PTRACE_PEEKTEXT, - but it doesn't support writes. */ + filesystem. Because we can use a single read or write call for /proc, this + can be much more efficient than banging away at PTRACE_PEEKTEXT or + PTRACE_POKETEXT. */ static LONGEST linux_proc_xfer_partial (struct target_ops *ops, enum target_object object, @@ -4508,29 +4508,35 @@ linux_proc_xfer_partial (struct target_ops *ops, enum target_object object, int fd; char filename[64]; - if (object != TARGET_OBJECT_MEMORY || !readbuf) - return 0; - - /* Don't bother for one word. */ - if (len < 3 * sizeof (long)) + if (object != TARGET_OBJECT_MEMORY) return 0; /* We could keep this file open and cache it - possibly one per thread. That requires some juggling, but is even faster. */ sprintf (filename, "/proc/%d/mem", PIDGET (inferior_ptid)); - fd = open (filename, O_RDONLY | O_LARGEFILE); + fd = open (filename, (readbuf ? O_RDONLY : O_WRONLY) | O_LARGEFILE); if (fd == -1) return 0; - /* If pread64 is available, use it. It's faster if the kernel + /* If pread64 or pwrite64 is available, use it. It's faster if the kernel supports it (only one syscall), and it's 64-bit safe even on 32-bit platforms (for instance, SPARC debugging a SPARC64 application). */ + if ((readbuf != NULL +#ifdef HAVE_PREAD64 + && (pread64 (fd, readbuf, len, offset) != len) +#else + && (lseek (fd, offset, SEEK_SET) == -1 || read (fd, readbuf, len) != len) +#endif + ) + || (writebuf != NULL #ifdef HAVE_PREAD64 - if (pread64 (fd, readbuf, len, offset) != len) + && (pwrite64 (fd, writebuf, len, offset) != len) #else - if (lseek (fd, offset, SEEK_SET) == -1 || read (fd, readbuf, len) != len) + && (lseek (fd, offset, SEEK_SET) == -1 + || write (fd, writebuf, len) != len) #endif + )) ret = 0; else ret = len; @@ -4759,13 +4765,24 @@ linux_xfer_partial (struct target_ops *ops, enum target_object object, offset &= ((ULONGEST) 1 << addr_bit) - 1; } - xfer = linux_proc_xfer_partial (ops, object, annex, readbuf, writebuf, - offset, len); + /* Use more expensive linux_proc_xfer_partial only for larger transfers. */ + if (len >= 3 * sizeof (long)) + { + xfer = linux_proc_xfer_partial (ops, object, annex, readbuf, writebuf, + offset, len); + if (xfer != 0) + return xfer; + } + + xfer = super_xfer_partial (ops, object, annex, readbuf, writebuf, + offset, len); if (xfer != 0) return xfer; - return super_xfer_partial (ops, object, annex, readbuf, writebuf, - offset, len); + /* PTRACE_* of super_xfer_partial may not work if the inferior is running. + linux_proc_xfer_partial still may work in such case. */ + return linux_proc_xfer_partial (ops, object, annex, readbuf, writebuf, + offset, len); } static void