This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with manual watchpoints


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]