Opensips/kamailio gdb code debugging method details, opensipskamailio

Source: Internet
Author: User
Tags snmp

Opensips/kamailio gdb code debugging method details, opensipskamailio
To debug kamailio/opensips in one step, Zookeeper needs to first understand the code structure and running mode. kamailio/opensips uses the IO network model combined with Reactor and Proactor, the main process is used to listen to the network. When a connection is generated or the first packet arrives, the pipe is used to send the file descriptor to the worker process, the worker process is responsible for data reading, business processing, and data sending of the connection, and then waits for the socket event again. When we want to debug a piece of code, first confirm the type of process that the code runs in. The Code usually used to process the SIP logic is executed in the worker process, the following is an instance started by the kamailio process:[Root @ xx sipserver] # kamctl ps
Process: ID = 0 PID = 6651 Type = attendant
Process: ID = 1 PID = 6653 Type = udp protocol er child = 0 sock = 172.16.0.16: 53
Process: ID = 2 PID = 6654 Type = udp protocol er child = 1 sock = 172.16.0.16: 53
Process: ID = 3 PID = 6656 Type = udp protocol er child = 2 sock = 172.16.0.16: 53Process: ID = 4 PID = 6658 Type = udp protocol er child = 3 sock = 172.16.0.16: 53Process: ID = 5 PID = 6661 Type = slow timer
Process: ID = 6 PID = 6662 Type = timer
Process: ID = 7 PID = 6665 Type = MI FIFO
Process: ID = 8 PID = 6668 Type = ctl handler
Process: ID = 9 PID = 6669 Type = SNMP AgentX
Process: ID = 10 PID = 6672 Type = tcp receiver Er (generic) child = 0
Process: ID = 11 PID = 6674 Type = tcp receiver Er (generic) child = 1
Process: ID = 12 PID = 6676 Type = tcp receiver Er (generic) child = 2
Process: ID = 13 PID = 6677 Type = tcp receiver Er (generic) child = 3
Process: ID = 14 PID = 6679 Type = tcp main process
In the preceding example, both the Type = tcp worker er and udp worker er process processes the SIP messages, including kamailio. in cfg configuration, the route segment is executed in this process. Generally, the modules we develop to process the SIP protocol are also executed in this process. Kamailio and opensips are consistent in the Code core architecture. The following uses kamailio as an example to describe how to use gdb for debugging. There are two ways to debug the program: method 1 run kamailio directly with GDB. cfg is configured as fork = no, so that kamailio runs in a single process, so the logic will be executed in one process, but the single process mode does not support TCP listen, therefore, you cannot use this method to debug the TCP logic. You can directly use gdb to debug the kamailio main program:[Root @ xx ~] # Gdb/usr/sbin/kamailio
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-45. el5)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3 +: gnu gpl version 3 or later This is free software: you are free to change and redistribute it.
There is no warranty, to the extent permitted by law. Type "show copying"
And "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu ".
For bug reporting instructions, please see:
<Http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from/usr/sbin/kamailio... done.
(Gdb) B main. c: 10Breakpoint 1 at 0x45725c: file main. c, line 10.
(Gdb) run

Method 2 after running kamailio, debug with gdb attach: the disadvantage of the first method is obvious. You cannot debug TCP processes or take advantage of kamailio multi-process. Set kamailio. if cfg is set to fork = yes, it will be started in multi-process mode. The related parameters include children = 1, and the number of processes that process udp port data is set to tcp_children = 1; configure the process data for processing tcp port data. If this parameter is not configured, the children parameter is used by default. If you use the preceding parameters to start the program, if the listen parameter has a corresponding port, one UDP processing process and one TCP processing process will be started. The example is as follows:[Root @ xx sipserver] # kamctl ps
Process: ID = 0 PID = 6651 Type = attendant
Process: ID = 1 PID = 6653 Type = udp protocol er child = 0 sock = 172.16.0.16: 53
Process: ID = 5 PID = 6661 Type = slow timer
Process: ID = 6 PID = 6662 Type = timer
Process: ID = 7 PID = 6665 Type = MI FIFO
Process: ID = 8 PID = 6668 Type = ctl handler
Process: ID = 9 PID = 6669 Type = SNMP AgentX
Process: ID = 10 PID = 6672 Type = tcp receiver Er (generic) child = 0
Process: ID = 14 PID = 6679 Type = tcp main process
When kamailio receives TCP data, it will be processed by the 6672 process. We can use gdb attach to debug the specified process. The example is as follows:[Root @ xx ~] # Gdb
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-45. el5)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3 +: gnu gpl version 3 or later This is free software: you are free to change and redistribute it.
There is no warranty, to the extent permitted by law. Type "show copying"
And "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu ".
For bug reporting instructions, please see:
<Http://www.gnu.org/software/gdb/bugs/>.
(Gdb) attach 6672.
Attaching to process 6672
......(Gdb) B redis_base.c: 100
Breakpoint 1 at 0x2b6c45e70082: file redis_base.c, line 100.
(Gdb) c
Continuing.

Then you can set the breakpoint and execute run. When the server receives the SIP message and runs it to the specified code, you can perform one-step debugging. In the debugging process, you can combine the log output to locate the problem. For more information about how to use gdb, see http://wenku.baidu.com/link? Url = UNUB8A6f2OGt_KJxU4p7-df-j9QFw2z2CFN6nCj4smzijx_UiMIkUTFh7JlOE-byIylp2yGfaTbtKPpOGR3lhTd09p3NTQtZDPrWp9N5pmu
Sina Weibo: @ quiet mad man Email: dennis. yu (@) live. cnQQ: 229675152 focuses on the mobile Internet audio and video communication field. You are welcome to share this article. This article is original and reprinted. Please retain the copyright and contact the author.

Kamailio/opensips QQ group: 118791050



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.