25 __all__ = [
"setCallbacks",
"mortal"]
29 from .citizen
import Citizen
33 """Set the callback IDs for the Citizen; if both is true, set both new and delete to the same value 35 You probably want to chant the following to gdb: 36 break defaultNewCallback 37 break defaultDeleteCallback 39 You might want to put this in your .gdbinit file. 41 You can retrieve a citizen's signature from python with obj.repr() 46 if delete
and new != delete:
47 raise RuntimeError(
"You may not specify new, delete, and both")
53 Citizen.setNewCallbackId(new)
55 Citizen.setDeleteCallbackId(delete)
58 def mortal(memId0=0, nleakPrintMax=20, first=True, showTypes=None):
59 """!Print leaked memory blocks 61 @param memId0 Only consider blocks allocated after this memId 62 @param nleakPrintMax Maximum number of leaks to print; <= 0 means unlimited 63 @param first Print the first nleakPrintMax blocks; if False print the last blocks. 64 @param showTypes Only print objects matching this regex (if starts with !, print objects that don't match) 66 If you want finer control than nleakPrintMax/first provide, use 67 Citizen.census() to get the entire list 69 You can get the next memId to be allocated with mortal("set"), e.g. 70 memId0 = mortal("set") 75 return Citizen.getNextMemId()
77 nleak = Citizen.census(0, memId0)
79 print(
"%d Objects leaked" % Citizen.census(0, memId0))
81 census = Citizen.census()
82 census = [census[i].repr()
for i
in range(len(census))]
84 if showTypes[0] ==
'!':
86 showTypes = showTypes[1:]
90 _census, census = census, []
92 memId, addr, dtype = c.split()
93 memId = int(memId[:-1])
95 if (
not invert
and re.search(showTypes, dtype))
or \
96 (invert
and not re.search(showTypes, dtype)):
100 print(
"%d leaked objects match" % nleak)
102 if nleakPrintMax <= 0
or nleak <= nleakPrintMax:
104 memId, addr, type = c.split()
105 memId = int(memId[:-1])
110 for i
in range(nleakPrintMax - 1, -1, -1):
def setCallbacks(new=None, delete=None, both=False)
def mortal(memId0=0, nleakPrintMax=20, first=True, showTypes=None)
Print leaked memory blocks.