title: How can I get info on run time errors for Python modules built with f2py
body: <p><strong>Edit 3/6:  Sorry, this was a false alarm.  It seems to be working now.  I believe the <code>-g</code> flag on gfortran and <code>--debug-capi</code> are sufficient after all to generate line numbers for GDB (gnu debugger).  I will make a short answer summarizing how to do this in case it is helpful for others (was a bit of a learning experience for me).  But please feel free to post additional answers that improve on this.  In particular I would be interested in being able to get line numbers without using GDB, if that's possible.</strong></p>
  
  <p>This must be a common problem but I can't find any answers. The error is in in the Fortran library (what I call <code>f2.f90</code> below), but it's a runtime error that isn't triggered until I am using the code via Python.</p>
  
  <p>To make it a little more explicit:</p>
  
  <ol>
  <li><p>I compile several files with <code>gfortran</code>:</p>
  
  <pre><code>gfortran -c f1.f90 f2.f90
  </code></pre></li>
  <li><p>I generate a module with <code>f2py</code>:</p>
  
  <pre><code>f2py -c f1.o f2.o -m main main.f90
  </code></pre></li>
  <li><p>In python:</p>
  
  <pre><code>import main
  </code></pre></li>
  <li><p>In python, call subroutine main, inside of main:</p>
  
  <pre><code>main.main()
  </code></pre></li>
  </ol>
  
  <p>I can get this to work successfully but when I play around with <code>f2.f90</code> I will often have some error, and when that happens it's in step 4 and will crash python and only give me the option to close it.  Unfortunately I get no information about what line in <code>f2.f90</code> caused the problem or any other info.</p>
  
  <p>So, pretty simple question, is there a way I can cause step 4 to give me some basic info about the run time crash?  Mainly the line number of the problem.</p>
  
  <p>I've tried adding <code>-g -fbacktrace</code> to gfortran call and <code>--debug-capi</code> to <code>f2py</code> and then using <code>gdb python</code> with backtrace.  This looks somewhat promising as it at least tells me that the offending file is <code>f2.f90</code>, but not the line number.  If I try "backtrace full" it will tell me <code>No symbol table info available</code> which is probably where the line number info is held?</p>