How to read matlab stack trace

jgillis edited this page Mar 30, 2018 · 4 revisions
0x00007f4c2f0059f5 /home/jgillis/meco-group/cpp_splines/buildmatlab/swig/../src/ _ZNK6spline8Function9fast_evalERK9AnyTensor+00002691

Convert to hex: 01149429 -> 0x1189F5

addr2line -p -C -f -e src/ 0x1189F5
spline::Function::fast_eval(AnyTensor const&) const at /home/jgillis/meco-group/cpp_splines/src/Function/Function.cpp:307 (discriminator 4)

The crashing instance and library must be the same (also both Debug mode or RelWithDebInfo mode!)

import sys
import subprocess
import os
import glob

if len(sys.argv)==1:
  crash_dumps = glob.glob(os.path.expanduser('~/matlab_crash_dump.*'))
  filename = max(crash_dumps, key=os.path.getctime)
  filename = sys.argv[1]

print("Translation of %s" % filename)

context = 5

with open(filename,'r') as f:
  for line in f:
    if line.startswith('['):
      parts = line.rstrip().split()
      if parts[0]=="[" and parts[1].endswith("]"):
        [lib_name, lib_pos] = parts[3].split("+")

        lib_pos_hex = "0x%X" % int(lib_pos)
        source_line = None
        source_file = None
        new_parts = parts[:2]
        if os.path.exists(lib_name):
          out = subprocess.check_output(["addr2line","-p","-C","-f","-e",lib_name,lib_pos_hex])
            source_line = int(out.split(":")[-1])
          if " at " in out:
            source_file = out[out.rindex(" at ")+4:-len(str(source_line))-2]
          new_parts+= parts[3:]

        print(" ".join(new_parts))

        if os.path.exists(source_file):
          with open(source_file,'r') as sf:
            for i,line in enumerate(sf):
              if i<source_line-context: continue
              if i>source_line+context: break

              print_line = str(i)
              print_line+= "*" if source_line==i else " "
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.