This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: touch and go breakpoints?
- From: Peter Barada <peter at baradas dot org>
- To: crawford at goingware dot com
- Cc: gdb at sources dot redhat dot com
- Date: Sun, 15 Jun 2003 10:04:01 -0400 (EDT)
- Subject: Re: touch and go breakpoints?
- References: <3EEC2751.8040201@goingware.com>
>Is there a way I can set a breakpoint, where if it is hit, gdb will execute
>some command, and then continue?
Yes. Look up the 'command' command syntax. Here's an example using
the simple testfile:
#include <stdio.h>
int foo(x)
{
return x+x+1;
}
int main(int argc, char *argv[])
{
int i, val, lim;
val = atoi(argv[1]);
lim = atoi(argv[2]);
for (i=0; i<lim; ++i)
val = foo(val);
printf("val is %d\n", val);
}
And its run:
Current directory is /tmp/
GNU gdb Red Hat Linux (5.2-2)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) b foo
Breakpoint 1 at 0x8048443: file test.c, line 4.
(gdb) command foo
No breakpoint number 0.
(gdb) command 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>p x
>c
>end
(gdb) run 1 10
Starting program: /tmp/a.out 1 5
Breakpoint 1, foo (x=1) at test.c:4
$1 = 1
Breakpoint 1, foo (x=3) at test.c:4
$2 = 3
Breakpoint 1, foo (x=7) at test.c:4
$3 = 7
Breakpoint 1, foo (x=15) at test.c:4
$4 = 15
Breakpoint 1, foo (x=31) at test.c:4
$5 = 31
Program exited with code 014.
(gdb)
--
Peter Barada
peter@baradas.org