]>
git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/ntstat.py
1 """ Please make sure you read the README COMPLETELY BEFORE reading anything below.
2 It is very critical that you read coding guidelines in Section E in README file.
11 from netdefines
import *
12 from routedefines
import *
14 def ShowNstatTUShadow(inshadow
):
15 """ Display summary for an nstat_tu_shadow struct
17 inshadow : cvalue object which points to 'struct nstat_tu_shadow *'
19 shad
= Cast(inshadow
, 'struct nstat_tu_shadow *')
20 procdetails
= shad
.shad_procdetails
23 format_string
= "nstat_tu_shadow {0: <s}: next={1: <s} prev={2: <s} context (necp_client *)={3: <s} live={4: <d}"
24 out_string
+= format_string
.format(hex(shad
), hex(shad
.shad_link
.tqe_next
), hex(shad
.shad_link
.tqe_prev
), hex(shad
.shad_provider_context
),shad
.shad_live
)
26 magic
= unsigned(shad
.shad_magic
)
27 if (magic
!= 0xfeedf00d) :
28 format_string
= " INVALID shad magic {0: <s}"
29 out_string
+= format_string
.format(hex(magic
))
32 format_string
= " --> procdetails {0: <s}: pid={1: <d} name={2: <s} numflows={3: <d}"
33 out_string
+= format_string
.format(hex(procdetails
), procdetails
.pdet_pid
, procdetails
.pdet_procname
, procdetails
.pdet_numflows
)
35 procmagic
= unsigned(procdetails
.pdet_magic
)
36 if (procmagic
!= 0xfeedc001) :
37 format_string
= " INVALID proc magic {0: <s}"
38 out_string
+= format_string
.format(hex(procmagic
))
42 def GetNstatProcdetailsBrief(procdetails
):
43 """ Display a brief summary for an nstat_procdetails struct
45 procdetails : cvalue object which points to 'struct nstat_procdetails *'
47 str : A string describing various information for the nstat_procdetails structure
49 procdetails
= Cast(procdetails
, 'struct nstat_procdetails *')
52 format_string
= " --> pid={0: <d} name={1: <s} numflows={2: <d}"
53 out_string
+= format_string
.format(procdetails
.pdet_pid
, procdetails
.pdet_procname
, procdetails
.pdet_numflows
)
55 procmagic
= unsigned(procdetails
.pdet_magic
)
56 if (procmagic
!= 0xfeedc001) :
57 format_string
= " INVALID proc magic {0: <s}"
58 out_string
+= format_string
.format(hex(procmagic
))
62 def ShowNstatProcdetails(procdetails
):
63 """ Display a summary for an nstat_procdetails struct
65 procdetails : cvalue object which points to 'struct nstat_procdetails *'
67 procdetails
= Cast(procdetails
, 'struct nstat_procdetails *')
70 format_string
= "nstat_procdetails: {0: <s} next={1: <s} prev={2: <s} "
71 out_string
+= format_string
.format(hex(procdetails
), hex(procdetails
.pdet_link
.tqe_next
), hex(procdetails
.pdet_link
.tqe_prev
))
72 out_string
+= GetNstatProcdetailsBrief(procdetails
)
76 def GetNstatTUShadowBrief(shadow
):
77 """ Display a summary for an nstat_tu_shadow struct
79 shadow : cvalue object which points to 'struct nstat_tu_shadow *'
81 str : A string describing various information for the nstat_tu_shadow structure
84 shad
= Cast(shadow
, 'struct nstat_tu_shadow *')
85 procdetails
= shad
.shad_procdetails
86 procdetails
= Cast(procdetails
, 'struct nstat_procdetails *')
89 format_string
= " shadow {0: <s}: necp_client ={1: <s} live={2: <d}"
90 out_string
+= format_string
.format(hex(shad
),hex(shad
.shad_provider_context
),shad
.shad_live
)
91 magic
= unsigned(shad
.shad_magic
)
92 if (magic
!= 0xfeedf00d) :
93 format_string
= " INVALID shad magic {0: <s}"
94 out_string
+= format_string
.format(hex(magic
))
96 out_string
+= GetNstatProcdetailsBrief(procdetails
)
100 def ShowNstatSrc(insrc
):
101 """ Display summary for an nstat_src struct
103 insrc : cvalue object which points to 'struct nstat_src *'
105 src
= Cast(insrc
, 'nstat_src *')
107 prov
= Cast(prov
, 'nstat_provider *')
109 if (prov
.nstat_provider_id
== 2):
110 prov_string
= "TCP k"
111 elif (prov
.nstat_provider_id
== 3):
112 prov_string
= "TCP u"
113 elif (prov
.nstat_provider_id
== 4):
114 prov_string
= "UDP k"
115 elif (prov
.nstat_provider_id
== 5):
116 prov_string
= "UDP u"
117 elif (prov
.nstat_provider_id
== 1):
118 prov_string
= "Route"
119 elif (prov
.nstat_provider_id
== 6):
120 prov_string
= "ifnet"
121 elif (prov
.nstat_provider_id
== 7):
122 prov_string
= "sysinfo"
124 prov_string
= "unknown-provider"
128 format_string
= " nstat_src {0: <s}: prov={1: <s} next={2: <s} prev={3: <s} ref={4: <d}"
129 out_string
+= format_string
.format(hex(src
), prov_string
, hex(src
.ns_control_link
.tqe_next
), hex(src
.ns_control_link
.tqe_prev
), src
.srcref
)
131 if (prov
.nstat_provider_id
== 3):
132 out_string
+= GetNstatTUShadowBrief(src
.cookie
);
136 def ShowNstatCtrl(inctrl
):
137 """ Display an nstat_control_state struct
139 ctrl : value object representing an nstat_control_state in the kernel
141 ctrl
= Cast(inctrl
, 'nstat_control_state *')
144 format_string
= "nstat_control_state {0: <s}: next={1: <s} src head={2: <s} tail={3: <s}"
145 out_string
+= format_string
.format(hex(ctrl
), hex(ctrl
.ncs_next
), hex(ctrl
.ncs_src_queue
.tqh_first
), hex(ctrl
.ncs_src_queue
.tqh_last
))
149 for src
in IterateTAILQ_HEAD(ctrl
.ncs_src_queue
, 'ns_control_link'):
152 # Macro: showallntstat
154 @lldb_command('showallntstat')
155 def ShowAllNtstat(cmd_args
=None) :
156 """ Show the contents of various ntstat (network statistics) data structures
158 print "nstat_controls list:\n"
159 ctrl
= kern
.globals.nstat_controls
160 ctrl
= cast(ctrl
, 'nstat_control_state *')
163 ctrl
= cast(ctrl
.ncs_next
, 'nstat_control_state *')
165 print "\nnstat_userprot_shad list:\n"
166 shadows
= kern
.globals.nstat_userprot_shad_head
167 for shad
in IterateTAILQ_HEAD(shadows
, 'shad_link'):
168 ShowNstatTUShadow(shad
)
170 print "\nnstat_procdetails list:\n"
171 procdetails_head
= kern
.globals.nstat_procdetails_head
172 for procdetails
in IterateTAILQ_HEAD(procdetails_head
, 'pdet_link'):
173 ShowNstatProcdetails(procdetails
)
175 # EndMacro: showallntstat