README 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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. Parameters
  16. 3.1. cfgtrace (int)
  17. 3.2. breakpoint (int)
  18. 3.3. log_level (int)
  19. 3.4. log_level_name (str)
  20. 3.5. log_facility (str)
  21. 3.6. log_prefix (str)
  22. 3.7. step_usleep (int)
  23. 3.8. step_loops (int)
  24. 3.9. mod_hash_size (int)
  25. 3.10. mod_level_mode (int)
  26. 3.11. mod_level (str)
  27. 3.12. log_assign (int)
  28. 3.13. cfgpkgcheck (int)
  29. 3.14. reset_msgid (int)
  30. 4. Functions
  31. 4.1. dbg_breakpoint(mode)
  32. 4.2. dbg_pv_dump([mask] [, level])
  33. 5. Exported RPC Functions
  34. 5.1. dbg.ls
  35. 5.2. dbg.trace
  36. 5.3. dbg.bp
  37. 5.4. dbg.mod_level
  38. 5.5. dbg.reset_msgid
  39. 6. Usage
  40. List of Examples
  41. 1.1. Set cfgtrace parameter
  42. 1.2. Set breakpoint parameter
  43. 1.3. Set log_level parameter
  44. 1.4. Set log_level_name parameter
  45. 1.5. Set log_facility parameter
  46. 1.6. Set log_prefix parameter
  47. 1.7. Set step_usleep parameter
  48. 1.8. Set step_loops parameter
  49. 1.9. Set mod_hash_size parameter
  50. 1.10. Set mod_level_mode parameter
  51. 1.11. Set mod_level parameter
  52. 1.12. Set log_assign parameter
  53. 1.13. Set cfgpkgcheck parameter
  54. 1.14. Set reset_msgid parameter
  55. 1.15. dbg_breakpoint usage
  56. 1.16. dbg_pv_dump usage
  57. Chapter 1. Admin Guide
  58. Table of Contents
  59. 1. Overview
  60. 2. Dependencies
  61. 2.1. Kamailio Modules
  62. 2.2. External Libraries or Applications
  63. 3. Parameters
  64. 3.1. cfgtrace (int)
  65. 3.2. breakpoint (int)
  66. 3.3. log_level (int)
  67. 3.4. log_level_name (str)
  68. 3.5. log_facility (str)
  69. 3.6. log_prefix (str)
  70. 3.7. step_usleep (int)
  71. 3.8. step_loops (int)
  72. 3.9. mod_hash_size (int)
  73. 3.10. mod_level_mode (int)
  74. 3.11. mod_level (str)
  75. 3.12. log_assign (int)
  76. 3.13. cfgpkgcheck (int)
  77. 3.14. reset_msgid (int)
  78. 4. Functions
  79. 4.1. dbg_breakpoint(mode)
  80. 4.2. dbg_pv_dump([mask] [, level])
  81. 5. Exported RPC Functions
  82. 5.1. dbg.ls
  83. 5.2. dbg.trace
  84. 5.3. dbg.bp
  85. 5.4. dbg.mod_level
  86. 5.5. dbg.reset_msgid
  87. 6. Usage
  88. 1. Overview
  89. This module provides an interactive config file debugger. It can print
  90. a trace of config script execution for a SIP message to log and set
  91. breakpoints on every script action, allowing step-by-step execution of
  92. the routing and response scripts.
  93. Debugging can be done from local or remote host via RPC interface
  94. (e.g., XMLRPC, kamcmd, siremis).
  95. The framework to set breakpoints on specific actions and config lines
  96. is not exported to RPC. Each action can be accompanied by an breakpoint
  97. or you can use dbg_breakpoint() function to set a breakpoint at certain
  98. line. Global breakpoints can be enabled/disabled at runtime. The script
  99. running trace can also be enabled/disabled at runtime.
  100. When the SIP router process is stopped at a breakpoint, you can
  101. investigate the values of any pseudo-variables. Note that some of
  102. pseudo-variables may produce memory leaks; a fix is planned in the
  103. future (here fall pseudo-variables with dynamic name such as htable,
  104. sqlops). References to SIP message, avps, headers, script and shared
  105. variables are safe.
  106. 2. Dependencies
  107. 2.1. Kamailio Modules
  108. 2.2. External Libraries or Applications
  109. 2.1. Kamailio Modules
  110. The following modules must be loaded before this module:
  111. * none.
  112. 2.2. External Libraries or Applications
  113. The following libraries or applications must be installed before
  114. running Kamailio with this module loaded:
  115. * None.
  116. 3. Parameters
  117. 3.1. cfgtrace (int)
  118. 3.2. breakpoint (int)
  119. 3.3. log_level (int)
  120. 3.4. log_level_name (str)
  121. 3.5. log_facility (str)
  122. 3.6. log_prefix (str)
  123. 3.7. step_usleep (int)
  124. 3.8. step_loops (int)
  125. 3.9. mod_hash_size (int)
  126. 3.10. mod_level_mode (int)
  127. 3.11. mod_level (str)
  128. 3.12. log_assign (int)
  129. 3.13. cfgpkgcheck (int)
  130. 3.14. reset_msgid (int)
  131. 3.1. cfgtrace (int)
  132. Control whether the config script trace is enabled or disabled at
  133. startup. You can change the value at runtime without restart, globally
  134. or per process.
  135. Default value is "0" (disabled).
  136. Example 1.1. Set cfgtrace parameter
  137. ...
  138. modparam("debugger", "cfgtrace", 1)
  139. ...
  140. 3.2. breakpoint (int)
  141. Control whether every line (global) breakpoint is enabled or disabled
  142. at startup.
  143. Default value is "0" (disabled).
  144. Example 1.2. Set breakpoint parameter
  145. ...
  146. modparam("debugger", "breakpoint", 1)
  147. ...
  148. 3.3. log_level (int)
  149. What log level is to be used to print module-specific messages.
  150. Default value is "-1" (L_ERR).
  151. Example 1.3. Set log_level parameter
  152. ...
  153. modparam("debugger", "log_level", 1)
  154. ...
  155. 3.4. log_level_name (str)
  156. What log level name is to be used to print cfg trace messages.
  157. Default value is "NULL" (use default log names).
  158. Example 1.4. Set log_level_name parameter
  159. ...
  160. modparam("debugger", "log_level_name", "exec")
  161. ...
  162. 3.5. log_facility (str)
  163. Which log facility is to be used to print module-specific messages. By
  164. using this setting, you can configure syslog to send debug messages to
  165. a separate log channel, like a specific kamailio-debug log file.
  166. Default value is "NULL" (default from core).
  167. Example 1.5. Set log_facility parameter
  168. ...
  169. modparam("debugger", "log_facility", "LOG_DAEMON")
  170. ...
  171. 3.6. log_prefix (str)
  172. String to print before any module-specific messages.
  173. Default value is "*** cfgtrace:".
  174. Example 1.6. Set log_prefix parameter
  175. ...
  176. modparam("debugger", "log_prefix", "from-debugger-with-love:")
  177. ...
  178. 3.7. step_usleep (int)
  179. Microseconds to sleep before checking for new commands when waiting at
  180. a breakpoint.
  181. Default value is "100000" (that is 0.1 sec).
  182. Example 1.7. Set step_usleep parameter
  183. ...
  184. modparam("debugger", "step_usleep", 500000)
  185. ...
  186. 3.8. step_loops (int)
  187. How many sleeps of 'step_usleep' the RPC process performs when waiting
  188. for a reply from a worker process before responding to RPC. This avoids
  189. blocking RPC process forever in case the worker process 'forgets' to
  190. write back a reply.
  191. Default value is "200".
  192. Example 1.8. Set step_loops parameter
  193. ...
  194. modparam("debugger", "step_loops", 100)
  195. ...
  196. 3.9. mod_hash_size (int)
  197. Used to compute power of two as size of internal hash table to store
  198. levels per module (e.g., if its set to 4, internal hash table has 16
  199. slots). This parameter is accesible readonly via the Kamailio config
  200. framework.
  201. Default value is "0" - feature disabled.
  202. Example 1.9. Set mod_hash_size parameter
  203. ...
  204. modparam("debugger", "mod_hash_size", 5)
  205. ...
  206. 3.10. mod_level_mode (int)
  207. Enable or disable per module log level (0 - disabled, 1 - enabled).
  208. This parameter is tunable via the Kamailio config framework.
  209. Default value is "0".
  210. Example 1.10. Set mod_level_mode parameter
  211. ...
  212. modparam("debugger", "mod_level_mode", 1)
  213. ...
  214. 3.11. mod_level (str)
  215. Specify module log level - the value must be in the format:
  216. modulename=level. The parameter can be set many times. For core log
  217. level, use module name 'core'.
  218. Example 1.11. Set mod_level parameter
  219. ...
  220. modparam("debugger", "mod_level", "core=3")
  221. modparam("debugger", "mod_level", "tm=3")
  222. ...
  223. 3.12. log_assign (int)
  224. Enable or disable log assign actions on config (0 - disabled, 1 -
  225. enabled).
  226. Default value is "0".
  227. Example 1.12. Set log_assign parameter
  228. ...
  229. modparam("debugger", "log_assign", 1)
  230. ...
  231. 3.13. cfgpkgcheck (int)
  232. If set, before each config action is done pkg memory check, useful to
  233. detect buffer overflows.
  234. Default value is "0" (disabled).
  235. Example 1.13. Set cfgpkgcheck parameter
  236. ...
  237. modparam("debugger", "cfgpkgcheck", 1)
  238. ...
  239. 3.14. reset_msgid (int)
  240. Used to enable or disable the ability to reset the msgid ($mi) through
  241. the dbg.reset_msgid RPC command. (0 - disabled, 1 - enabled).
  242. Default value is "0" - feature disabled.
  243. Example 1.14. Set reset_msgid parameter
  244. ...
  245. modparam("debugger", "reset_msgid", 1)
  246. ...
  247. 4. Functions
  248. 4.1. dbg_breakpoint(mode)
  249. 4.2. dbg_pv_dump([mask] [, level])
  250. 4.1. dbg_breakpoint(mode)
  251. Anchor a breakpoint at the current line of the config (the one on which
  252. this function is called). The 'mode' specifies whether the breakpoint
  253. is enabled (1) or disabled (0) at startup.
  254. Note that this version of the module does not export this anchors to
  255. RPC for interactive debugging (temporarily disabled).
  256. Example 1.15. dbg_breakpoint usage
  257. ...
  258. if($si=="10.0.0.10")
  259. dbg_breakpoint("1");
  260. ...
  261. 4.2. dbg_pv_dump([mask] [, level])
  262. Prints the content of pv_cache on json format. Defaults are mask=31 and
  263. level = "L_DBG"
  264. mask - Controls the content to dump:
  265. * 1 - dump null values
  266. * 2 - dump avp vars
  267. * 4 - dump script vars
  268. * 8 - dump xavp vars
  269. * 16 - dump DP_OTHER vars
  270. level - The level that will be used in LOG function. It can be:
  271. * L_ALERT - log level -5
  272. * L_BUG - log level -4
  273. * L_CRIT - log level -3
  274. * L_ERR - log level -1
  275. * L_WARN - log level 0
  276. * L_NOTICE - log level 1
  277. * L_INFO - log level 2
  278. * L_DBG - log level 3
  279. Example 1.16. dbg_pv_dump usage
  280. ...
  281. $var(temp) = 1;
  282. $avp(s:more_avp) = 2;
  283. $avp(s:more_avp) = 3;
  284. $xavp(x=>more) = "bye";
  285. $xavp(x[0]=>more) = "hi";
  286. $xavp(x[0]=>other) = 1;
  287. $xavp(x[0]=>other) = 2;
  288. $xavp(x=>different) = "foo";
  289. $var(empty) = $null;
  290. dbg_pv_dump(30, "L_DBG");
  291. ...
  292. Output
  293. ...
  294. 4(30943) DEBUG: debugger [debugger_api.c:1613]: dbg_dump_json(): {"$sp":37597,"
  295. $var(rc)":0,"$var(temp)":1,"$avp(more_avp)":[3,2],"$si":"127.0.0.1","$rc":0,"$xa
  296. vp(x)":[{"different":["foo"]},{"other":[2,1],"more":["hi","bye"]}],"$T_branch_id
  297. x":0,"$var(empty)":0}
  298. ...
  299. 5. Exported RPC Functions
  300. 5.1. dbg.ls
  301. 5.2. dbg.trace
  302. 5.3. dbg.bp
  303. 5.4. dbg.mod_level
  304. 5.5. dbg.reset_msgid
  305. 5.1. dbg.ls
  306. List Kamailio processes with info related to interactive debugging.
  307. Name: dbg.list
  308. Parameters:
  309. * _pid_ : pid for which to list the details. If 'pid' is omitted then
  310. will print for all processes.
  311. Examples of use with kamcmd:
  312. dbg.ls
  313. dbg.ls 1234
  314. 5.2. dbg.trace
  315. Control config script running trace.
  316. Name: dbg.trace
  317. Parameters:
  318. * _cmd_ : command can be 'on' or 'off' to enable or disable tracing
  319. for one or all processes.
  320. * _pid_ : pid for which to list the details. If 'pid' is omitted,
  321. then details for all processes will be printed.
  322. Examples for using with kamcmd:
  323. dbg.trace on
  324. dbg.trace off
  325. dbg.trace on 1234
  326. 5.3. dbg.bp
  327. Control breakpoints and config execution.
  328. Name: dbg.bp
  329. Parameters:
  330. * _cmd_ : command, see next section for the list of available values.
  331. * _pid_ : process id for which to apply the command. If 'pid' is
  332. omitted, then the inner command will be applied to all processes.
  333. * _params_ : extra params specific for each command.
  334. Commands:
  335. * on - turn on breakpoints. Pid parameter is optional.
  336. * off - turn off breakpoints. Pid parameter is optional.
  337. * keep - keep breakpoints only for pid given as parameter
  338. * release - disable breakpoints for processes that are not waiting at
  339. a breakpoint. Pid parameter is optional.
  340. * next - run the action under breakpoint and stop at next one (step
  341. by step execution). Pid parameter is mandatory.
  342. * move - run the action under breakpoint and remove the rest of
  343. breakpoints (continue execution without stopping again at next
  344. actions). Pid parameter is mandatory.
  345. * show - print details about the current breakpoint for pid. Pid
  346. parameter is mandatory.
  347. * eval - evaluate a pseudo-variable and print the result in RPC Pid
  348. parameter is mandatory.
  349. * log - evaluate a pseudo-variable and print the result in SIP router
  350. logs. Pid parameter is mandatory.
  351. Examples for using with kamcmd:
  352. dbg.bp off
  353. dbg.bp on
  354. dbg.bp release
  355. dbg.bp on 1234
  356. dbg.bp eval 1234 $fu
  357. dbg.bp move 1234
  358. 5.4. dbg.mod_level
  359. Specify module log level.
  360. Name: dbg.mod_level
  361. Parameters:
  362. * _module_ : For core log level, use module name 'core'
  363. * _level_ : integer
  364. Examples of use with kamcmd:
  365. dbg.mod_level core 3
  366. dbg.mod_level tm 3
  367. 5.5. dbg.reset_msgid
  368. Resets the message sequence ($mi). Internally there is no real change.
  369. This can be useful for unit test cases in order to be able to replicate
  370. exactly the same kamailio output. You need to set the debugger
  371. parameter reset_msgid to 1 to activate this functionallity.
  372. Name: dbg.reset_msgid
  373. Examples of use with kamcmd:
  374. dbg.reset_msgid
  375. 6. Usage
  376. A common usage is to investigate the execution path for a specific SIP
  377. message. Just enable cfg running trace, send the message and watch the
  378. logs.
  379. Another typical usage is to do interactive debugging and run each line
  380. of the route blocks of the configuration file step-by-step for a
  381. particular SIP message.
  382. You need to connect using kamcmd (or other RPC client) to Kamailio.
  383. Then you can enable cfg breakpoints and send the SIP message. One
  384. process will be in waiting state ('state' field different than 0 when
  385. you do dbg.ls). Calling dbg.release will set the other Kamailio
  386. processes in no-breakpoint mode so they can process other SIP messages
  387. without need to interact with them.
  388. A process blocked at a breakpoint is waiting for a command. Use 'dbg.bp
  389. next pid' to execute the current action and stop at the next one.
  390. 'dbg.bp eval pid PV' can be used to retrieve the value of PV. Once you
  391. are done and want to continue the execution of the config wihtout
  392. interaction use 'dbg.bp move pid'.
  393. Example of a session:
  394. ...
  395. kamcmd> dbg.ls
  396. {
  397. entry: 0
  398. pid: 6393
  399. set: 3
  400. state: 0
  401. in.pid: 0
  402. in.cmd: 0
  403. }
  404. {
  405. entry: 1
  406. pid: 6394
  407. set: 3
  408. state: 0
  409. in.pid: 0
  410. in.cmd: 0
  411. }
  412. ...
  413. {
  414. entry: 9
  415. pid: 6402
  416. set: 3
  417. state: 1
  418. in.pid: 0
  419. in.cmd: 0
  420. }
  421. kamcmd> dbg.bp show 6402
  422. at bkp [/etc/kamailio/debugger.cfg:369] a=6 n=route
  423. kamcmd> dbg.bp next 6402
  424. exec [/etc/kamailio/debugger.cfg:369] a=6 n=route
  425. kamcmd> dbg.bp next 6402
  426. exec [/etc/kamailio/debugger.cfg:462] a=17 n=if
  427. kamcmd> dbg.bp eval 6402 $fu
  428. $fu : t=str v=sip:[email protected]
  429. kamcmd> dbg.bp move 6402
  430. 200 ok
  431. ...
  432. Running the config trace looks like:
  433. ...
  434. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=368 a=6 n=route
  435. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=461 a=17 n=if
  436. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=456 a=26 n=mf_pro
  437. cess_maxfwd_header
  438. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=466 a=17 n=if
  439. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=461 a=27 n=sanity
  440. _check
  441. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=371 a=6 n=route
  442. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=659 a=3 n=return
  443. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=374 a=6 n=route
  444. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=501 a=17 n=if
  445. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=470 a=25 n=has_to
  446. tag
  447. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=386 a=17 n=if
  448. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=379 a=26 n=is_met
  449. hod
  450. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=386 a=25 n=t_chec
  451. k_trans
  452. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=389 a=6 n=route
  453. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=643 a=3 n=return
  454. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=393 a=26 n=remove
  455. _hf
  456. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=398 a=17 n=if
  457. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=394 a=26 n=is_met
  458. hod
  459. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=404 a=17 n=if
  460. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=398 a=26 n=is_met
  461. hod
  462. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=404 a=6 n=route
  463. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=682 a=17 n=if
  464. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=409 a=6 n=route
  465. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=575 a=17 n=if
  466. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=550 a=26 n=is_met
  467. hod
  468. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=551 a=3 n=return
  469. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=412 a=6 n=route
  470. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=518 a=17 n=if
  471. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=505 a=26 n=is_met
  472. hod
  473. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=513 a=17 n=if
  474. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=507 a=42 n=isflag
  475. set
  476. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=516 a=17 n=if
  477. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=513 a=26 n=save
  478. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=516 a=3 n=exit
  479. ...
  480. The above example is for a registration with default config for version
  481. 3.1.0, without authentication. Listed fields are: 'c' - config file;
  482. 'l' - line; 'a' - internal action id; 'n' - name of executed action.
  483. 'ERROR' prefix is printed because these messages were sent to the L_ERR
  484. log level.