0

I want to monitor (or place a breakpoint on) each change of a static field which is member of an internal class which resides in an external assembly for which I don't have code:

Assembly: PresentationCore.dll
Class   : MS.Internal.MemoryPressure
Field   : private static long _totalMemory

Ideally I should be able to see the stacktraces which trigger the changes.

Is this possible with VS and if yes then how do I have to setup VS in order to do this? Or will I need some external profiling tool?

1
  • You can possibly decompile it using smth like Reflector and then use VS to debug this. However, I'm not sure it will work.
    – Iarek
    Sep 18, 2011 at 13:07

4 Answers 4

1

You cannot set a breakpoint on a field. You are in luck, there's only one method that modifies the value, called AddToTotal. Debug + New Breakpoint + Break At Function. Type "MS.Internal.MemoryPressure.AddToTotal" and untick the "Use IntelliSense" option. The debugger will break as soon as the method is called, typically when the code creates a bitmap. You will only have machine code to look at.

As soon as it breaks, you can add a watch for MS.Internal.MemoryPressure._totalMemory. Adjust the breakpoint in the disassembly so it breaks past the field assignment.

4
  • The breakpoint got added and is visible in the Breakpoints window but the debugger does never stop there. (Just my code is already disabled)
    – springy76
    Sep 18, 2011 at 13:44
  • Test it by adding an Image control to the window with a valid Source property value. That reliably triggered the breakpoint when I tried it. The field only tracks Milcore resources. Sep 18, 2011 at 13:45
  • My app contains explicit calls to WriteableBitmap.ctor(width, height, [..]) so this definitely should stop there. But I have to find out why this counter seems to be constantly >1MB (and so triggering GC.Collect(2) very often) maybe caused by some 3rd party component (Actipro, xceed, ...).
    – springy76
    Sep 18, 2011 at 13:53
  • Having changed AnyCPU -> x86 at least this breakpoint stops (but still no PDBs for PresentationCore and PresentationFramework)
    – springy76
    Sep 18, 2011 at 14:32
1

Since PresentationCore is part of .Net you can debug the framework source
Take a look at this question

3
  • Ok, I can load symbols for a module but how do I then find the place where I want the debugger to stop?
    – springy76
    Sep 18, 2011 at 13:13
  • The sources are there, on your computer (assuming you're using VS 2008/2010), you just have to find the right file, take a look at the question I've added link to Sep 18, 2011 at 13:20
  • I have no luck: While symbols got loaded for most of the framework assemblies (System.Data.dll, System.Data.Entity.dll, etc.) they didn't for PresentationCore.dll: "Cannot find or open the PDB file" -- manually triggering "Loading Symbols from -> Microsoft Symbol servers" doesn't change anything.
    – springy76
    Sep 18, 2011 at 13:42
0

what about this: http://ayende.com/blog/4106/nhibernate-inotifypropertychanged

0

Both RedGate Reflector as well as JetBrains Resharper can help you do it. They both decompile the assembly and generate the C# source code after which they allow you to work with it as if it were yours including placing breakpoints, watching the stack, etc.

I started with reflector, but now (starting from v.6) I switched to resharper it seems at this point to be more robust. Resharper has a 30 days trial, reflector used to be free I am not sure what it is now

1
  • R# was able to show/download the source but breakpoints don't hit (most likely because debugger still doesn't find pdbs for PresentationCore.dll). BTW: R# has a 30 days trial.
    – springy76
    Sep 18, 2011 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.