24 from __future__
import absolute_import, division, print_function
26 __all__ = [
"setCallbacks",
"mortal"]
28 from builtins
import range
31 from .citizen
import Citizen
35 """Set the callback IDs for the Citizen; if both is true, set both new and delete to the same value
37 You probably want to chant the following to gdb:
38 break defaultNewCallback
39 break defaultDeleteCallback
41 You might want to put this in your .gdbinit file.
43 You can retrieve a citizen's signature from python with obj.repr()
48 if delete
and new != delete:
49 raise RuntimeError(
"You may not specify new, delete, and both")
55 Citizen.setNewCallbackId(new)
57 Citizen.setDeleteCallbackId(delete)
60 def mortal(memId0=0, nleakPrintMax=20, first=True, showTypes=None):
61 """!Print leaked memory blocks
63 @param memId0 Only consider blocks allocated after this memId
64 @param nleakPrintMax Maximum number of leaks to print; <= 0 means unlimited
65 @param first Print the first nleakPrintMax blocks; if False print the last blocks.
66 @param showTypes Only print objects matching this regex (if starts with !, print objects that don't match)
68 If you want finer control than nleakPrintMax/first provide, use
69 Citizen.census() to get the entire list
71 You can get the next memId to be allocated with mortal("set"), e.g.
72 memId0 = mortal("set")
77 return Citizen.getNextMemId()
79 nleak = Citizen.census(0, memId0)
81 print(
"%d Objects leaked" % Citizen.census(0, memId0))
83 census = Citizen.census()
84 census = [census[i].repr()
for i
in range(len(census))]
86 if showTypes[0] ==
'!':
88 showTypes = showTypes[1:]
92 _census, census = census, []
94 memId, addr, dtype = c.split()
95 memId = int(memId[:-1])
97 if (
not invert
and re.search(showTypes, dtype))
or \
98 (invert
and not re.search(showTypes, dtype)):
102 print(
"%d leaked objects match" % nleak)
104 if nleakPrintMax <= 0
or nleak <= nleakPrintMax:
106 memId, addr, type = c.split()
107 memId = int(memId[:-1])
112 for i
in range(nleakPrintMax - 1, -1, -1):
def mortal
Print leaked memory blocks.