From: Aravinda <aravindakidambi@gmail.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb@sourceware.org
Subject: Re: Problem with manual watchpoints
Date: Thu, 24 Dec 2009 21:42:00 -0000 [thread overview]
Message-ID: <26eb53620912241341w30a924afxf90f66166b8c552b@mail.gmail.com> (raw)
In-Reply-To: <20091224210825.GA29926@host0.dyn.jankratochvil.net>
Thanks Jan,
replied inline.
On Thu, Dec 24, 2009 at 4:08 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> 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"?
a is char*.
>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.
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
next prev parent reply other threads:[~2009-12-24 21:42 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
2009-12-24 21:42 ` Aravinda [this message]
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=26eb53620912241341w30a924afxf90f66166b8c552b@mail.gmail.com \
--to=aravindakidambi@gmail.com \
--cc=gdb@sourceware.org \
--cc=jan.kratochvil@redhat.com \
/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