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
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.
I'm having trouble with debugging C++ code using QtCreator.
As you can see, here is a very simple recursion in C++:
When trying to debug this code, I wanna keep inspecting the elements in "sorted" and "unsorted". However, QtCreator automatically shows the variables in the topmost stack frame when recursion goes on. Like this (see the small pane on the right):
If I wanna see the elements in "sorted" and "unsorted", I have to double-click the "Main()" function in stack pane. And every time the recursion goes on, it goes back to the topmost stack frame and shows information not helpful for me. I have to do that again to see the variables I want. Is there any way that I can keep inspecting the variables I want? Like "sorted" and "unsorted", which are not the variable of the "topmost stack frame", at the right pane in the picture below:
Thank you very much!
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.
Is this possible? When I'm debugging a program I can't bring the window up to see any changes. It's minimized during the debugging while I step through the program and I'd like to see the program changes while I step.
The only way I might see it is in Windows 7 you can hover over the task-bar to get a look at the program but the preview image gets in the way and It's just a weird way to see my program.
I've been trying to search for this problem but all I get is irrelevant results. Maybe I'm missing a few keywords or something. I don't know what to call my problem.
Two choices:
Don't maximize the IDE window and make it smaller until you can see the program window.
Have two monitors and put the program window on the secondary monitor.
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?)