]> granicus.if.org Git - apache/blob - .gdbinit
Introduce ap_(get|set)_core_module_config() functions/macros and use them
[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_string_hash
22     set $h = $arg0->array
23     set $n = $arg0->max
24     set $i = 0
25     while $i < $n
26         set $ent = $h[$i]       
27         while $ent != (void *)0L
28             printf "'%s' => '%p'\n", $ent->key, $ent->val
29             set $ent = $ent->next
30         end
31         set $i = $i + 1
32     end
33 end
34 document dump_string_hash
35     Print the entries in a hash table indexed by strings
36 end
37
38 define dump_string_shash
39     set $h = $arg0->array
40     set $n = $arg0->max
41     set $i = 0
42     while $i < $n
43         set $ent = $h[$i]       
44         while $ent != (void *)0L
45             printf "'%s' => '%s'\n", $ent->key, $ent->val
46             set $ent = $ent->next
47         end
48         set $i = $i + 1
49     end
50 end
51 document dump_string_shash
52     Print the entries in a hash table indexed by strings with string values
53 end
54
55 define ro
56         run -DONE_PROCESS
57 end
58
59 define dump_string_array
60     set $a = (char **)((apr_array_header_t *)$arg0)->elts
61     set $n = (int)((apr_array_header_t *)$arg0)->nelts
62     set $i = 0
63     while $i < $n
64         printf "[%u] '%s'\n", $i, $a[$i]
65         set $i = $i + 1
66     end
67 end
68 document dump_string_array
69     Print all of the elements in an array of strings.
70 end
71
72 define printmemn
73     set $i = 0
74     while $i < $arg1
75         if $arg0[$i] < 0x20 || $arg0[$i] > 0x7e
76             printf "~"
77         else
78             printf "%c", $arg0[$i]
79         end
80         set $i = $i + 1
81     end
82 end
83
84 define print_bkt_datacol
85     # arg0 == column name
86     # arg1 == format
87     # arg2 == value
88     # arg3 == suppress header?
89     set $suppressheader = $arg3
90
91     if !$suppressheader
92         printf " "
93         printf $arg0
94         printf "="
95     else
96         printf " | "
97     end
98     printf $arg1, $arg2
99 end
100
101 define dump_bucket_ex
102     # arg0 == bucket
103     # arg1 == suppress header?
104     set $bucket = (struct apr_bucket *)$arg0
105     set $sh = $arg1
106     set $refcount = -1
107
108     print_bkt_datacol "bucket" "%-9s" $bucket->type->name $sh
109     printf "(0x%08lx)", (unsigned long)$bucket
110     print_bkt_datacol "length" "%-6ld" (long)($bucket->length) $sh
111     print_bkt_datacol "data" "0x%08lx" $bucket->data $sh
112
113     if !$sh
114         printf "\n    "
115     end
116
117     if (($bucket->type == &apr_bucket_type_eos)   || \
118         ($bucket->type == &apr_bucket_type_flush))
119
120         # metadata buckets, no content
121         print_bkt_datacol "contents" "%c" ' ' $sh
122         printf "                     "
123         print_bkt_datacol "rc" "n/%c" 'a' $sh
124
125     else
126     if ($bucket->type == &ap_bucket_type_error)
127
128         # metadata bucket, no content but it does have an error code in it
129         print_bkt_datacol "contents" "%c" ' ' $sh
130         set $status = ((ap_bucket_error *)$bucket->data)->status
131         printf " (status=%3d)        ", $status
132         print_bkt_datacol "rc" "n/%c" 'a' $sh
133
134     else
135     if (($bucket->type == &apr_bucket_type_file) || \
136         ($bucket->type == &apr_bucket_type_pipe) || \
137         ($bucket->type == &apr_bucket_type_socket))
138
139         # buckets that contain data not in memory (ie not printable)
140
141         print_bkt_datacol "contents" "[**unprintable**%c" ']' $sh
142         printf "     "
143         if $bucket->type == &apr_bucket_type_file
144             set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
145             print_bkt_datacol "rc" "%d" $refcount $sh
146         end
147
148     else
149     if (($bucket->type == &apr_bucket_type_heap)      || \
150         ($bucket->type == &apr_bucket_type_pool)      || \
151         ($bucket->type == &apr_bucket_type_mmap)      || \
152         ($bucket->type == &apr_bucket_type_transient) || \
153         ($bucket->type == &apr_bucket_type_immortal))
154
155         # in-memory buckets
156
157         if $bucket->type == &apr_bucket_type_heap
158             set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
159             set $p = (apr_bucket_heap *)$bucket->data
160             set $data = $p->base+$bucket->start
161
162         else
163         if $bucket->type == &apr_bucket_type_pool
164             set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
165             set $p = (apr_bucket_pool *)$bucket->data
166             if !$p->pool
167                 set $p = (apr_bucket_heap *)$bucket->data
168             end
169             set $data = $p->base+$bucket->start
170
171         else
172         if $bucket->type == &apr_bucket_type_mmap
173             # is this safe if not APR_HAS_MMAP?
174             set $refcount = ((apr_bucket_refcount *)$bucket->data)->refcount
175             set $p = (apr_bucket_mmap *)$bucket->data
176             set $data = ((char *)$p->mmap->mm)+$bucket->start
177
178         else
179         if (($bucket->type == &apr_bucket_type_transient) || \
180             ($bucket->type == &apr_bucket_type_immortal))
181             set $data = ((char *)$bucket->data)+$bucket->start
182
183         end
184         end
185         end
186         end
187
188         if $sh
189             printf " | ["
190         else
191             printf " contents=["
192         end
193         set $datalen = $bucket->length
194         if $datalen > 17
195             printmem $data 17
196             printf "..."
197             set $datalen = 20
198         else
199             printmemn $data $datalen
200         end
201         printf "]"
202         while $datalen < 20
203             printf " "
204             set $datalen = $datalen + 1
205         end
206
207         if $refcount != -1
208             print_bkt_datacol "rc" "%d" $refcount $sh
209         else
210             print_bkt_datacol "rc" "n/%c" 'a' $sh
211         end
212
213     else
214         # 3rd-party bucket type
215         print_bkt_datacol "contents" "[**unknown**%c" ']' $sh
216         printf "         "
217         print_bkt_datacol "rc" "n/%c" 'a' $sh
218     end
219     end
220     end
221     end
222
223     printf "\n"
224
225 end
226
227 define dump_bucket
228     dump_bucket_ex $arg0 0
229 end
230 document dump_bucket
231     Print bucket info
232 end
233
234 define dump_brigade
235     set $bb = (apr_bucket_brigade *)$arg0
236     set $bucket = $bb->list.next
237     set $sentinel = ((char *)((&($bb->list)) \
238                                - ((size_t) &((struct apr_bucket *)0)->link)))
239     printf "dump of brigade 0x%lx\n", (unsigned long)$bb
240
241     printf "   | type     (address)    | length | "
242     printf "data addr  | contents               | rc\n"
243     printf "----------------------------------------"
244     printf "----------------------------------------\n"
245
246     if $bucket == $sentinel
247         printf "brigade is empty\n"
248     end
249
250     set $j = 0
251     while $bucket != $sentinel
252         printf "%2d", $j
253         dump_bucket_ex $bucket 1
254         set $j = $j + 1
255         set $bucket = $bucket->link.next
256     end
257     printf "end of brigade\n"
258 end
259 document dump_brigade
260     Print bucket brigade info
261 end
262
263 define dump_filters
264     set $f = $arg0
265     while $f
266         printf "%s(0x%lx): ctx=0x%lx, r=0x%lx, c=0x%lx\n", \
267         $f->frec->name, (unsigned long)$f, (unsigned long)$f->ctx, \
268         $f->r, $f->c
269         set $f = $f->next
270     end
271 end
272 document dump_filters
273     Print filter chain info
274 end
275
276 define dump_filter_chain
277     set $r = $arg0
278     set $f = $r->output_filters
279     while $f
280         if $f == $r->output_filters
281             printf "r->output_filters =>\n"
282         end
283         if $f == $r->proto_output_filters
284             printf "r->proto_output_filters =>\n"
285         end
286         if $f == $r->connection->output_filters
287             printf "r->connection->output_filters =>\n"
288         end
289         
290         printf "  %s(0x%lx): type=%d, ctx=0x%lx, r=%s(0x%lx), c=0x%lx\n", \
291           $f->frec->name, (unsigned long)$f, $f->frec->ftype, (unsigned long)$f->ctx, \
292           $f->r == $r ? "r" : ($f->r == 0L ? "null" : \
293           ($f->r == $r->main ? "r->main" :  \
294           ($r->main && $f->r == $r->main->main ? "r->main->main" : "????"))), \
295           $f->r, $f->c
296
297         set $f = $f->next
298     end
299 end
300 document dump_filter_chain
301     Print filter chain info given a request_rec pointer
302 end
303
304 define dump_process_rec
305     set $p = $arg0
306     printf "process_rec=0x%lx:\n", (unsigned long)$p
307     printf "   pool=0x%lx, pconf=0x%lx\n", \
308            (unsigned long)$p->pool, (unsigned long)$p->pconf
309 end
310 document dump_process_rec
311     Print process_rec info
312 end
313
314 define dump_server_rec
315     set $s = $arg0
316     printf "name=%s:%d\n", \
317             $s->server_hostname, $s->port
318     dump_process_rec($s->process)
319 end
320 document dump_server_rec
321     Print server_rec info
322 end
323
324 define dump_servers
325     set $s = $arg0
326     while $s
327         dump_server_rec($s)
328         printf "\n"
329         set $s = $s->next
330     end
331 end
332 document dump_servers
333     Print server_rec list info
334 end
335
336 define dump_request_tree
337     set $r = $arg0
338     set $i
339     while $r
340         printf "r=(0x%lx): uri=%s, handler=%s, r->main=0x%lx\n", \
341           $r, $r->unparsed_uri, $r->handler ? $r->handler : "(none)", $r->main
342         set $r = $r->main
343     end
344 end        
345
346 define dump_allocator
347     printf "Allocator current_free_index = %d, max_free_index = %d\n", \
348             ($arg0)->current_free_index, ($arg0)->max_free_index
349     printf "Allocator free list:\n"
350     set $i = 0
351     set $max =(sizeof $arg0->free)/(sizeof $arg0->free[0])
352     while $i < $max
353         set $node = $arg0->free[$i]
354         if $node != 0
355             printf " #%2d: ", $i
356             while $node != 0
357                 printf "%d, ", $node->endp - $node->first_avail
358                 set $node = $node->next
359             end
360             printf "ends.\n"
361         end
362         set $i = $i + 1
363     end
364 end
365 document dump_allocator
366     Print status of an allocator and its freelists.
367 end
368
369 # Set sane defaults for common signals:
370 handle SIGPIPE noprint pass nostop
371 handle SIGUSR1 print pass nostop