5 ######################################
7 ######################################
10 ######################################
12 ######################################
13 @lldb_type_summary(['OSObject *'])
15 def GetObjectSummary(obj
):
16 """ Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
21 vt
= dereference(Cast(obj
, 'uintptr_t *')) - 2 * sizeof('uintptr_t')
22 vtype
= kern
.SymbolicateFromAddress(vt
)
23 if hasattr(obj
, 'retainCount'):
24 retCount
= (obj
.retainCount
& 0xffff)
25 cntnrRetCount
= (retCount
>> 16)
26 out_string
= "`object 0x{0: <16x}, vt 0x{1: <16x} <{2:s}>, retain count {3:d}, container retain {4:d}` ".format(obj
, vt
, vtype
[0].GetName(), retCount
, cntnrRetCount
)
29 out_string
= "`object 0x{0: <16x}, vt 0x{1: <16x} <{2:s}>` ".format(obj
, vt
, vtype
[0].GetName())
31 out_string
= "`object 0x{0: <16x}, vt 0x{1: <16x}` ".format(obj
, vt
)
33 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV8OSString')
35 out_string
+= GetString(obj
)
38 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV8OSSymbol')
40 out_string
+= GetString(obj
)
43 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV8OSNumber')
45 out_string
+= GetNumber(obj
)
48 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV9OSBoolean')
50 out_string
+= GetBoolean(obj
)
53 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV7OSArray')
55 out_string
+= "(" + GetArray(Cast(obj
, 'OSArray *')) + ")"
58 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV5OSSet')
60 out_string
+= GetSet(Cast(obj
, 'OSSet *'))
63 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV12OSDictionary')
65 out_string
+= GetDictionary(Cast(obj
, 'OSDictionary *'))
70 @lldb_type_summary(['IORegistryEntry *'])
72 def GetRegistryEntrySummary(entry
):
73 """ returns a string containing summary information about an IORegistry
74 object including it's registry id , vtable ptr and retain count
78 registryTable
= entry
.fRegistryTable
79 propertyTable
= entry
.fPropertyTable
81 name
= LookupKeyInOSDict(registryTable
, kern
.globals.gIOServicePlane
.nameKey
)
83 name
= LookupKeyInOSDict(registryTable
, kern
.globals.gIONameKey
)
85 name
= LookupKeyInOSDict(propertyTable
, kern
.globals.gIOClassKey
)
88 out_string
+= "+-o {0:s} ".format(GetString(Cast(name
, 'OSString *')))
89 elif Cast(entry
, 'IOService *').pwrMgt
and Cast(entry
, 'IOService *').pwrMgt
.Name
:
90 out_string
+= "+-o {0:s} ".format(Cast(entry
, 'IOService *').pwrMgt
.Name
)
92 out_string
+= "+-o ?? "
94 # I'm using uintptr_t for now to work around <rdar://problem/12749733> FindFirstType & Co. should allow you to make pointer types directly
95 vtableAddr
= dereference(Cast(entry
, 'uintptr_t *')) - 2 * sizeof('uintptr_t *')
96 vtype
= kern
.SymbolicateFromAddress(vtableAddr
)
97 if vtype
is None or len(vtype
) < 1:
98 out_string
+= "<object 0x{0: <16x}, id 0x{1:x}, vtable 0x{2: <16x}".format(entry
, entry
.reserved
.fRegistryEntryID
, vtableAddr
)
100 out_string
+= "<object 0x{0: <16x}, id 0x{1:x}, vtable 0x{2: <16x} <{3:s}>".format(entry
, entry
.reserved
.fRegistryEntryID
, vtableAddr
, vtype
[0].GetName())
102 ztvAddr
= kern
.GetLoadAddressForSymbol('_ZTV15IORegistryEntry')
103 if vtableAddr
!= ztvAddr
:
105 state
= Cast(entry
, 'IOService *').__state
[0]
106 # kIOServiceRegisteredState
109 out_string
+= "registered, "
110 # kIOServiceMatchedState
113 out_string
+= "matched, "
114 #kIOServiceInactiveState
117 busyCount
= (Cast(entry
, 'IOService *').__state
[1] & 0xff)
118 retCount
= (Cast(entry
, 'IOService *').retainCount
& 0xffff)
119 out_string
+= "active, busy {0}, retain count {1}>".format(busyCount
, retCount
)
124 ######################################
126 ######################################
127 @lldb_command('showallclasses')
128 def ShowAllClasses(cmd_args
=None):
129 """ Show the instance counts and ivar size of all OSObject subclasses.
130 See ioclasscount man page for details
133 count
= unsigned(kern
.globals.sAllClassesDict
.count
)
136 meta
= Cast(kern
.globals.sAllClassesDict
.dictionary
[idx
].value
, 'OSMetaClass *')
138 print GetMetaClass(meta
)
140 @lldb_command('showobject')
141 def ShowObject(cmd_args
=None):
142 """ Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
145 print "Please specify the address of the OSObject whose info you want to view. Type help showobject for help"
148 obj
= kern
.GetValueFromAddress(cmd_args
[0], 'OSObject *')
149 print GetObjectSummary(obj
)
151 @lldb_command('setregistryplane')
152 def SetRegistryPlane(cmd_args
=None):
153 """ Set the plane to be used for the IOKit registry macros
154 syntax: (lldb) setregistryplane 0 - will display all known planes
155 syntax: (lldb) setregistryplane 0xaddr - will set the registry plane to 0xaddr
156 syntax: (lldb) setregistryplane gIODTPlane - will set the registry plane to gIODTPlane
159 print "Please specify the name of the plane you want to use with the IOKit registry macros."
160 print SetRegistryPlane
.__doc
__
162 if cmd_args
[0] == "0":
163 print GetObjectSummary(kern
.globals.gIORegistryPlanes
)
166 plane
= kern
.GetValueFromAddress(cmd_args
[0], 'IORegistryPlane *')
169 @lldb_command('showregistryentry')
170 def ShowRegistryEntry(cmd_args
=None):
171 """ Show info about a registry entry; its properties and descendants in the current plane
172 syntax: (lldb) showregistryentry 0xaddr
173 syntax: (lldb) showregistryentry gIOPMRootDomain
176 print "Please specify the address of the registry entry whose info you want to view."
177 print ShowRegistryEntry
.__doc
__
180 entry
= kern
.GetValueFromAddress(cmd_args
[0], 'IORegistryEntry *')
181 ShowRegistryEntryRecurse(entry
, "", True)
183 @lldb_command('showregistry')
184 def ShowRegistry(cmd_args
=None):
185 """ Show info about all registry entries in the current plane
186 If prior to invoking this command no registry plane is specified
187 using 'setregistryplane', the command defaults to the IOService plane
189 ShowRegistryEntryRecurse(kern
.globals.gRegistryRoot
, "", False)
191 @lldb_command('showregistryprops')
192 def ShowRegistryProps(cmd_args
=None):
193 """ Show info about all registry entries in the current plane, and their properties
194 If prior to invoking this command no registry plane is specified
195 using 'setregistryplane', the command defaults to the IOService plane
197 ShowRegistryEntryRecurse(kern
.globals.gRegistryRoot
, "", True)
199 @lldb_command('findregistryentry')
200 def FindRegistryEntry(cmd_args
=None):
201 """ Search for registry entry that matches the given string
202 If prior to invoking this command no registry plane is specified
203 using 'setregistryplane', the command defaults to searching entries from the IOService plane
204 syntax: (lldb) findregistryentries AppleACPICPU - will find the first registry entry that matches AppleACPICPU
207 print "Please specify the name of the registry entry you want to find"
208 print FindRegistryEntry
.__doc
__
211 FindRegistryEntryRecurse(kern
.globals.gRegistryRoot
, cmd_args
[0], True)
213 @lldb_command('findregistryentries')
214 def FindRegistryEntries(cmd_args
=None):
215 """ Search for all registry entries that match the given string
216 If prior to invoking this command no registry plane is specified
217 using 'setregistryplane', the command defaults to searching entries from the IOService plane
218 syntax: (lldb) findregistryentries AppleACPICPU - will find all registry entries that match AppleACPICPU
221 print "Please specify the name of the registry entry/entries you want to find"
222 print FindRegistryEntries
.__doc
__
225 FindRegistryEntryRecurse(kern
.globals.gRegistryRoot
, cmd_args
[0], False)
227 @lldb_command('findregistryprop')
228 def FindRegistryProp(cmd_args
=None):
229 """ Given a registry entry, print out the contents for the property that matches
231 syntax: (lldb) findregistryprop 0xaddr IOSleepSupported
232 syntax: (lldb) findregistryprop gIOPMRootDomain IOSleepSupported
233 syntax: (lldb) findregistryprop gIOPMRootDomain "Supported Features"
235 if not cmd_args
or len(cmd_args
) < 2:
236 print "Please specify the address of a IORegistry entry and the property you're looking for"
237 print FindRegistryProp
.__doc
__
240 entry
= kern
.GetValueFromAddress(cmd_args
[0], 'IOService *')
241 propertyTable
= entry
.fPropertyTable
242 print GetObjectSummary(LookupKeyInPropTable(propertyTable
, cmd_args
[1]))
244 @lldb_command('readioport8')
245 def ReadIOPort8(cmd_args
=None):
246 """ Read value stored in the specified IO port. The CPU can be optionally
248 Prints 0xBAD10AD in case of a bad read
249 Syntax: (lldb) readioport8 <port> [lcpu (kernel's numbering convention)]
252 print "Please specify a port to read out of"
253 print ReadIOPort8
.__doc__
256 portAddr
= ArgumentStringToInt(cmd_args
[0])
257 if len(cmd_args
) >= 2:
258 lcpu
= ArgumentStringToInt(cmd_args
[1])
260 lcpu
= xnudefines
.lcpu_self
262 ReadIOPortInt(portAddr
, 1, lcpu
)
264 @lldb_command('readioport16')
265 def ReadIOPort8(cmd_args
=None):
266 """ Read value stored in the specified IO port. The CPU can be optionally
268 Prints 0xBAD10AD in case of a bad read
269 Syntax: (lldb) readioport16 <port> [lcpu (kernel's numbering convention)]
272 print "Please specify a port to read out of"
273 print ReadIOPort16
.__doc__
276 portAddr
= ArgumentStringToInt(cmd_args
[0])
277 if len(cmd_args
) >= 2:
278 lcpu
= ArgumentStringToInt(cmd_args
[1])
280 lcpu
= xnudefines
.lcpu_self
282 ReadIOPortInt(portAddr
, 2, lcpu
)
284 @lldb_command('readioport32')
285 def ReadIOPort8(cmd_args
=None):
286 """ Read value stored in the specified IO port. The CPU can be optionally
288 Prints 0xBAD10AD in case of a bad read
289 Syntax: (lldb) readioport32 <port> [lcpu (kernel's numbering convention)]
292 print "Please specify a port to read out of"
293 print ReadIOPort32
.__doc__
296 portAddr
= ArgumentStringToInt(cmd_args
[0])
297 if len(cmd_args
) >= 2:
298 lcpu
= ArgumentStringToInt(cmd_args
[1])
300 lcpu
= xnudefines
.lcpu_self
302 ReadIOPortInt(portAddr
, 4, lcpu
)
304 @lldb_command('writeioport8')
305 def WriteIOPort8(cmd_args
=None):
306 """ Write the value to the specified IO port. The size of the value is
307 determined by the name of the command. The CPU used can be optionally
309 Syntax: (lldb) writeioport8 <port> <value> [lcpu (kernel's numbering convention)]
311 if not cmd_args
or len(cmd_args
) < 2:
312 print "Please specify a port to write to, followed by the value you want to write"
313 print WriteIOPort8
.__doc__
316 portAddr
= ArgumentStringToInt(cmd_args
[0])
317 value
= ArgumentStringToInt(cmd_args
[1])
319 if len(cmd_args
) >= 3:
320 lcpu
= ArgumentStringToInt(cmd_args
[2])
322 lcpu
= xnudefines
.lcpu_self
324 WriteIOPortInt(portAddr
, 1, value
, lcpu
)
326 @lldb_command('writeioport16')
327 def WriteIOPort8(cmd_args
=None):
328 """ Write the value to the specified IO port. The size of the value is
329 determined by the name of the command. The CPU used can be optionally
331 Syntax: (lldb) writeioport16 <port> <value> [lcpu (kernel's numbering convention)]
333 if not cmd_args
or len(cmd_args
) < 2:
334 print "Please specify a port to write to, followed by the value you want to write"
335 print WriteIOPort16
.__doc__
338 portAddr
= ArgumentStringToInt(cmd_args
[0])
339 value
= ArgumentStringToInt(cmd_args
[1])
341 if len(cmd_args
) >= 3:
342 lcpu
= ArgumentStringToInt(cmd_args
[2])
344 lcpu
= xnudefines
.lcpu_self
346 WriteIOPortInt(portAddr
, 2, value
, lcpu
)
348 @lldb_command('writeioport32')
349 def WriteIOPort8(cmd_args
=None):
350 """ Write the value to the specified IO port. The size of the value is
351 determined by the name of the command. The CPU used can be optionally
353 Syntax: (lldb) writeioport32 <port> <value> [lcpu (kernel's numbering convention)]
355 if not cmd_args
or len(cmd_args
) < 2:
356 print "Please specify a port to write to, followed by the value you want to write"
357 print WriteIOPort32
.__doc__
360 portAddr
= ArgumentStringToInt(cmd_args
[0])
361 value
= ArgumentStringToInt(cmd_args
[1])
363 if len(cmd_args
) >= 3:
364 lcpu
= ArgumentStringToInt(cmd_args
[2])
366 lcpu
= xnudefines
.lcpu_self
368 WriteIOPortInt(portAddr
, 4, value
, lcpu
)
370 @lldb_command('showioservicepm')
371 def ShowIOServicePM(cmd_args
=None):
372 """ Routine to dump the IOServicePM object
373 Syntax: (lldb) showioservicepm <IOServicePM pointer>
376 print "Please enter the pointer to the IOServicePM object you'd like to introspect"
377 print ShowIOServicePM
.__doc
__
380 iopmpriv
= kern
.GetValueFromAddress(cmd_args
[0], 'IOServicePM *')
381 out_string
= "MachineState {0: <6d} (".format(iopmpriv
.MachineState
)
386 1: 'kIOPM_OurChangeTellClientsPowerDown',
387 2: 'kIOPM_OurChangeTellClientsPowerDown',
388 3: 'kIOPM_OurChangeNotifyInterestedDriversWillChange',
389 4: 'kIOPM_OurChangeSetPowerState',
390 5: 'kIOPM_OurChangeWaitForPowerSettle',
391 6: 'kIOPM_OurChangeNotifyInterestedDriversDidChange',
392 7: 'kIOPM_OurChangeTellCapabilityDidChange',
393 8: 'kIOPM_OurChangeFinish',
394 9: 'Unused_MachineState_9',
395 10: 'kIOPM_ParentChangeTellPriorityClientsPowerDown',
396 11: 'kIOPM_ParentChangeNotifyInterestedDriversWillChange',
397 12: 'kIOPM_ParentChangeSetPowerState',
398 13: 'kIOPM_ParentChangeWaitForPowerSettle',
399 14: 'kIOPM_ParentChangeNotifyInterestedDriversDidChange',
400 15: 'kIOPM_ParentChangeTellCapabilityDidChange',
401 16: 'kIOPM_ParentChangeAcknowledgePowerChange',
402 17: 'kIOPM_NotifyChildrenStart',
403 18: 'kIOPM_NotifyChildrenOrdered',
404 19: 'kIOPM_NotifyChildrenDelayed',
405 20: 'kIOPM_SyncTellClientsPowerDown',
406 21: 'kIOPM_SyncTellPriorityClientsPowerDown',
407 22: 'kIOPM_SyncNotifyWillChange',
408 23: 'kIOPM_SyncNotifyDidChange',
409 24: 'kIOPM_SyncTellCapabilityDidChange',
410 25: 'kIOPM_SyncFinish',
411 26: 'kIOPM_TellCapabilityChangeDone',
412 27: 'kIOPM_DriverThreadCallDone'
414 powerstate
= unsigned(iopmpriv
.MachineState
)
415 if powerstate
in pstate_map
:
416 out_string
+= "{0:s}".format(pstate_map
[powerstate
])
418 out_string
+= "Unknown_MachineState"
421 if iopmpriv
.MachineState
!= 20:
422 out_string
+= "DriverTimer = {0: <6d}, SettleTime = {1: < 6d}, HeadNoteFlags = {2: #12x}, HeadNotePendingAcks = {3: #012x}, ".format(
423 unsigned(iopmpriv
.DriverTimer
),
424 unsigned(iopmpriv
.SettleTimeUS
),
425 unsigned(iopmpriv
.HeadNoteChangeFlags
),
426 unsigned(iopmpriv
.HeadNotePendingAcks
))
428 if iopmpriv
.DeviceOverrideEnabled
!= 0:
429 out_string
+= "DeviceOverrides, "
431 out_string
+= "DeviceDesire = {0: <6d}, DesiredPowerState = {1: <6d}, PreviousRequest = {2: <6d}\n".format(
432 unsigned(iopmpriv
.DeviceDesire
),
433 unsigned(iopmpriv
.DesiredPowerState
),
434 unsigned(iopmpriv
.PreviousRequestPowerFlags
))
438 ######################################
440 ######################################
441 def ShowRegistryEntryRecurse(entry
, prefix
, printProps
):
442 """ prints registry entry summary and recurses through all its children.
447 plen
= (len(prefix
)//2)
448 registryTable
= entry
.fRegistryTable
449 propertyTable
= entry
.fPropertyTable
451 # Print entry details
452 print "{0:s}{1:s}".format(prefix
, GetRegistryEntrySummary(entry
))
453 # Printing large property tables make it look like lldb is 'stuck'
455 print GetRegDictionary(propertyTable
, prefix
+ " | ")
459 childKey
= kern
.globals.gIOServicePlane
.keys
[1]
461 childKey
= plane
.keys
[1]
462 childArray
= LookupKeyInOSDict(registryTable
, childKey
)
463 if childArray
is not None:
465 ca
= Cast(childArray
, 'OSArray *')
466 count
= unsigned(ca
.count
)
468 if plen
!= 0 and plen
!= 1 and (plen
& (plen
- 1)) == 0:
469 ShowRegistryEntryRecurse(Cast(ca
.array
[idx
], 'IORegistryEntry *'), prefix
+ "| ", printProps
)
471 ShowRegistryEntryRecurse(Cast(ca
.array
[idx
], 'IORegistryEntry *'), prefix
+ " ", printProps
)
474 def FindRegistryEntryRecurse(entry
, search_name
, stopAfterFirst
):
475 """ Checks if given registry entry's name matches the search_name we're looking for
476 If yes, it prints the entry's summary and then recurses through its children
477 If no, it does nothing and recurses through its children
481 registryTable
= entry
.fRegistryTable
482 propertyTable
= entry
.fPropertyTable
486 name
= LookupKeyInOSDict(registryTable
, kern
.globals.gIOServicePlane
.nameKey
)
488 name
= LookupKeyInOSDict(registryTable
, kern
.globals.gIONameKey
)
490 name
= LookupKeyInOSDict(propertyTable
, kern
.globals.gIOClassKey
)
493 if str(Cast(name
, 'OSString *').string
) == search_name
:
494 print GetRegistryEntrySummary(entry
)
495 if stopAfterFirst
is True:
497 elif Cast(entry
, 'IOService *').pwrMgt
and Cast(entry
, 'IOService *').pwrMgt
.Name
:
498 name
= Cast(entry
, 'IOService *').pwrMgt
.Name
499 if str(name
) == search_name
:
500 print GetRegistryEntrySummary(entry
)
501 if stopAfterFirst
is True:
506 childKey
= kern
.globals.gIOServicePlane
.keys
[1]
508 childKey
= plane
.keys
[1]
509 childArray
= LookupKeyInOSDict(registryTable
, childKey
)
510 if childArray
is not None:
512 ca
= Cast(childArray
, 'OSArray *')
513 count
= unsigned(ca
.count
)
515 if FindRegistryEntryRecurse(Cast(ca
.array
[idx
], 'IORegistryEntry *'), search_name
, stopAfterFirst
) is True:
520 def FindRegistryObjectRecurse(entry
, search_name
):
521 """ Checks if given registry entry's name matches the search_name we're looking for
522 If yes, return the entry
523 If no, it does nothing and recurses through its children
524 Implicitly stops after finding the first entry
528 registryTable
= entry
.fRegistryTable
529 propertyTable
= entry
.fPropertyTable
533 name
= LookupKeyInOSDict(registryTable
, kern
.globals.gIOServicePlane
.nameKey
)
535 name
= LookupKeyInOSDict(registryTable
, kern
.globals.gIONameKey
)
537 name
= LookupKeyInOSDict(propertyTable
, kern
.globals.gIOClassKey
)
540 if str(Cast(name
, 'OSString *').string
) == search_name
:
542 elif Cast(entry
, 'IOService *').pwrMgt
and Cast(entry
, 'IOService *').pwrMgt
.Name
:
543 name
= Cast(entry
, 'IOService *').pwrMgt
.Name
544 if str(name
) == search_name
:
549 childKey
= kern
.globals.gIOServicePlane
.keys
[1]
551 childKey
= plane
.keys
[1]
552 childArray
= LookupKeyInOSDict(registryTable
, childKey
)
553 if childArray
is not None:
554 ca
= Cast(childArray
, 'OSArray *')
555 for idx
in range(ca
.count
):
556 registry_object
= FindRegistryObjectRecurse(Cast(ca
.array
[idx
], 'IORegistryEntry *'), search_name
)
557 if not registry_object
or int(registry_object
) == int(0):
560 return registry_object
563 def LookupKeyInOSDict(osdict
, key
):
564 """ Returns the value corresponding to a given key in a OSDictionary
565 Returns None if the key was not found
569 count
= unsigned(osdict
.count
)
572 while idx
< count
and result
is None:
573 if key
== osdict
.dictionary
[idx
].key
:
574 result
= osdict
.dictionary
[idx
].value
578 def LookupKeyInPropTable(propertyTable
, key_str
):
579 """ Returns the value corresponding to a given key from a registry entry's property table
580 Returns None if the key was not found
581 The property that is being searched for is specified as a string in key_str
583 if not propertyTable
:
585 count
= unsigned(propertyTable
.count
)
588 while idx
< count
and result
is None:
589 if key_str
== str(propertyTable
.dictionary
[idx
].key
.string
):
590 result
= propertyTable
.dictionary
[idx
].value
594 def GetRegDictionary(osdict
, prefix
):
595 """ Returns a specially formatted string summary of the given OSDictionary
596 This is done in order to pretty-print registry property tables in showregistry
599 out_string
= prefix
+ "{\n"
601 count
= unsigned(osdict
.count
)
604 out_string
+= prefix
+ " " + GetObjectSummary(osdict
.dictionary
[idx
].key
) + " = " + GetObjectSummary(osdict
.dictionary
[idx
].value
) + "\n"
606 out_string
+= prefix
+ "}\n"
609 def GetString(string
):
610 """ Returns the python string representation of a given OSString
612 out_string
= "\"{0:s}\"".format(Cast(string
, 'OSString *').string
)
616 out_string
= "{0:d}".format(Cast(num
, 'OSNumber *').value
)
620 """ Shows info about a given OSBoolean
623 if b
== kern
.globals.gOSBooleanFalse
:
629 def GetMetaClass(mc
):
630 """ Shows info about a given OSSymbol
632 out_string
= "{0: <5d}x {1: >5d} bytes {2:s}\n".format(mc
.instanceCount
, mc
.classSize
, mc
.className
.string
)
636 """ Returns a string containing info about a given OSArray
640 count
= unsigned(arr
.count
)
645 out_string
+= GetObjectSummary(obj
)
646 if idx
< unsigned(arr
.count
):
650 def GetDictionary(d
):
651 """ Returns a string containing info about a given OSDictionary
655 count
= unsigned(d
.count
)
658 obj
= d
.dictionary
[idx
].key
659 out_string
+= GetObjectSummary(obj
) + "="
660 obj
= d
.dictionary
[idx
].value
662 out_string
+= GetObjectSummary(obj
)
669 """ Returns a string containing info about a given OSSet
671 out_string
+= "[" + GetArray(se
.members
) + "]"
674 def ReadIOPortInt(addr
, numbytes
, lcpu
):
675 """ Prints results after reading a given ioport
679 if "kdp" != GetConnectionProtocol():
680 print "Target is not connected over kdp. Nothing to do here."
683 # Set up the manual KDP packet
684 input_address
= unsigned(addressof(kern
.globals.manual_pkt
.input))
685 len_address
= unsigned(addressof(kern
.globals.manual_pkt
.len))
686 data_address
= unsigned(addressof(kern
.globals.manual_pkt
.data
))
687 if not WriteInt32ToMemoryAddress(0, input_address
):
688 print "0x{0: <4x}: 0x{1: <1x}".format(addr
, result
)
691 kdp_pkt_size
= GetType('kdp_readioport_req_t').GetByteSize()
692 if not WriteInt32ToMemoryAddress(kdp_pkt_size
, len_address
):
693 print "0x{0: <4x}: 0x{1: <1x}".format(addr
, result
)
696 kgm_pkt
= kern
.GetValueFromAddress(data_address
, 'kdp_readioport_req_t *')
698 header_value
= GetKDPPacketHeaderInt(request
=GetEnumValue('kdp_req_t::KDP_READIOPORT'), length
= kdp_pkt_size
)
700 if( WriteInt64ToMemoryAddress((header_value
), int(addressof(kgm_pkt
.hdr
))) and
701 WriteInt16ToMemoryAddress(addr
, int(addressof(kgm_pkt
.address
))) and
702 WriteInt32ToMemoryAddress(numbytes
, int(addressof(kgm_pkt
.nbytes
))) and
703 WriteInt16ToMemoryAddress(lcpu
, int(addressof(kgm_pkt
.lcpu
))) and
704 WriteInt32ToMemoryAddress(1, input_address
)
707 result_pkt
= Cast(addressof(kern
.globals.manual_pkt
.data
), 'kdp_readioport_reply_t *')
709 if(result_pkt
.error
== 0):
710 print "This macro is incomplete till <rdar://problem/12868059> is fixed"
711 # FIXME: Uncomment me when <rdar://problem/12868059> is fixed
713 # result = dereference(Cast(result_pkt.data, 'uint8_t *'))
715 # result = dereference(Cast(result_pkt.data, 'uint16_t *'))
717 # result = dereference(cast(result_pkt.data, 'uint32_t *'))
719 print "0x{0: <4x}: 0x{1: <1x}".format(addr
, result
)
721 def WriteIOPortInt(addr
, numbytes
, value
, lcpu
):
722 """ Writes 'value' into ioport specified by 'addr'. Prints errors if it encounters any
724 if "kdp" != GetConnectionProtocol():
725 print "Target is not connected over kdp. Nothing to do here."
728 # Set up the manual KDP packet
729 input_address
= unsigned(addressof(kern
.globals.manual_pkt
.input))
730 len_address
= unsigned(addressof(kern
.globals.manual_pkt
.len))
731 data_address
= unsigned(addressof(kern
.globals.manual_pkt
.data
))
732 if not WriteInt32ToMemoryAddress(0, input_address
):
733 print "error writing 0x{0: x} to port 0x{1: <4x}".format(value
, addr
)
736 kdp_pkt_size
= GetType('kdp_writeioport_req_t').GetByteSize()
737 if not WriteInt32ToMemoryAddress(kdp_pkt_size
, len_address
):
738 print "error writing 0x{0: x} to port 0x{1: <4x}".format(value
, addr
)
741 kgm_pkt
= kern
.GetValueFromAddress(data_address
, 'kdp_writeioport_req_t *')
743 header_value
= GetKDPPacketHeaderInt(request
=GetEnumValue('kdp_req_t::KDP_WRITEIOPORT'), length
= kdp_pkt_size
)
745 if( WriteInt64ToMemoryAddress((header_value
), int(addressof(kgm_pkt
.hdr
))) and
746 WriteInt16ToMemoryAddress(addr
, int(addressof(kgm_pkt
.address
))) and
747 WriteInt32ToMemoryAddress(numbytes
, int(addressof(kgm_pkt
.nbytes
))) and
748 WriteInt16ToMemoryAddress(lcpu
, int(addressof(kgm_pkt
.lcpu
)))
750 print "This macro is incomplete till <rdar://problem/12868059> is fixed"
751 # FIXME: Uncomment me when <rdar://problem/12868059> is fixed
753 # if not WriteInt8ToMemoryAddress(value, int(addressof(kgm_pkt.data))):
754 # print "error writing 0x{0: x} to port 0x{1: <4x}".format(value, addr)
756 # if not WriteInt16ToMemoryAddress(value, int(addressof(kgm_pkt.data))):
757 # print "error writing 0x{0: x} to port 0x{1: <4x}".format(value, addr)
759 # if not WriteInt32ToMemoryAddress(value, int(addressof(kgm_pkt.data))):
760 # print "error writing 0x{0: x} to port 0x{1: <4x}".format(value, addr)
762 if not WriteInt32ToMemoryAddress(1, input_address
):
763 print "error writing 0x{0: x} to port 0x{1: <4x}".format(value
, addr
)
766 result_pkt
= Cast(addressof(kern
.globals.manual_pkt
.data
), 'kdp_writeioport_reply_t *')
768 # Done with the write
769 if(result_pkt
.error
== 0):
770 print "Writing 0x {0: x} to port {1: <4x} was successful".format(value
, addr
)
772 print "error writing 0x{0: x} to port 0x{1: <4x}".format(value
, addr
)