Skip to content

Commit

Permalink
Added -S argument for better stack traces.
Browse files Browse the repository at this point in the history
Uses StackTracePlus: https://github.com/ignacio/StackTracePlus

New look with -S:

    $ sudo ./snabb -S -e 'assert(nil)'
    [string "assert(nil)"]:1: assertion failed!
    line not found

    Stack Traceback
    ===============
    (1) Lua function 'handler' at file 'core/main.lua:137' (best guess)
	    Local variables:
	     reason = string: "[string \"assert(nil)\"]:1: assertion failed!"
	     (*temporary) = C function: print
    (2) global C function 'assert'
    (3) main chunk of [string "assert(nil)"] at line 1
    (4) Lua function 'main' at file 'core/main.lua:66' (best guess)
	    Local variables:
	     args = table: 0x53587ff0  {1:-S, 2:-e, 3:assert(nil)}
	     i = number: 2
	     thunk = Lua function '?' (defined at line 0 of chunk "assert(nil)"])
	     error = nil
    (5) global C function 'xpcall'
    (6) main chunk of file 'core/main.lua' at line 142
    (7) global C function 'require'
    (8) main chunk of [string "require "core.main""] at line 1
	    nil

Old look:

    $ sudo ./snabb -e 'assert(nil)'
    [string "assert(nil)"]:1: assertion failed!
    stack traceback:
	    core/main.lua:137: in function <core/main.lua:135>
	    [C]: in function 'assert'
	    [string "assert(nil)"]:1: in function 'thunk'
	    core/main.lua:66: in function <core/main.lua:44>
	    [C]: in function 'xpcall'
	    core/main.lua:142: in main chunk
	    [C]: in function 'require'
	    [string "require "core.main""]:1: in main chunk
  • Loading branch information
lukego committed Apr 30, 2014
1 parent 7fb42fb commit de02db6
Show file tree
Hide file tree
Showing 2 changed files with 416 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module(...,package.seeall)
-- (Can be overridden with -P argument: see below.)
package.path = ''

local STP = require("lib.lua.StackTracePlus")
local ffi = require("ffi")
local zone = require("jit.zone")
local C = ffi.C
Expand All @@ -28,6 +29,7 @@ Available options are:
-l name Require library 'name'.
-t name Test module 'name' with selftest().
-d Debug unhandled errors with the Lua interactive debugger.
-S Print enhanced stack traces with more debug information.
-jdump file Trace JIT decisions to 'file'. (Requires LuaJIT jit.* library.)
-jp Profile with the LuaJIT statistical profiler.
-jp=args[,.output]
Expand Down Expand Up @@ -66,6 +68,9 @@ function main ()
elseif args[i] == '-d' then
debug_on_error = true
i = i + 1
elseif args[i] == '-S' then
debug.traceback = STP.stacktrace
i = i + 1
elseif (args[i]):match("-jp") then
local pargs, poutput = (args[i]):gmatch("-jp=(%w*),?(.*)")()
if poutput == '' then poutput = nil end
Expand Down

0 comments on commit de02db6

Please sign in to comment.