Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 827
Jawad Avatar asked Dec 09 '11 20:12

Jawad


People also ask

How do you call a function in debugging?

All you have to do is hit “g” and the DoSomething function will run. Once it returns, the debugger will restore the original state. This technique even works with C++ methods: // pretend that we know that 0x00131320 is an IStream pointer 0:001> .

How do you go inside a function while debugging in Visual Studio?

In most languages supported by Visual Studio, you can edit your code in the middle of a debugging session and continue debugging. To use this feature, click into your code with your cursor while paused in the debugger, make edits, and press F5, F10, or F11 to continue debugging.

What is the purpose of the immediate window as it relates to debugging why would you use this over other kinds of debugging windows?

Use the Immediate window to debug and evaluate expressions, execute statements, and print variable values. The Immediate window evaluates expressions by building and using the currently selected project.

How do I skip the code while debugging in Visual Studio?

You can also click on the line you want to skip to and hit Ctrl+F10 (Run to Cursor). It will jump directly to that line.


2 Answers

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

like image 66
devjeetroy Avatar answered Nov 15 '22 19:11

devjeetroy


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.

like image 37
Luchian Grigore Avatar answered Nov 15 '22 19:11

Luchian Grigore