[sr-dev] git:master:491a8327: misc/examples: kemi lua - added debug callback function

Daniel-Constantin Mierla miconda at gmail.com
Tue Jul 14 09:22:41 CEST 2020


Module: kamailio
Branch: master
Commit: 491a8327933cb4471260fdd09ff93296a7a0ccfd
URL: https://github.com/kamailio/kamailio/commit/491a8327933cb4471260fdd09ff93296a7a0ccfd

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-07-14T09:22:12+02:00

misc/examples: kemi lua - added debug callback function

- commented - can be enabled to track the execution trace of the lua
script

---

Modified: misc/examples/kemi/kamailio-basic-kemi-lua.lua

---

Diff:  https://github.com/kamailio/kamailio/commit/491a8327933cb4471260fdd09ff93296a7a0ccfd.diff
Patch: https://github.com/kamailio/kamailio/commit/491a8327933cb4471260fdd09ff93296a7a0ccfd.patch

---

diff --git a/misc/examples/kemi/kamailio-basic-kemi-lua.lua b/misc/examples/kemi/kamailio-basic-kemi-lua.lua
index f5906d0bde..a896529965 100644
--- a/misc/examples/kemi/kamailio-basic-kemi-lua.lua
+++ b/misc/examples/kemi/kamailio-basic-kemi-lua.lua
@@ -12,6 +12,43 @@
 --  the execution of the script. Use KSR.x.exit() after it or KSR.x.drop()
 --
 
+-- debug callback function to print details of execution trace
+--[[
+local ksr_exec_level=0
+
+local function ksr_exec_hook(event)
+	local s = "";
+	local t = debug.getinfo(3)
+	s = s .. ksr_exec_level .. ">>> " .. string.rep(" ", ksr_exec_level);
+	if t~=nil and t.currentline>=0 then
+		s = s .. t.short_src .. ":" .. t.currentline .. " ";
+	end
+	t=debug.getinfo(2)
+	if event=="call" then
+		ksr_exec_level = ksr_exec_level + 1;
+	else
+		ksr_exec_level = ksr_exec_level - 1;
+		if ksr_exec_level < 0 then
+			ksr_exec_level = 0;
+		end
+	end
+	if t.what=="main" then
+		if event=="call" then
+			s = s .. "begin " .. t.short_src;
+		else
+			s = s .. "end " .. t.short_src;
+		end
+	elseif t.what=="Lua" then
+		s = s .. event .. " " .. t.name or "(Lua)" .. " <" .. t.linedefined .. ":" .. t.short_src .. ">";
+	else
+		s = s .. event .. " " .. t.name or "(C)" .. " [" .. t.what .. "] ";
+	end
+	KSR.info(s .. "\n");
+end
+
+debug.sethook(ksr_exec_hook, "cr")
+ksr_exec_level=0
+]]--
 
 -- global variables corresponding to defined values (e.g., flags) in kamailio.cfg
 FLT_ACC=1




More information about the sr-dev mailing list