[asterisk-dev] Debugging source code and extends an application

Mark Michelson mmichelson at digium.com
Fri Apr 26 13:54:23 CDT 2013


On 04/24/2013 05:43 AM, sgil wrote:
> Hello,
>
> I'm a new (and a fool in C language) developer in Asterisk, I want to 
> ask some questions here cause I have no answer in the whole Google (><).
>
> First, I wanna know if there is some way to debug into the source code 
> when Asterisk is running or any application rather. For example, when 
> my dialplan executes the Monitor application, I wanna see which steps 
> it follow.

It all depends what your goal is. There are debugging messages scattered 
throughout the Asterisk source that can be somewhat helpful in 
determining what is going on. See this wiki page [1] for some details on 
getting a debug trace. In addition, I'd recommend the tool gdb [2] in 
order to step through code and follow its execution path. Be careful 
with gdb though since slowing down code that runs in realtime can lead 
to some unintended consequences (for instance, your phone might hang up 
automatically if an answer does not arrive within a certain amount of time).

>
> In the other hand, I wanna extend the parameters of the Monitor 
> application, to introduce another 2 parameters (port and IP) for send 
> the audio recorded by the application in a socket opened with netcat.

So it sounds like there are two things you're trying for here:

1) Adding new parameters to the Monitor application
2) Writing media to a socket

1) isn't too tough. Have a look at monitor_exec in res/res_monitor.c. 
You'll find that there is a call to AST_DECLARE_APP_ARGS there with the 
arguments that Monitor() accepts. You can add a new line to this for 
your new argument.

Have a look at the functions available to you in 
include/asterisk/netsock2.h to see about parsing IP addresses and ports.

2) Is a bit more interesting. Unfortunately, the actual code that writes 
audio to a monitor's file is actually in main/channel.c in the 
__ast_read() and ast_write() functions. This is where you would have to 
insert your code to write the data out to a socket.

Hopefully that's a good hint on where to start. Good luck!

Mark!

[1] https://wiki.asterisk.org/wiki/display/AST/Collecting+Debug+Information
[2] http://www.gnu.org/software/gdb/



More information about the asterisk-dev mailing list