GDB backtrace

  • From: Thiago Padilha <tpadilha84@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 23 Jan 2015 08:34:16 -0300

Hi

Every once in a while I need to debug a hanged lua program, and the
following gdb function to see lua backtrace(have it defined in
.gdbinit) is incredibly helpful:

define lua-bt
  set $p = L->ci
  while ($p > L->base_ci )
    if ( $p->func->value.gc->cl.c.isC == 1 )
      printf "0x%x   C FUNCTION ", $p
      output $p->func->value.gc->cl.c.f
      printf "\n"
    else
      if ($p->func.tt==6)
        set $proto = $p->func->value.gc->cl.l.p
        set $filename = (char*)(&($proto->source->tsv) + 1)
        set $lineno = $proto->lineinfo[ $p->savedpc - $proto->code -1 ]
        printf "0x%x LUA FUNCTION : %d %s\n", $p, $lineno, $filename
      else
        printf "0x%x LUA BASE\n", $p
      end
    end
    set $p = $p - 1
  end
end

I can call this function in any frame that has the lua state bound to `L`.

Does someone know how I could adapt that function for luajit?

Other related posts: