Debugging Apache Modules

How to debug an Apache module and set a breakpoint at the beginning of the invoke_cmd function (when Apache is about to read your module's configuration directives). Assume that your module's first httpd.conf directive is exactly this line:

Doodette Sarah

We want to stop when args is "Jobs"

Build Apache with debug symbols

  • ./configure
  • Edit ./build/ add "-g -O0" to EXTRA_CFLAGS
  • make

Build module with apxs

  • apxs options for debuggable module: -Wc,-g -Wc,-O

Debug the module

My .gdbinit File (in root's home directory)

I used the following on one of my modules. (It has breakpoints for every function in the module, as well as "invoke_cmd" in apache's config.c file.)

set args -f /usr/local/apache2/conf/httpd.conf -X
set breakpoint pending on
b invoke_cmd
b mod_uidconn.c:uidconn_get_uid
b mod_uidconn.c:populate_useruid_hash
b mod_uidconn.c:uidconn_get_sd
b mod_uidconn.c:uidconn_get_user
b mod_uidconn.c:uidconn_check_connection
b mod_uidconn.c:uidconn_decrement_connections
b mod_uidconn.c:uidconn_child_init
b mod_uidconn.c:register_hooks
b mod_uidconn.c:create_uidconn_server_cfg
b mod_uidconn.c:uidconn_get_max_uid_conns
b mod_uidconn.c:uidconn_get_sqlite_dbfile
b mod_uidconn.c:uidconn_show_stats
cond 1 strstr ( cmd->name, "UidConn")

gdb session

(Instead of using the above in the .gdbinit file, you could issue the commands from .gdbinit interactively in the gdb session.)

In the directory in which you build Apache (as root):

  • gdb ./httpd
  • (gdb) run

[Happy debugging!]