Conversation
f745a8e to
099e850
Compare
| all: memchecker.undo | ||
|
|
||
| clean: | ||
| rm *.undo *.pyc memchecker |
There was a problem hiding this comment.
I don't think any recent Python would create .pyc files in the same directory. They should go in __pycache__.
Removing all recordings is a bit scary as it may remove things customers put in there and didn't want deleted. Maybe just remove memchecker and memchecker.undo?
| int *addr = (int *)malloc(10 * sizeof(int)); | ||
| printf("Address allocated: %p\n", addr); | ||
|
|
||
| if (!(i % 10 == 0)) |
There was a problem hiding this comment.
Why !(something == something) instead of something != something? Am I missing something silly?
A comment explaining what this is doing could also be useful to users.
|
|
||
| print( | ||
| f"""\ | ||
| The {script.name!r} script can be run outside of UDB: |
There was a problem hiding this comment.
You could use textwrap.dedent.
| gdb.Breakpoint("free") | ||
|
|
||
| # Declare allocations dictionary structure. | ||
| allocations = collections.OrderedDict() |
There was a problem hiding this comment.
You can just use a dict as it has been ordered since Python 3.6 (I think).
| if udb.time.get().bbcount >= end_of_time: | ||
| break | ||
|
|
||
| # Use the $PC output to get the symbol and idenfity whether execution has stopped |
| # Do "continue" until we have gone through the whole recording, potentially | ||
| # hitting the breakpoints several times. | ||
| end_of_time = udb.get_event_log_extent().end | ||
| while True: |
There was a problem hiding this comment.
This is likely to break if there are signals in the recording. I guess it doesn't particularly matter, but maybe we should expose signals_suspended from our internal API.
|
|
||
| print(f"{time}: malloc() called: {size} byte(s) allocated at {addr}.") | ||
|
|
||
| elif re.search("free", mypc): |
|
|
||
| if addr: | ||
| # Store details in the dictionary. | ||
| allocations[hex(addr)] = time, size |
There was a problem hiding this comment.
It would be cleanear if the address was stored as an integer rather than its string representation.
| else: | ||
| print("--- INFO: Free called with null address") | ||
|
|
||
| # with redirect_to_launcher_output(): |
There was a problem hiding this comment.
Delete this commented out line?
| for location, (time, size) in allocations.items(): | ||
| total += size | ||
| print("===============================================================================") | ||
| print(f"{time}: {size} bytes was allocated at {location}, but never freed.") |
There was a problem hiding this comment.
And then here location can be printed as {location:#x}.
|
There's nothing that really needs addressing here, but I made a few suggestions. Let me know which ones you don't think are worth addressing. |
This PR adds scripts implementing a malloc/free leak detector to the addons repository.
This feature was originally implemented by Chris Croft-White.