1 # gdb macros which may be useful for folks using gdb to debug
2 # apache. Delete it if it bothers you.
5 set $t = (apr_table_entry_t *)((apr_array_header_t *)$arg0)->elts
6 set $n = ((apr_array_header_t *)$arg0)->nelts
9 if $t[$i].val == (void *)0L
10 printf "[%u] '%s'=>NULL\n", $i, $t[$i].key
12 printf "[%u] '%s'='%s' [%p]\n", $i, $t[$i].key, $t[$i].val, $t[$i].val
18 Print the key/value pairs in a table.
22 set $sl = (apr_skiplist *)$arg0
24 printf "skiplist@%p: size=%lu: height=%d\n", $sl, $sl->size, $sl->height
26 printf "(%p,%.12lx)", $m, $m->data
29 printf " (%p,%.12lx)", $u, $u->data
36 document dump_skiplist
37 Print the nodes/values in a skiplist
40 define dump_string_hash
46 while $ent != (void *)0L
47 printf "'%s' => '%p'\n", $ent->key, $ent->val
53 document dump_string_hash
54 Print the entries in a hash table indexed by strings
57 define dump_string_shash
63 while $ent != (void *)0L
64 printf "'%s' => '%s'\n", $ent->key, $ent->val
70 document dump_string_shash
71 Print the entries in a hash table indexed by strings with string values
78 define dump_string_array
79 set $a = (char **)((apr_array_header_t *)$arg0)->elts
80 set $n = (int)((apr_array_header_t *)$arg0)->nelts
83 printf "[%u] '%s'\n", $i, $a[$i]
87 document dump_string_array
88 Print all of the elements in an array of strings.
94 if $arg0[$i] < 0x20 || $arg0[$i] > 0x7e
97 printf "%c", $arg0[$i]
103 define print_bkt_datacol
104 # arg0 == column name
107 # arg3 == suppress header?
108 set $suppressheader = $arg3
120 define dump_bucket_ex
122 # arg1 == suppress header?
123 set $bucket = (struct apr_bucket *)$arg0
127 print_bkt_datacol "bucket" "%-9s" $bucket->type->name $sh
128 printf "(0x%08lx)", (unsigned long)$bucket
129 print_bkt_datacol "length" "%-6ld" (long)($bucket->length) $sh
130 print_bkt_datacol "data" "0x%08lx" $bucket->data $sh
136 if (($bucket->type == &apr_bucket_type_eos) || \
137 ($bucket->type == &apr_bucket_type_flush))
139 # metadata buckets, no content
140 print_bkt_datacol "contents" "%c" ' ' $sh
142 print_bkt_datacol "rc" "n/%c" 'a' $sh
145 if ($bucket->type == &ap_bucket_type_error)
147 # metadata bucket, no content but it does have an error code in it
148 print_bkt_datacol "contents" "%c" ' ' $sh
149 set $status = ((ap_bucket_error *)$bucket->data)->status
150 printf " (status=%3d) ", $status
151 print_bkt_datacol "rc" "n/%c" 'a' $sh
154 if (($bucket->type == &apr_bucket_type_file) || \
155 ($bucket->type == &apr_bucket_type_pipe) || \
156 ($bucket->type == &apr_bucket_type_socket))
158 # buckets that contain data not in memory (ie not printable)
160 print_bkt_datacol "contents" "[**unprintable**%c" ']' $sh
162 if $bucket->type == &apr_bucket_type_file
163 set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
164 print_bkt_datacol "rc" "%d" $refcount $sh
168 if (($bucket->type == &apr_bucket_type_heap) || \
169 ($bucket->type == &apr_bucket_type_pool) || \
170 ($bucket->type == &apr_bucket_type_mmap) || \
171 ($bucket->type == &apr_bucket_type_transient) || \
172 ($bucket->type == &apr_bucket_type_immortal))
176 if $bucket->type == &apr_bucket_type_heap
177 set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
178 set $p = (apr_bucket_heap *)$bucket->data
179 set $data = $p->base+$bucket->start
182 if $bucket->type == &apr_bucket_type_pool
183 set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
184 set $p = (apr_bucket_pool *)$bucket->data
186 set $p = (apr_bucket_heap *)$bucket->data
188 set $data = $p->base+$bucket->start
191 if $bucket->type == &apr_bucket_type_mmap
192 # is this safe if not APR_HAS_MMAP?
193 set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
194 set $p = (apr_bucket_mmap *)$bucket->data
195 set $data = ((char *)$p->mmap->mm)+$bucket->start
198 if (($bucket->type == &apr_bucket_type_transient) || \
199 ($bucket->type == &apr_bucket_type_immortal))
200 set $data = ((char *)$bucket->data)+$bucket->start
212 set $datalen = $bucket->length
218 printmemn $data $datalen
223 set $datalen = $datalen + 1
227 print_bkt_datacol "rc" "%d" $refcount $sh
229 print_bkt_datacol "rc" "n/%c" 'a' $sh
233 # 3rd-party bucket type
234 print_bkt_datacol "contents" "[**unknown**%c" ']' $sh
236 print_bkt_datacol "rc" "n/%c" 'a' $sh
247 dump_bucket_ex $arg0 0
254 set $bb = (apr_bucket_brigade *)$arg0
255 set $bucket = $bb->list.next
256 set $sentinel = ((char *)((&($bb->list)) \
257 - ((size_t) &((struct apr_bucket *)0)->link)))
258 printf "dump of brigade 0x%lx\n", (unsigned long)$bb
260 printf " | type (address) | length | "
261 printf "data addr | contents | rc\n"
262 printf "----------------------------------------"
263 printf "----------------------------------------\n"
265 if $bucket == $sentinel
266 printf "brigade is empty\n"
270 while $bucket != $sentinel
272 dump_bucket_ex $bucket 1
274 set $bucket = $bucket->link.next
276 printf "end of brigade\n"
278 document dump_brigade
279 Print bucket brigade info
285 printf "%s(0x%lx): ctx=0x%lx, r=0x%lx, c=0x%lx\n", \
286 $f->frec->name, (unsigned long)$f, (unsigned long)$f->ctx, \
291 document dump_filters
292 Print filter chain info
295 define dump_filter_chain
297 set $f = $r->output_filters
299 if $f == $r->output_filters
300 printf "r->output_filters =>\n"
302 if $f == $r->proto_output_filters
303 printf "r->proto_output_filters =>\n"
305 if $f == $r->connection->output_filters
306 printf "r->connection->output_filters =>\n"
309 printf " %s(0x%lx): type=%d, ctx=0x%lx, r=%s(0x%lx), c=0x%lx\n", \
310 $f->frec->name, (unsigned long)$f, $f->frec->ftype, (unsigned long)$f->ctx, \
311 $f->r == $r ? "r" : ($f->r == 0L ? "null" : \
312 ($f->r == $r->main ? "r->main" : \
313 ($r->main && $f->r == $r->main->main ? "r->main->main" : "????"))), \
319 document dump_filter_chain
320 Print filter chain info given a request_rec pointer
323 define dump_process_rec
325 printf "process_rec=0x%lx:\n", (unsigned long)$p
326 printf " pool=0x%lx, pconf=0x%lx\n", \
327 (unsigned long)$p->pool, (unsigned long)$p->pconf
329 document dump_process_rec
330 Print process_rec info
333 define dump_server_addr_recs
337 ### need to call apr_sockaddr_info_getbuf to print ->host_addr properly
338 ### which is a PITA since we need a buffer :(
339 printf " addr#%d: vhost=%s -> :%d\n", $san_++, $sa_->virthost, $sa_->host_port
340 set $sa_ = $sa_->next
343 document dump_server_addr_recs
344 Print server_addr_rec info
348 define dump_server_rec
350 printf "name=%s:%d (0x%lx)\n", \
351 $s->server_hostname, $s->port, $s
352 dump_server_addr_recs $s->addrs
353 dump_process_rec($s->process)
355 document dump_server_rec
356 Print server_rec info
367 document dump_servers
368 Print server_rec list info
371 define dump_request_tree
375 printf "r=(0x%lx): uri=%s, handler=%s, r->main=0x%lx\n", \
376 $r, $r->unparsed_uri, $r->handler ? $r->handler : "(none)", $r->main
381 define dump_allocator
382 printf "Allocator current_free_index = %d, max_free_index = %d\n", \
383 ($arg0)->current_free_index, ($arg0)->max_free_index
384 printf "Allocator free list:\n"
386 set $max =(sizeof $arg0->free)/(sizeof $arg0->free[0])
389 set $node = $arg0->free[$i]
393 printf "%d, ", ($node->index + 1) << 12
394 set $kb = $kb + (($node->index + 1) << 2)
395 set $node = $node->next
401 printf "Sum of free blocks: %dkiB\n", $kb
403 document dump_allocator
404 Print status of an allocator and its freelists.
412 set $node = $arg0->active
415 set $size = $size + (($node->index + 1) << 12)
416 set $free = $free + ($node->endp - $node->first_avail)
417 set $nodes = $nodes + 1
418 set $node = $node->next
419 if $node == $arg0->active
429 printf "' [%p]: %d/%d free (%d blocks)\n", $p, $free, $size, $nodes
432 define dump_all_pools
435 set $root = $root->parent
437 dump_pool_and_children $root
439 document dump_all_pools
440 Dump the whole pool hierarchy starting from apr_global_pool. Requires an arbitrary pool as starting parameter.
445 from __future__ import print_function
447 class DumpPoolAndChilds (gdb.Command):
448 """Dump the whole pool hierarchy starting from the given pool."""
451 super (DumpPoolAndChilds, self).__init__ ("dump_pool_and_children", gdb.COMMAND_USER)
453 def _allocator_free_blocks(self, alloc):
454 salloc = "%s" % (alloc)
455 if self.total_free_blocks.get(salloc) != None:
456 return self.total_free_blocks[salloc]
458 dalloc = alloc.dereference()
459 max =(dalloc['free'].type.sizeof)/(dalloc['free'][0].type.sizeof)
462 node = dalloc['free'][i]
465 noded = node.dereference()
466 kb = kb + ((int(noded['index']) + 1) << 2)
469 self.total_free_blocks[salloc] = kb
473 def _dump_one_pool(self, arg):
477 darg = arg.dereference()
478 active = darg['active']
482 noded = node.dereference()
483 size = size + ((int(noded['index']) + 1) << 12)
484 free = free + (noded['endp'] - noded['first_avail'])
490 tag = darg['tag'].string()
493 print("Pool '%s' [%s]: %d/%d free (%d blocks) allocator: %s free blocks in allocator: %i kiB" % (tag, arg, free, size, nodes, darg['allocator'], self._allocator_free_blocks(darg['allocator'])))
494 self.free = self.free + free
495 self.size = self.size + size
496 self.nodes = self.nodes + nodes
498 def _dump(self, arg, depth):
500 print("%*c" % (depth * 4 + 1, " "), end="")
501 self._dump_one_pool(pool)
502 if pool['child'] != 0:
503 self._dump(pool['child'], depth + 1)
508 def invoke (self, arg, from_tty):
509 pool = gdb.parse_and_eval(arg)
513 self.total_free_blocks = {}
515 print("Total %d/%d free (%d blocks)" % (self.free, self.size, self.nodes))
517 for key in self.total_free_blocks:
518 sum = sum + self.total_free_blocks[key]
519 print("Total free allocator blocks: %i kiB" % (sum))
523 document dump_pool_and_children
524 Dump the whole pool hierarchy starting from the given pool.
527 # Set sane defaults for common signals:
528 handle SIGPIPE noprint pass nostop
529 handle SIGUSR1 print pass nostop