-- This function always succeeds or aborts.
function e2lib.init()
e2lib.log(4, "e2lib.init()")
- debug.sethook(e2lib.tracer, "cr")
+ -- DEBUG: change to "cr" to log return from function
+ debug.sethook(e2lib.tracer, "c")
e2lib.globals.warn_category = {
WDEFAULT = false,
end
end
-local tracer_bl_lua_fn = {
- ["xpcall"] = 0,
- ["tostring"] = 0,
- ["print"] = 0,
- ["unpack"] = 0,
- ["require"] = 0,
- ["getfenv"] = 0,
- ["setmetatable"] = 0,
- ["next"] = 0,
- ["assert"] = 0,
- ["tonumber"] = 0,
- ["rawequal"] = 0,
- ["collectgarbage"] = 0,
- ["getmetatable"] = 0,
- ["module"] = 0,
- ["rawset"] = 0,
- ["pcall"] = 0,
- ["newproxy"] = 0,
- ["type"] = 0,
- ["select"] = 0,
- ["gcinfo"] = 0,
- ["pairs"] = 0,
- ["rawget"] = 0,
- ["loadstring"] = 0,
- ["ipairs"] = 0,
- ["dofile"] = 0,
- ["setfenv"] = 0,
- ["load"] = 0,
- ["error"] = 0,
- ["loadfile"] = 0,
- ["sub"] = 0,
- ["upper"] = 0,
- ["len"] = 0,
- ["gfind"] = 0,
- ["rep"] = 0,
- ["find"] = 0,
- ["match"] = 0,
- ["char"] = 0,
- ["dump"] = 0,
- ["gmatch"] = 0,
- ["reverse"] = 0,
- ["byte"] = 0,
- ["format"] = 0,
- ["gsub"] = 0,
- ["lower"] = 0,
- ["setn"] = 0,
- ["insert"] = 0,
- ["getn"] = 0,
- ["foreachi"] = 0,
- ["maxn"] = 0,
- ["foreach"] = 0,
- ["concat"] = 0,
- ["sort"] = 0,
- ["remove"] = 0,
- ["lines"] = 0,
- ["write"] = 0,
- ["close"] = 0,
- ["flush"] = 0,
- ["open"] = 0,
- ["output"] = 0,
- ["type"] = 0,
- ["read"] = 0,
- ["input"] = 0,
- ["popen"] = 0,
- ["tmpfile"] = 0,
-}
-
-local tracer_bl_e2_fn = {
- -- logging stuff
- ["log"] = 0,
- ["logf"] = 0,
- ["getlog"] = 0,
- ["warn"] = 0,
- ["warnf"] = 0,
-
- -- error handling
- ["new_error"] = 0,
- ["append"] = 0,
- ["getcount"] = 0,
-
- -- lua internals
- ["(for generator)"] = 0,
-}
-
--- function call tracer
-- @param event string: type of event
-- @param line line number of event (unused)
function e2lib.tracer(event, line)
- if event ~= "call" and event ~= "return" then
- return
- end
-
local ftbl = debug.getinfo(2)
if ftbl == nil or ftbl.name == nil then
return
end
- if tracer_bl_lua_fn[ftbl.name] ~= nil then
- return
- end
-
- if tracer_bl_e2_fn[ftbl.name] ~= nil then
- return
- end
-
-- approximate module name, not always accurate but good enough
local module
if ftbl.source == nil or ftbl.source == "=[C]" then
module = "C."
+ -- DEBUG: comment this to see all C calls.
+ return
else
module = string.match(ftbl.source, "(%w+%.)lua$")
if module == nil then
module = "<unknown module>."
+ -- DEBUG: comment this to see all unknown calls.
+ return
end
end
end
if type(value) == "string" then
- local svalue = string.sub(value, 0, 800)
- if string.len(value) > string.len(svalue) then
- svalue = svalue .. "..."
+ local isbinary = false
+
+ -- check the first 40 bytes for values common in binary data
+ for _,v in ipairs({string.byte(value, 1, 41)}) do
+ if (v >= 0 and v < 9) or (v > 13 and v < 32) then
+ isbinary = true
+ break
+ end
end
- out = string.format("%s%s=\"%s\"", out, name, svalue)
+ if isbinary then
+ out = string.format("%s%s=<binary data>", out, name)
+ else
+ local svalue = string.sub(value, 0, 800)
+ if string.len(value) > string.len(svalue) then
+ svalue = svalue .. "..."
+ end
+
+ out = string.format("%s%s=\"%s\"", out, name, svalue)
+ end
else
out = string.format("%s%s=%s", out, name, tostring(value))
end