bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help GDB & Watchdog...


From: Toni Rönkkö
Subject: Re: Help GDB & Watchdog...
Date: 13 Mar 2001 15:51:31 +0200

I do not think the watchdog feature has been designed for the job you
are trying use it for.

Perhaps you could use signals to stop the application after a certain
time-out.  Depending on situation, that might need modifications to
the source but those modifications would not need to be executed
outside the GDB.  The following debug session demonstrates use of UNIX
signals:

address@hidden m18> cat x.c
#include <unistd.h>

int main(void) {
  int i;
  for(i=0; i<1000; i++) /*EMPTY*/;
  for(i=1; i!=0; i++) /*EMPTY*/;
  return 0;
}

int set_alarm(int secs) {
  alarm(secs);
  return 1;
}
address@hidden m18> gcc -g3 x.c
address@hidden m18> gdb a.out 
GNU gdb 5.0
Copyright 2000 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 "mips-sgi-irix6.2"...
(gdb) list
1       #include <unistd.h>
2
3       int main(void) {
4         int i;
5         for(i=0; i<1000; i++) /*EMPTY*/;
6         for(i=1; i!=0; i++) /*EMPTY*/;
7         return 0;
8       }
9
10      int set_alarm(int secs) {
(gdb) break 5
Breakpoint 1 at 0x10000fbc: file x.c, line 5.
(gdb) break 6
Breakpoint 2 at 0x10000ff0: file x.c, line 6.
(gdb) r
Starting program: /home/siirto/tronkko/m18/a.out 

Breakpoint 1, main () at x.c:5
5         for(i=0; i<1000; i++) /*EMPTY*/;
(gdb) print set_alarm(30)
$1 = 1
(gdb) c
Continuing.

Breakpoint 2, main () at x.c:6
6         for(i=1; i!=0; i++) /*EMPTY*/;
(gdb) print set_alarm(30)
$2 = 1
(gdb) c
Continuing.

Program terminated with signal SIGALRM, Alarm clock.
The program no longer exists.
(gdb) 


Function `set_alarm' is the modification I talked about.  It makes
a timer to go off after number of seconds and when the timer goes off
the program will be killed.  If the program hits another breakpoint,
just re-set or clear the timer to continue.  (Timer runs despite of
the program being stopped.)  If you cannot make the modification to
the source then perhaps you could place the `set_alarm' function to a
shared library and use it from there.  Alternatively, you could use
`alarm' function as is or build a special version of GDB that
implements it as a native command.

Toni



reply via email to

[Prev in Thread] Current Thread [Next in Thread]