From: Peter Barada <peter@baradas.org>
To: crawford@goingware.com
Cc: gdb@sources.redhat.com
Subject: Re: touch and go breakpoints?
Date: Sun, 15 Jun 2003 14:04:00 -0000 [thread overview]
Message-ID: <20030615140401.76BCF98DFD@baradas.org> (raw)
In-Reply-To: <3EEC2751.8040201@goingware.com> (crawford@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
prev parent reply other threads:[~2003-06-15 14:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-15 6:53 Michael D. Crawford
2003-06-15 14:04 ` Peter Barada [this message]
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=20030615140401.76BCF98DFD@baradas.org \
--to=peter@baradas.org \
--cc=crawford@goingware.com \
--cc=gdb@sources.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