From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Aravinda <aravindakidambi@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: Problem with manual watchpoints
Date: Thu, 24 Dec 2009 21:08:00 -0000 [thread overview]
Message-ID: <20091224210825.GA29926@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2009-12-24 21:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-24 20:47 Aravinda
2009-12-24 21:08 ` Jan Kratochvil [this message]
2009-12-24 21:42 ` Aravinda
2009-12-24 21:52 ` Jan Kratochvil
2009-12-28 21:22 ` Aravinda
2009-12-28 21:49 ` Jan Kratochvil
2009-12-29 3:00 ` Aravinda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091224210825.GA29926@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=aravindakidambi@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox