locked
how to examine a collection in debugger RRS feed

  • Question

  • How can I see what is in a collection (CStringArray)?
    I can see just the 1st item in the debugger (m_pData).

    Thanks
    Vaclav
    Friday, March 12, 2010 9:06 PM

Answers

  • How can I see what is in a collection (CStringArray)?
    I can see just the 1st item in the debugger (m_pData).

    In addition to my previous post, I developed a simple CStringArray visualizer.
    I tested it in VS2008 SP1, and it seems to work fine.

    You can copy-and-paste the following visualizer code in the autoexp.dat file (which is just a text file, located under <VS2008 Installation Directory>\Common7\Packages\Debugger\), under [Visualizer] section (I put it after ATL::CComBSTR definition in the [Visualizer] section).

    ;------------------------------------------------------------------------------
    ;  CStringArray
    ;------------------------------------------------------------------------------
    CStringArray{
        children 
        (
            #array
            (
                expr :      ($e.m_pData)[$i],
                size :      $e.m_nSize
    		)
        )
        preview 
        (
            #(
                "[", $e.m_nSize, "](",
                #array
                (
                    expr :	($e.m_pData)[$i],
                    size :	$e.m_nSize
                ),
                ")"
            )
        )
    }
    


    Giovanni

    • Marked as answer by vjedlicka Saturday, March 13, 2010 12:18 PM
    Saturday, March 13, 2010 11:55 AM

All replies

  • > How can I see what is in a collection (CStringArray)?
    > I can see just the 1st item in the debugger (m_pData).

    Which version of VS are you using?

    I've not used CStringArray for years, but in current versions of VS
    (from VS2005 I think) visualiser debugging support for standard
    collections such as std::vector (ex STL) is excellent.

    Dave
    Friday, March 12, 2010 10:14 PM
  • I don't think there is a data visualizer for the MFC collections.  I don't remember if there is one in vs 2010 or not.  I've always found this annoying since it's difficult to see what is in the containers while debugging.

    Most of the time, when I need to debug something like that I add in some code to just get each item in a loop and then put a breakpoint on that code and step through it incrementally.  The collections can be quite large and being able to change the index value in the loop from the debugger is pretty handy.

    Tom
    Friday, March 12, 2010 11:40 PM
  • How can I see what is in a collection (CStringArray)?
    I can see just the 1st item in the debugger (m_pData).

    Thanks
    Vaclav

    Suppose you have an instance of CStringArray called sa.

    During debugging, in the Command Window, you could type:

      ? sa.m_pData[i]

    where i is a integer in range 0,1, ... (sa.m_nSize-1), to read the content of the CStringArray.

    Not as convenient as std::vector<CString>, though.

    Giovanni
    Saturday, March 13, 2010 11:16 AM
  • How can I see what is in a collection (CStringArray)?
    I can see just the 1st item in the debugger (m_pData).

    In addition to my previous post, I developed a simple CStringArray visualizer.
    I tested it in VS2008 SP1, and it seems to work fine.

    You can copy-and-paste the following visualizer code in the autoexp.dat file (which is just a text file, located under <VS2008 Installation Directory>\Common7\Packages\Debugger\), under [Visualizer] section (I put it after ATL::CComBSTR definition in the [Visualizer] section).

    ;------------------------------------------------------------------------------
    ;  CStringArray
    ;------------------------------------------------------------------------------
    CStringArray{
        children 
        (
            #array
            (
                expr :      ($e.m_pData)[$i],
                size :      $e.m_nSize
    		)
        )
        preview 
        (
            #(
                "[", $e.m_nSize, "](",
                #array
                (
                    expr :	($e.m_pData)[$i],
                    size :	$e.m_nSize
                ),
                ")"
            )
        )
    }
    


    Giovanni

    • Marked as answer by vjedlicka Saturday, March 13, 2010 12:18 PM
    Saturday, March 13, 2010 11:55 AM
  • Hi Giovanni,

    Thank you very much! Works perfectly.
    Previously I forgot to mention I am using VS 2010 (migrating from VS 6).

    Thanks to all!
    Vaclav
    Saturday, March 13, 2010 12:11 PM