Seeing only local variables debugging C++ in VSCode - c++

I am using Visual Studio Code and when I debug (I am debugging C++ code compiled with Clang) I see only local variables.
I do not see any global variables list.
How can I see all variables?
In this case I am inside a loop and I see only all the variables defined inside the loop, not the one defined outside.

You will need to manually add global variables to a watch window.
Set a breakpoint
Start debugging (Debug -> Start Debugging or
F5)
Open a Watch window (Debug -> Windows -> Watch -> Watch 1)
Type in the name of the variable manually

In Visual Studio Code you can just go to the Watch pannel int the debug menu and click on + , then type the name of the variable you want to watch.
Hope it helps !

After you follow the stepes in Andrew L's answer you can modify the variable's value by the help of either:
1. Debug Console
2. Address-Of Operator
By prefixing the variable we want to watch with (&) we can now expand it and then right click on the dereferenced variable to set a value.

Related

Variable Code Completion in Netbeans without Ctrl+Space

Is it possible to enable auto code completion for variables in Netbeans?
I see a similar question here, but it doesn't work on variables (correct me if I'm wrong).
This is my current code completion setting:
This worked for me:
In NetBeans select Tools -> Options -> Editor -> Code Completion tab -> Language: C/C++
As given in this SO answer, set the content of the Auto Popup Triggers... field to contain the following string:
.;->;.;->;::;new ; ;a;b;c;d;e;f;g;h;i;j;k;l;m;n;o;p;q;r;s;t;u;v;w;x;y;z;
Click the Apply button, then click OK.
Here's a screenshot:
The change should be immediately effective. After doing that you can type the first letter of any variable in your C++ source code and eligible variables should be listed in the prompt which automatically appears.
The screen shot below is a contrived example where there are several variables starting with 's'. All I did was type the letter 's' and the prompt appeared instantly, listing all of the local and global variables starting with 's':

Qt debug - how to watch the value of the variable in Qt Cpp

Is there any way to check the value of the variable in Qt while debugging [other than calling the printf() or qDebug() function] ?
As per my understanding yes there is a way of seeing values of variables by hovering the mouse over the variables. For this you need to Enable the following option in the debugger option pane:
Option-->Debuger-->General-->"Use tooltips in main editor while
debugging"
You could use IDE(as example: QtCreator for Linux, VS for Win or even console) with integrated GDB (or other debugging tool), and set "breakpoint".
It's work for me.
qDebug("myVariable : %u " ,myVariable);
Proceed to go Debug->Add Expression Evaluator and the right side show a pane, right click and select again, "Add Expression Evaluator" option that prompt to write some expression or variable name( I use QT Creator 4.4.12)

Visual Studio 2013 - Variable Value Window In Debugging

I am a newbie programmer, and have Visual Studio Update 3 on my computer. I cannot find the window that displays the values of variables as I am debugging.
I have looked under the pull-down tab at the top entitled "Debug" and "Window", and cannot find anything. I do not know exactly what the window is called either. Please help.
If you're looking for the scoped local variable values or Autos:
you must first have the debugger running, then goto:
DEBUG => Windows => Autos
and
DEBUG => Windows => Locals
to actually see those values, you need to have a debug stopper in place and it get hit by the program.
Alternatively you can - while debugging - highlight a variable name and use the 'Quick Watch'
In the default layout, the Locals window will typically be visible in the lower left pane, but only while debugging is active.
Here you can see the debugger windows on the bottom. The left side shows current breakpoints while the right side is showing watched variables in the pane labeled Watch 1. At the bottom you'll see other panes available to display in the lower left, specifically Call Stack, Command Window, etc. The one you want to see all in scope variables at a given breakpoint is Locals
If you have closed the locals window, or otherwise cannot find it, there is a way to re-open it through the Debug->Windows menu as pnm points out

How to view contents of an array while debugging in Code Blocks?

This is probably a silly question and i am posting this Post-Googling,
The question is,
How do i view the contents of an array while debugging, Provided the Breakpoint is in function not Main?
I am using code::blocks 13.12 version and i set a break point in my sample simple c++ code,
and i want to observe how the contents of the array change with the code but all i see is the the address of the array under watch window,
It is however displaying the values of other integer variables correctly,
a is an array
I forgot to mention that i am tracking the array in a function and not in main,and i am aware that main passes the address of the array to the function being called(by reference i meant)
I am relatively new to codeblocks, Am i missing some setting or something?
Right click on the cell, then select "Properties", there you can tell it to "watch as array", and tell it the index range to watch.
i am using 12.11. I select the array variable suppose a, choose "watch a" in the right button down menu, and I can see the values in the array a.
Another thing that I use is watching under cursor.
If you go Settings -> Debugger... -> GDB/CDB debugger -> Default and you enable selection "Evaluate expressions under cursor", every time you leave mouse pointer above a variable in the code, it will be watched.
It's not the same with having it in Watches toolbar, but strangely it will show array's fields.
Debug -> Debugging windows -> Watches
you may watch the variables in this way
in convenience, you can find button "Debugging Windows" near to the debug toolbar, choose "watch", hope you can find it!

Visual Studio environment 2010 C++ Debug techniques suggestion required

I am using Visual Studio 2012 for my project in C++. I have a function where I put a break point.
MyFunction(int userid, double totalamount,char *ce_account_ref_num, int payment_type)
My debugger goes to this point and shows some undesirable inputs for userid. Is it possible to go back to the point where this function is called and verify inputs?
In the Call Stack window (usually on the bottom-right of Visual Studio), double-click the line with the name of the method where you want to see values of variables.
You can do many things but maybe the best choice is to comment all the lines in your MyFunction method and step over to the next line outside MyFunction to check the variables. You can also check the Call Stack and Call Hierarchy to see where your function is called from, in the case you have more than one call to the same method.
Unfortunately it is not possible to role back(undo executions) to the point where this function is called. However you can try put break point right after you give input and verify it. Call stack is also helpful to track how your program flow sequence get there.
I do this by pressing ctrl and - . This can be done recursively (press the combination again). This takes me back to the point where my cursor was last. By doing this I can go back to where the function is called and check the values etc. And by the way you can execute the same function again (in debug mode) by going to the point where the function is called by selecting "set next statement" from the right click menu, while you are debugging - a very powerful feature.