2 """ Please make sure you read the README COMPLETELY BEFORE reading anything below.
3 It is very critical that you read coding guidelines in Section E in README file.
12 from netdefines
import *
13 from routedefines
import *
15 def GetDlilIfFlagsAsString(dlil_if_flags
):
16 """ Return a formatted string description of the dlil interface flags
19 flags
= (unsigned
)(dlil_if_flags
& 0xffff)
24 out_string
+= dlil_if_flags_strings
[i
] + ","
27 return rstrip(out_string
, ",")
29 def GetIfFlagsAsString(if_flags
):
30 """ Return a formatted string description of the interface flags
33 flags
= (unsigned
)(if_flags
& 0xffff)
38 out_string
+= if_flags_strings
[i
] + ","
41 return rstrip(out_string
, ",")
44 def ShowIfConfiguration(ifnet
):
45 """ Display ifconfig-like output for the ifnet
47 iface
= Cast(ifnet
, 'ifnet *')
48 dlifnet
= Cast(ifnet
, 'dlil_ifnet *')
50 format_string
= "{0: <s}: flags={1: <x} <{2: <s}> index {3: <d} mtu {4: <d}"
52 out_string
+= format_string
.format(iface
.if_xname
, (iface
.if_flags
& 0xffff), GetIfFlagsAsString(iface
.if_flags
), iface
.if_index
, iface
.if_data
.ifi_mtu
)
53 out_string
+= "\n\tdlil flags=" + hex(dlifnet
.dl_if_flags
)+ " <" + GetDlilIfFlagsAsString(dlifnet
.dl_if_flags
) + ">"
54 out_string
+= "\n\t(struct ifnet *)" + hex(ifnet
)
55 if iface
.if_snd
.ifcq_len
:
56 out_string
+= "\n\t" + str(iface
.if_snd
.ifcq_len
)
57 if dlifnet
.dl_if_inpstorage
.rcvq_pkts
.qlen
:
58 out_string
+= "\n\t" + str(dlifnet
.dl_if_inpstorage
.rcvq_pkts
.qlen
)
61 def GetIfConfiguration(ifname
):
62 """ Return ifnet structure corresponding to the ifname passed in
65 ifnets
= kern
.globals.ifnet_head
66 for ifnet
in IterateTAILQ_HEAD(ifnets
, "if_link") :
67 if str(ifnet
.if_xname
) == ifname
:
71 # Macro: net_get_always_on_pktap
72 @lldb_command('net_get_always_on_pktap')
73 def NetGetAlwaysOnPktap(cmd_args
=None):
74 """ Dump the always-on packet capture to /tmp/dump.pktap
76 for i
in range(0, 10):
77 ifnet
= GetIfConfiguration("pktap"+str(i
))
83 if ifnet
.if_bpf
.bif_dlist
.bd_headdrop
== 0:
90 print "Could not find a pktap interface"
93 bpf_d
= ifnet
.if_bpf
.bif_dlist
95 f
= tempfile
.NamedTemporaryFile(prefix
="dump-", suffix
=".pktap", dir="/tmp/", mode
="wb", delete
=False)
99 if bpf_d
.bd_hbuf
!= 0:
100 addr
= bpf_d
.bd_hbuf
[0]._sbval
19k
84obscure
747.AddressOf().GetValueAsUnsigned()
101 buf
= LazyTarget
.GetProcess().ReadMemory(addr
, unsigned(bpf_d
.bd_hlen
), err
)
103 print "Error, getting sbuf"
106 addr
= bpf_d
.bd_sbuf
[0]._sbval
19k
84obscure
747.AddressOf().GetValueAsUnsigned()
107 buf
= LazyTarget
.GetProcess().ReadMemory(addr
, unsigned(bpf_d
.bd_slen
), err
)
109 print "Error, getting sbuf"
114 # EndMacro: net_get_always_on_pktap
117 @lldb_command('ifconfig')
118 def ShowIfconfig(cmd_args
=None) :
119 """ Display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
121 if cmd_args
!= None and len(cmd_args
) > 0:
126 ifnets
= kern
.globals.ifnet_head
127 for ifnet
in IterateTAILQ_HEAD(ifnets
, "if_link"):
128 ShowIfConfiguration(ifnet
)
130 print GetIfaddrs(ifnet
)
133 #Macro: ifconfig_dlil
134 @lldb_command('ifconfig_dlil')
135 def ShowIfconfigDlil(cmd_args
=None) :
136 """ Display ifconfig-like output for DLIL interface list, print (struct ifnet *) pointer and dlil info for further inspection
138 dlil_ifnets
= kern
.globals.dlil_ifnet_head
139 for dlil_ifnet
in IterateTAILQ_HEAD(dlil_ifnets
, "dl_if_link"):
140 ShowIfConfiguration(dlil_ifnet
)
141 print GetIfaddrs(Cast(dlil_ifnet
, 'ifnet *'))
142 # EndMacro: ifconfig_dlil
144 def GetAddressAsStringColonHex(addr
, count
):
147 addr_format_string
= "{0:02x}"
150 out_string
+= addr_format_string
.format(addr
[i
])[-2:]
152 out_string
+= ":" + addr_format_string
.format(addr
[i
])[-2:]
156 def GetSocketAddrAsStringUnspec(sockaddr
):
158 out_string
+= GetAddressAsStringColonHex(sockaddr
.sa_data
, sockaddr
.sa_len
- 2)
161 def GetSocketAddrAsStringUnix(sockaddr
):
162 sock_unix
= Cast(sockaddr
, 'sockaddr_un *')
166 if (len(str(sock_unix
.sun_path
)) > 0):
167 return str(sock_unix
.sun_path
)
171 def GetInAddrAsString(ia
):
173 inaddr
= Cast(ia
, 'in_addr *')
175 packed_value
= struct
.pack('I', unsigned(ia
.s_addr
))
176 out_string
= inet_ntoa(packed_value
)
179 def GetIn6AddrAsString(ia
):
183 addr_format_string
= "{0:02x}:{1:02x}:{2:02x}:{3:02x}{4:02x}:{5:02x}:{6:02x}:{7:02x}{8:02x}:{9:02x}:{10:02x}:{11:02x}{12:02x}:{13:02x}:{14:02x}:{15:02x}"
184 out_string
+= addr_format_string
.format(unsigned(addr
[0]), unsigned(addr
[1]), unsigned(addr
[2]), unsigned(addr
[3]), unsigned(addr
[4]), unsigned(addr
[5]), unsigned(addr
[6]), unsigned(addr
[7]), unsigned(addr
[8]), unsigned(addr
[9]), unsigned(addr
[10]), unsigned(addr
[11]), unsigned(addr
[12]), unsigned(addr
[13]), unsigned(addr
[14]), unsigned(addr
[15]))
187 def GetSocketAddrAsStringInet(sockaddr
):
188 sock_in
= Cast(sockaddr
, 'sockaddr_in *')
189 return GetInAddrAsString(addressof(sock_in
.sin_addr
))
191 def GetSocketAddrAsStringInet6(sockaddr
):
192 sock_in6
= Cast(sockaddr
, 'sockaddr_in6 *')
193 return GetIn6AddrAsString(sock_in6
.sin6_addr
.__u6_addr
.__u6_addr
8)
195 def GetSocketAddrAsStringLink(sockaddr
):
196 sock_link
= Cast(sockaddr
, 'sockaddr_dl *')
197 if sock_link
is None:
201 if (sock_link
.sdl_nlen
== 0 and sock_link
.sdl_alen
== 0 and sock_link
.sdl_slen
== 0):
202 out_string
= "link#" + str(int(sock_link
.sdl_index
))
204 out_string
+= GetAddressAsStringColonHex(addressof(sock_link
.sdl_data
[sock_link
.sdl_nlen
]), sock_link
.sdl_alen
)
207 def GetSocketAddrAsStringAT(sockaddr
):
209 sock_addr
= Cast(sockaddr
, 'sockaddr *')
210 out_string
+= GetAddressAsStringColonHex(sockaddr
.sa_data
, sockaddr
.sa_len
- 2)
213 def GetSocketAddrAsString(sockaddr
):
214 if sockaddr
is None :
217 if (sockaddr
.sa_family
== 0):
218 out_string
+= "UNSPC "
219 GetSocketAddrAsStringUnspec(sockaddr
)
220 elif (sockaddr
.sa_family
== 1):
221 out_string
+= "UNIX "
222 out_string
+= GetSocketAddrAsStringUnix(sockaddr
)
223 elif (sockaddr
.sa_family
== 2):
224 out_string
+= "INET "
225 out_string
+= GetSocketAddrAsStringInet(sockaddr
)
226 elif (sockaddr
.sa_family
== 30):
227 out_string
+= "INET6 "
228 out_string
+= GetSocketAddrAsStringInet6(sockaddr
)
229 elif (sockaddr
.sa_family
== 18):
230 out_string
+= "LINK "
231 out_string
+= GetSocketAddrAsStringLink(sockaddr
)
232 elif (sockaddr
.sa_family
== 16):
233 out_string
+= "ATLK "
234 out_string
+= GetSocketAddrAsStringAT(sockaddr
)
236 out_string
+= "FAM " + str(sockaddr
.sa_family
)
237 out_string
+= GetAddressAsStringColonHex(sockaddr
.sa_data
, sockaddr
.sa_len
)
241 @lldb_command('showifaddrs')
242 def ShowIfaddrs(cmd_args
=None):
243 """ Show the (struct ifnet).if_addrhead list of addresses for the given ifp
245 if cmd_args
!= None and len(cmd_args
) > 0 :
246 ifp
= kern
.GetValueFromAddress(cmd_args
[0], 'ifnet *')
248 print "Unknown value passed as argument."
251 for ifaddr
in IterateTAILQ_HEAD(ifp
.if_addrhead
, "ifa_link"):
252 format_string
= "\t{0: <d}: 0x{1: <x} {2: <s} [{3: <d}]"
253 print format_string
.format(i
, ifaddr
, GetSocketAddrAsString(ifaddr
.ifa_addr
), ifaddr
.ifa_refcnt
)
256 print "Missing argument 0 in user function."
257 # EndMacro: showifaddrs
263 for ifaddr
in IterateTAILQ_HEAD(ifp
.if_addrhead
, "ifa_link"):
264 format_string
= "\t{0: <d}: 0x{1: <x} {2: <s} [{3: <d}]"
265 out_string
+= format_string
.format(i
, ifaddr
, GetSocketAddrAsString(ifaddr
.ifa_addr
), ifaddr
.ifa_refcnt
) + "\n"
268 out_string
+= "Missing argument 0 in user function."
272 def GetCapabilitiesAsString(flags
):
273 """ Return a formatted string description of the interface flags
280 out_string
+= if_capenable_strings
[i
] + ","
283 return rstrip(out_string
, ",")
285 def GetIfEflagsAsString(if_eflags
):
286 """ Return a formatted string description of the interface flags
289 flags
= unsigned(if_eflags
)
294 out_string
+= if_eflags_strings
[i
] + ","
297 return rstrip(out_string
, ",")
299 def ShowDlilIfnetConfiguration(dlil_ifnet
, show_all
) :
300 """ Formatted display of dlil_ifnet structures
305 if dlil_ifnet
is None :
308 dlil_iface
= Cast(dlil_ifnet
, 'dlil_ifnet *')
309 iface
= Cast(dlil_ifnet
, 'ifnet *')
311 if (dlil_iface
.dl_if_flags
& DLIF_REUSE
) :
313 format_string
= "{0: <s}: flags={1: <x} <{2: <s}> index {3: <d} mtu {4: <d}"
314 extended_flags_format_string
= "\n\teflags={0: <x} <{1: <s}>"
315 capenabled_format_string
= "\n\toptions={0: <x} <{1: <s}>"
316 if (dlil_iface
.dl_if_flags
& DLIF_INUSE
) :
317 out_string
+= format_string
.format(iface
.if_xname
, (iface
.if_flags
& 0xffff), GetIfFlagsAsString(iface
.if_flags
), iface
.if_index
, iface
.if_data
.ifi_mtu
)
319 out_string
+= format_string
.format("[" + str(iface
.if_name
) + str(int(iface
.if_unit
)) + "]", (iface
.if_flags
& 0xffff), GetIfFlagsAsString(iface
.if_flags
), iface
.if_index
, iface
.if_data
.ifi_mtu
)
320 if (iface
.if_eflags
) :
321 out_string
+= extended_flags_format_string
.format(iface
.if_eflags
, GetIfEflagsAsString(iface
.if_eflags
))
322 if (iface
.if_capenable
) :
323 out_string
+= capenabled_format_string
.format(iface
.if_capenable
, GetCapabilitiesAsString(iface
.if_capenable
))
324 out_string
+= "\n\t(struct ifnet *)" + hex(dlil_ifnet
) + "\n"
326 out_string
+= GetIfaddrs(iface
)
331 @lldb_command('showifnets')
332 def ShowIfnets(cmd_args
=None) :
333 """ Display ifconfig-like output for all attached and detached interfaces
336 if cmd_args
!= None and len(cmd_args
) > 0 :
338 dlil_ifnets
= kern
.globals.dlil_ifnet_head
339 for dlil_ifnet
in IterateTAILQ_HEAD(dlil_ifnets
, "dl_if_link"):
340 ShowDlilIfnetConfiguration(dlil_ifnet
, showall
)
341 # EndMacro: showifnets
343 # Macro: showifmultiaddrs
344 @lldb_command('showifmultiaddrs')
345 def ShowIfMultiAddrs(cmd_args
=None) :
346 """ Show the list of multicast addresses for the given ifp
349 if cmd_args
!= None and len(cmd_args
) > 0 :
350 ifp
= kern
.GetValueFromAddress(cmd_args
[0], 'ifnet *')
352 print "Unknown value passed as argument."
354 ifmulti
= cast(ifp
.if_multiaddrs
.lh_first
, 'ifmultiaddr *')
357 ifma_format_string
= "\t{0: <d}: 0x{1: <x} "
358 out_string
+= (ifma_format_string
.format(i
+ 1, ifmulti
))
359 if (ifmulti
.ifma_addr
.sa_family
== 2):
360 if (ifmulti
.ifma_ll
!= 0):
361 out_string
+= GetSocketAddrAsStringLink(ifmulti
.ifma_ll
.ifma_addr
) + " "
362 out_string
+= GetSocketAddrAsStringInet(ifmulti
.ifma_addr
)
363 if (ifmulti
.ifma_addr
.sa_family
== 30):
364 if (ifmulti
.ifma_ll
!= 0):
365 out_string
+= GetSocketAddrAsStringLink(ifmulti
.ifma_ll
.ifma_addr
) + " "
366 out_string
+= GetSocketAddrAsStringInet6(ifmulti
.ifma_addr
) + " "
367 if (ifmulti
.ifma_addr
.sa_family
== 18):
368 out_string
+= GetSocketAddrAsStringLink(ifmulti
.ifma_addr
) + " "
369 if (ifmulti
.ifma_addr
.sa_family
== 0):
370 out_string
+= GetSocketAddrAsStringUnspec(ifmulti
.ifma_addr
) + " "
371 out_string
+= "[" + str(int(ifmulti
.ifma_refcount
)) + "]\n"
372 ifmulti
= cast(ifmulti
.ifma_link
.le_next
, 'ifmultiaddr *')
376 print "Missing argument 0 in user function."
377 # EndMacro: showifmultiaddrs
379 # Macro: showinmultiaddrs
380 @lldb_command('showinmultiaddrs')
381 def ShowInMultiAddrs(cmd_args
=None) :
382 """ Show the contents of IPv4 multicast address records
385 inmultihead
= kern
.globals.in_multihead
386 inmulti
= cast(inmultihead
.lh_first
, 'in_multi *')
389 ifp
= inmulti
.inm_ifp
390 inma_format_string
= "\t{0: <d}: 0x{1: <x} "
391 out_string
+= inma_format_string
.format(i
+ 1, inmulti
) + " "
392 out_string
+= GetInAddrAsString(addressof(inmulti
.inm_addr
)) + " "
393 ifma_format_string
= "(ifp 0x{0: <x} [{1: <s}] ifma {2: <x})"
394 out_string
+= ifma_format_string
.format(ifp
, ifp
.if_xname
, inmulti
.inm_ifma
) + "\n"
395 inmulti
= cast(inmulti
.inm_link
.le_next
, 'in_multi *')
398 # EndMacro: showinmultiaddrs
400 # Macro: showin6multiaddrs
401 @lldb_command('showin6multiaddrs')
402 def ShowIn6MultiAddrs(cmd_args
=None) :
403 """ Show the contents of IPv6 multicast address records
406 in6multihead
= kern
.globals.in6_multihead
407 in6multi
= cast(in6multihead
.lh_first
, 'in6_multi *')
410 ifp
= in6multi
.in6m_ifp
411 inma_format_string
= "\t{0: <d}: 0x{1: <x} "
412 out_string
+= inma_format_string
.format(i
+ 1, in6multi
) + " "
413 out_string
+= GetIn6AddrAsString((in6multi
.in6m_addr
.__u6_addr
.__u6_addr
8)) + " "
414 ifma_format_string
= "(ifp 0x{0: <x} [{1: <s}] ifma {2: <x})"
415 out_string
+= ifma_format_string
.format(ifp
, ifp
.if_xname
, in6multi
.in6m_ifma
) + "\n"
416 in6multi
= cast(in6multi
.in6m_entry
.le_next
, 'in6_multi *')
419 # EndMacro: showin6multiaddrs
421 def GetTcpState(tcpcb
):
423 tp
= Cast(tcpcb
, 'tcpcb *')
426 out_string
+= "CLOSED\t"
428 out_string
+= "LISTEN\t"
430 out_string
+= "SYN_SENT\t"
432 out_string
+= "SYN_RCVD\t"
434 out_string
+= "ESTABLISHED\t"
436 out_string
+= "CLOSE_WAIT\t"
438 out_string
+= "FIN_WAIT_1\t"
440 out_string
+= "CLOSING\t"
442 out_string
+= "LAST_ACK\t"
444 out_string
+= "FIN_WAIT_2\t"
446 out_string
+= "TIME_WAIT\t"
449 def GetSocketProtocolAsString(sock
):
451 inpcb
= Cast(sock
.so_pcb
, 'inpcb *')
452 if sock
.so_proto
.pr_protocol
== 6:
453 out_string
+= " TCP "
454 out_string
+= GetTcpState(inpcb
.inp_ppcb
)
455 if sock
.so_proto
.pr_protocol
== 17:
456 out_string
+= " UDP "
457 if sock
.so_proto
.pr_protocol
== 1:
458 out_string
+= " ICMP "
459 if sock
.so_proto
.pr_protocol
== 254:
460 out_string
+= " DIVERT "
461 if sock
.so_proto
.pr_protocol
== 255:
462 out_string
+= " RAW "
465 def GetInAddr4to6AsString(inaddr
):
467 if (inaddr
is not None):
468 ia
= Cast(inaddr
, 'unsigned char *')
469 inaddr_format_string
= "{0:d}:{1:d}:{2:d}:{3:d}"
470 out_string
+= inaddr_format_string
.format(unsigned(ia
[0]), unsigned(ia
[1]), unsigned(ia
[2]), unsigned(ia
[3]))
473 def GetInPortAsString(port
):
475 port_string
= Cast(port
, 'char *')
476 port_unsigned
= dereference(Cast(port
, 'unsigned short *'))
478 if ((((port_unsigned
& 0xff00) >> 8) == port_string
[0])) and (((port_unsigned
& 0x00ff) == port_string
[1])):
479 out_string
+= ":" + str(int(port_unsigned
))
481 out_string
+= ":" + str(int(((port_unsigned
& 0xff00) >> 8) |
((port_unsigned
& 0x00ff) << 8)))
485 def GetIPv4SocketAsString(sock
) :
487 pcb
= Cast(sock
.so_pcb
, 'inpcb *')
489 out_string
+= "inpcb: (null) "
491 out_string
+= "inpcb: " + hex(pcb
)
492 out_string
+= GetSocketProtocolAsString(sock
)
494 out_string
+= GetInAddr4to6AsString(addressof(pcb
.inp_dependladdr
.inp46_local
.ia46_addr4
))
495 out_string
+= GetInPortAsString(addressof(pcb
.inp_lport
))
497 out_string
+= GetInAddr4to6AsString(addressof(pcb
.inp_dependfaddr
.inp46_foreign
.ia46_addr4
))
498 out_string
+= GetInPortAsString(addressof(pcb
.inp_fport
))
501 def GetIPv6SocketAsString(sock
) :
503 pcb
= Cast(sock
.so_pcb
, 'inpcb *')
505 out_string
+= "inpcb: (null) "
507 out_string
+= "inpcb: " + hex(pcb
) + " "
508 out_string
+= GetSocketProtocolAsString(sock
)
510 out_string
+= GetIn6AddrAsString((pcb
.inp_dependladdr
.inp6_local
.__u6_addr
.__u6_addr
8))
511 out_string
+= GetInPortAsString(addressof(pcb
.inp_lport
))
513 out_string
+= GetIn6AddrAsString((pcb
.inp_dependfaddr
.inp6_foreign
.__u6_addr
.__u6_addr
8))
514 out_string
+= GetInPortAsString(addressof(pcb
.inp_fport
))
517 def GetUnixDomainSocketAsString(sock
) :
519 pcb
= Cast(sock
.so_pcb
, 'unpcb *')
521 out_string
+= "unpcb: (null) "
523 out_string
+= "unpcb: " + hex(pcb
) + " "
524 out_string
+= "unp_vnode: " + hex(pcb
.unp_vnode
) + " "
525 out_string
+= "unp_conn: " + hex(pcb
.unp_conn
) + " "
526 out_string
+= "unp_addr: " + GetSocketAddrAsStringUnix(pcb
.unp_addr
)
529 def GetSocket(socket
) :
530 """ Show the contents of a socket
532 so
= kern
.GetValueFromAddress(unsigned(socket
), 'socket *')
535 sock_format_string
= "so: 0x{0:<x}"
536 out_string
+= sock_format_string
.format(so
)
537 domain
= so
.so_proto
.pr_domain
538 domain_name_format_string
= " {0:<s} "
539 out_string
+= domain_name_format_string
.format(domain
.dom_name
)
540 if (domain
.dom_family
== 1):
541 out_string
+= GetUnixDomainSocketAsString(so
)
542 if (domain
.dom_family
== 2):
543 out_string
+= GetIPv4SocketAsString(so
)
544 if (domain
.dom_family
== 30):
545 out_string
+= GetIPv6SocketAsString(so
)
546 out_string
+= " s=" + str(int(so
.so_snd
.sb_cc
)) + " r=" + str(int(so
.so_rcv
.sb_cc
)) + " usecnt=" + str(int(so
.so_usecount
)) + "] "
548 out_string
+= "(null)"
550 # EndMacro: showsocket
554 @lldb_command('showsocket')
555 def ShowSocket(cmd_args
=None) :
556 """ Show the contents of a socket
558 if (cmd_args
== None or len(cmd_args
) == 0):
559 print "Missing argument 0 in user function."
561 so
= kern
.GetValueFromAddress(cmd_args
[0], 'socket *')
562 if (len(str(cmd_args
[0])) > 0):
564 sock_format_string
= "so: 0x{0:<x}"
565 out_string
+= sock_format_string
.format(so
)
566 domain
= so
.so_proto
.pr_domain
567 domain_name_format_string
= " {0:<s} "
568 out_string
+= domain_name_format_string
.format(domain
.dom_name
)
569 if (domain
.dom_family
== 1):
570 out_string
+= GetUnixDomainSocketAsString(so
)
571 if (domain
.dom_family
== 2):
572 out_string
+= GetIPv4SocketAsString(so
)
573 if (domain
.dom_family
== 30):
574 out_string
+= GetIPv6SocketAsString(so
)
577 print "Unknown value passed as argument."
579 # EndMacro: showsocket
581 def GetProcSockets(proc
, total_snd_cc
, total_rcv_cc
):
582 """ Given a proc_t pointer, display information about its sockets
587 out_string
+= "Unknown value passed as argument."
593 """struct filedesc *"""
594 proc_filedesc
= proc
.p_fd
595 """struct fileproc **"""
596 proc_ofiles
= proc_filedesc
.fd_ofiles
597 """ high-water mark of fd_ofiles """
598 proc_lastfile
= unsigned(proc_filedesc
.fd_lastfile
)
599 if proc_filedesc
.fd_nfiles
!= 0:
600 while count
<= proc_lastfile
:
601 if (unsigned(proc_ofiles
[count
]) != 0 and proc_ofiles
[count
].f_fglob
!= 0):
602 fg
= proc_ofiles
[count
].f_fglob
603 if (int(fg
.fg_ops
.fo_type
) == 2):
604 if (proc_filedesc
.fd_ofileflags
[count
] & 4):
608 out_string
+= "fd = " + str(count
) + " "
609 if (fg
.fg_data
!= 0):
610 out_string
+= GetSocket(unsigned(fg
.fg_data
))
613 so
= kern
.GetValueFromAddress(unsigned(fg
.fg_data
), 'socket *')
614 snd_cc
+= int(so
.so_snd
.sb_cc
)
615 total_snd_cc
[0] += int(so
.so_snd
.sb_cc
)
616 rcv_cc
+= int(so
.so_rcv
.sb_cc
)
617 total_rcv_cc
[0] += int(so
.so_rcv
.sb_cc
)
622 out_string
+= "total sockets " + str(int(sock_fd_seen
)) + " snd_cc " + str(int(snd_cc
)) + " rcv_cc " + str(int(rcv_cc
)) + "\n"
626 # Macro: showprocsockets
627 @lldb_command('showprocsockets')
628 def ShowProcSockets(cmd_args
=None):
629 """ Given a proc_t pointer, display information about its sockets
634 if cmd_args
!= None and len(cmd_args
) > 0 :
635 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc *')
638 print "Unknown value passed as argument."
641 print GetProcInfo(proc
)
642 print GetProcSockets(proc
, total_snd_cc
, total_rcv_cc
)
644 print "Missing argument 0 in user function."
645 # EndMacro: showprocsockets
647 # Macro: showallprocsockets
648 @lldb_command('showallprocsockets')
649 def ShowAllProcSockets(cmd_args
=None):
650 """Display information about the sockets of all the processes
654 for proc
in kern
.procs
:
655 print "================================================================================"
656 print GetProcInfo(proc
)
657 print GetProcSockets(proc
, total_snd_cc
, total_rcv_cc
)
658 print ("total_snd_cc: " + str(int(total_snd_cc
[0])) + " total_rcv_cc: " + str(int(total_rcv_cc
[0])) + "\n")
659 # EndMacro: showallprocsockets
662 def GetRtEntryPrDetailsAsString(rte
):
664 rt
= Cast(rte
, 'rtentry *')
665 dst
= Cast(rt
.rt_nodes
[0].rn_u
.rn_leaf
.rn_Key
, 'sockaddr *')
667 dst_string_format
= "{0:<18s}"
668 if (dst
.sa_family
== AF_INET
):
669 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet(dst
)) + " "
671 if (dst
.sa_family
== AF_INET6
):
672 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet6(dst
)) + " "
675 if (dst
.sa_family
== AF_LINK
):
676 out_string
+= dst_string_format
.format(GetSocketAddrAsStringLink(dst
))
682 out_string
+= dst_string_format
.format(GetSocketAddrAsStringUnspec(dst
)) + " "
684 gw
= Cast(rt
.rt_gateway
, 'sockaddr *')
685 if (gw
.sa_family
== AF_INET
):
686 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet(gw
)) + " "
688 if (gw
.sa_family
== 30):
689 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet6(gw
)) + " "
692 if (gw
.sa_family
== 18):
693 out_string
+= dst_string_format
.format(GetSocketAddrAsStringLink(gw
)) + " "
699 dst_string_format
.format(GetSocketAddrAsStringUnspec(gw
))
701 if (rt
.rt_flags
& RTF_WASCLONED
):
702 if (kern
.ptrsize
== 8):
703 rt_flags_string_format
= "0x{0:<16x}"
704 out_string
+= rt_flags_string_format
.format(rt
.rt_parent
) + " "
706 rt_flags_string_format
= "0x{0:<8x}"
707 out_string
+= rt_flags_string_format
.format(rt
.rt_parent
) + " "
709 if (kern
.ptrsize
== 8):
714 rt_refcnt_rmx_string_format
= "{0:<d} {1:>10d} "
715 out_string
+= rt_refcnt_rmx_string_format
.format(rt
.rt_refcnt
, rt
.rt_rmx
.rmx_pksent
) + " "
717 rtf_string_format
= "{0:>s}"
718 if (rt
.rt_flags
& RTF_UP
):
719 out_string
+= rtf_string_format
.format("U")
720 if (rt
.rt_flags
& RTF_GATEWAY
):
721 out_string
+= rtf_string_format
.format("G")
722 if (rt
.rt_flags
& RTF_HOST
):
723 out_string
+= rtf_string_format
.format("H")
724 if (rt
.rt_flags
& RTF_REJECT
):
725 out_string
+= rtf_string_format
.format("R")
726 if (rt
.rt_flags
& RTF_DYNAMIC
):
727 out_string
+= rtf_string_format
.format("D")
728 if (rt
.rt_flags
& RTF_MODIFIED
):
729 out_string
+= rtf_string_format
.format("M")
730 if (rt
.rt_flags
& RTF_CLONING
):
731 out_string
+= rtf_string_format
.format("C")
732 if (rt
.rt_flags
& RTF_PRCLONING
):
733 out_string
+= rtf_string_format
.format("c")
734 if (rt
.rt_flags
& RTF_LLINFO
):
735 out_string
+= rtf_string_format
.format("L")
736 if (rt
.rt_flags
& RTF_STATIC
):
737 out_string
+= rtf_string_format
.format("S")
738 if (rt
.rt_flags
& RTF_PROTO1
):
739 out_string
+= rtf_string_format
.format("1")
740 if (rt
.rt_flags
& RTF_PROTO2
):
741 out_string
+= rtf_string_format
.format("2")
742 if (rt
.rt_flags
& RTF_PROTO3
):
743 out_string
+= rtf_string_format
.format("3")
744 if (rt
.rt_flags
& RTF_WASCLONED
):
745 out_string
+= rtf_string_format
.format("W")
746 if (rt
.rt_flags
& RTF_BROADCAST
):
747 out_string
+= rtf_string_format
.format("b")
748 if (rt
.rt_flags
& RTF_MULTICAST
):
749 out_string
+= rtf_string_format
.format("m")
750 if (rt
.rt_flags
& RTF_XRESOLVE
):
751 out_string
+= rtf_string_format
.format("X")
752 if (rt
.rt_flags
& RTF_BLACKHOLE
):
753 out_string
+= rtf_string_format
.format("B")
754 if (rt
.rt_flags
& RTF_IFSCOPE
):
755 out_string
+= rtf_string_format
.format("I")
756 if (rt
.rt_flags
& RTF_CONDEMNED
):
757 out_string
+= rtf_string_format
.format("Z")
758 if (rt
.rt_flags
& RTF_IFREF
):
759 out_string
+= rtf_string_format
.format("i")
760 if (rt
.rt_flags
& RTF_PROXY
):
761 out_string
+= rtf_string_format
.format("Y")
762 if (rt
.rt_flags
& RTF_ROUTER
):
763 out_string
+= rtf_string_format
.format("r")
766 out_string
+= str(rt
.rt_ifp
.if_name
)
767 out_string
+= str(int(rt
.rt_ifp
.if_unit
))
773 def GetRtTableAsString(rt_tables
):
775 rn
= Cast(rt_tables
.rnh_treetop
, 'radix_node *')
776 rnh_cnt
= rt_tables
.rnh_cnt
778 while (rn
.rn_bit
>= 0):
779 rn
= rn
.rn_u
.rn_node
.rn_L
782 base
= Cast(rn
, 'radix_node *')
783 while ((rn
.rn_parent
.rn_u
.rn_node
.rn_R
== rn
) and (rn
.rn_flags
& RNF_ROOT
== 0)):
785 rn
= rn
.rn_parent
.rn_u
.rn_node
.rn_R
786 while (rn
.rn_bit
>= 0):
787 rn
= rn
.rn_u
.rn_node
.rn_L
791 base
= rn
.rn_u
.rn_leaf
.rn_Dupedkey
792 if ((rn
.rn_flags
& RNF_ROOT
) == 0):
793 rt
= Cast(rn
, 'rtentry *')
794 if (kern
.ptrsize
== 8):
795 rtentry_string_format
= "0x{0:<18x}"
796 out_string
+= rtentry_string_format
.format(rt
) + " "
798 rtentry_string_format
= "0x{0:<10x}"
799 out_string
+= rtentry_string_format
.format(rt
) + " "
800 out_string
+= GetRtEntryPrDetailsAsString(rt
) + " "
803 if ((rn
.rn_flags
& RNF_ROOT
) != 0):
807 def GetRtInetAsString():
808 rt_tables
= kern
.globals.rt_tables
[2]
809 if (kern
.ptrsize
== 8):
810 rt_table_header_format_string
= "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}"
811 print rt_table_header_format_string
.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if")
812 print rt_table_header_format_string
.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8)
813 print GetRtTableAsString(rt_tables
)
815 rt_table_header_format_string
= "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}"
816 print rt_table_header_format_string
.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if")
817 print rt_table_header_format_string
.format("-" * 8, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8, "-" * 8)
818 print GetRtTableAsString(rt_tables
)
820 def GetRtInet6AsString():
821 rt_tables
= kern
.globals.rt_tables
[30]
822 if (kern
.ptrsize
== 8):
823 rt_table_header_format_string
= "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}"
824 print rt_table_header_format_string
.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if")
825 print rt_table_header_format_string
.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8)
826 print GetRtTableAsString(rt_tables
)
828 rt_table_header_format_string
= "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}"
829 print rt_table_header_format_string
.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if")
830 print rt_table_header_format_string
.format("-" * 8, "-" * 16, "-" * 18, "-" * 8, "-" * 8, "-" * 8, "-" * 8)
831 print GetRtTableAsString(rt_tables
)
833 # Macro: show_rt_inet
834 @lldb_command('show_rt_inet')
835 def ShowRtInet(cmd_args
=None):
836 """ Display the IPv4 routing table
838 print GetRtInetAsString()
839 # EndMacro: show_rt_inet
841 # Macro: show_rt_inet6
842 @lldb_command('show_rt_inet6')
843 def ShowRtInet6(cmd_args
=None):
844 """ Display the IPv6 routing table
846 print GetRtInet6AsString()
847 # EndMacro: show_rt_inet6
849 # Macro: rtentry_showdbg
850 @lldb_command('rtentry_showdbg')
851 def ShowRtEntryDebug(cmd_args
=None):
852 """ Print the debug information of a route entry
854 if (cmd_args
== None or len(cmd_args
) == 0):
855 print "Missing argument 0 in user function."
859 rtd
= kern
.GetValueFromAddress(cmd_args
[0], 'rtentry_dbg *')
860 rtd_summary_format_string
= "{0:s} {1:d}"
861 out_string
+= rtd_summary_format_string
.format("Total holds : ", rtd
.rtd_refhold_cnt
) + "\n"
862 out_string
+= rtd_summary_format_string
.format("Total releases : ", rtd
.rtd_refrele_cnt
) + "\n"
865 while (ix
< CTRACE_STACK_SIZE
):
866 kgm_pc
= rtd
.rtd_alloc
.pc
[ix
]
869 out_string
+= "\nAlloc: (thread " + hex(rtd
.rtd_alloc
.th
) + "):\n"
870 out_string
+= str(int(ix
+ 1)) + ": "
871 out_string
+= GetSourceInformationForAddress(kgm_pc
)
876 while (ix
< CTRACE_STACK_SIZE
):
877 kgm_pc
= rtd
.rtd_free
.pc
[ix
]
880 out_string
+= "\nFree: (thread " + hex(rtd
.rtd_free
.th
) + "):\n"
881 out_string
+= str(int(ix
+ 1)) + ": "
882 out_string
+= GetSourceInformationForAddress(kgm_pc
)
886 while (cnt
< RTD_TRACE_HIST_SIZE
):
888 while (ix
< CTRACE_STACK_SIZE
):
889 kgm_pc
= rtd
.rtd_refhold
[cnt
].pc
[ix
]
892 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_refhold
[cnt
].th
) + "):\n"
893 out_string
+= str(int(ix
+ 1)) + ": "
894 out_string
+= GetSourceInformationForAddress(kgm_pc
)
900 while (cnt
< RTD_TRACE_HIST_SIZE
):
902 while (ix
< CTRACE_STACK_SIZE
):
903 kgm_pc
= rtd
.rtd_refrele
[cnt
].pc
[ix
]
906 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_refrele
[cnt
].th
) + "):\n"
907 out_string
+= str(int(ix
+ 1)) + ": "
908 out_string
+= GetSourceInformationForAddress(kgm_pc
)
913 out_string
+= "\nTotal locks : " + str(int(rtd
.rtd_lock_cnt
))
914 out_string
+= "\nTotal unlocks : " + str(int(rtd
.rtd_unlock_cnt
))
917 while (cnt
< RTD_TRACE_HIST_SIZE
):
919 while (ix
< CTRACE_STACK_SIZE
):
920 kgm_pc
= rtd
.rtd_lock
[cnt
].pc
[ix
]
923 out_string
+= "\nLock [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_lock
[cnt
].th
) + "):\n"
924 out_string
+= str(int(ix
+ 1)) + ": "
925 out_string
+= GetSourceInformationForAddress(kgm_pc
)
931 while (cnt
< RTD_TRACE_HIST_SIZE
):
933 while (ix
< CTRACE_STACK_SIZE
):
934 kgm_pc
= rtd
.rtd_unlock
[cnt
].pc
[ix
]
937 out_string
+= "\nUnlock [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_unlock
[cnt
].th
) + "):\n"
938 out_string
+= str(int(ix
+ 1)) + ": "
939 out_string
+= GetSourceInformationForAddress(kgm_pc
)
945 # EndMacro: rtentry_showdbg
947 # Macro: inifa_showdbg
948 @lldb_command('inifa_showdbg')
949 def InIfaShowDebug(cmd_args
=None):
950 """ Print the debug information of an IPv4 interface address
952 if (cmd_args
== None or len(cmd_args
) == 0):
953 print "Missing argument 0 in user function."
957 inifa
= kern
.GetValueFromAddress(cmd_args
[0], 'in_ifaddr_dbg *')
958 in_ifaddr_summary_format_string
= "{0:s} {1:d}"
959 out_string
+= in_ifaddr_summary_format_string
.format("Total holds : ", inifa
.inifa_refhold_cnt
) + "\n"
960 out_string
+= in_ifaddr_summary_format_string
.format("Total releases : ", inifa
.inifa_refrele_cnt
) + "\n"
963 while (ix
< CTRACE_STACK_SIZE
):
964 kgm_pc
= inifa
.inifa_alloc
.pc
[ix
]
967 out_string
+= "\nAlloc: (thread " + hex(inifa
.inifa_alloc
.th
) + "):\n"
968 out_string
+= str(int(ix
+ 1)) + ": "
969 out_string
+= GetSourceInformationForAddress(kgm_pc
)
974 while (ix
< CTRACE_STACK_SIZE
):
975 kgm_pc
= inifa
.inifa_free
.pc
[ix
]
978 out_string
+= "\nFree: (thread " + hex(inifa
.inifa_free
.th
) + "):\n"
979 out_string
+= str(int(ix
+ 1)) + ": "
980 out_string
+= GetSourceInformationForAddress(kgm_pc
)
984 while (cnt
< INIFA_TRACE_HIST_SIZE
):
986 while (ix
< CTRACE_STACK_SIZE
):
987 kgm_pc
= inifa
.inifa_refhold
[cnt
].pc
[ix
]
990 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(inifa
.inifa_refhold
[cnt
].th
) + "):\n"
991 out_string
+= str(int(ix
+ 1)) + ": "
992 out_string
+= GetSourceInformationForAddress(kgm_pc
)
998 while (cnt
< INIFA_TRACE_HIST_SIZE
):
1000 while (ix
< CTRACE_STACK_SIZE
):
1001 kgm_pc
= inifa
.inifa_refrele
[cnt
].pc
[ix
]
1004 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(inifa
.inifa_refrele
[cnt
].th
) + "):\n"
1005 out_string
+= str(int(ix
+ 1)) + ": "
1006 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1011 # EndMacro: inifa_showdbg
1013 # Macro: in6ifa_showdbg
1014 @lldb_command('in6ifa_showdbg')
1015 def In6IfaShowDebug(cmd_args
=None):
1016 """ Print the debug information of an IPv6 interface address
1018 if (cmd_args
== None or len(cmd_args
) == 0):
1019 print "Missing argument 0 in user function."
1023 in6ifa
= kern
.GetValueFromAddress(cmd_args
[0], 'in6_ifaddr_dbg *')
1024 in6_ifaddr_summary_format_string
= "{0:s} {1:d}"
1025 print in6_ifaddr_summary_format_string
.format("Total holds : ", in6ifa
.in6ifa_refhold_cnt
)
1026 print in6_ifaddr_summary_format_string
.format("Total releases : ", in6ifa
.in6ifa_refrele_cnt
)
1029 while (ix
< CTRACE_STACK_SIZE
):
1030 kgm_pc
= in6ifa
.in6ifa_alloc
.pc
[ix
]
1033 out_string
+= "\nAlloc: (thread " + hex(in6ifa
.in6ifa_alloc
.th
) + "):\n"
1034 out_string
+= str(int(ix
+ 1)) + ": "
1035 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1040 while (ix
< CTRACE_STACK_SIZE
):
1041 kgm_pc
= in6ifa
.in6ifa_free
.pc
[ix
]
1044 out_string
+= "\nFree: (thread " + hex(in6ifa
.in6ifa_free
.th
) + "):\n"
1045 out_string
+= str(int(ix
+ 1)) + ": "
1046 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1050 while (cnt
< IN6IFA_TRACE_HIST_SIZE
):
1052 while (ix
< CTRACE_STACK_SIZE
):
1053 kgm_pc
= in6ifa
.in6ifa_refhold
[cnt
].pc
[ix
]
1056 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(in6ifa
.in6ifa_refhold
[cnt
].th
) + "):\n"
1057 out_string
+= str(int(ix
+ 1)) + ": "
1058 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1064 while (cnt
< IN6IFA_TRACE_HIST_SIZE
):
1066 while (ix
< CTRACE_STACK_SIZE
):
1067 kgm_pc
= in6ifa
.in6ifa_refrele
[cnt
].pc
[ix
]
1070 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(in6ifa
.in6ifa_refrele
[cnt
].th
) + "):\n"
1071 out_string
+= str(int(ix
+ 1)) + ": "
1072 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1077 # EndMacro: in6ifa_showdbg
1079 # Macro: inm_showdbg
1080 @lldb_command('inm_showdbg')
1081 def InmShowDebug(cmd_args
=None):
1082 """ Print the debug information of an IPv4 multicast address
1084 if (cmd_args
== None or len(cmd_args
) == 0):
1085 print "Missing argument 0 in user function."
1089 inm
= kern
.GetValueFromAddress(cmd_args
[0], 'in_multi_dbg *')
1090 in_multi_summary_format_string
= "{0:s} {1:d}"
1091 out_string
+= in_multi_summary_format_string
.format("Total holds : ", inm
.inm_refhold_cnt
)
1092 out_string
+= in_multi_summary_format_string
.format("Total releases : ", inm
.inm_refrele_cnt
)
1094 while (cnt
< INM_TRACE_HIST_SIZE
):
1096 while (ix
< CTRACE_STACK_SIZE
):
1097 kgm_pc
= inm
.inm_refhold
[cnt
].pc
[ix
]
1100 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(inm
.inm_refhold
[cnt
].th
) + "):\n"
1101 out_string
+= str(int(ix
+ 1)) + ": "
1102 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1107 while (cnt
< INM_TRACE_HIST_SIZE
):
1109 while (ix
< CTRACE_STACK_SIZE
):
1110 kgm_pc
= inm
.inm_refrele
[cnt
].pc
[ix
]
1113 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(inm
.inm_refrele
[cnt
].th
) + "):\n"
1114 out_string
+= str(int(ix
+ 1)) + ": "
1115 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1120 # EndMacro: inm_showdbg
1122 # Macro: ifma_showdbg
1123 @lldb_command('ifma_showdbg')
1124 def IfmaShowDebug(cmd_args
=None):
1125 """ Print the debug information of a link multicast address
1127 if (cmd_args
== None or len(cmd_args
) == 0):
1128 print "Missing argument 0 in user function."
1132 ifma
= kern
.GetValueFromAddress(cmd_args
[0], 'ifmultiaddr_dbg *')
1133 link_multi_summary_format_string
= "{0:s} {1:d}"
1134 out_string
+= link_multi_summary_format_string
.format("Total holds : ", ifma
.ifma_refhold_cnt
) + "\n"
1135 out_string
+= link_multi_summary_format_string
.format("Total releases : ", ifma
.ifma_refrele_cnt
) + "\n"
1137 while (cnt
< IFMA_TRACE_HIST_SIZE
):
1139 while (ix
< CTRACE_STACK_SIZE
):
1140 kgm_pc
= ifma
.ifma_refhold
[cnt
].pc
[ix
]
1143 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(ifma
.ifma_refhold
[cnt
].th
) + "):\n"
1144 out_string
+= str(int(ix
+ 1)) + ": "
1145 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1150 while (cnt
< IFMA_TRACE_HIST_SIZE
):
1152 while (ix
< CTRACE_STACK_SIZE
):
1153 kgm_pc
= ifma
.ifma_refrele
[cnt
].pc
[ix
]
1156 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(ifma
.ifma_refrele
[cnt
].th
) + "):\n"
1157 out_string
+= str(int(ix
+ 1)) + ": "
1158 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1163 # EndMacro: ifma_showdbg
1165 # Macro: ifpref_showdbg
1166 @lldb_command('ifpref_showdbg')
1167 def IfpRefShowDebug(cmd_args
=None):
1168 """ Print the debug information of an interface ref count
1170 if (cmd_args
== None or len(cmd_args
) == 0):
1171 print "Missing argument 0 in user function."
1175 dl_if
= kern
.GetValueFromAddress(cmd_args
[0], 'dlil_ifnet_dbg *')
1176 dl_if_summary_format_string
= "{0:s} {1:d}"
1177 out_string
+= dl_if_summary_format_string
.format("Total holds : ", dl_if
.dldbg_if_refhold_cnt
)
1178 out_string
+= dl_if_summary_format_string
.format("Total releases : ", dl_if
.dldbg_if_refrele_cnt
)
1180 while (cnt
< IF_REF_TRACE_HIST_SIZE
):
1182 while (ix
< CTRACE_STACK_SIZE
):
1183 kgm_pc
= dl_if
.dldbg_if_refhold
[cnt
].pc
[ix
]
1186 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(dl_if
.dldbg_if_refhold
[cnt
].th
) + "):\n"
1187 out_string
+= str(int(ix
+ 1)) + ": "
1188 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1193 while (cnt
< IF_REF_TRACE_HIST_SIZE
):
1195 while (ix
< CTRACE_STACK_SIZE
):
1196 kgm_pc
= dl_if
.dldbg_if_refrele
[cnt
].pc
[ix
]
1199 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(dl_if
.dldbg_if_refrele
[cnt
].th
) + "):\n"
1200 out_string
+= str(int(ix
+ 1)) + ": "
1201 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1206 # EndMacro: ifpref_showdbg
1208 # Macro: ndpr_showdbg
1209 @lldb_command('ndpr_showdbg')
1210 def ndprShowDebug(cmd_args
=None):
1211 """ Print the debug information of a nd_prefix structure
1213 if (cmd_args
== None or len(cmd_args
) == 0):
1214 print "Missing argument 0 in user function."
1218 ndpr
= kern
.GetValueFromAddress(cmd_args
[0], 'nd_prefix_dbg *')
1219 ndpr_summary_format_string
= "{0:s} {1:d}"
1220 out_string
+= ndpr_summary_format_string
.format("Total holds : ", ndpr
.ndpr_refhold_cnt
)
1221 out_string
+= ndpr_summary_format_string
.format("Total releases : ", ndpr
.ndpr_refrele_cnt
)
1223 while (cnt
< NDPR_TRACE_HIST_SIZE
):
1225 while (ix
< CTRACE_STACK_SIZE
):
1226 kgm_pc
= ndpr
.ndpr_refhold
[cnt
].pc
[ix
]
1229 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(ndpr
.ndpr_refhold
[cnt
].th
) + "):\n"
1230 out_string
+= str(int(ix
+ 1)) + ": "
1231 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1236 while (cnt
< NDPR_TRACE_HIST_SIZE
):
1238 while (ix
< CTRACE_STACK_SIZE
):
1239 kgm_pc
= ndpr
.ndpr_refrele
[cnt
].pc
[ix
]
1242 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(ndpr
.ndpr_refrele
[cnt
].th
) + "):\n"
1243 out_string
+= str(int(ix
+ 1)) + ": "
1244 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1249 # EndMacro: ndpr_showdbg
1251 # Macro: nddr_showdbg
1252 @lldb_command('nddr_showdbg')
1253 def nddrShowDebug(cmd_args
=None):
1254 """ Print the debug information of a nd_defrouter structure
1256 if (cmd_args
== None or len(cmd_args
) == 0):
1257 print "Missing argument 0 in user function."
1261 nddr
= kern
.GetValueFromAddress(cmd_args
[0], 'nd_defrouter_dbg *')
1262 nddr_summary_format_string
= "{0:s} {1:d}"
1263 out_string
+= nddr_summary_format_string
.format("Total holds : ", nddr
.nddr_refhold_cnt
)
1264 out_string
+= nddr_summary_format_string
.format("Total releases : ", nddr
.nddr_refrele_cnt
)
1266 while (cnt
< NDDR_TRACE_HIST_SIZE
):
1268 while (ix
< CTRACE_STACK_SIZE
):
1269 kgm_pc
= nddr
.nddr_refhold
[cnt
].pc
[ix
]
1272 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(nddr
.nddr_refhold
[cnt
].th
) + "):\n"
1273 out_string
+= str(int(ix
+ 1)) + ": "
1274 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1279 while (cnt
< NDDR_TRACE_HIST_SIZE
):
1281 while (ix
< CTRACE_STACK_SIZE
):
1282 kgm_pc
= nddr
.nddr_refrele
[cnt
].pc
[ix
]
1285 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(nddr
.nddr_refrele
[cnt
].th
) + "):\n"
1286 out_string
+= str(int(ix
+ 1)) + ": "
1287 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1292 # EndMacro: nddr_showdbg
1294 # Macro: imo_showdbg
1295 @lldb_command('imo_showdbg')
1296 def IpmOptions(cmd_args
=None):
1297 """ Print the debug information of a ip_moptions structure
1299 if (cmd_args
== None or len(cmd_args
) == 0):
1300 print "Missing argument 0 in user function."
1304 imo
= kern
.GetValueFromAddress(cmd_args
[0], 'ip_moptions_dbg *')
1305 imo_summary_format_string
= "{0:s} {1:d}"
1306 out_string
+= imo_summary_format_string
.format("Total holds : ", imo
.imo_refhold_cnt
)
1307 out_string
+= imo_summary_format_string
.format("Total releases : ", imo
.imo_refrele_cnt
)
1309 while (cnt
< IMO_TRACE_HIST_SIZE
):
1311 while (ix
< CTRACE_STACK_SIZE
):
1312 kgm_pc
= imo
.imo_refhold
[cnt
].pc
[ix
]
1315 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(imo
.imo_refhold
[cnt
].th
) + "):\n"
1316 out_string
+= str(int(ix
+ 1)) + ": "
1317 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1322 while (cnt
< IMO_TRACE_HIST_SIZE
):
1324 while (ix
< CTRACE_STACK_SIZE
):
1325 kgm_pc
= imo
.imo_refrele
[cnt
].pc
[ix
]
1328 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(imo
.imo_refrele
[cnt
].th
) + "):\n"
1329 out_string
+= str(int(ix
+ 1)) + ": "
1330 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1335 # EndMacro: imo_showdbg
1337 # Macro: im6o_showdbg
1338 @lldb_command('im6o_showdbg')
1339 def IpmOptions(cmd_args
=None):
1340 """ Print the debug information of a ip6_moptions structure
1342 if (cmd_args
== None or len(cmd_args
) == 0):
1343 print "Missing argument 0 in user function."
1347 im6o
= kern
.GetValueFromAddress(cmd_args
[0], 'ip6_moptions_dbg *')
1348 im6o_summary_format_string
= "{0:s} {1:d}"
1349 out_string
+= im6o_summary_format_string
.format("Total holds : ", im6o
.im6o_refhold_cnt
)
1350 out_string
+= im6o_summary_format_string
.format("Total releases : ", im6o
.im6o_refrele_cnt
)
1352 while (cnt
< IM6O_TRACE_HIST_SIZE
):
1354 while (ix
< CTRACE_STACK_SIZE
):
1355 kgm_pc
= im6o
.im6o_refhold
[cnt
].pc
[ix
]
1358 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(im6o
.im6o_refhold
[cnt
].th
) + "):\n"
1359 out_string
+= str(int(ix
+ 1)) + ": "
1360 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1365 while (cnt
< IM6O_TRACE_HIST_SIZE
):
1367 while (ix
< CTRACE_STACK_SIZE
):
1368 kgm_pc
= im6o
.im6o_refrele
[cnt
].pc
[ix
]
1371 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(im6o
.im6o_refrele
[cnt
].th
) + "):\n"
1372 out_string
+= str(int(ix
+ 1)) + ": "
1373 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1378 # EndMacro: im6o_showdbg
1380 # Macro: rtentry_trash
1381 @lldb_command('rtentry_trash')
1382 def RtEntryTrash(cmd_args
=None):
1383 """ Walk the list of trash route entries
1386 rt_trash_head
= kern
.globals.rttrash_head
1387 rtd
= Cast(rt_trash_head
.tqh_first
, 'rtentry_dbg *')
1388 rt_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1390 while (int(rtd
) != 0):
1392 if (kern
.ptrsize
== 8):
1393 print " rtentry ref hold rele dst gw parent flags/if\n"
1394 print " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
1396 print " rtentry ref hold rele dst gw parent flags/if\n"
1397 print " --------- --- ------ ------ --------------- ----- ---------- -----------\n"
1398 out_string
+= rt_trash_format_string
.format(cnt
, rtd
, rtd
.rtd_refhold_cnt
- rtd
.rtd_refrele_cnt
, rtd
.rtd_refhold_cnt
, rtd
.rtd_refrele_cnt
) + " "
1399 out_string
+= GetRtEntryPrDetailsAsString(rtd
) + "\n"
1400 rtd
= rtd
.rtd_trash_link
.tqe_next
1403 # EndMacro: rtentry_trash
1405 # Macro: show_rtentry
1406 @lldb_command('show_rtentry')
1407 def ShRtEntry(cmd_args
=None):
1411 rt
= kern
.GetValueFromAddress(cmd_args
[0], 'rtentry *')
1412 out_string
+= GetRtEntryPrDetailsAsString(rt
) + "\n"
1414 # EndMacro: show_rtentry
1416 # Macro: inifa_trash
1417 @lldb_command('inifa_trash')
1418 def InIfaTrash(cmd_args
=None):
1419 """ Walk the list of trash in_ifaddr entries
1422 ifa_trash_head
= kern
.globals.inifa_trash_head
1423 ifa
= Cast(ifa_trash_head
.tqh_first
, 'in_ifaddr_dbg *')
1424 inifa_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1426 while (int(ifa
) != 0):
1428 if (kern
.ptrsize
== 8):
1429 print " in_ifa ref hold rele"
1430 print " ------------------ --- ------ ----"
1432 print " in_ifa ref hold rele"
1433 print " ---------- --- ----- ------"
1434 out_string
+= inifa_trash_format_string
.format(cnt
+ 1, ifa
, ifa
.inifa_refhold_cnt
- ifa
.inifa_refrele_cnt
, ifa
.inifa_refhold_cnt
, ifa
.inifa_refrele_cnt
) + " "
1435 out_string
+= GetSocketAddrAsStringInet(ifa
.inifa
.ia_ifa
.ifa_addr
) + "\n"
1436 ifa
= ifa
.inifa_trash_link
.tqe_next
1439 # EndMacro: inifa_trash
1441 # Macro: in6ifa_trash
1442 @lldb_command('in6ifa_trash')
1443 def In6IfaTrash(cmd_args
=None):
1444 """ Walk the list of trash in6_ifaddr entries
1447 in6ifa_trash_head
= kern
.globals.in6ifa_trash_head
1448 ifa
= Cast(in6ifa_trash_head
.tqh_first
, 'in6_ifaddr_dbg *')
1449 in6ifa_trash_format_string
= "{0:4d}: 0x{1:x} {2:3d} {3:6d} {4:6d}"
1451 while (int(ifa
) != 0):
1453 if (kern
.ptrsize
== 8):
1454 print " in6_ifa ref hold rele"
1455 print " ------------------ --- ------ ------"
1457 print " in6_ifa ref hold rele"
1458 print " ---------- --- ------ ------"
1459 out_string
+= in6ifa_trash_format_string
.format(cnt
+ 1, ifa
, ifa
.in6ifa_refhold_cnt
- ifa
.in6ifa_refrele_cnt
, ifa
.in6ifa_refhold_cnt
, ifa
.in6ifa_refrele_cnt
) + " "
1460 out_string
+= GetSocketAddrAsStringInet6(ifa
.in6ifa
.ia_ifa
.ifa_addr
) + "\n"
1461 ifa
= ifa
.in6ifa_trash_link
.tqe_next
1464 # EndMacro: in6ifa_trash
1467 @lldb_command('inm_trash')
1468 def InmTrash(cmd_args
=None):
1469 """ Walk the list of trash in_multi entries
1472 inm_trash_head
= kern
.globals.inm_trash_head
1473 inm
= Cast(inm_trash_head
.tqh_first
, 'in_multi_dbg *')
1474 inm_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1476 while (int(inm
) != 0):
1478 if (kern
.ptrsize
== 8):
1479 print " inm ref hold rele"
1480 print " ------------------ --- ------ ------"
1482 print " inm ref hold rele"
1483 print " ---------- --- ------ ------"
1484 out_string
+= inm_trash_format_string
.format(cnt
+ 1, inm
, inm
.inm_refhold_cnt
- inm
.inm_refrele_cnt
, inm
.inm_refhold_cnt
, inm
.inm_refrele_cnt
) + " "
1485 out_string
+= GetInAddrAsString(addressof(inm
.inm
.inm_addr
)) + "\n"
1486 inm
= inm
.inm_trash_link
.tqe_next
1489 # EndMacro: inm_trash
1492 @lldb_command('in6m_trash')
1493 def In6mTrash(cmd_args
=None):
1494 """ Walk the list of trash in6_multi entries
1497 in6m_trash_head
= kern
.globals.in6m_trash_head
1498 in6m
= Cast(in6m_trash_head
.tqh_first
, 'in6_multi_dbg *')
1499 in6m_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1501 while (int(in6m
) != 0):
1503 if (kern
.ptrsize
== 8):
1504 print " in6m ref hold rele"
1505 print " ------------------ --- ------ ------"
1507 print " in6m ref hold rele"
1508 print " ---------- --- ------ ------"
1509 out_string
+= in6m_trash_format_string
.format(cnt
+ 1, in6m
, in6m
.in6m_refhold_cnt
- in6m
.in6m_refrele_cnt
, in6m
.in6m_refhold_cnt
, in6m
.in6m_refrele_cnt
) + " "
1510 out_string
+= GetIn6AddrAsString(addressof(in6m
.in6m
.in6m_addr
)) + "\n"
1511 in6m
= in6m
.in6m_trash_link
.tqe_next
1514 # EndMacro: in6m_trash
1517 @lldb_command('ifma_trash')
1518 def IfmaTrash(cmd_args
=None):
1519 """ Walk the list of trash ifmultiaddr entries
1522 ifma_trash_head
= kern
.globals.ifma_trash_head
1523 ifma
= Cast(ifma_trash_head
.tqh_first
, 'ifmultiaddr_dbg *')
1524 ifma_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1526 while (int(ifma
) != 0):
1528 if (kern
.ptrsize
== 8):
1529 print " ifma ref hold rele"
1530 print " ------------------ --- ------ ------"
1532 print " ifma ref hold rele"
1533 print " ---------- --- ------ ------"
1534 out_string
+= ifma_trash_format_string
.format(cnt
+ 1, ifma
, ifma
.ifma_refhold_cnt
- ifma
.ifma_refrele_cnt
, ifma
.ifma_refhold_cnt
, ifma
.ifma_refrele_cnt
) + " "
1535 out_string
+= GetSocketAddrAsString(ifma
.ifma
.ifma_addr
) + "\n"
1536 out_string
+= " @ " + ifma
.ifma
.ifma_ifp
.if_xname
1537 ifma
= ifma
.ifma_trash_link
.tqe_next
1540 # EndMacro: ifma_trash
1542 def GetInPcb(pcb
, proto
):
1544 out_string
+= hex(pcb
)
1546 if (proto
== IPPROTO_TCP
):
1547 out_string
+= " tcp"
1548 elif (proto
== IPPROTO_UDP
):
1549 out_string
+= " udp"
1550 elif (proto
== IPPROTO_RAW
):
1551 out_string
+= " raw"
1553 out_string
+= str(proto
) + "."
1555 if (pcb
.inp_vflag
& INP_IPV4
):
1557 if (pcb
.inp_vflag
& INP_IPV6
):
1560 if (pcb
.inp_vflag
& INP_IPV4
):
1562 out_string
+= GetInAddrAsString(addressof(pcb
.inp_dependladdr
.inp46_local
.ia46_addr4
))
1565 out_string
+= GetIn6AddrAsString((pcb
.inp_dependladdr
.inp6_local
.__u6_addr
.__u6_addr
8))
1568 out_string
+= Getntohs(pcb
.inp_lport
)
1571 if (pcb
.inp_vflag
& INP_IPV4
):
1573 out_string
+= GetInAddrAsString(addressof(pcb
.inp_dependfaddr
.inp46_foreign
.ia46_addr4
))
1575 out_string
+= GetIn6AddrAsString((pcb
.inp_dependfaddr
.inp6_foreign
.__u6_addr
.__u6_addr
8))
1578 out_string
+= Getntohs(pcb
.inp_fport
)
1581 if (proto
== IPPROTO_TCP
):
1582 out_string
+= GetTcpState(pcb
.inp_ppcb
)
1584 out_string
+= "\n\t"
1585 if (pcb
.inp_flags
& INP_RECVOPTS
):
1586 out_string
+= "recvopts "
1587 if (pcb
.inp_flags
& INP_RECVRETOPTS
):
1588 out_string
+= "recvretopts "
1589 if (pcb
.inp_flags
& INP_RECVDSTADDR
):
1590 out_string
+= "recvdstaddr "
1591 if (pcb
.inp_flags
& INP_HDRINCL
):
1592 out_string
+= "hdrincl "
1593 if (pcb
.inp_flags
& INP_HIGHPORT
):
1594 out_string
+= "highport "
1595 if (pcb
.inp_flags
& INP_LOWPORT
):
1596 out_string
+= "lowport "
1597 if (pcb
.inp_flags
& INP_ANONPORT
):
1598 out_string
+= "anonport "
1599 if (pcb
.inp_flags
& INP_RECVIF
):
1600 out_string
+= "recvif "
1601 if (pcb
.inp_flags
& INP_MTUDISC
):
1602 out_string
+= "mtudisc "
1603 if (pcb
.inp_flags
& INP_STRIPHDR
):
1604 out_string
+= "striphdr "
1605 if (pcb
.inp_flags
& INP_RECV_ANYIF
):
1606 out_string
+= "recv_anyif "
1607 if (pcb
.inp_flags
& INP_INADDR_ANY
):
1608 out_string
+= "inaddr_any "
1609 if (pcb
.inp_flags
& INP_RECVTTL
):
1610 out_string
+= "recvttl "
1611 if (pcb
.inp_flags
& INP_UDP_NOCKSUM
):
1612 out_string
+= "nocksum "
1613 if (pcb
.inp_flags
& INP_BOUND_IF
):
1614 out_string
+= "boundif "
1615 if (pcb
.inp_flags
& IN6P_IPV6_V6ONLY
):
1616 out_string
+= "v6only "
1617 if (pcb
.inp_flags
& IN6P_PKTINFO
):
1618 out_string
+= "pktinfo "
1619 if (pcb
.inp_flags
& IN6P_HOPLIMIT
):
1620 out_string
+= "hoplimit "
1621 if (pcb
.inp_flags
& IN6P_HOPOPTS
):
1622 out_string
+= "hopopts "
1623 if (pcb
.inp_flags
& IN6P_DSTOPTS
):
1624 out_string
+= "dstopts "
1625 if (pcb
.inp_flags
& IN6P_RTHDR
):
1626 out_string
+= "rthdr "
1627 if (pcb
.inp_flags
& IN6P_RTHDRDSTOPTS
):
1628 out_string
+= "rthdrdstopts "
1629 if (pcb
.inp_flags
& IN6P_TCLASS
):
1630 out_string
+= "rcv_tclass "
1631 if (pcb
.inp_flags
& IN6P_AUTOFLOWLABEL
):
1632 out_string
+= "autoflowlabel "
1633 if (pcb
.inp_flags
& IN6P_BINDV6ONLY
):
1634 out_string
+= "bindv6only "
1635 if (pcb
.inp_flags
& IN6P_RFC2292
):
1636 out_string
+= "RFC2292 "
1637 if (pcb
.inp_flags
& IN6P_MTU
):
1638 out_string
+= "rcv_pmtu "
1639 if (pcb
.inp_flags
& INP_PKTINFO
):
1640 out_string
+= "pktinfo "
1641 if (pcb
.inp_flags
& INP_FLOW_SUSPENDED
):
1642 out_string
+= "suspended "
1643 if (pcb
.inp_flags
& INP_NO_IFT_CELLULAR
):
1644 out_string
+= "nocellular "
1645 if (pcb
.inp_flags
& INP_FLOW_CONTROLLED
):
1646 out_string
+= "flowctld "
1647 if (pcb
.inp_flags
& INP_FC_FEEDBACK
):
1648 out_string
+= "fcfeedback "
1649 if (pcb
.inp_flags2
& INP2_TIMEWAIT
):
1650 out_string
+= "timewait "
1651 if (pcb
.inp_flags2
& INP2_IN_FCTREE
):
1652 out_string
+= "in_fctree "
1653 if (pcb
.inp_flags2
& INP2_WANT_APP_POLICY
):
1654 out_string
+= "want_app_policy "
1656 out_string
+= "\n\t"
1659 out_string
+= "so=" + str(so
) + " s=" + str(int(so
.so_snd
.sb_cc
)) + " r=" + str(int(so
.so_rcv
.sb_cc
)) + " usecnt=" + str(int(so
.so_usecount
)) + ", "
1661 if (pcb
.inp_state
== 0 or pcb
.inp_state
== INPCB_STATE_INUSE
):
1662 out_string
+= "inuse"
1664 if (pcb
.inp_state
== INPCB_STATE_DEAD
):
1665 out_string
+= "dead"
1667 out_string
+= "unknown (" + str(int(pcb
.inp_state
)) + ")"
1671 def CalcMbufInList(mpkt
, pkt_cnt
, buf_byte_cnt
, mbuf_cnt
, mbuf_cluster_cnt
):
1674 mpkt
= mpkt
.m_hdr
.mh_nextpkt
1678 buf_byte_cnt
[int(mp
.m_hdr
.mh_type
)] += 256
1679 buf_byte_cnt
[Mbuf_Type
.MT_LAST
] += 256
1680 if (mp
.m_hdr
.mh_flags
& 0x01):
1681 mbuf_cluster_cnt
[0] += 1
1682 buf_byte_cnt
[int(mp
.m_hdr
.mh_type
)] += mp
.M_dat
.MH
.MH_dat
.MH_ext
.ext_size
1683 buf_byte_cnt
[Mbuf_Type
.MT_LAST
] += mp
.M_dat
.MH
.MH_dat
.MH_ext
.ext_size
1684 mp
= mp
.m_hdr
.mh_next
1686 def CalcMbufInSB(so
, snd_cc
, snd_buf
, rcv_cc
, rcv_buf
, snd_record_cnt
, rcv_record_cnt
, snd_mbuf_cnt
, rcv_mbuf_cnt
, snd_mbuf_cluster_cnt
, rcv_mbuf_cluster_cnt
):
1687 snd_cc
[0] += so
.so_snd
.sb_cc
1688 mpkt
= so
.so_snd
.sb_mb
1689 CalcMbufInList(mpkt
, snd_record_cnt
, snd_buf
, snd_mbuf_cnt
, snd_mbuf_cluster_cnt
)
1690 rcv_cc
[0] += so
.so_rcv
.sb_cc
1691 mpkt
= so
.so_rcv
.sb_mb
1692 CalcMbufInList(mpkt
, rcv_record_cnt
, rcv_buf
, rcv_mbuf_cnt
, rcv_mbuf_cluster_cnt
)
1694 def GetPcbInfo(pcbi
, proto
):
1698 snd_mbuf_cluster_cnt
= [0]
1699 snd_record_cnt
= [0]
1701 snd_buf
= [0] * (Mbuf_Type
.MT_LAST
+ 1)
1703 rcv_mbuf_cluster_cnt
= [0]
1704 rcv_record_cnt
= [0]
1706 rcv_buf
= [0] * (Mbuf_Type
.MT_LAST
+ 1)
1708 out_string
+= "lastport " + str(int(pcbi
.ipi_lastport
)) + " lastlow " + str(int(pcbi
.ipi_lastlow
)) + " lasthi " + str(int(pcbi
.ipi_lasthi
)) + "\n"
1709 out_string
+= "active pcb count is " + str(int(pcbi
.ipi_count
)) + "\n"
1710 hashsize
= pcbi
.ipi_hashmask
+ 1
1711 out_string
+= "hash size is " + str(int(hashsize
)) + "\n"
1712 out_string
+= str(pcbi
.ipi_hashbase
) + " has the following inpcb(s):\n"
1713 if (kern
.ptrsize
== 8):
1714 out_string
+= "pcb proto source port destination port\n"
1716 out_string
+= "pcb proto source address port destination address port\n\n"
1718 if proto
== IPPROTO_RAW
:
1719 head
= cast(pcbi
.ipi_listhead
, 'inpcbhead *')
1720 pcb
= cast(head
.lh_first
, 'inpcb *')
1723 out_string
+= GetInPcb(pcb
, proto
) + "\n"
1726 CalcMbufInSB(so
, snd_cc
, snd_buf
, rcv_cc
, rcv_buf
, snd_record_cnt
, rcv_record_cnt
, snd_mbuf_cnt
, rcv_mbuf_cnt
, snd_mbuf_cluster_cnt
, rcv_mbuf_cluster_cnt
)
1727 pcb
= cast(pcb
.inp_list
.le_next
, 'inpcb *')
1730 hashbase
= pcbi
.ipi_hashbase
1731 while (i
< hashsize
):
1733 pcb
= cast(head
.lh_first
, 'inpcb *')
1736 out_string
+= GetInPcb(pcb
, proto
) + "\n"
1739 CalcMbufInSB(so
, snd_cc
, snd_buf
, rcv_cc
, rcv_buf
, snd_record_cnt
, rcv_record_cnt
, snd_mbuf_cnt
, rcv_mbuf_cnt
, snd_mbuf_cluster_cnt
, rcv_mbuf_cluster_cnt
)
1740 if proto
== IPPROTO_TCP
and pcb
.inp_ppcb
:
1741 tcpcb
= cast(pcb
.inp_ppcb
, 'tcpcb *')
1742 tcp_reassqlen
+= tcpcb
.t_reassqlen
1744 pcb
= cast(pcb
.inp_hash
.le_next
, 'inpcb *')
1747 out_string
+= "total pcbs seen: " + str(int(pcbseen
)) + "\n"
1748 out_string
+= "total send mbuf count: " + str(int(snd_mbuf_cnt
[0])) + " receive mbuf count: " + str(int(rcv_mbuf_cnt
[0])) + "\n"
1749 out_string
+= "total send mbuf cluster count: " + str(int(snd_mbuf_cluster_cnt
[0])) + " receive mbuf cluster count: " + str(int(rcv_mbuf_cluster_cnt
[0])) + "\n"
1750 out_string
+= "total send record count: " + str(int(snd_record_cnt
[0])) + " receive record count: " + str(int(rcv_record_cnt
[0])) + "\n"
1751 out_string
+= "total snd_cc (total bytes in send buffers): " + str(int(snd_cc
[0])) + " rcv_cc (total bytes in receive buffers): " + str(int(rcv_cc
[0])) + "\n"
1752 out_string
+= "total snd_buf bytes " + str(int(snd_buf
[Mbuf_Type
.MT_LAST
])) + " rcv_buf bytes " + str(int(rcv_buf
[Mbuf_Type
.MT_LAST
])) + "\n"
1753 for x
in range(Mbuf_Type
.MT_LAST
):
1754 if (snd_buf
[x
] != 0 or rcv_buf
[x
] != 0):
1755 out_string
+= "total snd_buf bytes of type " + Mbuf_Type
.reverse_mapping
[x
] + " : " + str(int(snd_buf
[x
])) + " total recv_buf bytes of type " + Mbuf_Type
.reverse_mapping
[x
] + " : " + str(int(rcv_buf
[x
])) + "\n"
1756 out_string
+= "port hash base is " + hex(pcbi
.ipi_porthashbase
) + "\n"
1757 if proto
== IPPROTO_TCP
:
1758 out_string
+= "TCP reassembly queue length: " + str(tcp_reassqlen
) + "\n"
1761 hashbase
= pcbi
.ipi_porthashbase
1762 while (i
< hashsize
):
1764 pcb
= cast(head
.lh_first
, 'inpcbport *')
1767 out_string
+= GetInPcbPort(pcb
)
1769 pcb
= cast(pcb
.phd_hash
.le_next
, 'inpcbport *')
1774 def GetInPcbPort(ppcb
):
1776 out_string
+= hex(ppcb
) + ": lport "
1777 out_string
+= Getntohs(ppcb
.phd_port
)
1783 #p = unsigned(int(port) & 0x0000ffff)
1784 p
= ((port
& 0x0000ff00) >> 8)
1785 p |
= ((port
& 0x000000ff) << 8)
1788 # Macro: show_kern_event_pcbinfo
1789 def GetKernEventPcbInfo(kev_pcb_head
):
1791 pcb
= Cast(kev_pcb_head
.lh_first
, 'kern_event_pcb *')
1792 if (kern
.ptrsize
== 8):
1793 kev_pcb_format_string
= "0x{0:<16x} {1:12d} {2:16d} {3:16d}"
1794 out_string
+= " evp socket vendor code class filter subclass filter\n"
1795 out_string
+= "-------------- ----------- ------------ ---------------\n"
1797 kev_pcb_format_string
= "0x{0:<8x} {1:12d} {2:16d} {3:16d}"
1798 out_string
+= "evp socket vendor code class filter subclass filter\n"
1799 out_string
+= "---------- ----------- ------------ ---------------\n"
1801 out_string
+= kev_pcb_format_string
.format(pcb
.evp_socket
, pcb
.evp_vendor_code_filter
, pcb
.evp_class_filter
, pcb
.evp_subclass_filter
)
1803 pcb
= pcb
.evp_link
.le_next
1806 @lldb_command('show_kern_event_pcbinfo')
1807 def ShowKernEventPcbInfo(cmd_args
=None):
1808 """ Display the list of Kernel Event protocol control block information
1810 print GetKernEventPcbInfo(addressof(kern
.globals.kern_event_head
))
1811 # EndMacro: show_kern_event_pcbinfo
1813 # Macro: show_kern_control_pcbinfo
1814 def GetKernControlPcbInfo(ctl_head
):
1816 kctl
= Cast(ctl_head
.tqh_first
, 'kctl *')
1817 if (kern
.ptrsize
== 8):
1818 kcb_format_string
= "0x{0:<16x} {1:10d} {2:10d} {3:10d}\n"
1820 kcb_format_string
= "0x{0:<8x} {1:10d} {2:10d} {3:10d}\n"
1821 while unsigned(kctl
) != 0:
1822 kctl_name
= "controller: " + str(kctl
.name
) + "\n"
1823 out_string
+= kctl_name
1824 kcb
= Cast(kctl
.kcb_head
.tqh_first
, 'ctl_cb *')
1825 if unsigned(kcb
) != 0:
1826 if (kern
.ptrsize
== 8):
1827 out_string
+= "socket usecount snd_cc rcv_cc\n"
1828 out_string
+= "------ -------- ------ ------\n"
1830 out_string
+= "socket usecount snd_cc rcv_cc\n"
1831 out_string
+= "------ -------- ------ ------\n"
1832 while unsigned(kcb
) != 0:
1833 so
= Cast(kcb
.so
, 'socket *')
1834 snd_cc
= so
.so_snd
.sb_cc
1835 rcv_cc
= so
.so_rcv
.sb_cc
1836 out_string
+= kcb_format_string
.format(kcb
.so
, kcb
.usecount
, snd_cc
, rcv_cc
)
1837 kcb
= kcb
.next
.tqe_next
1839 kctl
= kctl
.next
.tqe_next
1842 @lldb_command('show_kern_control_pcbinfo')
1843 def ShowKernControlPcbInfo(cmd_args
=None):
1844 """ Display the list of Kernel Control protocol control block information
1846 print GetKernControlPcbInfo(addressof(kern
.globals.ctl_head
))
1847 # EndMacro: show_kern_control_pcbinfo
1849 # Macro: show_tcp_pcbinfo
1850 @lldb_command('show_tcp_pcbinfo')
1851 def ShowTcpPcbInfo(cmd_args
=None):
1852 """ Display the list of TCP protocol control block information
1854 print GetPcbInfo(addressof(kern
.globals.tcbinfo
), IPPROTO_TCP
)
1855 # EndMacro: show_tcp_pcbinfo
1857 # Macro: show_udp_pcbinfo
1858 @lldb_command('show_udp_pcbinfo')
1859 def ShowUdpPcbInfo(cmd_args
=None):
1860 """ Display the list of UDP protocol control block information
1862 print GetPcbInfo(addressof(kern
.globals.udbinfo
), IPPROTO_UDP
)
1863 # EndMacro: show_udp_pcbinfo
1865 # Macro: show_rip_pcbinfo
1866 @lldb_command('show_rip_pcbinfo')
1867 def ShowRipPcbInfo(cmd_args
=None):
1868 """ Display the list of Raw IP protocol control block information
1870 print GetPcbInfo(addressof(kern
.globals.ripcbinfo
), IPPROTO_RAW
)
1871 # EndMacro: show_rip_pcbinfo
1873 # Macro: show_tcp_timewaitslots
1874 @lldb_command('show_tcp_timewaitslots')
1875 def ShowTcpTimeWaitSlots(cmd_args
=None):
1876 """ Display the list of the TCP protocol control blocks in TIMEWAIT
1882 if len(cmd_args
) > 0:
1883 if (int(cmd_args
[0]) == -1):
1886 slot
= int(cmd_args
[0])
1888 out_string
+= "time wait slot size " + str(N_TIME_WAIT_SLOTS
) + " cur_tw_slot " + str(int(kern
.globals.cur_tw_slot
)) + "\n"
1891 while (i
< N_TIME_WAIT_SLOTS
):
1893 head
= kern
.globals.time_wait_slots
[i
]
1894 if (i
== slot
or slot
== -1):
1895 pcb0
= cast(head
.lh_first
, 'inpcb *')
1898 pcb0
= pcb0
.inp_list
.le_next
1900 out_string
+= " slot " + str(i
) + " count " + str(perslot
) + "\n"
1902 if (_all
or i
== slot
):
1903 pcb0
= cast(head
.lh_first
, 'inpcb *')
1906 out_string
+= GetInPcb(pcb0
, IPPROTO_TCP
)
1908 pcb0
= pcb0
.inp_list
.le_next
1912 # EndMacro: show_tcp_timewaitslots
1914 # Macro: show_domains
1915 @lldb_command('show_domains')
1916 def ShowDomains(cmd_args
=None):
1917 """ Display the list of the domains
1920 domains
= kern
.globals.domains
1921 dp
= Cast(domains
.tqh_first
, 'domain *')
1922 ifma_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1925 out_string
+= "\"" + str(dp
.dom_name
) + "\"" + "[" + str(int(dp
.dom_refs
)) + " refs] domain " + hex(dp
) + "\n"
1926 out_string
+= " family:\t" + str(int(dp
.dom_family
)) + "\n"
1927 out_string
+= " flags:0x\t" + str(int(dp
.dom_flags
)) + "\n"
1928 out_string
+= " rtparams:\toff=" + str(int(dp
.dom_rtoffset
)) + ", maxrtkey=" + str(int(dp
.dom_maxrtkey
)) + "\n"
1931 out_string
+= " init:\t"
1932 out_string
+= GetSourceInformationForAddress(dp
.dom_init
) + "\n"
1933 if (dp
.dom_externalize
):
1934 out_string
+= " externalize:\t"
1935 out_string
+= GetSourceInformationForAddress(dp
.dom_externalize
) + "\n"
1936 if (dp
.dom_dispose
):
1937 out_string
+= " dispose:\t"
1938 out_string
+= GetSourceInformationForAddress(dp
.dom_dispose
) + "\n"
1939 if (dp
.dom_rtattach
):
1940 out_string
+= " rtattach:\t"
1941 out_string
+= GetSourceInformationForAddress(dp
.dom_rtattach
) + "\n"
1943 out_string
+= " old:\t"
1944 out_string
+= GetSourceInformationForAddress(dp
.dom_old
) + "\n"
1946 pr
= Cast(dp
.dom_protosw
.tqh_first
, 'protosw *')
1949 out_string
+= "\ttype " + str(int(pr
.pr_type
)) + ", protocol " + str(int(pr
.pr_protocol
)) + ", protosw " + hex(pr
) + "\n"
1950 out_string
+= "\t flags:0x\t" + hex(pr
.pr_flags
) + "\n"
1952 out_string
+= "\t input:\t"
1953 out_string
+= GetSourceInformationForAddress(pr
.pr_input
) + "\n"
1955 out_string
+= "\t output:\t"
1956 out_string
+= GetSourceInformationForAddress(pr
.pr_output
) + "\n"
1957 if (pr
.pr_ctlinput
):
1958 out_string
+= "\t ctlinput:\t"
1959 out_string
+= GetSourceInformationForAddress(pr
.pr_ctlinput
) + "\n"
1960 if (pr
.pr_ctloutput
):
1961 out_string
+= "\t ctloutput:\t"
1962 out_string
+= GetSourceInformationForAddress(pr
.pr_ctloutput
) + "\n"
1964 out_string
+= "\t init:\t"
1965 out_string
+= GetSourceInformationForAddress(pr
.pr_init
) + "\n"
1967 out_string
+= "\t drain:\t"
1968 out_string
+= GetSourceInformationForAddress(pr
.pr_drain
) + "\n"
1970 out_string
+= "\t sysctl:\t"
1971 out_string
+= GetSourceInformationForAddress(pr
.pr_sysctl
) + "\n"
1973 out_string
+= "\t lock:\t"
1974 out_string
+= GetSourceInformationForAddress(pr
.pr_lock
) + "\n"
1976 out_string
+= "\t unlock:\t"
1977 out_string
+= GetSourceInformationForAddress(pr
.pr_unlock
) + "\n"
1979 out_string
+= "\t getlock:\t"
1980 out_string
+= GetSourceInformationForAddress(pr
.pr_getlock
) + "\n"
1982 out_string
+= "\t old:\t"
1983 out_string
+= GetSourceInformationForAddress(pr
.pr_old
) + "\n"
1985 out_string
+= "\t pru_flags:0x\t" + hex(pru
.pru_flags
) + "\n"
1986 out_string
+= "\t abort:\t"
1987 out_string
+= GetSourceInformationForAddress(pru
.pru_abort
) + "\n"
1988 out_string
+= "\t accept:\t"
1989 out_string
+= GetSourceInformationForAddress(pru
.pru_accept
) + "\n"
1990 out_string
+= "\t attach:\t"
1991 out_string
+= GetSourceInformationForAddress(pru
.pru_attach
) + "\n"
1992 out_string
+= "\t bind:\t"
1993 out_string
+= GetSourceInformationForAddress(pru
.pru_bind
) + "\n"
1994 out_string
+= "\t connect:\t"
1995 out_string
+= GetSourceInformationForAddress(pru
.pru_connect
) + "\n"
1996 out_string
+= "\t connect2:\t"
1997 out_string
+= GetSourceInformationForAddress(pru
.pru_connect2
) + "\n"
1998 out_string
+= "\t connectx:\t"
1999 out_string
+= GetSourceInformationForAddress(pru
.pru_connectx
) + "\n"
2000 out_string
+= "\t control:\t"
2001 out_string
+= GetSourceInformationForAddress(pru
.pru_control
) + "\n"
2002 out_string
+= "\t detach:\t"
2003 out_string
+= GetSourceInformationForAddress(pru
.pru_detach
) + "\n"
2004 out_string
+= "\t disconnect:\t"
2005 out_string
+= GetSourceInformationForAddress(pru
.pru_disconnect
) + "\n"
2006 out_string
+= "\t listen:\t"
2007 out_string
+= GetSourceInformationForAddress(pru
.pru_listen
) + "\n"
2008 out_string
+= "\t peeraddr:\t"
2009 out_string
+= GetSourceInformationForAddress(pru
.pru_peeraddr
) + "\n"
2010 out_string
+= "\t rcvd:\t"
2011 out_string
+= GetSourceInformationForAddress(pru
.pru_rcvd
) + "\n"
2012 out_string
+= "\t rcvoob:\t"
2013 out_string
+= GetSourceInformationForAddress(pru
.pru_rcvoob
) + "\n"
2014 out_string
+= "\t send:\t"
2015 out_string
+= GetSourceInformationForAddress(pru
.pru_send
) + "\n"
2016 out_string
+= "\t sense:\t"
2017 out_string
+= GetSourceInformationForAddress(pru
.pru_sense
) + "\n"
2018 out_string
+= "\t shutdown:\t"
2019 out_string
+= GetSourceInformationForAddress(pru
.pru_shutdown
) + "\n"
2020 out_string
+= "\t sockaddr:\t"
2021 out_string
+= GetSourceInformationForAddress(pru
.pru_sockaddr
) + "\n"
2022 out_string
+= "\t sopoll:\t"
2023 out_string
+= GetSourceInformationForAddress(pru
.pru_sopoll
) + "\n"
2024 out_string
+= "\t soreceive:\t"
2025 out_string
+= GetSourceInformationForAddress(pru
.pru_soreceive
) + "\n"
2026 out_string
+= "\t sosend:\t"
2027 out_string
+= GetSourceInformationForAddress(pru
.pru_sosend
) + "\n"
2028 pr
= pr
.pr_entry
.tqe_next
2029 dp
= dp
.dom_entry
.tqe_next
2032 # EndMacro: show_domains