Re: gdb stops in a command file if there is an error. How to continue executing the command file? (643 Views)
Reply
Regular Advisor
blackwater
Posts: 129
Registered: ‎05-14-2009
Message 1 of 5 (651 Views)
Accepted Solution

gdb stops in a command file if there is an error. How to continue executing the command file?

[ Edited ]

In my real gdb script while analyzing a core file I try to dereference a pointer and get "Error in sourced command file: Cannot access memory at address " and then my gdb script stops. What I want is just to go on executing my gdb script without stopping. Is it possible?

This is a test program and a test gdb script that demonstrates my problem. In this situation the pointer has NULL value but in a real situation the pointer will like have not null invalid value.

 

This is test C program:

#include <stdio.h>
struct my_struct {
  int v1;
  int v2;
};

int main()
{
  my_struct *p;
  printf("%d %d\n", p->v1, p->v2);
  return 0;
}

This is a test gdb script:

 

>cat analyze.gdb
p p->v1
q

 

And this is demonstration of the problem (what I want from gdb here is to get this error message and then go processing quit command):

 

>gdb ./a.out ./core.25847 -x ./analyze.gdb
HP gdb 6.1 for HP Itanium (32 or 64 bit) and target HP-UX 11iv2 and 11iv3.
Copyright 1986 - 2009 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 6.1 (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for warranty/support.
..
Core was generated by `a.out'.
Program terminated with signal 11, Segmentation fault.
SEGV_ACCERR - Invalid Permissions for object
#0  0x4000000000000d60:1 in main () at main.cpp:11
11        printf("%d %d\n", p->v1, p->v2);
./analyze.gdb:1: Error in sourced command file:
Cannot access memory at address 0x0
(gdb)

 

 

 

 

P.S. This thread has been moved from HP-UX > General > to HP-UX > languages. -Hp forum moderator

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 2 of 5 (643 Views)

Re: gdb stops in a command file if there is an error. How to continue executing the command file?

[ Edited ]

I'm not sure if there is a variable that will allow it to continue.  Did you look at the list of them?

 

I didn't see any obvious variable or command line option.

Please use plain text.
Regular Advisor
blackwater
Posts: 129
Registered: ‎05-14-2009
Message 3 of 5 (608 Views)

Re: gdb stops in a command file if there is an error. How to continue executing the command file?

[ Edited ]

Just to note. GNU gdb on Linux can handle this type of errors in a simple Python script. Hope it would be possible with HP wdb also in future.

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,888
Registered: ‎03-06-2006
Message 4 of 5 (600 Views)

Re: gdb stops in a command file if there is an error. How to continue executing the command file?

>GNU gdb on Linux can handle this type of errors

 

Is there a particular option or variable setting to enable this?

I.e. if they implement this in WDB, they should match.

Please use plain text.
Regular Advisor
blackwater
Posts: 129
Registered: ‎05-14-2009
Message 5 of 5 (598 Views)

Re: gdb stops in a command file if there is an error. How to continue executing the command file?

[ Edited ]

I found a way to handle the error with python. Look for ignore_errors.py.

In a simplified way it looks like:

 

>cat ./analyze.v2.gdb
python
def my_ignore_errors(arg):
  try:
    gdb.execute("print \"" + "Executing: " + arg + "\"")
    gdb.execute (arg)
  except:
    gdb.execute("print \"" + "ERROR: " + arg + "\"")
    pass

my_ignore_errors("p p")
my_ignore_errors("p p->v1")
gdb.execute("quit")

And then:

 

gdb -silent ./a.out -x ./analyze.v2.gdb -c ./core.1090

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation