Problem with manual watchpoints
Jan Kratochvil
jan.kratochvil@redhat.com
Thu Dec 24 21:08:00 GMT 2009
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
More information about the Gdb
mailing list