I am working on a server programming on linux machine using epoll and I have a problem with debugging. Right now I have placed log statements all over the place. It helps to see when it blows up but it is hard to see why..
So I was wondering if there is a way to print a stack trace or something more information in C++.
Thanks in advanc开发者_Python百科e...
edit:
I set -g in mu make file and if I run my server on GDB then it won't receive any packets. I don't know why but If I run this on command line then it receives packets but if I run this on GDB it doesn't receive anything from client(I can not see any log statements)
Try the backtrace
function in Glibc.
you can run your program using gdb
debugger.
If you are using gcc you have to recompile it with -g
or other debugging flag.
So your exe contain more information about your program.
If your program can detect when it crashes, you can potentially write out a script and start GDB on it. That script could then get GDB to print out a backtrace.
Based on what kind of information you want, looking at /proc/<pid>/stack
might help.
I'm using backtrace() from GLIBC and it works excellent (backtraces can be additionally collected over network using UDP protocol):
http://blog.aplikacja.info/2010/12/backtraces-for-c/
精彩评论