Hi,
below are my findings on this. I thought I'd share them here in case
someone else is asking the same question.
Cheers,
Michael
There are 2 cases to consider:
1. Inline instructions inside <%cpp></%cpp>
2. calls to own functions, included via <%pre></%pre>, from within the
<%cpp></%cpp> tags.
Ad 1
----
The best I have come up with so far for the debugging of cpp inline code
in ecpp files, is throwing an exception inside a try/catch block just
before the lines of code that interest me and use the "catch catch"
construct in gdb. Then stepping through with n or s, depending on the
context, does the trick, even though one learns may be more than
intended about the inner workings of tntnet :-)
See a step by step guide below.
Ad 2
----
This one is much simpler. There is no need to modify your code for this.
You simply tell gdb to break on your function name like so:
(gdb) *break myfunc.**
Function "myfunc.*" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
And as you can see you can even use regular expressions for this. As
soon as gdb hits a function that matches the given name, it will break.
Note
----
You may want to disable compiler optimisations for this kind of
debugging. Otherwise numerous of your variables will "disappear" and
make the value inspection more difficult. You will notice it when gdb
tells you "optimized out" after a "print http_msg"
You can disable optimization by simply modifying your Makefile. In the
case of the one generated by tntnet-config locate the line below and
replace the final 2 by a 0 (zero)
CXXFLAGS+=-I/usr/local/include -fPIC -O2
Step 1
------
is modifying your ecpp file like below:
<%cpp>
// put your C++ code here
try
{
throw std::exception();
}
catch (std::exception& e)
{
;
}
std::string str = "a test";
//some code of interest ...
</%cpp>
Step 2
------
in a terminal, with cwd set to your projects directory, do as shown in
this transcript (the actual input is bold).
gdb has a very good help, just type h or help.
$ *gdb tntnet*
GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
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-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/bin/tntnet...done.
(gdb) *catch catch*
(gdb) *run*
Starting program: /usr/local/bin/tntnet
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/x86_64-linux-gnu/libthread_db.so.1".
tntnet 2.2rc2
2013-10-10 16:50:40.61311 [8109.140737353930560] INFO
tntnet.listener - listen ip= port=8000
2013-10-10 16:50:40.61324 [8109.140737353930560] INFO tntnet.tntnet
- create 5 worker threads
[New Thread 0x7ffff5d95700 (LWP 8112)]
[New Thread 0x7ffff5594700 (LWP 8113)]
[New Thread 0x7ffff4d93700 (LWP 8114)]
[New Thread 0x7fffeffff700 (LWP 8115)]
[New Thread 0x7fffef7fe700 (LWP 8116)]
[New Thread 0x7fffeeffd700 (LWP 8117)]
[New Thread 0x7fffee7fc700 (LWP 8118)] // *now go to your browser
and load the url, i.e. localhost:8000 or whatever you configured*
2013-10-10 16:50:46.93639 [8109.140737318049536] INFO tntnet.worker
- request GET / from client 127.0.0.1 user-Agent "Mozilla/5.0 (X11;
Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0" user ""
2013-10-10 16:50:46.93660 [8109.140737318049536] INFO
tntnet.comploader - load library "tcms"
2013-10-10 16:50:46.94173 [8109.140737318049536] INFO
tntnet.comploader - library "./tcms.so"
[Switching to Thread 0x7ffff5d95700 (LWP 8112)]
Catchpoint 1 (exception caught), 0x00007ffff7320050 in
__cxa_begin_catch () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) *n*
Single stepping until exit from function __cxa_begin_catch,
which has no line number information.
0x00007ffff40bb9c0 in (anonymous
namespace)::_component_::operator()(tnt::HttpRequest&,
tnt::HttpReply&, tnt::QueryParams&) () from ./tcms.so
(gdb) *n*
Single stepping until exit from function
_ZN12_GLOBAL__N_111_component_clERN3tnt11HttpRequestERNS1_9HttpReplyERNS1_11QueryParamsE,
which has no line number information.
tnt::Worker::dispatch (this=this@entry=0x644df0, request=...,
reply=...) at worker.cpp:442
442 http_msg = HttpReturn::httpMessage(http_return);
(gdb) *n*
441 http_return = comp->topCall(request, reply,
request.getQueryParams());
(gdb) *n*
442 http_msg = HttpReturn::httpMessage(http_return);
(gdb) *n*
451 if (http_return != DECLINED)
(gdb) return
Make tnt::Worker::dispatch(tnt::HttpRequest&, tnt::HttpReply&)
return now? (y or n) y
#0 tnt::Worker::processRequest (this=this@entry=0x644df0,
request=..., socket=..., keepAliveCount=999)
at worker.cpp:252
252 if (!request.keepAlive() || !reply.keepAlive())
(gdb)
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general