Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to stay on current document after a "break all" in Visual Studio?

Visual Studio opens source code on top of the stack when I "break all" while debugging; I want to keep the cursor on the document I'm currently working on, without any other document or window (e.g.: no symbols loaded) being opened.

like image 671
ccalboni Avatar asked Feb 01 '13 11:02

ccalboni


People also ask

How do I keep breakpoints in Visual Studio?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

How do I go back to previous line while debugging in Visual Studio?

So, if you've just taken a step in live debugging (F10 or F11), you can use the Step Backward button to quickly navigate to the previous step. This will automatically put Visual Studio in Historical debugging mode, at the line of code you've stepped back to.

How do you step through code in Visual Studio?

Begin code stepping by selecting F10 or F11. Doing so allows you to quickly find the entry point of your app. You can then continue to press step commands to navigate through the code. Run to a specific location or function, for example, by setting a breakpoint and starting your app.

How do I Debug multiple processes in Visual Studio?

To change the startup project, in Solution Explorer, right-click a different project and select Set as StartUp Project. To start debugging a project from Solution Explorer without making it the startup project, right-click the project and select Debug > Start new instance or Step into new instance.


2 Answers

There is a way to stay on the current document, but that requires creating a Visual Studio add-in and a new UI command in the Debug toolbar. Credits for this answer should actually also go to openshac, who posted a similar SO question and also gave a workaround in his OP by using a macro.

The implementation is fairly simple (it took me a few minutes to have it working). First, in the add-in project, modify the Exec method in the Connect.cs file like this:

public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
    handled = false;
    if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
    {
        if(commandName == "BreakInCurrentDocument.Connect.BreakInCurrentDocument")
        {

            // here's where the magic happens
            // ******************************
            var activeWindow = _applicationObject.ActiveWindow;
            _applicationObject.Debugger.Break();
            if (_applicationObject.ActiveWindow != activeWindow)
            {
                _applicationObject.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo);
            }
            // ******************************

            handled = true;
            return;
        }
    }
}

After creating and registering the add-in, just:

  1. click TOOLS on the Visual Studio's menu
  2. Customize
  3. Commands
  4. Choose the "Toolbar" radio button
  5. Select "Debug"
  6. Add Command...
  7. From the "Addins" category, choose your custom add-in.

That's it.

like image 127
Alex Filipovici Avatar answered Oct 17 '22 00:10

Alex Filipovici


Latest build of VSCommands extension (free version) available from http://visualstudiogallery.msdn.microsoft.com/a83505c6-77b3-44a6-b53b-73d77cba84c8 has just what you want. It adds a Break In Current Document button to Debug Toolbar and Debug Menu:

http://vscommands.squaredinfinity.com/Media/VSCommands/BlogPost//blog/breakincurrentdocument.png

like image 32
Jarek Kardas Avatar answered Oct 17 '22 00:10

Jarek Kardas