Reputation: 51
Using gdb, I am trying to trace the function calls of a web server. I set breakpoints on every function call and when I tell gdb to 'run' it breaks at all the right places while the server starts up. Then gdb says 'Program ended with code 01' and doesn't stop at breakpoints anymore (obviously). However, the web server is still running.
I want to be able to trace the function calls made on an incoming HTTP request, so just breaking during server startup is useless to me.
Is there some trick to using gdb when tracing a daemon server so that it doesn't just end like above?
Upvotes: 5
Views: 672
Reputation: 41967
set follow-fork-mode child
see https://sourceware.org/gdb/onlinedocs/gdb/Forks.html for example
From the link:
If you want to follow the child process instead of the parent process, use the command
set follow-fork-mode
.
set follow-fork-mode
mode Set the debugger response to a program call offork
orvfork
. A call tofork
orvfork
creates a new process. The mode argument can be:
parent
The original process is debugged after afork
. The child process runs unimpeded. This is the default.
child
The new process is debugged after afork
. The parent process runs unimpeded.
show follow-fork-mode
Display the current debugger response to afork
orvfork
call.
Upvotes: 1
Reputation: 213576
You didn't say which server you are trying to trace, but likely it is Apache.
Detailed instructions are here. Note the -X
command line argument, which prevents httpd from forking children.
Also note that the instructions are the first result for this search.
Upvotes: 2