Calling functions while in debug mode in VC++ (Immediate Window)
Asked Answered
T

2

10

I wonder can I call functions during the debug mode in VC++? Assume that I have a function to which I set a break point at, when the execution stops at that point during debugging, can I call other functions and see their results before proceeding to the next line of code?

Thoth answered 9/12, 2011 at 20:15 Comment(1)
I don't think so. Debugger helps to stop at a point in the sequential process of execution but not subvert it.Hallucinogen
G
7

I believe you can. I think its called Immediate Window. I use VS2010 Ultimate, so I don't know if it exists in your version.

Ctrl + Alt + I

But this only prints output for when the function returns a value. Also, it may not work in some cases.

Let's say you have :

#include <iostream>

int number = 10; //global
void setNumber(int n);

int main()
{
    std::cout<<std::endl; //breakpoint 1 here
    setNumber(4);
    std::cout<<std::endl; //breakpoint 2 here
}

int getNumberSquared()
{
    return number * number;
}

void setNumber(int n)
{
    number = n;
}

when you encounter breakpoint 1, press the shortcut and type:

getNumberSquared()

The output will be 100 After encountering breakpoint 2, do the same thing and the output will be 16

Grindlay answered 10/12, 2011 at 22:19 Comment(3)
Thanks. I did that and got this error: CXX0052: Error: member function not present. I'm using pre-compiled libraries with no source code, and hence I can't step into any of their functions; however, tech. support says that I should still be able to call any of the functions in the library and view its output in the debug mode, something like finding the size of an array.Thoth
ah, as I said, the interactive mode does not work always. But mostly it does. I woudldn't be able to tell you anything about it's compatibility with libraries.Grindlay
Thank you. I'll try other functions, hopefully something will work.Thoth
N
1

Visual studio has the option to jump to a specific statement (right click + set next statement or ctrl+shift+F10), but be aware when doing so. A function call requires registries to be valid, which will most likely not be if you jump across classes or out of scope.

Nummary answered 9/12, 2011 at 20:18 Comment(1)
@Thoth this is by design of course. No way for the runtime to know what you want...Nummary

© 2022 - 2024 — McMap. All rights reserved.