README 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. debugger Module
  2. Daniel-Constantin Mierla
  3. asipto.com
  4. Edited by
  5. Daniel-Constantin Mierla
  6. <[email protected]>
  7. Copyright © 2010 Daniel-Constantin Mierla (asipto.com)
  8. __________________________________________________________________
  9. Table of Contents
  10. 1. Admin Guide
  11. 1. Overview
  12. 2. Dependencies
  13. 2.1. Kamailio Modules
  14. 2.2. External Libraries or Applications
  15. 3. Exported Parameters
  16. 3.1. cfgtrace (int)
  17. 3.2. breakpoint (int)
  18. 3.3. log_level (int)
  19. 3.4. log_facility (str)
  20. 3.5. log_prefix (str)
  21. 3.6. step_usleep (int)
  22. 3.7. step_loops (int)
  23. 4. Exported Functions
  24. 4.1. dbg_breakpoint(mode)
  25. 5. Exported RPC Functions
  26. 5.1. dbg.ls
  27. 5.2. dbg.trace
  28. 5.3. dbg.bp
  29. 6. Usage
  30. List of Examples
  31. 1.1. Set cfgtrace parameter
  32. 1.2. Set breakpoint parameter
  33. 1.3. Set log_level parameter
  34. 1.4. Set log_facility parameter
  35. 1.5. Set log_prefix parameter
  36. 1.6. Set step_usleep parameter
  37. 1.7. Set step_loops parameter
  38. 1.8. dbg_breakpoint usage
  39. Chapter 1. Admin Guide
  40. Table of Contents
  41. 1. Overview
  42. 2. Dependencies
  43. 2.1. Kamailio Modules
  44. 2.2. External Libraries or Applications
  45. 3. Exported Parameters
  46. 3.1. cfgtrace (int)
  47. 3.2. breakpoint (int)
  48. 3.3. log_level (int)
  49. 3.4. log_facility (str)
  50. 3.5. log_prefix (str)
  51. 3.6. step_usleep (int)
  52. 3.7. step_loops (int)
  53. 4. Exported Functions
  54. 4.1. dbg_breakpoint(mode)
  55. 5. Exported RPC Functions
  56. 5.1. dbg.ls
  57. 5.2. dbg.trace
  58. 5.3. dbg.bp
  59. 6. Usage
  60. 1. Overview
  61. This module provides an interactive config file debugger. It can print
  62. a trace of config execution for a SIP message to log and set
  63. breakpoints on every config action, allowing step-by-step execution of
  64. the config.
  65. Debugging can be done from local or remote host via RPC interface
  66. (e.g., XMLRPC, sercmd, siremis).
  67. The framework to set breakpoints on specific actions and config lines
  68. is not exported to RPC yet. Each action can be accompanied by an
  69. breakpoint or you can use dbg_breakpoint() function to set a breakpoint
  70. at certain line. Global breakpoint can be enabled/disabled at runtime.
  71. Also the config running trace can be enabled/disabled at runtime.
  72. When the SIP router process is stopped at a breakpoint, you can
  73. investigate the values of any pseudo-variables. Note that some of
  74. pseudo-variables may produce memory leaks; a fix is planned in the
  75. future (here fall pseudo-variables with dynamic name such as htable,
  76. sqlops). References to SIP message, avps, headers, script and shared
  77. variables are safe.
  78. 2. Dependencies
  79. 2.1. Kamailio Modules
  80. 2.2. External Libraries or Applications
  81. 2.1. Kamailio Modules
  82. The following modules must be loaded before this module:
  83. * none.
  84. 2.2. External Libraries or Applications
  85. The following libraries or applications must be installed before
  86. running Kamailio with this module loaded:
  87. * None.
  88. 3. Exported Parameters
  89. 3.1. cfgtrace (int)
  90. 3.2. breakpoint (int)
  91. 3.3. log_level (int)
  92. 3.4. log_facility (str)
  93. 3.5. log_prefix (str)
  94. 3.6. step_usleep (int)
  95. 3.7. step_loops (int)
  96. 3.1. cfgtrace (int)
  97. Control whether config running trace is enabled or disabled at startup.
  98. You can change the value at runtime without restart, globally or per
  99. process.
  100. Default value is “0” (disabled).
  101. Example 1.1. Set cfgtrace parameter
  102. ...
  103. modparam("debugger", "cfgtrace", 1)
  104. ...
  105. 3.2. breakpoint (int)
  106. Control whether every line (global) breakpoint is enabled or disabled
  107. at startup.
  108. Default value is “0” (disabled).
  109. Example 1.2. Set breakpoint parameter
  110. ...
  111. modparam("debugger", "breakpoint", 1)
  112. ...
  113. 3.3. log_level (int)
  114. What log level is to be used to print module-specific messages.
  115. Default value is “-1” (L_ERR).
  116. Example 1.3. Set log_level parameter
  117. ...
  118. modparam("debugger", "log_level", 1)
  119. ...
  120. 3.4. log_facility (str)
  121. What log facility is to be used to print module-specific messages.
  122. Default value is “NULL” (default from core).
  123. Example 1.4. Set log_facility parameter
  124. ...
  125. modparam("debugger", "log_facility", "LOG_DAEMON")
  126. ...
  127. 3.5. log_prefix (str)
  128. String to print before any module-specific messages.
  129. Default value is “*** cfgtrace:”.
  130. Example 1.5. Set log_prefix parameter
  131. ...
  132. modparam("debugger", "log_prefix", "from-debugger-with-love:")
  133. ...
  134. 3.6. step_usleep (int)
  135. Microseconds to sleep before checking for new commands when waiting at
  136. breakpoint.
  137. Default value is “100000” (that is 0.1 sec).
  138. Example 1.6. Set step_usleep parameter
  139. ...
  140. modparam("debugger", "step_usleep", 500000)
  141. ...
  142. 3.7. step_loops (int)
  143. How many sleeps of 'step_usleep' the RPC process performs when waiting
  144. for a reply from worker process before responding to RPC. This avoids
  145. blocking RPC process forever in case the worker process 'forgets' to
  146. write back a reply.
  147. Default value is “200”.
  148. Example 1.7. Set step_loops parameter
  149. ...
  150. modparam("debugger", "step_loops", 100)
  151. ...
  152. 4. Exported Functions
  153. 4.1. dbg_breakpoint(mode)
  154. 4.1. dbg_breakpoint(mode)
  155. Anchor a breakpoint at the current line of the config (the one on which
  156. this function is called). The 'mode' specifies whether the breakpoint
  157. is enabled (1) or disabled (0) at startup.
  158. Note that this version does not export this anchors to RPC for
  159. interactive debugging (temporarily disabled).
  160. Example 1.8. dbg_breakpoint usage
  161. ...
  162. if($si=="10.0.0.10")
  163. dbg_breakpoint("1");
  164. ...
  165. 5. Exported RPC Functions
  166. 5.1. dbg.ls
  167. 5.2. dbg.trace
  168. 5.3. dbg.bp
  169. 5.1. dbg.ls
  170. List SIP router processes with info related to interactive debugging.
  171. Name: dbg.list
  172. Parameters:
  173. * _pid_ : pid for which to list the details. If 'pid' is omitted then
  174. will print for all processes.
  175. Examples of use with sercmd:
  176. dbg.ls
  177. dbg.ls 1234
  178. 5.2. dbg.trace
  179. Control config running trace.
  180. Name: dbg.trace
  181. Parameters:
  182. * _cmd_ : inner command can be 'on' or 'off' to enable or disable
  183. tracing for one or all processes.
  184. * _pid_ : pid for which to list the details. If 'pid' is omitted,
  185. then it will print details for all processes.
  186. Examples for using with sercmd:
  187. dbg.trace on
  188. dbg.trace off
  189. dbg.trace on 1234
  190. 5.3. dbg.bp
  191. Control breakpoints and config execution.
  192. Name: dbg.bp
  193. Parameters:
  194. * _cmd_ : inner command, see next section for the list of available
  195. values.
  196. * _pid_ : pid for which to apply the inner command. If 'pid' is
  197. omitted, then the inner command will be applied to all processes.
  198. * _params_ : extra params specific for each inner command.
  199. Inner commands:
  200. * on - turn on breakpoints. Pid parameter is optional.
  201. * off - turn off breakpoints. Pid parameter is optional.
  202. * keep - keep breakpoints only for pid given as parameter
  203. * release - disable breakpoints for processes that are not waiting at
  204. a breakpoint. Pid parameter is optional.
  205. * next - run the action under breakpoint and stop at next one (step
  206. by step execution). Pid parameter is mandatory.
  207. * move - run the action under breakpoint and remove the rest of
  208. breakpoints (continue execution without stopping again at next
  209. actions). Pid parameter is mandatory.
  210. * show - print details about the current breakpoint for pid. Pid
  211. parameter is mandatory.
  212. * eval - eval a pseudo-variable and print the result in RPC Pid
  213. parameter is mandatory.
  214. * log - eval a pseudo-variable and print the result in SIP router
  215. logs. Pid parameter is mandatory.
  216. Examples for using with sercmd:
  217. dbg.bp off
  218. dbg.bp on
  219. dbg.bp release
  220. dbg.bp on 1234
  221. dbg.bp eval 1234 $fu
  222. dbg.bp move 1234
  223. 6. Usage
  224. A common usage is to investigate the execution path for a specific SIP
  225. message. Just enable cfg running trace, send the message and watch the
  226. logs.
  227. Another typical usage is to do interactive debugging and run each line
  228. of the route blocks of the config file step-by-step for a particular
  229. SIP message.
  230. You need to connect using sercmd (or other RPC client) to SIP Router.
  231. Then you can enable cfg breakpoints and send the SIP message. One
  232. process will be in waiting state ('state' field different than 0 when
  233. you do dbg.ls). Calling dbg.release will set the other SIP router
  234. processes in no-breakpoint mode so they can process other SIP messages
  235. without need to interact with them.
  236. The process blocked at breakpoint is waiting for a command. Use 'dbg.bp
  237. next pid' to execute the current action and stop at the next one.
  238. 'dbg.bp eval pid PV' can be used to retrive the value of PV. Once you
  239. are done and want to continue the execution of the config wihtout
  240. interaction use 'dbg.bp move pid'.
  241. Here is an example of session:
  242. ...
  243. sercmd> dbg.ls
  244. {
  245. entry: 0
  246. pid: 6393
  247. set: 3
  248. state: 0
  249. in.pid: 0
  250. in.cmd: 0
  251. }
  252. {
  253. entry: 1
  254. pid: 6394
  255. set: 3
  256. state: 0
  257. in.pid: 0
  258. in.cmd: 0
  259. }
  260. ...
  261. {
  262. entry: 9
  263. pid: 6402
  264. set: 3
  265. state: 1
  266. in.pid: 0
  267. in.cmd: 0
  268. }
  269. sercmd> dbg.bp show 6402
  270. at bkp [/etc/kamailio/debugger.cfg:369] a=6 n=route
  271. sercmd> dbg.bp next 6402
  272. exec [/etc/kamailio/debugger.cfg:369] a=6 n=route
  273. sercmd> dbg.bp next 6402
  274. exec [/etc/kamailio/debugger.cfg:462] a=17 n=if
  275. sercmd> dbg.bp eval 6402 $fu
  276. $fu : t=str v=sip:[email protected]
  277. sercmd> dbg.bp move 6402
  278. 200 ok
  279. ...
  280. Running the config trace looks like:
  281. ...
  282. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=368 a=6 n=route
  283. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=461 a=17 n=if
  284. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=456 a=26 n=mf_pro
  285. cess_maxfwd_header
  286. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=466 a=17 n=if
  287. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=461 a=27 n=sanity
  288. _check
  289. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=371 a=6 n=route
  290. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=659 a=3 n=return
  291. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=374 a=6 n=route
  292. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=501 a=17 n=if
  293. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=470 a=25 n=has_to
  294. tag
  295. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=386 a=17 n=if
  296. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=379 a=26 n=is_met
  297. hod
  298. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=386 a=25 n=t_chec
  299. k_trans
  300. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=389 a=6 n=route
  301. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=643 a=3 n=return
  302. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=393 a=26 n=remove
  303. _hf
  304. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=398 a=17 n=if
  305. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=394 a=26 n=is_met
  306. hod
  307. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=404 a=17 n=if
  308. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=398 a=26 n=is_met
  309. hod
  310. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=404 a=6 n=route
  311. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=682 a=17 n=if
  312. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=409 a=6 n=route
  313. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=575 a=17 n=if
  314. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=550 a=26 n=is_met
  315. hod
  316. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=551 a=3 n=return
  317. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=412 a=6 n=route
  318. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=518 a=17 n=if
  319. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=505 a=26 n=is_met
  320. hod
  321. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=513 a=17 n=if
  322. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=507 a=42 n=isflag
  323. set
  324. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=516 a=17 n=if
  325. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=513 a=26 n=save
  326. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=516 a=3 n=exit
  327. ...
  328. The above example is for registration with default config for version
  329. 3.1.0, without authentication. Listed fields are: 'c' - config file;
  330. 'l' - line; 'a' - internal action id; 'n' - name of executed action.
  331. 'ERROR' prefix is printed because these messages were sent to the L_ERR
  332. log level.