Visual Studio 2008 - Debugging tips/tricks - Continue "until next function" or "until next file" - visual-studio

Is there any way to tell the debugger to just continue until the next file is accessed, and/or until the next (developer written) function is accessed, without setting debug points ahead of time? I'm kind of new to VS debugging so all I use right now are f5, f10, and f11.

There is currently no way to do what you are asking. The main ways of telling VS to go until something happens are the following
Hit F5 and VS will go until the next user breakpoint or ,depending on your settings and where it occurs, the next exception is raised
Right click and select "Run to cursor"
Shift-F11 breaks out of the current method
Run to cursor doesn't require an explicit break point but it does require that you know where you want to break next.

You can right-click and select "run to cursor" if you just want to run to a specific line ahead in the execution stream.
Another one is Shift-F11 which finishes the current method and breaks again when you get back to the caller.

Actually, there is a way to set conditional break points.
Click in the left margin on the line where you want to break, as usual. (or F9)
Right-click on the red dot. In the context menu, click on "Condition...."
In the dialog, set your condition, e.g., fileName == "foo"
Hit F5 and go until the conditional break is hit.

Looks like there's not a way to do what I wanted to do

Related

Visual Studio: Is there a way to skip execution of code between two breakpoints?

I know I can comment the code but would be even better if there is a shortcut to skip execution of code between two breakpoints.
VS has a feature 'set next statement' which moves the program counter to the to that location and continues execution from there (skipping anything in between). You can read more about it at: https://learn.microsoft.com/en-us/visualstudio/debugger/navigating-through-code-with-the-debugger?view=vs-2017#BKMK_Set_the_next_statement_to_execute. The easiest way to use it is to either use the context menu item "Set Next Statement" (right click on where you want to set it) or hold down the ctrl key which changes the green "Run to click" editor glyphs into yellow "Set next statement" glyphs and just click on where you want to set it.
Set next statement is a great tool but it's really dangerous as a debugging tool. You're using the debugger to execute code in a way which would never happen normally. The results of which could cause crashes or other failures easily. It's real easy to do things like skipping over the initialization of a variable that's later used and will now cause an exception/crash.
It can be used in JS, .NET and native.

Going back to previous line while debugging on visual studio

I am debugging a piece of code on visual studio and I forgot to note down the values I have kept a watch on. Can I go to previous line without rerunning the entire code?
There are similar questions asked on SO but in my case i haven't run through any error or exception. The code is running normally.
After pausing on a break point, right click on the line you want to "go back" to. From the menu that pops up, select "set next statement".
This will adjust the instruction pointer to continue from the specified line of code, but it will not roll back any variables or memory addresses to the values they were at before that line of code was originally executed.
It sounds like what you want to do is rewind / replay your code rather than just move to a specific line. You can move to a specific line, you can just right click and choose set next statement. Unfortunately, this won't rewind the state of the program to some past point (beyond setting the stack and doing a bit of unwinding).
To rewind/replay you need to be a bit trickier. Some options are: -
VMWare replay which will allow you to record and then go back to a certain point in time.
Intellitrace. I haven't tried it, but it allows you to replay to a point.
Which is a bit heavyweight and wont help you right now.
You can use the mouse to drag the yellow arrow pointing to the "next statement to be executed." This actually changes which statement will be executed next. It's not guaranteed to work, but as long as the code is not too complex, it could.

Xcode - stepping over the debugger to cursor location

Is there a way to to step over the debugger to the cursor location?
In many occasions I want to skip a whole section of code while debugging, in that case I have to put a new breakpoint in the line I want to go to and click the continue execution button. I can't believe Xcode lacks the step over to cursor function.
Right-click on the line and select "Continue to Here".
If you move the cursor over the line number a little icon comes out that is a little play button That lets you run the code and stop at that selected line. Give that a try.

Visual Studio debug jump out of loop

I know about basic features of visual studio debugging. F10, F11, Shift+F11, Ctrl+F10.
If I am inside a for loop is there a way of stopping right after the loop is completed?
Right now the way I am doing it is to manually go to the location after the loop and press Ctrl+F10. Is there a better way of doing this?
There is no dedicated "Step Out of Loop" command in Visual Studio. "Step Out" (Shift+F11) works only for functions. There are only two options that I can think of:
Like Brian suggests, there is Run to Cursor, which has been there at least since VC++ 6. This is what you're already getting with the Ctrl+F10 keyboard shortcut. I use this literally all the time while debugging; it's an extremely useful tool. I don't really understand why you think this is a lousy way of doing it, or why you think there should be a "better" way.
You could set a simple breakpoint on the line of code immediately following the loop. This is relatively simple if you use the keyboard shortcut F9. But you still have to navigate to the appropriate line of code, so you might as well use Run to Cursor.
If you're working in a C-derived language, your loops probably conclude with a }. So you could use the Ctrl+] keyboard shortcut to move to the matching brace in the source file if your caret is at the loop's opening brace. That might make navigation easier. It certainly can help avoid moving your hands over to the mouse, killing precious seconds.
* Note that keyboard combinations are subject to change, depending on how you have configured your Visual Studio environment.
I just found out that if you hover with your cursor at beginning of the desired line, VS automatically blends in a little play symbol. When you click on it, debugger jumps to this point.
Perhaps you would like to use a breakpoint, which can be used to trigger the debugger once your program has reached a specific line. You can set one by clicking on the left side of the code line, where errors and arrows usually show up during debugging. Hope this helps!
Simple way is to put a break statement in the for loop and add a condition. This will allow you to test the loop while debugging.

Is there any way to set or code breakpoints conditionally?

I've been wondering this for a while - is there a way to code/program breakpoints...? Conditionally? For example, can I specify something like - "when this variable becomes this value, break and open the debugger"? (Would be quite useful, especially in long loops when you want to debug loop execution of a late loop value.)
I suppose this may be IDE-specific since debugging is implemented differently in different IDEs... I'd be interested to know how to do this in any IDE, but specifically in Eclipse and Visual Studio.
This is definitely possible in Visual Studio. You can normally click in the left margin to insert the breakpoint, and then right click on that breakpoint. One of the options in the right click menu is "Condition...", and you can specify a predicate that will tell the debugger only the break on that breakpoint if the predicate is met.
In Visual Studio, you can declaratively set conditional breakpoint, which are like normal breakpoint but will only break when a certain condition is true. The condition can use local variables and whatever is accessible from where the breakpoint is set. Just right click any breakpoint (red dot) and select "Condition...".
In addition, .NET languages can call the Debugger.Break() method to programmatically break the execution. This also can be done within an if statement:
if (count > 8 && Debugger.IsAttached)
Debugger.Break();
If conditional breakpoints aren't supported by your IDE, add in an if statement and break inside of it.
if (variable == 3) {
// Stub code to attach breakpoint.
1 = 1;
}
Setting a conditional breakpoint in Eclipse (thanks for all the Visual Studio answers!):
Set a breakpoint. Right-click and choose "Breakpoint Properties...". Check "Enable Condition" and enter your condition code into the text area.
Most IDEs allow for conditional break points for this very reason. In Visual Studio, you can right click on the red dot for the breakpoint in the margin and open the condition dialog from there. You can also get at the condition dialog from the breakpoint window in Visual Studio. I am not familiar with Eclipse.

Resources