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

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!

Related

Seeing only local variables debugging C++ in VSCode

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.

watch window in the debug is empty

I was trying to understand how to fix my watch window but didn't find any good answer(I'm using visual studio 2013).
I used the debugger and suddenly the watch window didn't show the values or the object i'm have in the block - actually it didn't show anything anymore.
Does anyone know how can it be fixed?
Many thanks!!!
Maby this will help you:
To open the QuickWatch dialog box with a variable added While in break
mode, right-click a variable name in the source window name and choose
QuickWatch. This automatically places the variable into the QuickWatch
dialog box.
Source
The Watch windows don't show anything by default, you need to add things to them to see the values. What might have happened in your case, is that either you deleted what you had by mistake, or you ran into a bug, where something got corrupted in your solution and they were lost.
If you want to see everything that is currently in scope, the Locals window is the way to go.
And if you want a superset of that (which has both current and previous statement), use the Autos window.
The QuickWatch dialog box is similar in concept to the Watch window, but QuickWatch can display only one variable or expression at a time
https://msdn.microsoft.com/en-us/library/bhawk8xd.aspx

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

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.

How to skip assembly code when debugging?

Sometimes when I use the debugger to step through my code, it goes into some assembly code (I guess I've stepped into some system library code).
The question is, how can I skip over it and jump to the nearest c++ code of my project?
Use the "Step-out" button or Shift+F11, this will step back up the call stack.
Alternatively display the call stack (Alt+7), then double click on the function level you want to return to; this will indicate in the source window where the call was made. Then in the source window right-click the statement following the call, and select "Run to cursor". Of course if you already know where the call came from, you could just use "Run to cursor" in any case.
You can close that assembly window by clicking X on right side in the code window. Not the one at top most right(which closes the solution)
Jump Out of the current function? (Shift-F11 in the C++ settings?)