debugging an apache module in netbeans

Thu, Apr 29, 2010

As I’ve started to develop mod_guanxi as an Apache module version of a Guanxi Guard, I needed a way to debug it running inside Apache. I eventually gave up trying to use Eclipse and CDT and gave NetBeans a go instead.

  • Make sure your Makefile can produce a debug build. I just added -g to CXXFLAGS and ran configure to get a debug specific Makefile
  • After you build and use apxs to install the module, the code will be loaded by Apache so you will be able to step through it in the IDE
  • Right click on the project in NetBeans and choose Properties
  • Under Build/Make/Build Result, point it to the httpd executable
  • Run Apache in single process mode: httpd -X
  • In NetBeans, choose Debug -> Attach Debugger. In the filter, type httpd and you’ll see the single Apache process. Click on it  and hit OK
That’s it. When you open the site in a browser, NetBeans will kick in and you can step through the module code.

[UPDATE: 3/5/10]

Whenever I tried attaching to the httpd process in Eclipse the browser would just hang. Then I remembered something about gdb and automatically breaking on main(). Sure enough the apache thread was suspended in the debugger on child_main. Resuming the thread in the debugger sorted that. I can now use Eclipse to code/debug the module which is just as well really as NetBeans on the Mac is very slow and clunky but for some reason, the Eclipse attach to application debug type doesn’t let you not break at main()

comments powered by Disqus