This project has moved. For the latest updates, please go here.
3

Closed

Separation of "GetSymbols" and "StackWalk"

description

Original from:
http://www.codeproject.com/Messages/3136502/Many-thanks-and-a-couple-of-change-suggestions.aspx
 
Dear Jochen,
 
First of all, many thanks for this excellent and well-written project.
 
I have used it to build a memory leak checker that dumps the callstack of each leak. The leak checker works by recording the addresses of the callstack for each malloc. When the program exits, the record is examined for unfreed blocks and at that time (not before!) the symbols (functionName, filename, line number, etc) are resolved and a report is generated.
 
In order to make this work efficiently, I have had to make a couple of small changes to StackWalker, which I would like to share with you as they may be of general interest.
 
  1. Logical separation of Stack Walking and Symbols Resolution. ShowCallstack separated into 2 methods: ShowCallStack() and GetSymbols(). Based on the options flags, the ShowCallstack() method may or may not call the GetSymbols() method. This was done in order to be able to call GetSymbols from elsewhere also - e.g. at exit time when dumping the recorded callstacks.
     
  2. Logical separation of DLL initialization and symbols loading. The first call to ShowCallstack inits the DbgHelp DLLs, the first call to GetSymbols() loads the modules. Why bother? Because for some reason stack walking (even if we don't resolve the symbols at that time) is 1 to 2 orders of magnitude slower if the modules have been loaded! Anybody know why? (this observation made on an intel running Vista Ultimate, service pack 2).
     
  3. OnCallstackEntry() returns a BOOL indicating whether or not to terminate the StackWalk. This is to allow clients to walk up to a maximum depth (helpful, because StackWalking is slow).
     
    I would be happy to share the modified sources with anyone who is interested.
    Once again, thanks for a most excellent and useful post.
     
    Kind regards,
     
    Greg Labute
    Software Architect
    National Film Board of Canada

file attachments

Closed Dec 30, 2016 at 9:03 AM by jkalmbach
Waiting for a pull request

comments

boumaour wrote Feb 25, 2010 at 2:42 PM

Hi Greg,

I'm in the very same situation (memory leak checker) and I'd like to get your changes if they are still available.

Thanks in advance.
Éric Boumaour

rhfritz wrote Nov 29, 2011 at 4:49 PM

Hi Greg,

Ditto for me. :-)

Thanks in advance.

Rob Fritz

glabute wrote Jan 7, 2013 at 5:05 PM

Here is my my version of the header, based on v14.Implementation to follow.Best regards,Greg

glabute wrote Jan 7, 2013 at 5:07 PM

And here is the implementation, based on v14.Best regards,Greg

jkalmbach wrote Dec 30, 2016 at 9:02 AM

Can you create a pull-request?