lib.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. # GDB macros for use with Quagga.
  2. #
  3. # Macros in this file are not daemon specific. E.g., OS or Quagga library
  4. # APIs.
  5. #
  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.
  9. #
  10. # E.g.:
  11. #
  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.
  15. # (gdb) cont
  16. # ...
  17. # (gdb) cont
  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
  21. # IPv4:10.1.1.0/24
  22. # (gdb) dump_prefix &adv->rn->p
  23. # IPv4:10.1.1.0/24
  24. #
  25. define def_ntohs
  26. set $data = (char *)$arg0
  27. set $i = 0
  28. set $_ = $data[$i++] << 8
  29. set $_ += $data[$i++]
  30. end
  31. document def_ntohs
  32. Read a 2-byte short at the given pointed to area as big-endian and
  33. return it in $_
  34. Argument: Pointer to a 2-byte, big-endian short word.
  35. Returns: Integer value of that word in $_
  36. end
  37. define def_ntohl
  38. set $data = (char *)$arg0
  39. set $i = 0
  40. set $_ = $data[$i++] << 24
  41. set $_ += $data[$i++] << 16
  42. set $_ += $data[$i++] << 8
  43. set $_ += $data[$i++]
  44. end
  45. document def_ntohl
  46. Read a 4-byte integer at the given pointed to area as big-endian and
  47. return it in $_
  48. Argument: Pointer to a big-endian 4-byte word.
  49. Returns: Integer value of that word in $_
  50. end
  51. # NB: This is in more complicated iterative form, rather than more
  52. # conventional and simpler recursive form, because GDB has a recursion limit
  53. # on macro calls (I think).
  54. define walk_route_table_next
  55. # callee saves
  56. set $_top = $top
  57. set $_node = $node
  58. set $_prevl = $prevl
  59. set $top = (struct route_node *)$arg0
  60. set $node = (struct route_node *)$arg1
  61. set $prevl = $node
  62. # first try left
  63. #echo try left\n
  64. set $node = $prevl->link[0]
  65. # otherwise try right
  66. if ($node == 0)
  67. #echo left null, try right\n
  68. set $node = $prevl->link[1]
  69. end
  70. # otherwise go up, till we find the first right that
  71. # we havn't been to yet
  72. if ($node == 0)
  73. set $node = $prevl
  74. while ($node != $top)
  75. #echo right null, try up and right\n
  76. set $prevl = $node
  77. set $parent = $node->parent
  78. set $node = $parent->link[1]
  79. if ($node != 0 && $node != $prevl)
  80. #echo found node \n
  81. loop_break
  82. end
  83. #echo go up\n
  84. set $node = $parent
  85. end
  86. end
  87. #printf "next node: 0x%x\n", $node
  88. set $_ = $node
  89. set $top = $_top
  90. set $node = $_node
  91. set $prevl = $_prevl
  92. end
  93. document walk_route_table_next
  94. Return the next node to visit in the given route_table (or subset of) and
  95. the given current node.
  96. Arguments:
  97. 1st: (struct route_node *) to the top of the route_table to walk
  98. 2nd: (struct route_node *) to the current node
  99. Returns: The (struct route_node *) for the next to visit in $_
  100. end
  101. define walk_route_table
  102. set $_visited = $visited
  103. set $_node = $node
  104. set $top = $_top
  105. set $node = (struct route_node *)$arg0
  106. set $top = (struct route_node *)$arg0
  107. set $visited = 0
  108. while ($node != 0)
  109. printf "Node: 0x%x", $node
  110. if ($node->info != 0)
  111. printf "\tinfo: 0x%x", $node->info
  112. set $visited = $visited + 1
  113. end
  114. printf "\n"
  115. walk_route_table_next $top $node
  116. set $node = $_
  117. # we've gotten back to the top, finish
  118. if ($node == $top)
  119. set $node = 0
  120. end
  121. end
  122. printf "Visited: %u\n", $visited
  123. set $top = $_top
  124. set $visited = $_visited
  125. set $node = $_node
  126. end
  127. document walk_route_table
  128. Walk through a routing table (or subset thereof) and dump all the non-null
  129. (struct route_node *)->info pointers.
  130. Argument: A lib/thread.h::(struct route_node *) pointing to the route_node
  131. under which all data should be dumped
  132. end
  133. define dump_timeval
  134. set $tv = (struct timeval *)$arg0
  135. set $day = 3600*24
  136. if $tv->tv_sec > $day
  137. printf "%d days, ", $tv->tv_sec / $day
  138. end
  139. if $tv->tv_sec > 3600
  140. printf "%dh", $tv->tv_sec / 3600
  141. end
  142. if ($tv->tv_sec % 3600) > 60
  143. printf "%dm", ($tv->tv_sec % 3600) / 60
  144. end
  145. printf "%d", $tv->tv_sec % 3600 % 60
  146. if $tv->tv_usec != 0
  147. printf ".%06d", $tv->tv_usec
  148. end
  149. printf "s"
  150. end
  151. document dump_timeval
  152. Human readable dump of a (struct timeval *) argument
  153. end
  154. define dump_s_addr
  155. set $addr = (char *)$arg0
  156. printf "%d.%d.%d.%d", $addr[0], $addr[1], $addr[2], $addr[3]
  157. end
  158. define dump_s6_addr
  159. set $a6 = (char *)$arg0
  160. set $field = 0
  161. while ($field < 16)
  162. set $i1 = $field++
  163. set $i2 = $field++
  164. printf "%x%x", $a6[$i1], $a6[$i2]
  165. if ($field > 2 && ($field % 4 == 0))
  166. printf ":"
  167. end
  168. end
  169. end
  170. document dump_s6_addr
  171. Interpret the memory starting at given address as an IPv6 s6_addr and
  172. print in human readable form.
  173. end
  174. define dump_prefix4
  175. set $p = (struct prefix *) $arg0
  176. echo IPv4:
  177. dump_s_addr &($p->u.prefix4)
  178. printf "/%d\n", $p->prefixlen
  179. end
  180. document dump_prefix4
  181. Textual dump of a (struct prefix4 *) argument.
  182. end
  183. define dump_prefix6
  184. set $p = (struct prefix *) $arg0
  185. echo IPv6:
  186. dump_s6_addr &($p->u.prefix6)
  187. printf "/%d\n", $p->prefixlen
  188. end
  189. document dump_prefix6
  190. Textual dump of a (struct prefix6 *) argument.
  191. end
  192. define dump_prefix
  193. set $p = $arg0
  194. if ($p->family == 2)
  195. dump_prefix4 $p
  196. end
  197. if ($p->family == 10)
  198. dump_prefix6 $p
  199. end
  200. end
  201. document dump_prefix
  202. Human readable dump of a (struct prefix *) argument.
  203. end
  204. define rn_next_down
  205. set $node = $arg0
  206. while ($node != 0)
  207. print/x $node
  208. if ($node->link[0] != 0)
  209. set $node = $node->link[0]
  210. else
  211. set $node = $node->link[1]
  212. end
  213. end
  214. end
  215. document rn_next_down
  216. Walk left-down a given route table, dumping locations of route_nodes
  217. Argument: A single (struct route_node *).
  218. end
  219. define rn_next_up
  220. set $top = (struct route_node *)$arg0
  221. set $node = (struct route_node *)$arg1
  222. while ($node != $top)
  223. echo walk up\n
  224. set $prevl = $node
  225. set $parent = $node->parent
  226. set $node = $parent->link[1]
  227. if ($node != 0 && $node != $prevl)
  228. echo found a node\n
  229. loop_break
  230. end
  231. echo going up\n
  232. set $node = $parent
  233. end
  234. output/x $node
  235. echo \n
  236. end
  237. document rn_next_up
  238. Walk up-and-right from the given route_node to the next valid route_node
  239. which is not the given "top" route_node
  240. Arguments:
  241. 1st: A (struct route_node *) to the top of the route table.
  242. 2nd: The (struct route_node *) to walk up from
  243. end