From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16596 invoked by alias); 24 Dec 2009 21:42:03 -0000 Received: (qmail 16587 invoked by uid 22791); 24 Dec 2009 21:42:02 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-qy0-f180.google.com (HELO mail-qy0-f180.google.com) (209.85.221.180) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Dec 2009 21:41:58 +0000 Received: by qyk10 with SMTP id 10so4440585qyk.12 for ; Thu, 24 Dec 2009 13:41:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.1.200 with SMTP id 8mr5293671qcg.64.1261690917102; Thu, 24 Dec 2009 13:41:57 -0800 (PST) In-Reply-To: <20091224210825.GA29926@host0.dyn.jankratochvil.net> References: <26eb53620912241247i718992d6i422451f4b7f9931@mail.gmail.com> <20091224210825.GA29926@host0.dyn.jankratochvil.net> From: Aravinda Date: Thu, 24 Dec 2009 21:42:00 -0000 Message-ID: <26eb53620912241341w30a924afxf90f66166b8c552b@mail.gmail.com> Subject: Re: Problem with manual watchpoints To: Jan Kratochvil Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-12/txt/msg00152.txt.bz2 Thanks Jan, replied inline. On Thu, Dec 24, 2009 at 4:08 PM, Jan Kratochvil wrote: > On Thu, 24 Dec 2009 21:47:06 +0100, Aravinda wrote: >> a =3D malloc(20); >> __add_watchpoint(getpid(), &a[20]); >> >> for (i =3D 0; i < 25; i ++) { >> =A0 =A0 =A0 /* getc(stdin); ----> without this, no SIGTRAP is getting ge= nerated */ >> =A0 =A0 =A0 printf("Accessing now %x\n", &a[i]); >> =A0 =A0 =A0 a[i]++; >> } > > What is the type of "a"? a is char*. >After "a =3D malloc(20);" you can access elements > a[0]...a[19] but a[20] is already after the allocated array size. > > Also the loop is till "i < 25" but you have allocated only 20 elements. = =A0In > fact you may have allocated only 5 elements if "*a" is "int" etc. Yes, thats why I have a watchpoint added at &a[20]. So on accessing the first element out of the allocated array, I want the program to receive a SIGTRAP. > > >> However, if I just add a 'getc(stdin)' before accessing every element, it >> does get the exception on accessing a[20]. > > You have data corruption in your program so it behaves very unpredictably. But I have &a[20] in DR0 with necessary DR7 bits enabled, isnt the program supposed to get a Trap/Breakpoint exception on accessing it (the very first element out of the allocated buffer) ? Im trying to avoid the memory corruption by handling SIGTRAP and aborting the program. Infact it gets this signal when the getc(stdin) is included, is it something to do with the program should be in single step mode to get SIGTRAPs or is the loop way too simple that it executes in no time before the SIGTRAP is even raised ? Thanks, Aravinda