Finding GDI/User resource usage from a crash dump
Asked Answered
T

3

6

I have a crash dump of an application that is supposedly leaking GDI. The app is running on XP and I have no problems loading it into WinDbg to look at it. Previously we have use the Gdikdx.dll extension to look at Gdi information but this extension is not supported on XP or Vista.

Does anyone have any pointers for finding GDI object usage in WinDbg.

Alternatively, I do have access to the failing program (and its stress testing suite) so I can reproduce on a running system if you know of any 'live' debugging tools for XP and Vista (or Windows 2000 though this is not our target).

Typist answered 19/9, 2008 at 18:0 Comment(0)
C
4

There was a MSDN Magazine article from several years ago that talked about GDI leaks. This points to several different places with good information.

In WinDbg, you may also try the !poolused command for some information.

Finding resource leaks in from a crash dump (post-mortem) can be difficult -- if it was always the same place, using the same variable that leaks the memory, and you're lucky, you could see the last place that it will be leaked, etc. It would probably be much easier with a live program running under the debugger.

You can also try using Microsoft Detours, but the license doesn't always work out. It's also a bit more invasive and advanced.

Compony answered 19/9, 2008 at 18:5 Comment(0)
U
5

I've spent the last week working on a GDI leak finder tool. We also perform regular stress testing and it never lasted longer than a day's worth w/o stopping due to user/gdi object handle overconsumption.

My attempts have been pretty successful as far as I can tell. Of course, I spent some time beforehand looking for an alternative and quicker solution. It is worth mentioning, I had some previous semi-lucky experience with the GDILeaks tool from msdn article mentioned above. Not to mention that i had to solve a few problems prior to putting it to work and this time it just didn't give me what and how i wanted it. The downside of their approach is the heavyweight debugger interface (it slows down the researched target by orders of magnitude which I found unacceptable). Another downside is that it did not work all the time - on some runs I simply could not get it to report/compute anything! Its complexity (judging by the amount of code) was another scare-away factor. I'm not a big fan of GUIs, as it is my belief that I'm more productive with no windows at all ;o). I also found it hard to make it find and use my symbols.

One more tool I used before setting on to write my own, was the leakbrowser.

Anyways, I finally settled on an iterative approach to achieve following goals:

  • minor performance penalties
  • implementation simplicity
  • non-invasiveness (used for multiple products)
  • relying on as much available as possible

I used detours (non-commercial use) for core functionality (it is an injectible DLL). Put Javascript to use for automatic code generation (15K script to gen 100K source code - no way I code this manually and no C preprocessor involved!) plus a windbg extension for data analysis and snapshot/diff support.

To tell the long story short - after I was finished, it was a matter of a few hours to collect information during another stress test and another hour to analyze and fix the leaks.

I'll be more than happy to share my findings.

P.S. some time did I spend on trying to improve on the previous work. My intention was minimizing false positives (I've seen just about too many of those while developing), so it will also check for allocation/release consistency as well as avoid taking into account allocations that are never leaked.

Edit: Find the tool here

Unearthly answered 17/10, 2008 at 19:33 Comment(0)
C
4

There was a MSDN Magazine article from several years ago that talked about GDI leaks. This points to several different places with good information.

In WinDbg, you may also try the !poolused command for some information.

Finding resource leaks in from a crash dump (post-mortem) can be difficult -- if it was always the same place, using the same variable that leaks the memory, and you're lucky, you could see the last place that it will be leaked, etc. It would probably be much easier with a live program running under the debugger.

You can also try using Microsoft Detours, but the license doesn't always work out. It's also a bit more invasive and advanced.

Compony answered 19/9, 2008 at 18:5 Comment(0)
M
0

I have created a Windbg script for that. Look at the answer of

Command to get GDI handle count from a crash dump

To track the allocation stack you could set a ba (Break on Access) breakpoint past the last allocated GDICell object to break just at the point when another GDI allocation happens. That could be a bit complex because the address changes but it could be enough to find pretty much any leak.

Mockingbird answered 27/6, 2016 at 8:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.