Operating System - HP-UX
1748259 Members
3482 Online
108760 Solutions
New Discussion

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

 
SOLVED
Go to solution
blackwater
Regular Advisor

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

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

4 REPLIES 4
Dennis Handly
Acclaimed Contributor
Solution

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

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.

blackwater
Regular Advisor

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

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.

Dennis Handly
Acclaimed Contributor

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.

blackwater
Regular Advisor

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

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