Repository navigation
Expand file tree
/
Copy pathdebug.lua
More file actions
116 lines (99 loc) · 3.35 KB
/
Copy pathdebug.lua
File metadata and controls
116 lines (99 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env lua
-- -*- lua -*-
-- Copyright 2012 Appwill Inc.
-- Author : KDr2
--
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
module('mch.debug',package.seeall)
local mchutil = require('mch.util')
local front = require('mch.front')
local mchvars = require('mch.vars')
local functional = require('mch.functional')
local debug_getinfo = debug.getinfo
local string_format = string.format
function traceback ()
for level = 1, math.huge do
local info = debug_getinfo(level, "Sl")
if not info then break end
if info.what == "C" then -- is a C function?
print(level, "C function")
else -- a Lua function
print(string_format("[%s]:%d", info.short_src,
info.currentline))
end
end
end
function debug_utils()
local debug_info={info={}}
function _debug_hook(event, extra)
local info = debug_getinfo(2)
if info.currentline<=0 then return end
--if (string.find(info.short_src,"moochine/luasrc") or
--string.find(info.short_src,"moochine/lualib")) then
--return
--end
info.event=event
table.insert(debug_info.info,info)
end
function _debug_clear()
debug_info.info={}
end
function _debug_info()
return debug_info
end
return _debug_hook, _debug_clear, _debug_info
end
debug_hook, debug_clear, debug_info = debug_utils()
function debug_info2html()
local ret = front.DEBUG_INFO_CSS .. [==[
<div id="moochine-table-of-contents">
<h2>DEBUG INFO </h2>
<div id="moochine-text-table-of-contents"><ul>
]==]
for _, info in ipairs(debug_info().info) do
local estr= "unkown event"
if info.event=="call" then
estr = " -> "
elseif info.event=="return" then
estr = " <- "
end
local sinfo=(string_format("<li>%s [function %s] in file [%s]:%d,</li>\r\n",
estr,
tostring(info.name),
info.short_src,
info.currentline))
ret = ret .. sinfo
end
return ret .. "</ul></div></div>"
end
function debug_info2text()
local ret = "DEBUG INFO:\n"
for _, info in ipairs(debug_info().info) do
local estr = "unkown event"
if info.event=="call" then
estr = " -> "
elseif info.event=="return" then
estr = " <- "
end
local sinfo=(string_format("%s [function %s] in file [%s]:%d,\n",
estr,
tostring(info.name),
info.short_src,
info.currentline))
ret = ret .. sinfo
end
return ret
end