title: gdb stops in a command file if there is an error. How to continue despite the error?
body: <p>I 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?</p>
  
  <p>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.</p>
  
  <p>This is test C program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  struct my_struct {
    int v1;
    int v2;
  };
  
  int main()
  {
    my_struct *p;
    printf("%d %d\n", p-&gt;v1, p-&gt;v2);
    return 0;
  }
  </code></pre>
  
  <p>This is a test gdb script:</p>
  
  <pre><code>&gt;cat analyze.gdb
  p p-&gt;v1
  q
  </code></pre>
  
  <p>And this is demonstration of the problem (what I want from gdb here is to get this error message and then go process <code>quit</code> command):</p>
  
  <pre><code>&gt;gdb -silent a.out ./core.22384 -x ./analyze.gdb
  Reading symbols from /a.out...done.
  [New Thread 22384]
  Core was generated by `./a.out'.
  Program terminated with signal 11, Segmentation fault.
  #0  0x0000000000400598 in main () at main.cpp:11
  11        printf("%d %d\n", p-&gt;v1, p-&gt;v2);
  ./analyze.gdb:1: Error in sourced command file:
  Cannot access memory at address 0x0
  Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.el6.x86_64
  </code></pre>
  
  <p><hr/>
  <strong>Update<br/></strong>
  Thanks to Tom. This is a gdb script that handles this problem:</p>
  
  <pre><code>&gt;cat ./analyze.v2.gdb
  python
  def my_ignore_errors(arg):
    try:
      gdb.execute("print \"" + "Executing command: " + arg + "\"")
      gdb.execute (arg)
    except:
      gdb.execute("print \"" + "ERROR: " + arg + "\"")
      pass
  
  my_ignore_errors("p p")
  my_ignore_errors("p p-&gt;v1")
  gdb.execute("quit")
  </code></pre>
  
  <p>This is how it works:</p>
  
  <pre><code>&gt;gdb -silent ./a.out -x ./analyze.v2.gdb -c ./core.15045
  Reading symbols from /import/home/a.out...done.
  [New Thread 15045]
  Core was generated by `./a.out'.
  Program terminated with signal 11, Segmentation fault.
  #0  0x0000000000400598 in main () at main.cpp:11
  11        printf("%d %d\n", p-&gt;v1, p-&gt;v2);
  $1 = "Executing command: p p"
  $2 = (my_struct *) 0x0
  $3 = "Executing command: p p-&gt;v1"
  $4 = "ERROR: p p-&gt;v1"
  $5 = "Executing command: quit"
  </code></pre>