This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Problem with manual watchpoints
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Aravinda <aravindakidambi at gmail dot com>
- Cc: gdb at sourceware dot org
- Date: Thu, 24 Dec 2009 22:08:25 +0100
- Subject: Re: Problem with manual watchpoints
- References: <26eb53620912241247i718992d6i422451f4b7f9931@mail.gmail.com>
On Thu, 24 Dec 2009 21:47:06 +0100, Aravinda wrote:
> a = malloc(20);
> __add_watchpoint(getpid(), &a[20]);
>
> for (i = 0; i < 25; i ++) {
> /* getc(stdin); ----> without this, no SIGTRAP is getting generated */
> printf("Accessing now %x\n", &a[i]);
> a[i]++;
> }
What is the type of "a"? After "a = 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. In
fact you may have allocated only 5 elements if "*a" is "int" etc.
> 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.
Please run some valgrind or mudflap on it. At least try it first in userland
if it should be a kernel module.
Regards,
Jan