Is it possible to execute functions while debugging (VS)

This is a discussion on Is it possible to execute functions while debugging (VS) within the C++ Programming forums, part of the General Programming Boards category; Assume you have a complex structure (e.g. hash table) that you hold ptr to (pHash). Now in the middle of ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    37

    Is it possible to execute functions while debugging (VS)

    Assume you have a complex structure (e.g. hash table) that you hold ptr to (pHash).
    Now in the middle of nowhere, you would like to print the data within pHash (with no real time edit+compile) .
    Is it possible in Visual Studio? and if so how?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    If pHash is an array you can set a watch on pHash. Click on the watch line and add ",<num_elements>" and the debugger will show you the elements of the array.

    Example:
    pHash,10 - shows the first 10 elements of the pHash array.

    You can also look into stringstream, vectors, etc this way. MSVC 2005+ is able to examine the contents of most STL containers but there are a few that the debugger still does not support.

    For stringstream:
    std::ostringstream ostrm;
    ostrm << "Hello";

    Debugger:
    ostrm._Stringbuffer._Seekhigh,<num_characters>

    This works with any data object you put a watch on. You can directly access any of the internal elements of an object by using the dot operator. For more advanced debugging I recommend purchasing a book about debugging in MSVS. There are a lot of things it can do but does not do out of the box.
    Last edited by VirtualAce; 12-28-2011 at 10:07 AM.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Switch to the Immediate window and type in a function call, for example PrintMyHash(pHash) or whatever
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    37
    we already managed but thanks, apparently this is not trivial, not all functions you can run

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-18-2010, 01:34 PM
  2. Debugging into functions
    By fl00d in forum C++ Programming
    Replies: 8
    Last Post: 12-08-2007, 08:45 AM
  3. Making functions execute at certain times
    By bengreenwood in forum C++ Programming
    Replies: 8
    Last Post: 09-30-2007, 11:55 AM
  4. Won't Execute, Help Please.
    By wazx in forum C Programming
    Replies: 4
    Last Post: 01-26-2006, 03:05 AM
  5. Replies: 8
    Last Post: 04-28-2003, 07:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21