debugger_admin.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. This module provides an interactive config file debugger. It can print
  15. a trace of config execution for a SIP message to log and set
  16. breakpoints on every config action, allowing step-by-step execution of
  17. the config.
  18. </para>
  19. <para>
  20. Debugging can be done from local or remote host via RPC interface (e.g.,
  21. XMLRPC, sercmd, siremis).
  22. </para>
  23. <para>
  24. The framework to set breakpoints on specific actions and config lines
  25. is not exported to RPC yet. Each action can be accompanied by an
  26. breakpoint or you can use dbg_breakpoint() function to set a breakpoint
  27. at certain line. Global breakpoint can be enabled/disabled at runtime.
  28. Also the config running trace can be enabled/disabled at runtime.
  29. </para>
  30. <para>
  31. When the SIP router process is stopped at a breakpoint, you can
  32. investigate the values of any pseudo-variables. Note that some of
  33. pseudo-variables may produce memory leaks; a fix is planned in the
  34. future (here fall pseudo-variables with dynamic name such as htable,
  35. sqlops). References to SIP message, avps, headers, script and shared
  36. variables are safe.
  37. </para>
  38. </section>
  39. <section>
  40. <title>Dependencies</title>
  41. <section>
  42. <title>&kamailio; Modules</title>
  43. <para>
  44. The following modules must be loaded before this module:
  45. <itemizedlist>
  46. <listitem>
  47. <para>
  48. <emphasis>none</emphasis>.
  49. </para>
  50. </listitem>
  51. </itemizedlist>
  52. </para>
  53. </section>
  54. <section>
  55. <title>External Libraries or Applications</title>
  56. <para>
  57. The following libraries or applications must be installed before running
  58. &kamailio; with this module loaded:
  59. <itemizedlist>
  60. <listitem>
  61. <para>
  62. <emphasis>None</emphasis>.
  63. </para>
  64. </listitem>
  65. </itemizedlist>
  66. </para>
  67. </section>
  68. </section>
  69. <section>
  70. <title>Exported Parameters</title>
  71. <section>
  72. <title><varname>cfgtrace</varname> (int)</title>
  73. <para>
  74. Control whether config running trace is enabled or disabled
  75. at startup. You can change the value at runtime without
  76. restart, globally or per process.
  77. </para>
  78. <para>
  79. <emphasis>
  80. Default value is <quote>0</quote> (disabled).
  81. </emphasis>
  82. </para>
  83. <example>
  84. <title>Set <varname>cfgtrace</varname> parameter</title>
  85. <programlisting format="linespecific">
  86. ...
  87. modparam("debugger", "cfgtrace", 1)
  88. ...
  89. </programlisting>
  90. </example>
  91. </section>
  92. <section>
  93. <title><varname>breakpoint</varname> (int)</title>
  94. <para>
  95. Control whether every line (global) breakpoint is enabled
  96. or disabled at startup.
  97. </para>
  98. <para>
  99. <emphasis>
  100. Default value is <quote>0</quote> (disabled).
  101. </emphasis>
  102. </para>
  103. <example>
  104. <title>Set <varname>breakpoint</varname> parameter</title>
  105. <programlisting format="linespecific">
  106. ...
  107. modparam("debugger", "breakpoint", 1)
  108. ...
  109. </programlisting>
  110. </example>
  111. </section>
  112. <section>
  113. <title><varname>log_level</varname> (int)</title>
  114. <para>
  115. What log level is to be used to print module-specific messages.
  116. </para>
  117. <para>
  118. <emphasis>
  119. Default value is <quote>-1</quote> (L_ERR).
  120. </emphasis>
  121. </para>
  122. <example>
  123. <title>Set <varname>log_level</varname> parameter</title>
  124. <programlisting format="linespecific">
  125. ...
  126. modparam("debugger", "log_level", 1)
  127. ...
  128. </programlisting>
  129. </example>
  130. </section>
  131. <section>
  132. <title><varname>log_facility</varname> (str)</title>
  133. <para>
  134. What log facility is to be used to print module-specific messages.
  135. </para>
  136. <para>
  137. <emphasis>
  138. Default value is <quote>NULL</quote> (default from core).
  139. </emphasis>
  140. </para>
  141. <example>
  142. <title>Set <varname>log_facility</varname> parameter</title>
  143. <programlisting format="linespecific">
  144. ...
  145. modparam("debugger", "log_facility", "LOG_DAEMON")
  146. ...
  147. </programlisting>
  148. </example>
  149. </section>
  150. <section>
  151. <title><varname>log_prefix</varname> (str)</title>
  152. <para>
  153. String to print before any module-specific messages.
  154. </para>
  155. <para>
  156. <emphasis>
  157. Default value is <quote>*** cfgtrace:</quote>.
  158. </emphasis>
  159. </para>
  160. <example>
  161. <title>Set <varname>log_prefix</varname> parameter</title>
  162. <programlisting format="linespecific">
  163. ...
  164. modparam("debugger", "log_prefix", "from-debugger-with-love:")
  165. ...
  166. </programlisting>
  167. </example>
  168. </section>
  169. <section>
  170. <title><varname>step_usleep</varname> (int)</title>
  171. <para>
  172. Microseconds to sleep before checking for new commands when
  173. waiting at breakpoint.
  174. </para>
  175. <para>
  176. <emphasis>
  177. Default value is <quote>100000</quote> (that is 0.1 sec).
  178. </emphasis>
  179. </para>
  180. <example>
  181. <title>Set <varname>step_usleep</varname> parameter</title>
  182. <programlisting format="linespecific">
  183. ...
  184. modparam("debugger", "step_usleep", 500000)
  185. ...
  186. </programlisting>
  187. </example>
  188. </section>
  189. <section>
  190. <title><varname>step_loops</varname> (int)</title>
  191. <para>
  192. How many sleeps of 'step_usleep' the RPC process performs when
  193. waiting for a reply from worker process before responding to RPC.
  194. This avoids blocking RPC process forever in case the worker
  195. process 'forgets' to write back a reply.
  196. </para>
  197. <para>
  198. <emphasis>
  199. Default value is <quote>200</quote>.
  200. </emphasis>
  201. </para>
  202. <example>
  203. <title>Set <varname>step_loops</varname> parameter</title>
  204. <programlisting format="linespecific">
  205. ...
  206. modparam("debugger", "step_loops", 100)
  207. ...
  208. </programlisting>
  209. </example>
  210. </section>
  211. </section>
  212. <section>
  213. <title>Exported Functions</title>
  214. <section>
  215. <title>
  216. <function moreinfo="none">dbg_breakpoint(mode)</function>
  217. </title>
  218. <para>
  219. Anchor a breakpoint at the current line of the config (the one
  220. on which this function is called). The 'mode' specifies whether
  221. the breakpoint is enabled (1) or disabled (0) at startup.
  222. </para>
  223. <para>
  224. Note that this version does not export this anchors to RPC for
  225. interactive debugging (temporarily disabled).
  226. </para>
  227. <example>
  228. <title><function>dbg_breakpoint</function> usage</title>
  229. <programlisting format="linespecific">
  230. ...
  231. if($si=="10.0.0.10")
  232. dbg_breakpoint("1");
  233. ...
  234. </programlisting>
  235. </example>
  236. </section>
  237. </section>
  238. <section>
  239. <title>Exported RPC Functions</title>
  240. <section>
  241. <title>
  242. <function moreinfo="none">dbg.ls</function>
  243. </title>
  244. <para>
  245. List SIP router processes with info related to interactive
  246. debugging.
  247. </para>
  248. <para>
  249. Name: <emphasis>dbg.list</emphasis>
  250. </para>
  251. <para>Parameters:</para>
  252. <itemizedlist>
  253. <listitem><para>_pid_ : pid for which to list the details. If 'pid' is
  254. omitted then will print for all processes.</para></listitem>
  255. </itemizedlist>
  256. <para>
  257. Examples of use with sercmd:
  258. </para>
  259. <programlisting format="linespecific">
  260. dbg.ls
  261. dbg.ls 1234
  262. </programlisting>
  263. </section>
  264. <section>
  265. <title>
  266. <function moreinfo="none">dbg.trace</function>
  267. </title>
  268. <para>
  269. Control config running trace.
  270. </para>
  271. <para>
  272. Name: <emphasis>dbg.trace</emphasis>
  273. </para>
  274. <para>Parameters:</para>
  275. <itemizedlist>
  276. <listitem><para>_cmd_ : inner command can be 'on' or 'off' to
  277. enable or disable tracing for one or all processes.</para>
  278. </listitem>
  279. <listitem><para>_pid_ : pid for which to list the details. If 'pid' is
  280. omitted, then it will print details for all processes.</para>
  281. </listitem>
  282. </itemizedlist>
  283. <para>
  284. Examples for using with sercmd:
  285. </para>
  286. <programlisting format="linespecific">
  287. dbg.trace on
  288. dbg.trace off
  289. dbg.trace on 1234
  290. </programlisting>
  291. </section>
  292. <section>
  293. <title>
  294. <function moreinfo="none">dbg.bp</function>
  295. </title>
  296. <para>
  297. Control breakpoints and config execution.
  298. </para>
  299. <para>
  300. Name: <emphasis>dbg.bp</emphasis>
  301. </para>
  302. <para>Parameters:</para>
  303. <itemizedlist>
  304. <listitem><para>_cmd_ : inner command, see next section for
  305. the list of available values.</para>
  306. </listitem>
  307. <listitem><para>_pid_ : pid for which to apply the inner command.
  308. If 'pid' is omitted, then the inner command will be applied
  309. to all processes.</para>
  310. </listitem>
  311. <listitem><para>_params_ : extra params specific for each inner
  312. command.</para>
  313. </listitem>
  314. </itemizedlist>
  315. <para>Inner commands:</para>
  316. <itemizedlist>
  317. <listitem>
  318. <para>on - turn on breakpoints. Pid parameter is optional.
  319. </para>
  320. </listitem>
  321. <listitem>
  322. <para>off - turn off breakpoints. Pid parameter is optional.
  323. </para>
  324. </listitem>
  325. <listitem>
  326. <para>keep - keep breakpoints only for pid given as parameter
  327. </para>
  328. </listitem>
  329. <listitem>
  330. <para>release - disable breakpoints for processes that are
  331. not waiting at a breakpoint. Pid parameter is optional.</para>
  332. </listitem>
  333. <listitem>
  334. <para>next - run the action under breakpoint and stop at next one
  335. (step by step execution). Pid parameter is mandatory.
  336. </para>
  337. </listitem>
  338. <listitem>
  339. <para>move - run the action under breakpoint and remove the rest
  340. of breakpoints (continue execution without stopping again at next
  341. actions). Pid parameter is mandatory.</para>
  342. </listitem>
  343. <listitem>
  344. <para>show - print details about the current breakpoint for pid.
  345. Pid parameter is mandatory.</para>
  346. </listitem>
  347. <listitem>
  348. <para>eval - eval a pseudo-variable and print the result in RPC
  349. Pid parameter is mandatory.</para>
  350. </listitem>
  351. <listitem>
  352. <para>log - eval a pseudo-variable and print the result in SIP
  353. router logs. Pid parameter is mandatory.</para>
  354. </listitem>
  355. </itemizedlist>
  356. <para>
  357. Examples for using with sercmd:
  358. </para>
  359. <programlisting format="linespecific">
  360. dbg.bp off
  361. dbg.bp on
  362. dbg.bp release
  363. dbg.bp on 1234
  364. dbg.bp eval 1234 $fu
  365. dbg.bp move 1234
  366. </programlisting>
  367. </section>
  368. </section>
  369. <section>
  370. <title>Usage</title>
  371. <para>
  372. A common usage is to investigate the execution path for a specific
  373. SIP message. Just enable cfg running trace, send the message and
  374. watch the logs.
  375. </para>
  376. <para>
  377. Another typical usage is to do interactive debugging and run
  378. each line of the route blocks of the config file step-by-step for a
  379. particular SIP message.
  380. </para>
  381. <para>
  382. You need to connect using sercmd (or other RPC client) to SIP Router.
  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 SIP router
  386. processes in no-breakpoint mode so they can process other SIP messages
  387. without need to interact with them.
  388. </para>
  389. <para>
  390. The process blocked at breakpoint is waiting for a command. Use
  391. 'dbg.bp next pid' to execute the current action and stop at the next
  392. one. 'dbg.bp eval pid PV' can be used to retrive the value of PV. Once
  393. you are done and want to continue the execution of the config wihtout
  394. interaction use 'dbg.bp move pid'.
  395. </para>
  396. <para>
  397. Here is an example of session:
  398. </para>
  399. <programlisting format="linespecific">
  400. ...
  401. sercmd> dbg.ls
  402. {
  403. entry: 0
  404. pid: 6393
  405. set: 3
  406. state: 0
  407. in.pid: 0
  408. in.cmd: 0
  409. }
  410. {
  411. entry: 1
  412. pid: 6394
  413. set: 3
  414. state: 0
  415. in.pid: 0
  416. in.cmd: 0
  417. }
  418. ...
  419. {
  420. entry: 9
  421. pid: 6402
  422. set: 3
  423. state: 1
  424. in.pid: 0
  425. in.cmd: 0
  426. }
  427. sercmd> dbg.bp show 6402
  428. at bkp [/etc/kamailio/debugger.cfg:369] a=6 n=route
  429. sercmd> dbg.bp next 6402
  430. exec [/etc/kamailio/debugger.cfg:369] a=6 n=route
  431. sercmd> dbg.bp next 6402
  432. exec [/etc/kamailio/debugger.cfg:462] a=17 n=if
  433. sercmd> dbg.bp eval 6402 $fu
  434. $fu : t=str v=sip:[email protected]
  435. sercmd> dbg.bp move 6402
  436. 200 ok
  437. ...
  438. </programlisting>
  439. <para>
  440. Running the config trace looks like:
  441. </para>
  442. <programlisting format="linespecific">
  443. ...
  444. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=368 a=6 n=route
  445. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=461 a=17 n=if
  446. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=456 a=26 n=mf_process_maxfwd_header
  447. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=466 a=17 n=if
  448. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=461 a=27 n=sanity_check
  449. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=371 a=6 n=route
  450. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=659 a=3 n=return
  451. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=374 a=6 n=route
  452. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=501 a=17 n=if
  453. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=470 a=25 n=has_totag
  454. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=386 a=17 n=if
  455. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=379 a=26 n=is_method
  456. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=386 a=25 n=t_check_trans
  457. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=389 a=6 n=route
  458. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=643 a=3 n=return
  459. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=393 a=26 n=remove_hf
  460. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=398 a=17 n=if
  461. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=394 a=26 n=is_method
  462. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=404 a=17 n=if
  463. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=398 a=26 n=is_method
  464. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=404 a=6 n=route
  465. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=682 a=17 n=if
  466. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=409 a=6 n=route
  467. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=575 a=17 n=if
  468. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=550 a=26 n=is_method
  469. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=551 a=3 n=return
  470. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=412 a=6 n=route
  471. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=518 a=17 n=if
  472. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=505 a=26 n=is_method
  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=isflagset
  475. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=516 a=17 n=if
  476. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=513 a=26 n=save
  477. 9(6285) ERROR: *** cfgtrace: c=[/etc/kamailio/debugger.cfg] l=516 a=3 n=exit
  478. ...
  479. </programlisting>
  480. <para>
  481. The above example is for registration with default config for
  482. version 3.1.0, without authentication. Listed fields are:
  483. 'c' - config file; 'l' - line; 'a' - internal action id;
  484. 'n' - name of executed action. 'ERROR' prefix is printed
  485. because these messages were sent to the L_ERR log level.
  486. </para>
  487. </section>
  488. </chapter>