#!/usr/bin/env bash

gdb third_party/glog/stacktrace_gen <<EOF

run
backtrace
frame 7

python
print()

sym = gdb.selected_frame().find_sal()

if sym is None:
  print("Unable to find symbol table for stack")
  sys.exit(1)

if sym.symtab.filename != 'third_party/glog/stacktrace_gen.cpp':
  print("Backtrace was not in correct file")
  sys.exit(1)
else:
  print("Backtrace file correct")

if sym.line != 5:
  print("Backtrace was not at correct line")
  sys.exit(1)
else:
  print("Backtrace line correct")

end

run foo
backtrace
frame 7

python
print()

sym = gdb.selected_frame().find_sal()

if sym is None:
  print("Unable to find symbol table for stack")
  sys.exit(1)

if sym.symtab.filename != 'third_party/glog/stacktrace_gen.cpp':
  print("Backtrace was not in correct file")
  sys.exit(1)
else:
  print("Backtrace file correct")

if sym.line != 8:
  print("Backtrace was not at correct line")
  sys.exit(1)
else:
  print("Backtrace line correct")

end
quit
EOF


