• Sign in
 
  •  
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...

  • Blog Home
  • About
  • Email Blog Author
  • Share this
  • RSS for posts
  • Atom
  • RSS for comments
  • CDO (24)
  • Code Snippet (43)
  • Custom Providers (17)
  • Debugging (7)
  • DevMsgTeam (300)
  • Documentation (108)
  • DST (8)
  • EWS (7)
  • Exchange (108)
  • Gotchas (97)
  • Hotfix (28)
  • MAPI (239)
  • MAPI Download (53)
  • MFCMAPI (101)
  • MSDN (59)
  • Non Dev (11)
  • OOM (17)
  • Outlook (171)
  • Outlook 2007 Auxiliary Reference (45)
  • Outlook Integration API (12)
  • Protocol Docs (20)
  • PST/OST (23)
  • Referrals (8)
  • Vista (12)
  • WrapPST (18)
Links:
  • Download MFCMAPI
  • MFCMAPI on Facebook
  • Troubleshooting Outlook Crashes
  • Office Update Center
  • Developer Messaging Team Blog
This site is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.
Archives
  • May 2013 (2)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (2)
  • January 2013 (2)
  • December 2012 (4)
  • November 2012 (2)
  • October 2012 (2)
  • September 2012 (1)
  • August 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (3)
  • March 2012 (3)
  • February 2012 (3)
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (1)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (4)
  • June 2011 (3)
  • May 2011 (3)
  • April 2011 (3)
  • March 2011 (5)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (4)
  • October 2010 (1)
  • September 2010 (3)
  • August 2010 (5)
  • July 2010 (3)
  • June 2010 (3)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (4)
  • September 2009 (5)
  • August 2009 (5)
  • July 2009 (11)
  • June 2009 (6)
  • May 2009 (5)
  • April 2009 (3)
  • March 2009 (18)
  • February 2009 (10)
  • January 2009 (3)
  • December 2008 (2)
  • November 2008 (2)
  • October 2008 (5)
  • September 2008 (4)
  • August 2008 (10)
  • July 2008 (6)
  • June 2008 (8)
  • May 2008 (2)
  • April 2008 (4)
  • March 2008 (2)
  • February 2008 (2)
  • January 2008 (5)
  • December 2007 (3)
  • November 2007 (2)
  • October 2007 (3)
  • September 2007 (1)
  • August 2007 (4)
  • July 2007 (5)
  • June 2007 (3)
  • May 2007 (4)
  • April 2007 (1)
  • March 2007 (6)
  • February 2007 (3)
  • January 2007 (2)
  • December 2006 (4)
  • November 2006 (3)
  • October 2006 (1)
  • August 2006 (1)
  • June 2006 (5)
  • May 2006 (5)
  • December 2005 (1)
  • November 2005 (4)
  • October 2005 (2)
  • September 2005 (1)
  • April 2005 (3)
  • December 2004 (2)
  • September 2004 (2)
  • August 2004 (3)
  • July 2004 (3)

MAPI and User Mode Stack Tracing

MSDN Blogs > SGriffin's MAPI Internals > MAPI and User Mode Stack Tracing

MAPI and User Mode Stack Tracing

Stephen Griffin - MSFT
13 Mar 2009 10:17 AM
  • Comments 6

James wrote up a good article on analyzing a MAPI memory leak using user mode stack tracing. I wanted to highlight some points he made. Let’s look at some !heap output from one of my recent cases (using only public symbols here):

0:000> !heap -p -a 03fbec28    
    address 03fbec28 found in
    _HEAP @ 3f90000
      HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
        03fbec20 0021 0000  [07]   03fbec28    000f0 - (busy)
          ? EMSMDB32!MSProviderInit+1d27a
        Trace: 1922
        7c8531e4 ntdll!RtlAllocateHeapSlowly+0x00000041
        7c83d97a ntdll!RtlAllocateHeap+0x00000e9f
        35b732f4 EMSMDB32!MSProviderInit+0x0000186a

The line starting with the ? is the output of dps (Display Words and Symbols) against the start of the allocation. Basically, it’s saying “suppose this was a pointer – what does it point to?”. The reason it does this is in case this allocation happens to be an object. Objects are usually laid out in memory with pointers to the object’s virtual tables (vtable) at the beginning. Even without symbols, we can see that this in this case, it *could* be an object. Let’s take a closer look:

0:000> dps 03fbec28 l3
03fbec28  35b8ed04 EMSMDB32!MSProviderInit+0x1d27a
03fbec2c  35b728b8 EMSMDB32!MSProviderInit+0xe2e
03fbec30  00000001
0:000> dps 35b8ed04 l3
35b8ed04  35b90861 EMSMDB32!MSProviderInit+0x1edd7
35b8ed08  e958026a
35b8ed0c  ffff4140
0:000> dps 35b728b8 l3
35b728b8  35b90839 EMSMDB32!MSProviderInit+0x1edaf
35b728bc  35b7d7eb EMSMDB32!MSProviderInit+0xbd61
35b728c0  35b7d91f EMSMDB32!MSProviderInit+0xbe95

First, we run dps against the allocation, and see two possible vtables. If they are indeed vtables, dps against what they point to should also be code within emsmdb32. And we see that it is – the first points to a vtable with a single function, and the second points to a vtable with several functions. We can carry this further by unassembling the possible functions (such as 35b90861 or 35b90839) to see that the output does resemble a function header. Assuming we’re debugging our own process, we can look further down the stack from the !heap command and see that this memory was allocated in response to an OpenEntry call for a message, and conclude this is a message object.

Next time: we’ll take a look at flags and recognizing MAPI properties in memory.

  • 6 Comments
MAPI, DevMsgTeam, Debugging
Comments
  • SGriffin's MAPI Internals
    16 Mar 2009 11:26 AM

    Continuing our look at lessons learned from James’ article on the MAPI memory leak , we look at the memory

  • SGriffin's MAPI Internals
    16 Mar 2009 11:26 AM

    Continuing our look at lessons learned from James’ article on the MAPI memory leak , we look at the memory

  • SGriffin's MAPI Internals
    17 Mar 2009 10:07 AM

    Digging more into lessons learned from James’ blog on analyzing memory usage (my first two articles are

  • SGriffin's MAPI Internals
    20 Mar 2009 11:26 AM

    I think this will be the last article to come from James’ post on debugging MAPI (previous posts here

  • Lev
    13 Aug 2010 10:15 AM

    windbg & dv command ( sorry about hijacking this thread ).

    I'm looking at a trivial crash. if ( testCondition == 0 ) { dereference NULL; }, where testCondition is an int.

    I use dv command of WinDbg to see what the testCondition is and it gives me some meaningless number.

    I know for a fact ( and see in the debugger ) that testCondition is 0; otherwise it would not have executed the crashing code.

    What gives?  Is this not a proper use of the dv command?

    Thanks.

  • Stephen Griffin - MSFT
    16 Aug 2010 8:00 AM

    Lev - it's a well known fact that the debugger lies. :) When you run a command like dv, the debugger is making it's best guess as to where in memory/registers to look for the local variables. The trouble is - compiler optimizations can make this guess difficult or impossible. Some local variables may only actually exist for a short time, with their memory being shared with other variables after they're no longer needed. So, when the debugger guesses wrong, it may as well be showing you random data. Hence - we say it lies.

    Your best bet here is to disassemble your function and find the assembly where you actually do the test. Put your breakpoint there and read the value directly from the memory/register which is being tested. Then, assuming you read the assembly right, you know you're looking at the right data.

Page 1 of 1 (6 items)
Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post
  • © 2013 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy & Cookies
  • Report Abuse
  • 5.6.426.415