public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* touch and go breakpoints?
@ 2003-06-15  6:53 Michael D. Crawford
  2003-06-15 14:04 ` Peter Barada
  0 siblings, 1 reply; 2+ messages in thread
From: Michael D. Crawford @ 2003-06-15  6:53 UTC (permalink / raw)
  To: gdb

Is there a way I can set a breakpoint, where if it is hit, gdb will execute 
some command, and then continue?

What I want to do is print out the value of a variable everytime a certain line 
in the code is encountered, but then continue.  I have a crash somewhat later, 
but only after lots of iterations, so what I'd like to do is see what the last 
value of this variable is before the crash.

I used to do this in MacsBug for the old Mac OS like this:

brp 1234 ';dm a0;g'

that will break at location 1234, display some memory starting at whatever 
register a0 is, then go.

Thanks,

Mike
-- 
Michael D. Crawford
GoingWare Inc. - Expert Software Development and Consulting
http://www.goingware.com/
crawford@goingware.com

      Tilting at Windmills for a Better Tomorrow.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: touch and go breakpoints?
  2003-06-15  6:53 touch and go breakpoints? Michael D. Crawford
@ 2003-06-15 14:04 ` Peter Barada
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Barada @ 2003-06-15 14:04 UTC (permalink / raw)
  To: crawford; +Cc: gdb


>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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-06-15 14:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-15  6:53 touch and go breakpoints? Michael D. Crawford
2003-06-15 14:04 ` Peter Barada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).