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.
Related
I know how to debug a console program, but what if the program has a GUI?
For example, there is a Calc icon, when I push it down, it will call some methods.
I want to know what methods it will call. I have the source codes but have no idea about which file corresponds to what, and want to back-track what codes it will implement if I click on the icon.
There conceptually isn't any difference between debugging a GUI application and a console application - they both come down procedural programming - some action calls a particular function. There's no difference whether the trigger of the action is you pressing a button on the GUI, or typing in a command in the console. You can use a debugger for both of them (visual or command line).
If you have the source, and know what the triggering mechanism is, it should be easy enough to follow along in the source code to see which functions are called by the trigger (eg. not at runtime). You have the question tagged as Qt, which uses the connect function to connect 'signals' (events) to either other signals or 'slots'. This is essentially associates a callback function, with a particular event, so searching your source for that would be a good starting place.
While debugging, if (and only if) i have a break point in my node destructor i get this screen saying:
Source Not Available
Source information is missing from the debug information for this module.
You can view disassembly in the Disassembly window. To always view disassembly for missing source files, change the setting in the Options dialog.
(Here is a picture of the whole screen)
I've looked everywhere on the net and the only "solution" i've found is moving the breakpoint which is not a real solution,
What can i do to fix the issue? Thanks.
(Windows 8.1, Visual Studio 2013)
Here is the code of the destructor which is one step before the screen appears:
MatchmakingAgency::Node::~Node(){
cout << "Deleting: ";
getClient()->printName();
cout << endl;
if (next){
delete next;
}
}
As written in the comments you're stepping into the scalar helping destructor (a helper function set up by Visual Studio for the destructor). You can also see this from the call stack.
Stepping out with Shift+F11 should bring you directly into the destructor's code.
Regarding why this is happening it could be that Visual Studio is breaking into the helper function (glitch?) or that you're entering that function by stepping into it before the actual destructor code gets executed.
If that bothers you you might also take a look at breakpoint macros and see if that helps (try stepping out of the scalar deleting destructor if putting a breakpoint on the first line of the destructor doesn't help)
You can show the stack window (Debug -> Windows -> Call Stack or Ctrl+Alt+C in Visual Studio 2013) and then double-click on a stack frame that is in your code to see where in your code the break is happening.
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!
How do I trace recursive functions like these that calls itself recursively two times? I wanted to create a tree of the calls. When I stumbled into this, how do I know which of the methods that currently are being executed? CountWays(numStairs-1) or CountWays(numStairs-2)
GDB answer?
If you see near the bottom-right of your screenshot there are 3 buttons in a group and the left-most button has been selected. Press either the center or the far-right button to open the debug console. In there you may type 'bt' and it will print your back-trace.
GUI answer?
You need to trigger a backtrace upon your breakpoint (or exception breakpoint), instructions for this can be found here:
http://www.oramind.com/index.php/articles/182-ios-5-xcode-backtrace
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?)