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
.dlth_pkts
.qlen
:
58 out_string
+= "\n\t" + str(dlifnet
.dl_if_inpstorage
.dlth_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 GetVsockSocketAsString(sock
) :
531 pcb
= Cast(sock
.so_pcb
, 'vsockpcb *')
533 out_string
+= "vsockpcb: (null) "
535 out_string
+= "vsockpcb: " + hex(pcb
) + " "
536 out_string
+= str(pcb
.local_address
) + " "
537 out_string
+= str(pcb
.remote_address
)
540 def GetSocket(socket
) :
541 """ Show the contents of a socket
543 so
= kern
.GetValueFromAddress(unsigned(socket
), 'socket *')
546 sock_format_string
= "so: 0x{0:<x}"
547 out_string
+= sock_format_string
.format(so
)
548 domain
= so
.so_proto
.pr_domain
549 domain_name_format_string
= " {0:<s} "
550 out_string
+= domain_name_format_string
.format(domain
.dom_name
)
551 if (domain
.dom_family
== 1):
552 out_string
+= GetUnixDomainSocketAsString(so
)
553 if (domain
.dom_family
== 2):
554 out_string
+= GetIPv4SocketAsString(so
)
555 if (domain
.dom_family
== 30):
556 out_string
+= GetIPv6SocketAsString(so
)
557 if (domain
.dom_family
== 40):
558 out_string
+= GetVsockSocketAsString(so
)
559 out_string
+= " s=" + str(int(so
.so_snd
.sb_cc
)) + " r=" + str(int(so
.so_rcv
.sb_cc
)) + " usecnt=" + str(int(so
.so_usecount
)) + "] "
561 out_string
+= "(null)"
563 # EndMacro: showsocket
567 @lldb_command('showsocket')
568 def ShowSocket(cmd_args
=None) :
569 """ Show the contents of a socket
571 if (cmd_args
== None or len(cmd_args
) == 0):
572 print "Missing argument 0 in user function."
574 so
= kern
.GetValueFromAddress(cmd_args
[0], 'socket *')
575 if (len(str(cmd_args
[0])) > 0):
577 sock_format_string
= "so: 0x{0:<x}"
578 out_string
+= sock_format_string
.format(so
)
579 domain
= so
.so_proto
.pr_domain
580 domain_name_format_string
= " {0:<s} "
581 out_string
+= domain_name_format_string
.format(domain
.dom_name
)
582 if (domain
.dom_family
== 1):
583 out_string
+= GetUnixDomainSocketAsString(so
)
584 if (domain
.dom_family
== 2):
585 out_string
+= GetIPv4SocketAsString(so
)
586 if (domain
.dom_family
== 30):
587 out_string
+= GetIPv6SocketAsString(so
)
588 if (domain
.dom_family
== 40):
589 out_string
+= GetVsockSocketAsString(so
)
592 print "Unknown value passed as argument."
594 # EndMacro: showsocket
596 def GetProcSockets(proc
, total_snd_cc
, total_rcv_cc
):
597 """ Given a proc_t pointer, display information about its sockets
602 out_string
+= "Unknown value passed as argument."
608 """struct filedesc *"""
609 proc_filedesc
= proc
.p_fd
610 """struct fileproc **"""
611 proc_ofiles
= proc_filedesc
.fd_ofiles
612 """ high-water mark of fd_ofiles """
613 proc_lastfile
= unsigned(proc_filedesc
.fd_lastfile
)
614 if proc_filedesc
.fd_nfiles
!= 0:
615 while count
<= proc_lastfile
:
616 if (unsigned(proc_ofiles
[count
]) != 0 and proc_ofiles
[count
].fp_glob
!= 0):
617 fg
= proc_ofiles
[count
].fp_glob
618 if (int(fg
.fg_ops
.fo_type
) == 2):
619 if (proc_filedesc
.fd_ofileflags
[count
] & 4):
623 out_string
+= "fd = " + str(count
) + " "
624 if (fg
.fg_data
!= 0):
625 out_string
+= GetSocket(unsigned(fg
.fg_data
))
628 so
= kern
.GetValueFromAddress(unsigned(fg
.fg_data
), 'socket *')
629 snd_cc
+= int(so
.so_snd
.sb_cc
)
630 total_snd_cc
[0] += int(so
.so_snd
.sb_cc
)
631 rcv_cc
+= int(so
.so_rcv
.sb_cc
)
632 total_rcv_cc
[0] += int(so
.so_rcv
.sb_cc
)
637 out_string
+= "total sockets " + str(int(sock_fd_seen
)) + " snd_cc " + str(int(snd_cc
)) + " rcv_cc " + str(int(rcv_cc
)) + "\n"
641 # Macro: showprocsockets
642 @lldb_command('showprocsockets')
643 def ShowProcSockets(cmd_args
=None):
644 """ Given a proc_t pointer, display information about its sockets
649 if cmd_args
!= None and len(cmd_args
) > 0 :
650 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc *')
653 print "Unknown value passed as argument."
656 print GetProcInfo(proc
)
657 print GetProcSockets(proc
, total_snd_cc
, total_rcv_cc
)
659 print "Missing argument 0 in user function."
660 # EndMacro: showprocsockets
662 # Macro: showallprocsockets
663 @lldb_command('showallprocsockets')
664 def ShowAllProcSockets(cmd_args
=None):
665 """Display information about the sockets of all the processes
669 for proc
in kern
.procs
:
670 print "================================================================================"
671 print GetProcInfo(proc
)
672 print GetProcSockets(proc
, total_snd_cc
, total_rcv_cc
)
673 print ("total_snd_cc: " + str(int(total_snd_cc
[0])) + " total_rcv_cc: " + str(int(total_rcv_cc
[0])) + "\n")
674 # EndMacro: showallprocsockets
677 def GetRtEntryPrDetailsAsString(rte
):
679 rt
= Cast(rte
, 'rtentry *')
680 dst
= Cast(rt
.rt_nodes
[0].rn_u
.rn_leaf
.rn_Key
, 'sockaddr *')
682 dst_string_format
= "{0:<18s}"
683 if (dst
.sa_family
== AF_INET
):
684 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet(dst
)) + " "
686 if (dst
.sa_family
== AF_INET6
):
687 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet6(dst
)) + " "
690 if (dst
.sa_family
== AF_LINK
):
691 out_string
+= dst_string_format
.format(GetSocketAddrAsStringLink(dst
))
697 out_string
+= dst_string_format
.format(GetSocketAddrAsStringUnspec(dst
)) + " "
699 gw
= Cast(rt
.rt_gateway
, 'sockaddr *')
700 if (gw
.sa_family
== AF_INET
):
701 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet(gw
)) + " "
703 if (gw
.sa_family
== 30):
704 out_string
+= dst_string_format
.format(GetSocketAddrAsStringInet6(gw
)) + " "
707 if (gw
.sa_family
== 18):
708 out_string
+= dst_string_format
.format(GetSocketAddrAsStringLink(gw
)) + " "
714 dst_string_format
.format(GetSocketAddrAsStringUnspec(gw
))
716 if (rt
.rt_flags
& RTF_WASCLONED
):
717 if (kern
.ptrsize
== 8):
718 rt_flags_string_format
= "0x{0:<16x}"
719 out_string
+= rt_flags_string_format
.format(rt
.rt_parent
) + " "
721 rt_flags_string_format
= "0x{0:<8x}"
722 out_string
+= rt_flags_string_format
.format(rt
.rt_parent
) + " "
724 if (kern
.ptrsize
== 8):
729 rt_refcnt_rmx_string_format
= "{0:<d} {1:>10d} "
730 out_string
+= rt_refcnt_rmx_string_format
.format(rt
.rt_refcnt
, rt
.rt_rmx
.rmx_pksent
) + " "
732 rtf_string_format
= "{0:>s}"
733 if (rt
.rt_flags
& RTF_UP
):
734 out_string
+= rtf_string_format
.format("U")
735 if (rt
.rt_flags
& RTF_GATEWAY
):
736 out_string
+= rtf_string_format
.format("G")
737 if (rt
.rt_flags
& RTF_HOST
):
738 out_string
+= rtf_string_format
.format("H")
739 if (rt
.rt_flags
& RTF_REJECT
):
740 out_string
+= rtf_string_format
.format("R")
741 if (rt
.rt_flags
& RTF_DYNAMIC
):
742 out_string
+= rtf_string_format
.format("D")
743 if (rt
.rt_flags
& RTF_MODIFIED
):
744 out_string
+= rtf_string_format
.format("M")
745 if (rt
.rt_flags
& RTF_CLONING
):
746 out_string
+= rtf_string_format
.format("C")
747 if (rt
.rt_flags
& RTF_PRCLONING
):
748 out_string
+= rtf_string_format
.format("c")
749 if (rt
.rt_flags
& RTF_LLINFO
):
750 out_string
+= rtf_string_format
.format("L")
751 if (rt
.rt_flags
& RTF_STATIC
):
752 out_string
+= rtf_string_format
.format("S")
753 if (rt
.rt_flags
& RTF_PROTO1
):
754 out_string
+= rtf_string_format
.format("1")
755 if (rt
.rt_flags
& RTF_PROTO2
):
756 out_string
+= rtf_string_format
.format("2")
757 if (rt
.rt_flags
& RTF_PROTO3
):
758 out_string
+= rtf_string_format
.format("3")
759 if (rt
.rt_flags
& RTF_WASCLONED
):
760 out_string
+= rtf_string_format
.format("W")
761 if (rt
.rt_flags
& RTF_BROADCAST
):
762 out_string
+= rtf_string_format
.format("b")
763 if (rt
.rt_flags
& RTF_MULTICAST
):
764 out_string
+= rtf_string_format
.format("m")
765 if (rt
.rt_flags
& RTF_XRESOLVE
):
766 out_string
+= rtf_string_format
.format("X")
767 if (rt
.rt_flags
& RTF_BLACKHOLE
):
768 out_string
+= rtf_string_format
.format("B")
769 if (rt
.rt_flags
& RTF_IFSCOPE
):
770 out_string
+= rtf_string_format
.format("I")
771 if (rt
.rt_flags
& RTF_CONDEMNED
):
772 out_string
+= rtf_string_format
.format("Z")
773 if (rt
.rt_flags
& RTF_IFREF
):
774 out_string
+= rtf_string_format
.format("i")
775 if (rt
.rt_flags
& RTF_PROXY
):
776 out_string
+= rtf_string_format
.format("Y")
777 if (rt
.rt_flags
& RTF_ROUTER
):
778 out_string
+= rtf_string_format
.format("r")
781 out_string
+= str(rt
.rt_ifp
.if_name
)
782 out_string
+= str(int(rt
.rt_ifp
.if_unit
))
788 def GetRtTableAsString(rt_tables
):
790 rn
= Cast(rt_tables
.rnh_treetop
, 'radix_node *')
791 rnh_cnt
= rt_tables
.rnh_cnt
793 while (rn
.rn_bit
>= 0):
794 rn
= rn
.rn_u
.rn_node
.rn_L
797 base
= Cast(rn
, 'radix_node *')
798 while ((rn
.rn_parent
.rn_u
.rn_node
.rn_R
== rn
) and (rn
.rn_flags
& RNF_ROOT
== 0)):
800 rn
= rn
.rn_parent
.rn_u
.rn_node
.rn_R
801 while (rn
.rn_bit
>= 0):
802 rn
= rn
.rn_u
.rn_node
.rn_L
806 base
= rn
.rn_u
.rn_leaf
.rn_Dupedkey
807 if ((rn
.rn_flags
& RNF_ROOT
) == 0):
808 rt
= Cast(rn
, 'rtentry *')
809 if (kern
.ptrsize
== 8):
810 rtentry_string_format
= "0x{0:<18x}"
811 out_string
+= rtentry_string_format
.format(rt
) + " "
813 rtentry_string_format
= "0x{0:<10x}"
814 out_string
+= rtentry_string_format
.format(rt
) + " "
815 out_string
+= GetRtEntryPrDetailsAsString(rt
) + " "
818 if ((rn
.rn_flags
& RNF_ROOT
) != 0):
822 def GetRtInetAsString():
823 rt_tables
= kern
.globals.rt_tables
[2]
824 if (kern
.ptrsize
== 8):
825 rt_table_header_format_string
= "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}"
826 print rt_table_header_format_string
.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if")
827 print rt_table_header_format_string
.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8)
828 print GetRtTableAsString(rt_tables
)
830 rt_table_header_format_string
= "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}"
831 print rt_table_header_format_string
.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if")
832 print rt_table_header_format_string
.format("-" * 8, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8, "-" * 8)
833 print GetRtTableAsString(rt_tables
)
835 def GetRtInet6AsString():
836 rt_tables
= kern
.globals.rt_tables
[30]
837 if (kern
.ptrsize
== 8):
838 rt_table_header_format_string
= "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}"
839 print rt_table_header_format_string
.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if")
840 print rt_table_header_format_string
.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8)
841 print GetRtTableAsString(rt_tables
)
843 rt_table_header_format_string
= "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}"
844 print rt_table_header_format_string
.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if")
845 print rt_table_header_format_string
.format("-" * 8, "-" * 16, "-" * 18, "-" * 8, "-" * 8, "-" * 8, "-" * 8)
846 print GetRtTableAsString(rt_tables
)
848 # Macro: show_rt_inet
849 @lldb_command('show_rt_inet')
850 def ShowRtInet(cmd_args
=None):
851 """ Display the IPv4 routing table
853 print GetRtInetAsString()
854 # EndMacro: show_rt_inet
856 # Macro: show_rt_inet6
857 @lldb_command('show_rt_inet6')
858 def ShowRtInet6(cmd_args
=None):
859 """ Display the IPv6 routing table
861 print GetRtInet6AsString()
862 # EndMacro: show_rt_inet6
864 # Macro: rtentry_showdbg
865 @lldb_command('rtentry_showdbg')
866 def ShowRtEntryDebug(cmd_args
=None):
867 """ Print the debug information of a route entry
869 if (cmd_args
== None or len(cmd_args
) == 0):
870 print "Missing argument 0 in user function."
874 rtd
= kern
.GetValueFromAddress(cmd_args
[0], 'rtentry_dbg *')
875 rtd_summary_format_string
= "{0:s} {1:d}"
876 out_string
+= rtd_summary_format_string
.format("Total holds : ", rtd
.rtd_refhold_cnt
) + "\n"
877 out_string
+= rtd_summary_format_string
.format("Total releases : ", rtd
.rtd_refrele_cnt
) + "\n"
880 while (ix
< CTRACE_STACK_SIZE
):
881 kgm_pc
= rtd
.rtd_alloc
.pc
[ix
]
884 out_string
+= "\nAlloc: (thread " + hex(rtd
.rtd_alloc
.th
) + "):\n"
885 out_string
+= str(int(ix
+ 1)) + ": "
886 out_string
+= GetSourceInformationForAddress(kgm_pc
)
891 while (ix
< CTRACE_STACK_SIZE
):
892 kgm_pc
= rtd
.rtd_free
.pc
[ix
]
895 out_string
+= "\nFree: (thread " + hex(rtd
.rtd_free
.th
) + "):\n"
896 out_string
+= str(int(ix
+ 1)) + ": "
897 out_string
+= GetSourceInformationForAddress(kgm_pc
)
901 while (cnt
< RTD_TRACE_HIST_SIZE
):
903 while (ix
< CTRACE_STACK_SIZE
):
904 kgm_pc
= rtd
.rtd_refhold
[cnt
].pc
[ix
]
907 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_refhold
[cnt
].th
) + "):\n"
908 out_string
+= str(int(ix
+ 1)) + ": "
909 out_string
+= GetSourceInformationForAddress(kgm_pc
)
915 while (cnt
< RTD_TRACE_HIST_SIZE
):
917 while (ix
< CTRACE_STACK_SIZE
):
918 kgm_pc
= rtd
.rtd_refrele
[cnt
].pc
[ix
]
921 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_refrele
[cnt
].th
) + "):\n"
922 out_string
+= str(int(ix
+ 1)) + ": "
923 out_string
+= GetSourceInformationForAddress(kgm_pc
)
928 out_string
+= "\nTotal locks : " + str(int(rtd
.rtd_lock_cnt
))
929 out_string
+= "\nTotal unlocks : " + str(int(rtd
.rtd_unlock_cnt
))
932 while (cnt
< RTD_TRACE_HIST_SIZE
):
934 while (ix
< CTRACE_STACK_SIZE
):
935 kgm_pc
= rtd
.rtd_lock
[cnt
].pc
[ix
]
938 out_string
+= "\nLock [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_lock
[cnt
].th
) + "):\n"
939 out_string
+= str(int(ix
+ 1)) + ": "
940 out_string
+= GetSourceInformationForAddress(kgm_pc
)
946 while (cnt
< RTD_TRACE_HIST_SIZE
):
948 while (ix
< CTRACE_STACK_SIZE
):
949 kgm_pc
= rtd
.rtd_unlock
[cnt
].pc
[ix
]
952 out_string
+= "\nUnlock [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_unlock
[cnt
].th
) + "):\n"
953 out_string
+= str(int(ix
+ 1)) + ": "
954 out_string
+= GetSourceInformationForAddress(kgm_pc
)
960 # EndMacro: rtentry_showdbg
962 # Macro: inifa_showdbg
963 @lldb_command('inifa_showdbg')
964 def InIfaShowDebug(cmd_args
=None):
965 """ Print the debug information of an IPv4 interface address
967 if (cmd_args
== None or len(cmd_args
) == 0):
968 print "Missing argument 0 in user function."
972 inifa
= kern
.GetValueFromAddress(cmd_args
[0], 'in_ifaddr_dbg *')
973 in_ifaddr_summary_format_string
= "{0:s} {1:d}"
974 out_string
+= in_ifaddr_summary_format_string
.format("Total holds : ", inifa
.inifa_refhold_cnt
) + "\n"
975 out_string
+= in_ifaddr_summary_format_string
.format("Total releases : ", inifa
.inifa_refrele_cnt
) + "\n"
978 while (ix
< CTRACE_STACK_SIZE
):
979 kgm_pc
= inifa
.inifa_alloc
.pc
[ix
]
982 out_string
+= "\nAlloc: (thread " + hex(inifa
.inifa_alloc
.th
) + "):\n"
983 out_string
+= str(int(ix
+ 1)) + ": "
984 out_string
+= GetSourceInformationForAddress(kgm_pc
)
989 while (ix
< CTRACE_STACK_SIZE
):
990 kgm_pc
= inifa
.inifa_free
.pc
[ix
]
993 out_string
+= "\nFree: (thread " + hex(inifa
.inifa_free
.th
) + "):\n"
994 out_string
+= str(int(ix
+ 1)) + ": "
995 out_string
+= GetSourceInformationForAddress(kgm_pc
)
999 while (cnt
< INIFA_TRACE_HIST_SIZE
):
1001 while (ix
< CTRACE_STACK_SIZE
):
1002 kgm_pc
= inifa
.inifa_refhold
[cnt
].pc
[ix
]
1005 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(inifa
.inifa_refhold
[cnt
].th
) + "):\n"
1006 out_string
+= str(int(ix
+ 1)) + ": "
1007 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1013 while (cnt
< INIFA_TRACE_HIST_SIZE
):
1015 while (ix
< CTRACE_STACK_SIZE
):
1016 kgm_pc
= inifa
.inifa_refrele
[cnt
].pc
[ix
]
1019 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(inifa
.inifa_refrele
[cnt
].th
) + "):\n"
1020 out_string
+= str(int(ix
+ 1)) + ": "
1021 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1026 # EndMacro: inifa_showdbg
1028 # Macro: in6ifa_showdbg
1029 @lldb_command('in6ifa_showdbg')
1030 def In6IfaShowDebug(cmd_args
=None):
1031 """ Print the debug information of an IPv6 interface address
1033 if (cmd_args
== None or len(cmd_args
) == 0):
1034 print "Missing argument 0 in user function."
1038 in6ifa
= kern
.GetValueFromAddress(cmd_args
[0], 'in6_ifaddr_dbg *')
1039 in6_ifaddr_summary_format_string
= "{0:s} {1:d}"
1040 print in6_ifaddr_summary_format_string
.format("Total holds : ", in6ifa
.in6ifa_refhold_cnt
)
1041 print in6_ifaddr_summary_format_string
.format("Total releases : ", in6ifa
.in6ifa_refrele_cnt
)
1044 while (ix
< CTRACE_STACK_SIZE
):
1045 kgm_pc
= in6ifa
.in6ifa_alloc
.pc
[ix
]
1048 out_string
+= "\nAlloc: (thread " + hex(in6ifa
.in6ifa_alloc
.th
) + "):\n"
1049 out_string
+= str(int(ix
+ 1)) + ": "
1050 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1055 while (ix
< CTRACE_STACK_SIZE
):
1056 kgm_pc
= in6ifa
.in6ifa_free
.pc
[ix
]
1059 out_string
+= "\nFree: (thread " + hex(in6ifa
.in6ifa_free
.th
) + "):\n"
1060 out_string
+= str(int(ix
+ 1)) + ": "
1061 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1065 while (cnt
< IN6IFA_TRACE_HIST_SIZE
):
1067 while (ix
< CTRACE_STACK_SIZE
):
1068 kgm_pc
= in6ifa
.in6ifa_refhold
[cnt
].pc
[ix
]
1071 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(in6ifa
.in6ifa_refhold
[cnt
].th
) + "):\n"
1072 out_string
+= str(int(ix
+ 1)) + ": "
1073 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1079 while (cnt
< IN6IFA_TRACE_HIST_SIZE
):
1081 while (ix
< CTRACE_STACK_SIZE
):
1082 kgm_pc
= in6ifa
.in6ifa_refrele
[cnt
].pc
[ix
]
1085 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(in6ifa
.in6ifa_refrele
[cnt
].th
) + "):\n"
1086 out_string
+= str(int(ix
+ 1)) + ": "
1087 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1092 # EndMacro: in6ifa_showdbg
1094 # Macro: inm_showdbg
1095 @lldb_command('inm_showdbg')
1096 def InmShowDebug(cmd_args
=None):
1097 """ Print the debug information of an IPv4 multicast address
1099 if (cmd_args
== None or len(cmd_args
) == 0):
1100 print "Missing argument 0 in user function."
1104 inm
= kern
.GetValueFromAddress(cmd_args
[0], 'in_multi_dbg *')
1105 in_multi_summary_format_string
= "{0:s} {1:d}"
1106 out_string
+= in_multi_summary_format_string
.format("Total holds : ", inm
.inm_refhold_cnt
)
1107 out_string
+= in_multi_summary_format_string
.format("Total releases : ", inm
.inm_refrele_cnt
)
1109 while (cnt
< INM_TRACE_HIST_SIZE
):
1111 while (ix
< CTRACE_STACK_SIZE
):
1112 kgm_pc
= inm
.inm_refhold
[cnt
].pc
[ix
]
1115 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(inm
.inm_refhold
[cnt
].th
) + "):\n"
1116 out_string
+= str(int(ix
+ 1)) + ": "
1117 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1122 while (cnt
< INM_TRACE_HIST_SIZE
):
1124 while (ix
< CTRACE_STACK_SIZE
):
1125 kgm_pc
= inm
.inm_refrele
[cnt
].pc
[ix
]
1128 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(inm
.inm_refrele
[cnt
].th
) + "):\n"
1129 out_string
+= str(int(ix
+ 1)) + ": "
1130 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1135 # EndMacro: inm_showdbg
1137 # Macro: ifma_showdbg
1138 @lldb_command('ifma_showdbg')
1139 def IfmaShowDebug(cmd_args
=None):
1140 """ Print the debug information of a link multicast address
1142 if (cmd_args
== None or len(cmd_args
) == 0):
1143 print "Missing argument 0 in user function."
1147 ifma
= kern
.GetValueFromAddress(cmd_args
[0], 'ifmultiaddr_dbg *')
1148 link_multi_summary_format_string
= "{0:s} {1:d}"
1149 out_string
+= link_multi_summary_format_string
.format("Total holds : ", ifma
.ifma_refhold_cnt
) + "\n"
1150 out_string
+= link_multi_summary_format_string
.format("Total releases : ", ifma
.ifma_refrele_cnt
) + "\n"
1152 while (cnt
< IFMA_TRACE_HIST_SIZE
):
1154 while (ix
< CTRACE_STACK_SIZE
):
1155 kgm_pc
= ifma
.ifma_refhold
[cnt
].pc
[ix
]
1158 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(ifma
.ifma_refhold
[cnt
].th
) + "):\n"
1159 out_string
+= str(int(ix
+ 1)) + ": "
1160 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1165 while (cnt
< IFMA_TRACE_HIST_SIZE
):
1167 while (ix
< CTRACE_STACK_SIZE
):
1168 kgm_pc
= ifma
.ifma_refrele
[cnt
].pc
[ix
]
1171 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(ifma
.ifma_refrele
[cnt
].th
) + "):\n"
1172 out_string
+= str(int(ix
+ 1)) + ": "
1173 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1178 # EndMacro: ifma_showdbg
1180 # Macro: ifpref_showdbg
1181 @lldb_command('ifpref_showdbg')
1182 def IfpRefShowDebug(cmd_args
=None):
1183 """ Print the debug information of an interface ref count
1185 if (cmd_args
== None or len(cmd_args
) == 0):
1186 print "Missing argument 0 in user function."
1190 dl_if
= kern
.GetValueFromAddress(cmd_args
[0], 'dlil_ifnet_dbg *')
1191 dl_if_summary_format_string
= "{0:s} {1:d}"
1192 out_string
+= dl_if_summary_format_string
.format("Total holds : ", dl_if
.dldbg_if_refhold_cnt
)
1193 out_string
+= dl_if_summary_format_string
.format("Total releases : ", dl_if
.dldbg_if_refrele_cnt
)
1195 while (cnt
< IF_REF_TRACE_HIST_SIZE
):
1197 while (ix
< CTRACE_STACK_SIZE
):
1198 kgm_pc
= dl_if
.dldbg_if_refhold
[cnt
].pc
[ix
]
1201 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(dl_if
.dldbg_if_refhold
[cnt
].th
) + "):\n"
1202 out_string
+= str(int(ix
+ 1)) + ": "
1203 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1208 while (cnt
< IF_REF_TRACE_HIST_SIZE
):
1210 while (ix
< CTRACE_STACK_SIZE
):
1211 kgm_pc
= dl_if
.dldbg_if_refrele
[cnt
].pc
[ix
]
1214 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(dl_if
.dldbg_if_refrele
[cnt
].th
) + "):\n"
1215 out_string
+= str(int(ix
+ 1)) + ": "
1216 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1221 # EndMacro: ifpref_showdbg
1223 # Macro: ndpr_showdbg
1224 @lldb_command('ndpr_showdbg')
1225 def ndprShowDebug(cmd_args
=None):
1226 """ Print the debug information of a nd_prefix structure
1228 if (cmd_args
== None or len(cmd_args
) == 0):
1229 print "Missing argument 0 in user function."
1233 ndpr
= kern
.GetValueFromAddress(cmd_args
[0], 'nd_prefix_dbg *')
1234 ndpr_summary_format_string
= "{0:s} {1:d}"
1235 out_string
+= ndpr_summary_format_string
.format("Total holds : ", ndpr
.ndpr_refhold_cnt
)
1236 out_string
+= ndpr_summary_format_string
.format("Total releases : ", ndpr
.ndpr_refrele_cnt
)
1238 while (cnt
< NDPR_TRACE_HIST_SIZE
):
1240 while (ix
< CTRACE_STACK_SIZE
):
1241 kgm_pc
= ndpr
.ndpr_refhold
[cnt
].pc
[ix
]
1244 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(ndpr
.ndpr_refhold
[cnt
].th
) + "):\n"
1245 out_string
+= str(int(ix
+ 1)) + ": "
1246 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1251 while (cnt
< NDPR_TRACE_HIST_SIZE
):
1253 while (ix
< CTRACE_STACK_SIZE
):
1254 kgm_pc
= ndpr
.ndpr_refrele
[cnt
].pc
[ix
]
1257 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(ndpr
.ndpr_refrele
[cnt
].th
) + "):\n"
1258 out_string
+= str(int(ix
+ 1)) + ": "
1259 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1264 # EndMacro: ndpr_showdbg
1266 # Macro: nddr_showdbg
1267 @lldb_command('nddr_showdbg')
1268 def nddrShowDebug(cmd_args
=None):
1269 """ Print the debug information of a nd_defrouter structure
1271 if (cmd_args
== None or len(cmd_args
) == 0):
1272 print "Missing argument 0 in user function."
1276 nddr
= kern
.GetValueFromAddress(cmd_args
[0], 'nd_defrouter_dbg *')
1277 nddr_summary_format_string
= "{0:s} {1:d}"
1278 out_string
+= nddr_summary_format_string
.format("Total holds : ", nddr
.nddr_refhold_cnt
)
1279 out_string
+= nddr_summary_format_string
.format("Total releases : ", nddr
.nddr_refrele_cnt
)
1281 while (cnt
< NDDR_TRACE_HIST_SIZE
):
1283 while (ix
< CTRACE_STACK_SIZE
):
1284 kgm_pc
= nddr
.nddr_refhold
[cnt
].pc
[ix
]
1287 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(nddr
.nddr_refhold
[cnt
].th
) + "):\n"
1288 out_string
+= str(int(ix
+ 1)) + ": "
1289 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1294 while (cnt
< NDDR_TRACE_HIST_SIZE
):
1296 while (ix
< CTRACE_STACK_SIZE
):
1297 kgm_pc
= nddr
.nddr_refrele
[cnt
].pc
[ix
]
1300 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(nddr
.nddr_refrele
[cnt
].th
) + "):\n"
1301 out_string
+= str(int(ix
+ 1)) + ": "
1302 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1307 # EndMacro: nddr_showdbg
1309 # Macro: imo_showdbg
1310 @lldb_command('imo_showdbg')
1311 def IpmOptions(cmd_args
=None):
1312 """ Print the debug information of a ip_moptions structure
1314 if (cmd_args
== None or len(cmd_args
) == 0):
1315 print "Missing argument 0 in user function."
1319 imo
= kern
.GetValueFromAddress(cmd_args
[0], 'ip_moptions_dbg *')
1320 imo_summary_format_string
= "{0:s} {1:d}"
1321 out_string
+= imo_summary_format_string
.format("Total holds : ", imo
.imo_refhold_cnt
)
1322 out_string
+= imo_summary_format_string
.format("Total releases : ", imo
.imo_refrele_cnt
)
1324 while (cnt
< IMO_TRACE_HIST_SIZE
):
1326 while (ix
< CTRACE_STACK_SIZE
):
1327 kgm_pc
= imo
.imo_refhold
[cnt
].pc
[ix
]
1330 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(imo
.imo_refhold
[cnt
].th
) + "):\n"
1331 out_string
+= str(int(ix
+ 1)) + ": "
1332 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1337 while (cnt
< IMO_TRACE_HIST_SIZE
):
1339 while (ix
< CTRACE_STACK_SIZE
):
1340 kgm_pc
= imo
.imo_refrele
[cnt
].pc
[ix
]
1343 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(imo
.imo_refrele
[cnt
].th
) + "):\n"
1344 out_string
+= str(int(ix
+ 1)) + ": "
1345 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1350 # EndMacro: imo_showdbg
1352 # Macro: im6o_showdbg
1353 @lldb_command('im6o_showdbg')
1354 def IpmOptions(cmd_args
=None):
1355 """ Print the debug information of a ip6_moptions structure
1357 if (cmd_args
== None or len(cmd_args
) == 0):
1358 print "Missing argument 0 in user function."
1362 im6o
= kern
.GetValueFromAddress(cmd_args
[0], 'ip6_moptions_dbg *')
1363 im6o_summary_format_string
= "{0:s} {1:d}"
1364 out_string
+= im6o_summary_format_string
.format("Total holds : ", im6o
.im6o_refhold_cnt
)
1365 out_string
+= im6o_summary_format_string
.format("Total releases : ", im6o
.im6o_refrele_cnt
)
1367 while (cnt
< IM6O_TRACE_HIST_SIZE
):
1369 while (ix
< CTRACE_STACK_SIZE
):
1370 kgm_pc
= im6o
.im6o_refhold
[cnt
].pc
[ix
]
1373 out_string
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(im6o
.im6o_refhold
[cnt
].th
) + "):\n"
1374 out_string
+= str(int(ix
+ 1)) + ": "
1375 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1380 while (cnt
< IM6O_TRACE_HIST_SIZE
):
1382 while (ix
< CTRACE_STACK_SIZE
):
1383 kgm_pc
= im6o
.im6o_refrele
[cnt
].pc
[ix
]
1386 out_string
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(im6o
.im6o_refrele
[cnt
].th
) + "):\n"
1387 out_string
+= str(int(ix
+ 1)) + ": "
1388 out_string
+= GetSourceInformationForAddress(kgm_pc
)
1393 # EndMacro: im6o_showdbg
1395 # Macro: rtentry_trash
1396 @lldb_command('rtentry_trash')
1397 def RtEntryTrash(cmd_args
=None):
1398 """ Walk the list of trash route entries
1401 rt_trash_head
= kern
.globals.rttrash_head
1402 rtd
= Cast(rt_trash_head
.tqh_first
, 'rtentry_dbg *')
1403 rt_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1405 while (int(rtd
) != 0):
1407 if (kern
.ptrsize
== 8):
1408 print " rtentry ref hold rele dst gw parent flags/if\n"
1409 print " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
1411 print " rtentry ref hold rele dst gw parent flags/if\n"
1412 print " --------- --- ------ ------ --------------- ----- ---------- -----------\n"
1413 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
) + " "
1414 out_string
+= GetRtEntryPrDetailsAsString(rtd
) + "\n"
1415 rtd
= rtd
.rtd_trash_link
.tqe_next
1418 # EndMacro: rtentry_trash
1420 # Macro: show_rtentry
1421 @lldb_command('show_rtentry')
1422 def ShRtEntry(cmd_args
=None):
1426 rt
= kern
.GetValueFromAddress(cmd_args
[0], 'rtentry *')
1427 out_string
+= GetRtEntryPrDetailsAsString(rt
) + "\n"
1429 # EndMacro: show_rtentry
1431 # Macro: inifa_trash
1432 @lldb_command('inifa_trash')
1433 def InIfaTrash(cmd_args
=None):
1434 """ Walk the list of trash in_ifaddr entries
1437 ifa_trash_head
= kern
.globals.inifa_trash_head
1438 ifa
= Cast(ifa_trash_head
.tqh_first
, 'in_ifaddr_dbg *')
1439 inifa_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1441 while (int(ifa
) != 0):
1443 if (kern
.ptrsize
== 8):
1444 print " in_ifa ref hold rele"
1445 print " ------------------ --- ------ ----"
1447 print " in_ifa ref hold rele"
1448 print " ---------- --- ----- ------"
1449 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
) + " "
1450 out_string
+= GetSocketAddrAsStringInet(ifa
.inifa
.ia_ifa
.ifa_addr
) + "\n"
1451 ifa
= ifa
.inifa_trash_link
.tqe_next
1454 # EndMacro: inifa_trash
1456 # Macro: in6ifa_trash
1457 @lldb_command('in6ifa_trash')
1458 def In6IfaTrash(cmd_args
=None):
1459 """ Walk the list of trash in6_ifaddr entries
1462 in6ifa_trash_head
= kern
.globals.in6ifa_trash_head
1463 ifa
= Cast(in6ifa_trash_head
.tqh_first
, 'in6_ifaddr_dbg *')
1464 in6ifa_trash_format_string
= "{0:4d}: 0x{1:x} {2:3d} {3:6d} {4:6d}"
1466 while (int(ifa
) != 0):
1468 if (kern
.ptrsize
== 8):
1469 print " in6_ifa ref hold rele"
1470 print " ------------------ --- ------ ------"
1472 print " in6_ifa ref hold rele"
1473 print " ---------- --- ------ ------"
1474 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
) + " "
1475 out_string
+= GetSocketAddrAsStringInet6(ifa
.in6ifa
.ia_ifa
.ifa_addr
) + "\n"
1476 ifa
= ifa
.in6ifa_trash_link
.tqe_next
1479 # EndMacro: in6ifa_trash
1482 @lldb_command('inm_trash')
1483 def InmTrash(cmd_args
=None):
1484 """ Walk the list of trash in_multi entries
1487 inm_trash_head
= kern
.globals.inm_trash_head
1488 inm
= Cast(inm_trash_head
.tqh_first
, 'in_multi_dbg *')
1489 inm_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1491 while (int(inm
) != 0):
1493 if (kern
.ptrsize
== 8):
1494 print " inm ref hold rele"
1495 print " ------------------ --- ------ ------"
1497 print " inm ref hold rele"
1498 print " ---------- --- ------ ------"
1499 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
) + " "
1500 out_string
+= GetInAddrAsString(addressof(inm
.inm
.inm_addr
)) + "\n"
1501 inm
= inm
.inm_trash_link
.tqe_next
1504 # EndMacro: inm_trash
1507 @lldb_command('in6m_trash')
1508 def In6mTrash(cmd_args
=None):
1509 """ Walk the list of trash in6_multi entries
1512 in6m_trash_head
= kern
.globals.in6m_trash_head
1513 in6m
= Cast(in6m_trash_head
.tqh_first
, 'in6_multi_dbg *')
1514 in6m_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1516 while (int(in6m
) != 0):
1518 if (kern
.ptrsize
== 8):
1519 print " in6m ref hold rele"
1520 print " ------------------ --- ------ ------"
1522 print " in6m ref hold rele"
1523 print " ---------- --- ------ ------"
1524 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
) + " "
1525 out_string
+= GetIn6AddrAsString(addressof(in6m
.in6m
.in6m_addr
)) + "\n"
1526 in6m
= in6m
.in6m_trash_link
.tqe_next
1529 # EndMacro: in6m_trash
1532 @lldb_command('ifma_trash')
1533 def IfmaTrash(cmd_args
=None):
1534 """ Walk the list of trash ifmultiaddr entries
1537 ifma_trash_head
= kern
.globals.ifma_trash_head
1538 ifma
= Cast(ifma_trash_head
.tqh_first
, 'ifmultiaddr_dbg *')
1539 ifma_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1541 while (int(ifma
) != 0):
1543 if (kern
.ptrsize
== 8):
1544 print " ifma ref hold rele"
1545 print " ------------------ --- ------ ------"
1547 print " ifma ref hold rele"
1548 print " ---------- --- ------ ------"
1549 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
) + " "
1550 out_string
+= GetSocketAddrAsString(ifma
.ifma
.ifma_addr
) + "\n"
1551 out_string
+= " @ " + ifma
.ifma
.ifma_ifp
.if_xname
1552 ifma
= ifma
.ifma_trash_link
.tqe_next
1555 # EndMacro: ifma_trash
1557 def GetInPcb(pcb
, proto
):
1559 out_string
+= hex(pcb
)
1561 if (proto
== IPPROTO_TCP
):
1562 out_string
+= " tcp"
1563 elif (proto
== IPPROTO_UDP
):
1564 out_string
+= " udp"
1565 elif (proto
== IPPROTO_RAW
):
1566 out_string
+= " raw"
1568 out_string
+= str(proto
) + "."
1570 if (pcb
.inp_vflag
& INP_IPV4
):
1572 if (pcb
.inp_vflag
& INP_IPV6
):
1575 if (pcb
.inp_vflag
& INP_IPV4
):
1577 out_string
+= GetInAddrAsString(addressof(pcb
.inp_dependladdr
.inp46_local
.ia46_addr4
))
1580 out_string
+= GetIn6AddrAsString((pcb
.inp_dependladdr
.inp6_local
.__u6_addr
.__u6_addr
8))
1583 out_string
+= Getntohs(pcb
.inp_lport
)
1586 if (pcb
.inp_vflag
& INP_IPV4
):
1588 out_string
+= GetInAddrAsString(addressof(pcb
.inp_dependfaddr
.inp46_foreign
.ia46_addr4
))
1590 out_string
+= GetIn6AddrAsString((pcb
.inp_dependfaddr
.inp6_foreign
.__u6_addr
.__u6_addr
8))
1593 out_string
+= Getntohs(pcb
.inp_fport
)
1596 if (proto
== IPPROTO_TCP
):
1597 out_string
+= GetTcpState(pcb
.inp_ppcb
)
1599 out_string
+= "\n\t"
1600 if (pcb
.inp_flags
& INP_RECVOPTS
):
1601 out_string
+= "recvopts "
1602 if (pcb
.inp_flags
& INP_RECVRETOPTS
):
1603 out_string
+= "recvretopts "
1604 if (pcb
.inp_flags
& INP_RECVDSTADDR
):
1605 out_string
+= "recvdstaddr "
1606 if (pcb
.inp_flags
& INP_HDRINCL
):
1607 out_string
+= "hdrincl "
1608 if (pcb
.inp_flags
& INP_HIGHPORT
):
1609 out_string
+= "highport "
1610 if (pcb
.inp_flags
& INP_LOWPORT
):
1611 out_string
+= "lowport "
1612 if (pcb
.inp_flags
& INP_ANONPORT
):
1613 out_string
+= "anonport "
1614 if (pcb
.inp_flags
& INP_RECVIF
):
1615 out_string
+= "recvif "
1616 if (pcb
.inp_flags
& INP_MTUDISC
):
1617 out_string
+= "mtudisc "
1618 if (pcb
.inp_flags
& INP_STRIPHDR
):
1619 out_string
+= "striphdr "
1620 if (pcb
.inp_flags
& INP_RECV_ANYIF
):
1621 out_string
+= "recv_anyif "
1622 if (pcb
.inp_flags
& INP_INADDR_ANY
):
1623 out_string
+= "inaddr_any "
1624 if (pcb
.inp_flags
& INP_RECVTTL
):
1625 out_string
+= "recvttl "
1626 if (pcb
.inp_flags
& INP_UDP_NOCKSUM
):
1627 out_string
+= "nocksum "
1628 if (pcb
.inp_flags
& INP_BOUND_IF
):
1629 out_string
+= "boundif "
1630 if (pcb
.inp_flags
& IN6P_IPV6_V6ONLY
):
1631 out_string
+= "v6only "
1632 if (pcb
.inp_flags
& IN6P_PKTINFO
):
1633 out_string
+= "pktinfo "
1634 if (pcb
.inp_flags
& IN6P_HOPLIMIT
):
1635 out_string
+= "hoplimit "
1636 if (pcb
.inp_flags
& IN6P_HOPOPTS
):
1637 out_string
+= "hopopts "
1638 if (pcb
.inp_flags
& IN6P_DSTOPTS
):
1639 out_string
+= "dstopts "
1640 if (pcb
.inp_flags
& IN6P_RTHDR
):
1641 out_string
+= "rthdr "
1642 if (pcb
.inp_flags
& IN6P_RTHDRDSTOPTS
):
1643 out_string
+= "rthdrdstopts "
1644 if (pcb
.inp_flags
& IN6P_TCLASS
):
1645 out_string
+= "rcv_tclass "
1646 if (pcb
.inp_flags
& IN6P_AUTOFLOWLABEL
):
1647 out_string
+= "autoflowlabel "
1648 if (pcb
.inp_flags
& IN6P_BINDV6ONLY
):
1649 out_string
+= "bindv6only "
1650 if (pcb
.inp_flags
& IN6P_RFC2292
):
1651 out_string
+= "RFC2292 "
1652 if (pcb
.inp_flags
& IN6P_MTU
):
1653 out_string
+= "rcv_pmtu "
1654 if (pcb
.inp_flags
& INP_PKTINFO
):
1655 out_string
+= "pktinfo "
1656 if (pcb
.inp_flags
& INP_FLOW_SUSPENDED
):
1657 out_string
+= "suspended "
1658 if (pcb
.inp_flags
& INP_NO_IFT_CELLULAR
):
1659 out_string
+= "nocellular "
1660 if (pcb
.inp_flags
& INP_FLOW_CONTROLLED
):
1661 out_string
+= "flowctld "
1662 if (pcb
.inp_flags
& INP_FC_FEEDBACK
):
1663 out_string
+= "fcfeedback "
1664 if (pcb
.inp_flags2
& INP2_TIMEWAIT
):
1665 out_string
+= "timewait "
1666 if (pcb
.inp_flags2
& INP2_IN_FCTREE
):
1667 out_string
+= "in_fctree "
1668 if (pcb
.inp_flags2
& INP2_WANT_APP_POLICY
):
1669 out_string
+= "want_app_policy "
1671 out_string
+= "\n\t"
1674 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
)) + ", "
1676 if (pcb
.inp_state
== 0 or pcb
.inp_state
== INPCB_STATE_INUSE
):
1677 out_string
+= "inuse"
1679 if (pcb
.inp_state
== INPCB_STATE_DEAD
):
1680 out_string
+= "dead"
1682 out_string
+= "unknown (" + str(int(pcb
.inp_state
)) + ")"
1686 def CalcMbufInList(mpkt
, pkt_cnt
, buf_byte_cnt
, mbuf_cnt
, mbuf_cluster_cnt
):
1689 mpkt
= mpkt
.m_hdr
.mh_nextpkt
1693 buf_byte_cnt
[int(mp
.m_hdr
.mh_type
)] += 256
1694 buf_byte_cnt
[Mbuf_Type
.MT_LAST
] += 256
1695 if (mp
.m_hdr
.mh_flags
& 0x01):
1696 mbuf_cluster_cnt
[0] += 1
1697 buf_byte_cnt
[int(mp
.m_hdr
.mh_type
)] += mp
.M_dat
.MH
.MH_dat
.MH_ext
.ext_size
1698 buf_byte_cnt
[Mbuf_Type
.MT_LAST
] += mp
.M_dat
.MH
.MH_dat
.MH_ext
.ext_size
1699 mp
= mp
.m_hdr
.mh_next
1701 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
):
1702 snd_cc
[0] += so
.so_snd
.sb_cc
1703 mpkt
= so
.so_snd
.sb_mb
1704 CalcMbufInList(mpkt
, snd_record_cnt
, snd_buf
, snd_mbuf_cnt
, snd_mbuf_cluster_cnt
)
1705 rcv_cc
[0] += so
.so_rcv
.sb_cc
1706 mpkt
= so
.so_rcv
.sb_mb
1707 CalcMbufInList(mpkt
, rcv_record_cnt
, rcv_buf
, rcv_mbuf_cnt
, rcv_mbuf_cluster_cnt
)
1709 def GetPcbInfo(pcbi
, proto
):
1713 snd_mbuf_cluster_cnt
= [0]
1714 snd_record_cnt
= [0]
1716 snd_buf
= [0] * (Mbuf_Type
.MT_LAST
+ 1)
1718 rcv_mbuf_cluster_cnt
= [0]
1719 rcv_record_cnt
= [0]
1721 rcv_buf
= [0] * (Mbuf_Type
.MT_LAST
+ 1)
1723 out_string
+= "lastport " + str(int(pcbi
.ipi_lastport
)) + " lastlow " + str(int(pcbi
.ipi_lastlow
)) + " lasthi " + str(int(pcbi
.ipi_lasthi
)) + "\n"
1724 out_string
+= "active pcb count is " + str(int(pcbi
.ipi_count
)) + "\n"
1725 hashsize
= pcbi
.ipi_hashmask
+ 1
1726 out_string
+= "hash size is " + str(int(hashsize
)) + "\n"
1727 out_string
+= str(pcbi
.ipi_hashbase
) + " has the following inpcb(s):\n"
1728 if (kern
.ptrsize
== 8):
1729 out_string
+= "pcb proto source port destination port\n"
1731 out_string
+= "pcb proto source address port destination address port\n\n"
1733 if proto
== IPPROTO_RAW
:
1734 head
= cast(pcbi
.ipi_listhead
, 'inpcbhead *')
1735 pcb
= cast(head
.lh_first
, 'inpcb *')
1738 out_string
+= GetInPcb(pcb
, proto
) + "\n"
1741 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
)
1742 pcb
= cast(pcb
.inp_list
.le_next
, 'inpcb *')
1745 hashbase
= pcbi
.ipi_hashbase
1746 while (i
< hashsize
):
1748 pcb
= cast(head
.lh_first
, 'inpcb *')
1751 out_string
+= GetInPcb(pcb
, proto
) + "\n"
1754 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
)
1755 if proto
== IPPROTO_TCP
and pcb
.inp_ppcb
:
1756 tcpcb
= cast(pcb
.inp_ppcb
, 'tcpcb *')
1757 tcp_reassqlen
+= tcpcb
.t_reassqlen
1759 pcb
= cast(pcb
.inp_hash
.le_next
, 'inpcb *')
1762 out_string
+= "total pcbs seen: " + str(int(pcbseen
)) + "\n"
1763 out_string
+= "total send mbuf count: " + str(int(snd_mbuf_cnt
[0])) + " receive mbuf count: " + str(int(rcv_mbuf_cnt
[0])) + "\n"
1764 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"
1765 out_string
+= "total send record count: " + str(int(snd_record_cnt
[0])) + " receive record count: " + str(int(rcv_record_cnt
[0])) + "\n"
1766 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"
1767 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"
1768 for x
in range(Mbuf_Type
.MT_LAST
):
1769 if (snd_buf
[x
] != 0 or rcv_buf
[x
] != 0):
1770 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"
1771 out_string
+= "port hash base is " + hex(pcbi
.ipi_porthashbase
) + "\n"
1772 if proto
== IPPROTO_TCP
:
1773 out_string
+= "TCP reassembly queue length: " + str(tcp_reassqlen
) + "\n"
1776 hashbase
= pcbi
.ipi_porthashbase
1777 while (i
< hashsize
):
1779 pcb
= cast(head
.lh_first
, 'inpcbport *')
1782 out_string
+= GetInPcbPort(pcb
)
1784 pcb
= cast(pcb
.phd_hash
.le_next
, 'inpcbport *')
1789 def GetInPcbPort(ppcb
):
1791 out_string
+= hex(ppcb
) + ": lport "
1792 out_string
+= Getntohs(ppcb
.phd_port
)
1798 #p = unsigned(int(port) & 0x0000ffff)
1799 p
= ((port
& 0x0000ff00) >> 8)
1800 p |
= ((port
& 0x000000ff) << 8)
1804 # Macro: mbuf_list_usage_summary
1805 @lldb_command('mbuf_list_usage_summary')
1806 def ShowMbufListUsageSummary(cmd_args
=None):
1807 """ Print mbuf list usage summary
1811 buf_byte_cnt
= [0] * (Mbuf_Type
.MT_LAST
+ 1)
1813 mbuf_cluster_cnt
= [0]
1815 mpkt
= kern
.GetValueFromAddress(cmd_args
[0], 'struct mbuf *')
1816 CalcMbufInList(mpkt
, pkt_cnt
, buf_byte_cnt
, mbuf_cnt
, mbuf_cluster_cnt
)
1818 out_string
+= "Total packet count is " + str(int(pkt_cnt
[0])) + "\n"
1819 for x
in range(Mbuf_Type
.MT_LAST
):
1820 if (buf_byte_cnt
[x
] != 0):
1821 out_string
+= "Total buf bytes of type " + Mbuf_Type
.reverse_mapping
[x
] + " : " + str(int(buf_byte_cnt
[x
])) + "\n"
1822 out_string
+= "Total mbuf count " + str(int(mbuf_cnt
[0])) + "\n"
1823 out_string
+= "Total mbuf cluster count " + str(int(mbuf_cluster_cnt
[0])) + "\n"
1826 # Macro: show_kern_event_pcbinfo
1827 def GetKernEventPcbInfo(kev_pcb_head
):
1829 pcb
= Cast(kev_pcb_head
.lh_first
, 'kern_event_pcb *')
1830 if (kern
.ptrsize
== 8):
1831 kev_pcb_format_string
= "0x{0:<16x} {1:12d} {2:16d} {3:16d}"
1832 out_string
+= " evp socket vendor code class filter subclass filter\n"
1833 out_string
+= "-------------- ----------- ------------ ---------------\n"
1835 kev_pcb_format_string
= "0x{0:<8x} {1:12d} {2:16d} {3:16d}"
1836 out_string
+= "evp socket vendor code class filter subclass filter\n"
1837 out_string
+= "---------- ----------- ------------ ---------------\n"
1839 out_string
+= kev_pcb_format_string
.format(pcb
.evp_socket
, pcb
.evp_vendor_code_filter
, pcb
.evp_class_filter
, pcb
.evp_subclass_filter
)
1841 pcb
= pcb
.evp_link
.le_next
1844 @lldb_command('show_kern_event_pcbinfo')
1845 def ShowKernEventPcbInfo(cmd_args
=None):
1846 """ Display the list of Kernel Event protocol control block information
1848 print GetKernEventPcbInfo(addressof(kern
.globals.kern_event_head
))
1849 # EndMacro: show_kern_event_pcbinfo
1851 # Macro: show_kern_control_pcbinfo
1852 def GetKernControlPcbInfo(ctl_head
):
1854 kctl
= Cast(ctl_head
.tqh_first
, 'kctl *')
1855 if (kern
.ptrsize
== 8):
1856 kcb_format_string
= "0x{0:<16x} {1:10d} {2:10d} {3:10d}\n"
1858 kcb_format_string
= "0x{0:<8x} {1:10d} {2:10d} {3:10d}\n"
1859 while unsigned(kctl
) != 0:
1860 kctl_name
= "controller: " + str(kctl
.name
) + "\n"
1861 out_string
+= kctl_name
1862 kcb
= Cast(kctl
.kcb_head
.tqh_first
, 'ctl_cb *')
1863 if unsigned(kcb
) != 0:
1864 if (kern
.ptrsize
== 8):
1865 out_string
+= "socket usecount snd_cc rcv_cc\n"
1866 out_string
+= "------ -------- ------ ------\n"
1868 out_string
+= "socket usecount snd_cc rcv_cc\n"
1869 out_string
+= "------ -------- ------ ------\n"
1870 while unsigned(kcb
) != 0:
1871 so
= Cast(kcb
.so
, 'socket *')
1872 snd_cc
= so
.so_snd
.sb_cc
1873 rcv_cc
= so
.so_rcv
.sb_cc
1874 out_string
+= kcb_format_string
.format(kcb
.so
, kcb
.usecount
, snd_cc
, rcv_cc
)
1875 kcb
= kcb
.next
.tqe_next
1877 kctl
= kctl
.next
.tqe_next
1880 @lldb_command('show_kern_control_pcbinfo')
1881 def ShowKernControlPcbInfo(cmd_args
=None):
1882 """ Display the list of Kernel Control protocol control block information
1884 print GetKernControlPcbInfo(addressof(kern
.globals.ctl_head
))
1885 # EndMacro: show_kern_control_pcbinfo
1887 # Macro: show_tcp_pcbinfo
1888 @lldb_command('show_tcp_pcbinfo')
1889 def ShowTcpPcbInfo(cmd_args
=None):
1890 """ Display the list of TCP protocol control block information
1892 print GetPcbInfo(addressof(kern
.globals.tcbinfo
), IPPROTO_TCP
)
1893 # EndMacro: show_tcp_pcbinfo
1895 # Macro: show_udp_pcbinfo
1896 @lldb_command('show_udp_pcbinfo')
1897 def ShowUdpPcbInfo(cmd_args
=None):
1898 """ Display the list of UDP protocol control block information
1900 print GetPcbInfo(addressof(kern
.globals.udbinfo
), IPPROTO_UDP
)
1901 # EndMacro: show_udp_pcbinfo
1903 # Macro: show_rip_pcbinfo
1904 @lldb_command('show_rip_pcbinfo')
1905 def ShowRipPcbInfo(cmd_args
=None):
1906 """ Display the list of Raw IP protocol control block information
1908 print GetPcbInfo(addressof(kern
.globals.ripcbinfo
), IPPROTO_RAW
)
1909 # EndMacro: show_rip_pcbinfo
1911 # Macro: show_tcp_timewaitslots
1912 @lldb_command('show_tcp_timewaitslots')
1913 def ShowTcpTimeWaitSlots(cmd_args
=None):
1914 """ Display the list of the TCP protocol control blocks in TIMEWAIT
1920 if len(cmd_args
) > 0:
1921 if (int(cmd_args
[0]) == -1):
1924 slot
= int(cmd_args
[0])
1926 out_string
+= "time wait slot size " + str(N_TIME_WAIT_SLOTS
) + " cur_tw_slot " + str(int(kern
.globals.cur_tw_slot
)) + "\n"
1929 while (i
< N_TIME_WAIT_SLOTS
):
1931 head
= kern
.globals.time_wait_slots
[i
]
1932 if (i
== slot
or slot
== -1):
1933 pcb0
= cast(head
.lh_first
, 'inpcb *')
1936 pcb0
= pcb0
.inp_list
.le_next
1938 out_string
+= " slot " + str(i
) + " count " + str(perslot
) + "\n"
1940 if (_all
or i
== slot
):
1941 pcb0
= cast(head
.lh_first
, 'inpcb *')
1944 out_string
+= GetInPcb(pcb0
, IPPROTO_TCP
)
1946 pcb0
= pcb0
.inp_list
.le_next
1950 # EndMacro: show_tcp_timewaitslots
1952 # Macro: show_domains
1953 @lldb_command('show_domains')
1954 def ShowDomains(cmd_args
=None):
1955 """ Display the list of the domains
1958 domains
= kern
.globals.domains
1959 dp
= Cast(domains
.tqh_first
, 'domain *')
1960 ifma_trash_format_string
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}"
1963 out_string
+= "\"" + str(dp
.dom_name
) + "\"" + "[" + str(int(dp
.dom_refs
)) + " refs] domain " + hex(dp
) + "\n"
1964 out_string
+= " family:\t" + str(int(dp
.dom_family
)) + "\n"
1965 out_string
+= " flags:0x\t" + str(int(dp
.dom_flags
)) + "\n"
1966 out_string
+= " rtparams:\toff=" + str(int(dp
.dom_rtoffset
)) + ", maxrtkey=" + str(int(dp
.dom_maxrtkey
)) + "\n"
1969 out_string
+= " init:\t"
1970 out_string
+= GetSourceInformationForAddress(dp
.dom_init
) + "\n"
1971 if (dp
.dom_externalize
):
1972 out_string
+= " externalize:\t"
1973 out_string
+= GetSourceInformationForAddress(dp
.dom_externalize
) + "\n"
1974 if (dp
.dom_dispose
):
1975 out_string
+= " dispose:\t"
1976 out_string
+= GetSourceInformationForAddress(dp
.dom_dispose
) + "\n"
1977 if (dp
.dom_rtattach
):
1978 out_string
+= " rtattach:\t"
1979 out_string
+= GetSourceInformationForAddress(dp
.dom_rtattach
) + "\n"
1981 out_string
+= " old:\t"
1982 out_string
+= GetSourceInformationForAddress(dp
.dom_old
) + "\n"
1984 pr
= Cast(dp
.dom_protosw
.tqh_first
, 'protosw *')
1987 out_string
+= "\ttype " + str(int(pr
.pr_type
)) + ", protocol " + str(int(pr
.pr_protocol
)) + ", protosw " + hex(pr
) + "\n"
1988 out_string
+= "\t flags:0x\t" + hex(pr
.pr_flags
) + "\n"
1990 out_string
+= "\t input:\t"
1991 out_string
+= GetSourceInformationForAddress(pr
.pr_input
) + "\n"
1993 out_string
+= "\t output:\t"
1994 out_string
+= GetSourceInformationForAddress(pr
.pr_output
) + "\n"
1995 if (pr
.pr_ctlinput
):
1996 out_string
+= "\t ctlinput:\t"
1997 out_string
+= GetSourceInformationForAddress(pr
.pr_ctlinput
) + "\n"
1998 if (pr
.pr_ctloutput
):
1999 out_string
+= "\t ctloutput:\t"
2000 out_string
+= GetSourceInformationForAddress(pr
.pr_ctloutput
) + "\n"
2002 out_string
+= "\t init:\t"
2003 out_string
+= GetSourceInformationForAddress(pr
.pr_init
) + "\n"
2005 out_string
+= "\t drain:\t"
2006 out_string
+= GetSourceInformationForAddress(pr
.pr_drain
) + "\n"
2008 out_string
+= "\t sysctl:\t"
2009 out_string
+= GetSourceInformationForAddress(pr
.pr_sysctl
) + "\n"
2011 out_string
+= "\t lock:\t"
2012 out_string
+= GetSourceInformationForAddress(pr
.pr_lock
) + "\n"
2014 out_string
+= "\t unlock:\t"
2015 out_string
+= GetSourceInformationForAddress(pr
.pr_unlock
) + "\n"
2017 out_string
+= "\t getlock:\t"
2018 out_string
+= GetSourceInformationForAddress(pr
.pr_getlock
) + "\n"
2020 out_string
+= "\t old:\t"
2021 out_string
+= GetSourceInformationForAddress(pr
.pr_old
) + "\n"
2023 out_string
+= "\t pru_flags:0x\t" + hex(pru
.pru_flags
) + "\n"
2024 out_string
+= "\t abort:\t"
2025 out_string
+= GetSourceInformationForAddress(pru
.pru_abort
) + "\n"
2026 out_string
+= "\t accept:\t"
2027 out_string
+= GetSourceInformationForAddress(pru
.pru_accept
) + "\n"
2028 out_string
+= "\t attach:\t"
2029 out_string
+= GetSourceInformationForAddress(pru
.pru_attach
) + "\n"
2030 out_string
+= "\t bind:\t"
2031 out_string
+= GetSourceInformationForAddress(pru
.pru_bind
) + "\n"
2032 out_string
+= "\t connect:\t"
2033 out_string
+= GetSourceInformationForAddress(pru
.pru_connect
) + "\n"
2034 out_string
+= "\t connect2:\t"
2035 out_string
+= GetSourceInformationForAddress(pru
.pru_connect2
) + "\n"
2036 out_string
+= "\t connectx:\t"
2037 out_string
+= GetSourceInformationForAddress(pru
.pru_connectx
) + "\n"
2038 out_string
+= "\t control:\t"
2039 out_string
+= GetSourceInformationForAddress(pru
.pru_control
) + "\n"
2040 out_string
+= "\t detach:\t"
2041 out_string
+= GetSourceInformationForAddress(pru
.pru_detach
) + "\n"
2042 out_string
+= "\t disconnect:\t"
2043 out_string
+= GetSourceInformationForAddress(pru
.pru_disconnect
) + "\n"
2044 out_string
+= "\t listen:\t"
2045 out_string
+= GetSourceInformationForAddress(pru
.pru_listen
) + "\n"
2046 out_string
+= "\t peeraddr:\t"
2047 out_string
+= GetSourceInformationForAddress(pru
.pru_peeraddr
) + "\n"
2048 out_string
+= "\t rcvd:\t"
2049 out_string
+= GetSourceInformationForAddress(pru
.pru_rcvd
) + "\n"
2050 out_string
+= "\t rcvoob:\t"
2051 out_string
+= GetSourceInformationForAddress(pru
.pru_rcvoob
) + "\n"
2052 out_string
+= "\t send:\t"
2053 out_string
+= GetSourceInformationForAddress(pru
.pru_send
) + "\n"
2054 out_string
+= "\t sense:\t"
2055 out_string
+= GetSourceInformationForAddress(pru
.pru_sense
) + "\n"
2056 out_string
+= "\t shutdown:\t"
2057 out_string
+= GetSourceInformationForAddress(pru
.pru_shutdown
) + "\n"
2058 out_string
+= "\t sockaddr:\t"
2059 out_string
+= GetSourceInformationForAddress(pru
.pru_sockaddr
) + "\n"
2060 out_string
+= "\t sopoll:\t"
2061 out_string
+= GetSourceInformationForAddress(pru
.pru_sopoll
) + "\n"
2062 out_string
+= "\t soreceive:\t"
2063 out_string
+= GetSourceInformationForAddress(pru
.pru_soreceive
) + "\n"
2064 out_string
+= "\t sosend:\t"
2065 out_string
+= GetSourceInformationForAddress(pru
.pru_sosend
) + "\n"
2066 pr
= pr
.pr_entry
.tqe_next
2067 dp
= dp
.dom_entry
.tqe_next
2070 # EndMacro: show_domains