Tuesday, March 18, 2008

How to debug segfaulting apache module?

Recently I had a strange segmentation fault in one of the apache modules.

I want to get closer to the point of segmentation fault.
First let me share the ineffective approaches and then share the effective approaches.
Ineffective approaches:
  1. Logged lots of printfs to some text file, to trace the flow of execution.
  2. Attached the debugger to 'apache listen process'
    1. set follow-fork-mode child
'2' Looks elegant but it did not work for me, because one can not be sure about which child process will serve their request.

Effective approach:
Configured my apache to have only one child(worker process) at any time.

StartServers 1
MinSpareServers 1
MaxSpareServers 0
MaxClients 150
MaxRequestsPerChild 0


With this configuration you will see only 2 apache processes at any time.
One process owned by 'root', a listener process(which we do not care), another by apache user(which we care).


  • Attach a debugger to process owned by 'apache'
  • set a relevant breakpoints, watchpoints etc.
  • Allow the process to continue
  • Make a http request
  • You will get a control in your debugger.
Even if you run apache as non-root user it does not matter, it is easy to identify the worker process.
Apache process which remains alive across requests is not a worker apache.

No comments: