Skip to content

Capture function info from call stack for memory leak detection.#1146

Open
jgonzalezdr wants to merge 6 commits intocpputest:masterfrom
jgonzalezdr:memleak_callstack
Open

Capture function info from call stack for memory leak detection.#1146
jgonzalezdr wants to merge 6 commits intocpputest:masterfrom
jgonzalezdr:memleak_callstack

Conversation

@jgonzalezdr
Copy link
Copy Markdown
Contributor

When the new operator override macros are not used (e.g. to avoid STL
errors), the function that called the new operator is traced by
inspecting the call stack.

Currently only works for GCC when the backtrace function is supported
(i.e. no support for MinGW).

When the new operator override macros are not used (e.g. to avoid STL
errors), the function that called the new operator is traced by
inspecting the call stack.

Currently only works for GCC when the backtrace function is supported
(i.e. no support for MinGW).
@coveralls
Copy link
Copy Markdown

coveralls commented Mar 19, 2018

Coverage Status

Coverage decreased (-0.3%) to 99.612% when pulling 175e585 on jgonzalezdr:memleak_callstack into 952bf2d on cpputest:master.

@jgonzalezdr
Copy link
Copy Markdown
Contributor Author

This is a preliminary PR just to discuss this feature, as started in #34. The next step I'll do is to call addr2line to obtain file and line info when printing report.

Afterwards, many different improvement can be done: Add support for Win32 equivalent functionality, maybe clang support also, partially import addr2line functionality to avoid executing external calls (and break dependency with addr2line being installed / accessible), etc.

Also, not related to mem leaks, I'll also explore adding callstack printing when a failure is raised.

Some specific tail call optimizations have been disabled in GCC and
Clang to ensure call stack distance is constant and consistent
@basvodde
Copy link
Copy Markdown
Member

Thanks for the initial PR. This will definitively not be integrated as-is. It'll require a lot of work still.

As a starting point though. Could you make a pull request for the rfind in SimpleString. But please rename it properly, fix the implementation to be more in the style of the rest of CppUTest, and add proper test to it. It is a good chance for practices TDD as it is such an isolated piece of code.

@basvodde
Copy link
Copy Markdown
Member

Also, the eventual implementation will need to be so that there are much much much less #if in the code.

@jgonzalezdr
Copy link
Copy Markdown
Contributor Author

@basvodde This is just a proof of concept, I wanted to keep it simple so you an others can test it a bit, see if it is useful, see quickly what needs to be changed, etc. A final version will definitely need some "preparation" PRs to make some structural changes, will need to add some optimization to keep the memory footprint of memory allocation info nodes the same than now, etc., but will of course be a bit more complex (even if tidier) and a bit harder to review.

Regarding the rfind functions, I've just cherry picked that quickly from a dangling branch I've got here for another feature I'm playing with, it's got its UT, so I can push that quickly. However, what do you mean by "fix the implementation to be more in the style of the rest of CppUTest"? Just code style?

@basvodde
Copy link
Copy Markdown
Member

Ok. I'll ignore this for now then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants