1 # GDB macros for use with Quagga.
3 # Macros in this file are not daemon specific. E.g., OS or Quagga library
6 # The macro file can be loaded with 'source <filename>'. They can then be
7 # called by the user. Macros that explore more complicated structs generally
8 # take pointer arguments.
12 # (gdb) source ~paul/code/quagga/gdb/lib.txt
13 # (gdb) break bgp_packet.c:613
14 # Breakpoint 3 at 0x7fa883033a32: file bgp_packet.c, line 613.
18 # Breakpoint 3, bgp_write_packet (peer=0x7fa885199080) at bgp_packet.c:614
19 # 614 if (CHECK_FLAG (adv->binfo->peer->cap,PEER_CAP_RESTART_RCV)
20 # (gdb) dump_prefix4 &adv->rn->p
22 # (gdb) dump_prefix &adv->rn->p
28 set $data = (char *)$arg0
31 set $_ = $data[$i++] << 8
35 Read a 2-byte short at the given pointed to area as big-endian and
38 Argument: Pointer to a 2-byte, big-endian short word.
39 Returns: Integer value of that word in $_
43 set $data = (char *)$arg0
46 set $_ = $data[$i++] << 24
47 set $_ += $data[$i++] << 16
48 set $_ += $data[$i++] << 8
52 Read a 4-byte integer at the given pointed to area as big-endian and
55 Argument: Pointer to a big-endian 4-byte word.
56 Returns: Integer value of that word in $_
59 # NB: This is in more complicated iterative form, rather than more
60 # conventional and simpler recursive form, because GDB has a recursion limit
61 # on macro calls (I think).
62 define walk_route_table_next
68 set $top = (struct route_node *)$arg0
69 set $node = (struct route_node *)$arg1
74 set $node = $prevl->link[0]
78 #echo left null, try right\n
79 set $node = $prevl->link[1]
82 # otherwise go up, till we find the first right that
83 # we havn't been to yet
87 #echo right null, try up and right\n
90 set $parent = $node->parent
91 set $node = $parent->link[1]
93 if ($node != 0 && $node != $prevl)
103 #printf "next node: 0x%x\n", $node
111 document walk_route_table_next
112 Return the next node to visit in the given route_table (or subset of) and
113 the given current node.
116 1st: (struct route_node *) to the top of the route_table to walk
117 2nd: (struct route_node *) to the current node
119 Returns: The (struct route_node *) for the next to visit in $_
122 define walk_route_table
123 set $_visited = $visited
127 set $node = (struct route_node *)$arg0
128 set $top = (struct route_node *)$arg0
132 printf "Node: 0x%x", $node
134 if ($node->info != 0)
135 printf "\tinfo: 0x%x", $node->info
136 set $visited = $visited + 1
141 walk_route_table_next $top $node
144 # we've gotten back to the top, finish
149 printf "Visited: %u\n", $visited
152 set $visited = $_visited
156 document walk_route_table
157 Walk through a routing table (or subset thereof) and dump all the non-null
158 (struct route_node *)->info pointers.
160 Argument: A lib/thread.h::(struct route_node *) pointing to the route_node
161 under which all data should be dumped
165 set $tv = (struct timeval *)$arg0
168 if $tv->tv_sec > $day
169 printf "%d days, ", $tv->tv_sec / $day
171 if $tv->tv_sec > 3600
172 printf "%dh", $tv->tv_sec / 3600
174 if ($tv->tv_sec % 3600) > 60
175 printf "%dm", ($tv->tv_sec % 3600) / 60
177 printf "%d", $tv->tv_sec % 3600 % 60
179 printf ".%06d", $tv->tv_usec
183 document dump_timeval
184 Human readable dump of a (struct timeval *) argument
188 set $addr = (char *)$arg0
190 printf "%d.%d.%d.%d", $addr[0], $addr[1], $addr[2], $addr[3]
194 set $a6 = (char *)$arg0
201 printf "%x%x", $a6[$i1], $a6[$i2]
203 if ($field > 2 && ($field % 4 == 0))
208 document dump_s6_addr
209 Interpret the memory starting at given address as an IPv6 s6_addr and
210 print in human readable form.
214 set $p = (struct prefix *) $arg0
216 dump_s_addr &($p->u.prefix4)
217 printf "/%d\n", $p->prefixlen
219 document dump_prefix4
220 Textual dump of a (struct prefix4 *) argument.
224 set $p = (struct prefix *) $arg0
226 dump_s6_addr &($p->u.prefix6)
227 printf "/%d\n", $p->prefixlen
229 document dump_prefix6
230 Textual dump of a (struct prefix6 *) argument.
239 if ($p->family == 10)
244 Human readable dump of a (struct prefix *) argument.
251 if ($node->link[0] != 0)
252 set $node = $node->link[0]
254 set $node = $node->link[1]
259 document rn_next_down
260 Walk left-down a given route table, dumping locations of route_nodes
262 Argument: A single (struct route_node *).
266 set $top = (struct route_node *)$arg0
267 set $node = (struct route_node *)$arg1
269 while ($node != $top)
273 set $parent = $node->parent
274 set $node = $parent->link[1]
276 if ($node != 0 && $node != $prevl)
289 Walk up-and-right from the given route_node to the next valid route_node
290 which is not the given "top" route_node
293 1st: A (struct route_node *) to the top of the route table.
294 2nd: The (struct route_node *) to walk up from