From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16193 invoked by alias); 13 Mar 2012 23:08:17 -0000 Received: (qmail 16184 invoked by uid 22791); 13 Mar 2012 23:08:16 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_CP,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; Tue, 13 Mar 2012 23:08:03 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2DN7f7J016658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 13 Mar 2012 19:07:41 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q2DN42wM009661; Tue, 13 Mar 2012 19:04:03 -0400 Message-ID: <4F5FD262.9030708@redhat.com> Date: Tue, 13 Mar 2012 23:08:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 MIME-Version: 1.0 To: Joel Brobecker CC: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [RFA] Problem after hitting breakpoint on Windows (with GDBserver) References: <1331602756-23567-1-git-send-email-brobecker@adacore.com> <1331602756-23567-2-git-send-email-brobecker@adacore.com> <4F5F6187.50209@redhat.com> <20120313215956.GT2853@adacore.com> In-Reply-To: <20120313215956.GT2853@adacore.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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-03/txt/msg00455.txt.bz2 On 03/13/2012 09:59 PM, Joel Brobecker wrote: >>> + if (val == 0) >>> + memcpy (bp_tgt->shadow_contents, readbuf, bp_tgt->placed_size); >>> >>> /* Write the breakpoint. */ >>> if (val == 0) >> >> Merge? > > I actually started that way, with the two blocks merged. But I felt > that it was breaking the separation between the two steps. With the > comments clearly separating the two steps, I didn't want to break > that unless asked. So now I changed it. If that's a concern, we can still keep it, like e.g.: /* Fetch the memory contents "under" the breakpoint, and save it in the shadow_contents buffer. */ readbuf = alloca (bp_tgt->placed_size); val = target_read_memory (bp_tgt->placed_address, readbuf, bp_tgt->placed_size); if (val == 0) { /* Success, save it. */ bp_tgt->shadow_len = bp_tgt->placed_size; memcpy (bp_tgt->shadow_contents, readbuf, bp_tgt->placed_size); /* Now write the breakpoint instruction. */ val = target_write_raw_memory (bp_tgt->placed_address, bp, bp_tgt->placed_size); } > >>> + As a limitation, MYADDR must not be the shadow_contents buffer of one >> >> I wouldn't call it a limitation; it's more a design choice thing, like >> memcpy doesn't handle overlapping buffers. > > OK - I just removed the "As a limitation" from the comments. > >> Otherwise this is fine with me. > > Thanks! Attached is a new version of the patch. The only changes > should be the changes you pointed out. > >> An assertion in breakpoint_xfer_memory to catch that READBUF or >> WRITEBUF doesn't overlap bp->target_info.shadow_contents would be >> nice. > > I thought about that, but decided to look at that separately, since > it doesn't help correctness, and can potentially be a little expensive > (at least compared to just allocating a buffer on the heap - I think!). Eh, it's meant to insure correctness. :-) Certainly a heap allocation on every read is more expensive than a simple range check, and more so one that only triggers when we have breakpoints in the range we're reading. > > But I don't mind writing a patch - probably a function in breakpoint.c > and a gdb_assert calling that breakpoint? Oh, I was only thinking of something along the lines of what Jan did on gdbserver. That is, something like: --- c/gdb/breakpoint.c +++ w/gdb/breakpoint.c @@ -1446,6 +1446,10 @@ breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, if (readbuf != NULL) { + gdb_assert (bl->target_info.shadow_contents >= readbuf + len + || readbuf >= (bl->target_info.shadow_contents + + bl->target_info.shadow_len)); + /* Update the read buffer with this inserted breakpoint's shadow. */ memcpy (readbuf + bp_addr - memaddr, -- Pedro Alves