title: How to get a stack trace for C++ using gcc with line number information?
body: <p>We use stack traces in proprietary <code>assert</code> like macro to catch developer mistakes - when error is caught, stack trace is printed.</p>
  
  <p>I find gcc's pair <code>backtrace()</code>/<code>backtrace_symbols()</code> methods insufficient:</p>
  
  <ol>
  <li>Names are mangled</li>
  <li>No line information</li>
  </ol>
  
  <p>1st problem can be resolved by <a href="http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html" rel="noreferrer">abi::__cxa_demangle</a>.</p>
  
  <p>However 2nd problem s more tough. I found <a href="http://cairo.sourcearchive.com/documentation/1.9.4/backtrace-symbols_8c-source.html" rel="noreferrer">replacement for backtrace_symbols()</a>. 
  This is better than gcc's backtrace_symbols(), since it can retrieve line numbers (if compiled with -g) and you don't need to compile with -rdynamic.</p>
  
  <p>Hoverer the code is GNU licenced, so IMHO I can't use it in commercial code.</p>
  
  <p>Any proposal?</p>
  
  <p><strong>P.S.</strong></p>
  
  <p>gdb is capable to print out arguments passed to functions. 
       Probably it's already too much to ask for :)</p>
  
  <p><strong>PS 2</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes">Similar question</a> (thanks nobar)</p>