]> granicus.if.org Git - apache/blob - .gdbinit
fix bld break in r1831165
[apache] / .gdbinit
1 # gdb macros which may be useful for folks using gdb to debug
2 # apache.  Delete it if it bothers you.
3
4 define dump_table
5     set $t = (apr_table_entry_t *)((apr_array_header_t *)$arg0)->elts
6     set $n = ((apr_array_header_t *)$arg0)->nelts
7     set $i = 0
8     while $i < $n
9         if $t[$i].val == (void *)0L
10            printf "[%u] '%s'=>NULL\n", $i, $t[$i].key
11         else
12            printf "[%u] '%s'='%s' [%p]\n", $i, $t[$i].key, $t[$i].val, $t[$i].val
13         end
14         set $i = $i + 1
15     end
16 end
17 document dump_table
18     Print the key/value pairs in a table.
19 end
20
21 define dump_skiplist
22     set $sl = (apr_skiplist *)$arg0
23     set $m = $sl->bottom
24     printf "skiplist@%p: size=%lu: height=%d\n", $sl, $sl->size, $sl->height
25     while ($m)
26         printf "(%p,%.12lx)", $m, $m->data
27         set $u = $m->up
28         while ($u)
29             printf " (%p,%.12lx)", $u, $u->data
30             set $u = $u->up
31         end
32         printf "\n"
33         set $m = $m->next
34     end
35 end
36 document dump_skiplist
37     Print the nodes/values in a skiplist
38 end
39
40 define dump_string_hash
41     set $h = $arg0->array
42     set $n = $arg0->max
43     set $i = 0
44     while $i < $n
45         set $ent = $h[$i]       
46         while $ent != (void *)0L
47             printf "'%s' => '%p'\n", $ent->key, $ent->val
48             set $ent = $ent->next
49         end
50         set $i = $i + 1
51     end
52 end
53 document dump_string_hash
54     Print the entries in a hash table indexed by strings
55 end
56
57 define dump_string_shash
58     set $h = $arg0->array
59     set $n = $arg0->max
60     set $i = 0
61     while $i < $n
62         set $ent = $h[$i]       
63         while $ent != (void *)0L
64             printf "'%s' => '%s'\n", $ent->key, $ent->val
65             set $ent = $ent->next
66         end
67         set $i = $i + 1
68     end
69 end
70 document dump_string_shash
71     Print the entries in a hash table indexed by strings with string values
72 end
73
74 define ro
75         run -DONE_PROCESS
76 end
77
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
81     set $i = 0
82     while $i < $n
83         printf "[%u] '%s'\n", $i, $a[$i]
84         set $i = $i + 1
85     end
86 end
87 document dump_string_array
88     Print all of the elements in an array of strings.
89 end
90
91 define printmemn
92     set $i = 0
93     while $i < $arg1
94         if $arg0[$i] < 0x20 || $arg0[$i] > 0x7e
95             printf "~"
96         else
97             printf "%c", $arg0[$i]
98         end
99         set $i = $i + 1
100     end
101 end
102
103 define print_bkt_datacol
104     # arg0 == column name
105     # arg1 == format
106     # arg2 == value
107     # arg3 == suppress header?
108     set $suppressheader = $arg3
109
110     if !$suppressheader
111         printf " "
112         printf $arg0
113         printf "="
114     else
115         printf " | "
116     end
117     printf $arg1, $arg2
118 end
119
120 define dump_bucket_ex
121     # arg0 == bucket
122     # arg1 == suppress header?
123     set $bucket = (struct apr_bucket *)$arg0
124     set $sh = $arg1
125     set $refcount = -1
126
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
131
132     if !$sh
133         printf "\n    "
134     end
135
136     if (($bucket->type == &apr_bucket_type_eos)   || \
137         ($bucket->type == &apr_bucket_type_flush))
138
139         # metadata buckets, no content
140         print_bkt_datacol "contents" "%c" ' ' $sh
141         printf "                     "
142         print_bkt_datacol "rc" "n/%c" 'a' $sh
143
144     else
145     if ($bucket->type == &ap_bucket_type_error)
146
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
152
153     else
154     if (($bucket->type == &apr_bucket_type_file) || \
155         ($bucket->type == &apr_bucket_type_pipe) || \
156         ($bucket->type == &apr_bucket_type_socket))
157
158         # buckets that contain data not in memory (ie not printable)
159
160         print_bkt_datacol "contents" "[**unprintable**%c" ']' $sh
161         printf "     "
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
165         end
166
167     else
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))
173
174         # in-memory buckets
175
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
180
181         else
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
185             if !$p->pool
186                 set $p = (apr_bucket_heap *)$bucket->data
187             end
188             set $data = $p->base+$bucket->start
189
190         else
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
196
197         else
198         if (($bucket->type == &apr_bucket_type_transient) || \
199             ($bucket->type == &apr_bucket_type_immortal))
200             set $data = ((char *)$bucket->data)+$bucket->start
201
202         end
203         end
204         end
205         end
206
207         if $sh
208             printf " | ["
209         else
210             printf " contents=["
211         end
212         set $datalen = $bucket->length
213         if $datalen > 17
214             printmem $data 17
215             printf "..."
216             set $datalen = 20
217         else
218             printmemn $data $datalen
219         end
220         printf "]"
221         while $datalen < 20
222             printf " "
223             set $datalen = $datalen + 1
224         end
225
226         if $refcount != -1
227             print_bkt_datacol "rc" "%d" $refcount $sh
228         else
229             print_bkt_datacol "rc" "n/%c" 'a' $sh
230         end
231
232     else
233         # 3rd-party bucket type
234         print_bkt_datacol "contents" "[**unknown**%c" ']' $sh
235         printf "         "
236         print_bkt_datacol "rc" "n/%c" 'a' $sh
237     end
238     end
239     end
240     end
241
242     printf "\n"
243
244 end
245
246 define dump_bucket
247     dump_bucket_ex $arg0 0
248 end
249 document dump_bucket
250     Print bucket info
251 end
252
253 define dump_brigade
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
259
260     printf "   | type     (address)    | length | "
261     printf "data addr  | contents               | rc\n"
262     printf "----------------------------------------"
263     printf "----------------------------------------\n"
264
265     if $bucket == $sentinel
266         printf "brigade is empty\n"
267     end
268
269     set $j = 0
270     while $bucket != $sentinel
271         printf "%2d", $j
272         dump_bucket_ex $bucket 1
273         set $j = $j + 1
274         set $bucket = $bucket->link.next
275     end
276     printf "end of brigade\n"
277 end
278 document dump_brigade
279     Print bucket brigade info
280 end
281
282 define dump_filters
283     set $f = $arg0
284     while $f
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, \
287         $f->r, $f->c
288         set $f = $f->next
289     end
290 end
291 document dump_filters
292     Print filter chain info
293 end
294
295 define dump_filter_chain
296     set $r = $arg0
297     set $f = $r->output_filters
298     while $f
299         if $f == $r->output_filters
300             printf "r->output_filters =>\n"
301         end
302         if $f == $r->proto_output_filters
303             printf "r->proto_output_filters =>\n"
304         end
305         if $f == $r->connection->output_filters
306             printf "r->connection->output_filters =>\n"
307         end
308         
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" : "????"))), \
314           $f->r, $f->c
315
316         set $f = $f->next
317     end
318 end
319 document dump_filter_chain
320     Print filter chain info given a request_rec pointer
321 end
322
323 define dump_process_rec
324     set $p = $arg0
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
328 end
329 document dump_process_rec
330     Print process_rec info
331 end
332
333 define dump_server_addr_recs
334     set $sa_ = $arg0
335     set $san_ = 0
336     while $sa_
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
341     end
342 end
343 document dump_server_addr_recs
344     Print server_addr_rec info
345 end
346
347
348 define dump_server_rec
349     set $s = $arg0
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)
354 end
355 document dump_server_rec
356     Print server_rec info
357 end
358
359 define dump_servers
360     set $s = $arg0
361     while $s
362         dump_server_rec($s)
363         printf "\n"
364         set $s = $s->next
365     end
366 end
367 document dump_servers
368     Print server_rec list info
369 end
370
371 define dump_request_tree
372     set $r = $arg0
373     set $i
374     while $r
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
377         set $r = $r->main
378     end
379 end        
380
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"
385     set $i = 0
386     set $max =(sizeof $arg0->free)/(sizeof $arg0->free[0])
387     set $kb = 0
388     while $i < $max
389         set $node = $arg0->free[$i]
390         if $node != 0
391             printf " #%2d: ", $i
392             while $node != 0
393                 printf "%d, ", ($node->index + 1) << 12
394                 set $kb = $kb + (($node->index + 1) << 2)
395                 set $node = $node->next
396             end
397             printf "ends.\n"
398         end
399         set $i = $i + 1
400     end
401     printf "Sum of free blocks: %dkiB\n", $kb
402 end
403 document dump_allocator
404     Print status of an allocator and its freelists.
405 end
406
407 define dump_one_pool
408     set $p = $arg0
409     set $size = 0
410     set $free = 0
411     set $nodes = 0
412     set $node = $arg0->active
413     set $done = 0
414     while $done == 0
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
420             set $done = 1
421         end
422     end
423     printf "Pool '"
424     if $p->tag
425         printf "%s", $p->tag
426     else
427         printf "no tag"
428     end
429     printf "' [%p]: %d/%d free (%d blocks)\n", $p, $free, $size, $nodes
430 end
431
432 define dump_all_pools
433     set $root = $arg0
434     while $root->parent
435         set $root = $root->parent
436     end
437     dump_pool_and_children $root
438 end
439 document dump_all_pools
440     Dump the whole pool hierarchy starting from apr_global_pool. Requires an arbitrary pool as starting parameter.
441 end
442
443 python
444
445 from __future__ import print_function
446
447 class DumpPoolAndChilds (gdb.Command):
448   """Dump the whole pool hierarchy starting from the given pool."""
449
450   def __init__ (self):
451     super (DumpPoolAndChilds, self).__init__ ("dump_pool_and_children", gdb.COMMAND_USER)
452
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]
457     i = 0
458     dalloc = alloc.dereference()
459     max =(dalloc['free'].type.sizeof)/(dalloc['free'][0].type.sizeof)
460     kb = 0
461     while i < max:
462       node = dalloc['free'][i]
463       if node != 0:
464         while node != 0:
465           noded = node.dereference()
466           kb = kb + ((int(noded['index']) + 1) << 2)
467           node = noded['next']
468       i = i + 1
469     self.total_free_blocks[salloc] = kb
470     return kb
471
472
473   def _dump_one_pool(self, arg):
474     size = 0
475     free = 0
476     nodes = 0
477     darg = arg.dereference()
478     active = darg['active']
479     node = active
480     done = 0
481     while done == 0:
482       noded = node.dereference()
483       size = size + ((int(noded['index']) + 1) << 12)
484       free = free + (noded['endp'] - noded['first_avail'])
485       nodes = nodes + 1
486       node = noded['next']
487       if node == active:
488         done = 1
489     if darg['tag'] != 0:
490       tag = darg['tag'].string()
491     else:
492       tag = "No tag"
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
497
498   def _dump(self, arg, depth):
499     pool = arg
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)
504     s = pool['sibling']
505     if s != 0:
506       self._dump(s, depth)
507
508   def invoke (self, arg, from_tty):
509     pool = gdb.parse_and_eval(arg)
510     self.free = 0
511     self.size = 0
512     self.nodes = 0
513     self.total_free_blocks = {}
514     self._dump(pool, 0)
515     print("Total %d/%d free (%d blocks)" % (self.free, self.size, self.nodes))
516     sum = 0
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))
520
521 DumpPoolAndChilds ()
522 end
523 document dump_pool_and_children
524     Dump the whole pool hierarchy starting from the given pool.
525 end
526
527 # Set sane defaults for common signals:
528 handle SIGPIPE noprint pass nostop
529 handle SIGUSR1 print pass nostop