For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2008 > gdb break









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author gdb break
sinbad

2008-03-15, 4:59 am

hi
how to make gdb to break ,with the change in some memory location.i
tried watchpoint but it's not working.
is there anyother way

thanks
sinbad
WANG Cong

2008-03-15, 8:11 am

On Fri, 14 Mar 2008 23:16:23 -0700,sinbad wrote:

> hi
> how to make gdb to break ,with the change in some memory location.i
> tried watchpoint but it's not working. is there anyother way
>


I think gnu.gcc.help is a more appropriate place to discuss this
problem.

I think 'watch' should work, what's wrong with it?

--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
Paul Pluzhnikov

2008-03-15, 7:28 pm

sinbad <sinbad.sinbad@gmail.com> writes:

> how to make gdb to break ,with the change in some memory location.


You'll do well to read this:
http://catb.org/esr/faqs/smart-questions.html
and ask a smarter question next time.

> i tried watchpoint but it's not working.


Since you didn't tell us what exactly you did, we can't tell you
what you did wrong. Gdb watchpoints work just fine. They are even
fast on some platforms.

> is there anyother way


No.

Here are precise instructions:
Suppose you have a global variable "count" and you want gdb to stop
every time it is updated.

$ cat t.c
#include <stdio.h>
int count;

int incr()
{
return count++;
}

int main()
{
int i;
while ((i = incr()) < 5)
printf("%d\n", i);
return 0;
}
$ gcc -g t.c && gdb -q ./a.out
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) p &count
$1 = (int *) 0x804959c
(gdb) watch *$1
Hardware watchpoint 1: *$1
(gdb) r
Hardware watchpoint 1: *$1
Hardware watchpoint 1: *$1
Hardware watchpoint 1: *$1

Old value = 0
New value = 1
incr () at t.c:7
7 }
(gdb) bt
#0 incr () at t.c:7
#1 0x08048395 in main () at t.c:12
(gdb) c
0
Hardware watchpoint 1: *$1

Old value = 1
New value = 2
incr () at t.c:7
7 }
.... etc ...

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com