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 34 delete to the same value. 36 You probably want to chant the following to gdb: 37 * break defaultNewCallback 38 * break defaultDeleteCallback 40 You might want to put this in your ``.gdbinit`` file. 42 You can retrieve a citizen's signature from python with ``obj.repr()``. 47 if delete
and new != delete:
48 raise RuntimeError(
"You may not specify new, delete, and both")
54 Citizen.setNewCallbackId(new)
56 Citizen.setDeleteCallbackId(delete)
59 def mortal(memId0=0, nleakPrintMax=20, first=True, showTypes=None):
60 """!Print leaked memory blocks 62 @param memId0 Only consider blocks allocated after this memId 63 @param nleakPrintMax Maximum number of leaks to print; <= 0 means unlimited 64 @param first Print the first nleakPrintMax blocks; if False print the last 66 @param showTypes Only print objects matching this regex (if starts with !, 67 print objects that don't match) 69 If you want finer control than nleakPrintMax/first provide, use 70 Citizen.census() to get the entire list 72 You can get the next memId to be allocated with mortal("set"), e.g. 73 memId0 = mortal("set") 78 return Citizen.getNextMemId()
80 nleak = Citizen.census(0, memId0)
82 print(
"%d Objects leaked" % Citizen.census(0, memId0))
84 census = Citizen.census()
85 census = [census[i].repr()
for i
in range(len(census))]
87 if showTypes[0] ==
'!':
89 showTypes = showTypes[1:]
93 _census, census = census, []
95 memId, addr, dtype = c.split()
96 memId =
int(memId[:-1])
98 if (
not invert
and re.search(showTypes, dtype))
or \
99 (invert
and not re.search(showTypes, dtype)):
103 print(
"%d leaked objects match" % nleak)
105 if nleakPrintMax <= 0
or nleak <= nleakPrintMax:
107 memId, addr, type = c.split()
108 memId =
int(memId[:-1])
113 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.