Visual studio 2012 debugging - stop when the project/namespace is being hit - c#

I am currently debugging large project, I put a breakpoint on the starting point of the application, but it takes forever to hold f10 until it gets into the location I want it to get.
Is there any way to tell the debugger to hold f10 until it gets to a project or the namespace that I want to stop it on?

just right click on your breakpoint, there are various options for filters, location, etc.
http://msdn.microsoft.com/en-us/library/5557y8b4.aspx

Related

How to enable break point in visual studio 2017

I am trying to put break point to web api service which is written in visual studio 2017.
However, I am unable to see the option to put break point.
I have used F9 and Alt+F9 to put breakpoint to my code.
Still its not working.
Kindly let me know how to enable break point in visual studio 2017
Try to talk your cursor to the extreme end of the code editor, very close to that place that as the line number. Then click it, you should see a red circle there. That is your breakpoint.
click on the left side of the line number. A red dot should appear
You can create breakpoints in Visual Studio in several ways. One way is to have your cursor on the line you want to have a breakpoint, and then press F9. You will see a red circle on the left indicating a breakpoint.
However, you can also click to the left of the line number you want to add a breakpoint on, and that will also create a breakpoint.
Example: https://learn.microsoft.com/en-us/visualstudio/debugger/media/dbg-tour-set-a-breakpoint.gif?view=vs-2019
Also, see this for reference: https://learn.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2019

How to set breakpoints to all lines in a c# file in visual studio?

I am working with Visual Studio 2015.
I have a big c# class file with lot of properties and methods. I want to set breakpoints to all possible lines (set and get of properties, methods) at once. How can I do that?
You could add Debugger.Break() on the end of every single line. Therefore you could use the search and replace function of visual studio and replace \n with Debugger.Break()\n (Remember activating the regular expression option). This would cause the debugger to break at every single line, even though you won't have an indicated breakpoint.
I don't think that there's a method to add normal vs breakpoints to every single line though, due to the fact that it's quite useless, considering that you normally just step through the code with F11.
I think you are looking for this,
steps to follow:
1) Add a break point on the first line of code you want to debug.
2) Run the application.
3) When you want to run the next line of code, Select Debug | Step Into
4) Repeat step #3 for each line of the code
With vim (vsvim) you can set a breakpoint, move down a line, then repeat however many times you like, eg:
{Escape}qq:vsc Debug.ToggleBreakpoint{Enter}jq100#q
will set breakpoints on the next 100 lines
edit: here is example video, wouldnt let me embed gif https://imgur.com/SFhlEr7
Step Into(F11) or use the Debugger.Break() or add breakpoint directly would be the workarounds for you, of course, I suggest you use the Step Into(F11) which was much more convenient.
If you could use the latest VS2017 version, it has a new feature "Run to Click" which is also a better workaround for you during debugging.
Actually you don't have to debug every line code, that's also the reason I suggest you use this new feature.
Run to Click: Simply click the icon next to a line of code while debugging to run to that line. No longer set temporary breakpoints or
perform several steps to execute your code and stop on the line you
want. Now while stopped at a break state under the debugger, the Run
to Click icon subtly appears next to the line of code that your mouse
is hovered over. Move your mouse to the icon and click the button, now
your code will run and stop on that line the next time it is hit in
your code path. Turn it off from Debug> Options > Enable Run to
Click.
Reference:
https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes
Open a feature request with Microsoft https://learn.microsoft.com/en-us/visualstudio/ide/suggest-a-feature?view=vs-2022
There should be a mode that visual studio can be put in so that it automatically stops on every line of code in a particular project. This would be VERY valuable when you attach the debugger to a pre-existing process and you don't know where in the app is the current point of execution is, ie: web apps where you do not know the entry point.

Prevent showing visual studio window when Breakpoint hits while debugging c#

When a breakpoints hits, the VS window is showed automatically and points to the line with the breakpoint. For my case that's not helping. Is it possible to prevent the VS studio window from showing when the breakpoint hits ? Thanks
EDIT: he problem is that I'm reading from a barcode scanner gun. While reading, the breakpoint hits thus switching to the VS window and some portion of the barcode is printed in the source file :) That's why I don't want it to switch to the VS window
If you set the breakpoint in the Visual Studio, you can change it to "tracepoint" by specifying "Continue execution" as "When hit".
If the breakpoint is present in the executable, it can be disabled as described in How to disable a programmatical breakpoint / assert?
You can start your application as Start Without Debugging or use (Ctrl + F5) for that.
Or If you want to debug, but not for a condition, you can provide the condition on breakpoints when to hit.

Call stack time machine in Visual Studio 2010

I know the title is a bit ambitious, but I am wondering if there is a way, after displaying a previous state in the call stack window (Visual Studio 2010) when debugging a C# program, to restart (like when hitting "Continue"/F5) from there.
This would be particularly useful to debug a lambda expression that generates an exception, as there is no way to move outside.
For a real OO code time machine, the historical state of all objects would need to be stored in memory, so I doubt it is feasible at this stage.
Now if the state of all objects has not changed much, then we could keep the current state and jump back in time (as a shortcut to doing the same thing with "edit and continue").
Some times, you can right click on a stack frame and choose "Unwind to here" (or very similar wording). It's not always possible, and I'm not sure what the necessary conditions are, but I'm going to make a guess as to what might prevent it:
A native code frame on the call stack in the middle
Being halted at a StackOverflowException (obviously, death to a process in any case)
Maybe lambda expressions or other things that prevent Edit-and-Continue from working (?)
Basically, anything "unusual".
Other than that, if it works, then there you go!
This is a bit kludgy but:
While viewing the previous state in the call stack window, open the disassembly window (Debug | Windows | Disassembly or CTRL+ALT+D). Now you should be able to create a breakpoint which will stop execution when you get back to that location.
If you don't care what else executes, press F5 and allow the code to run back to your new breakpoint.
Now right click on the statement you want to restart from and select Set Next Statement. Press F5 to restart from there.
If you do care about what else executes on your way back to the new breakpoint you could use Set Next Statement to set the program counter to the end of the function you are in and use Shift+F11 to step out of that function (thus not executing any of the remaining logic in that function). Repeat as needed until you get back to your new breakpoint.
Note the various dire warnings about using Set Next Statement
Edit 6/18 When I tested the above I was running Visual Studio 2010 Ultimate. I just checked Visual Studio Express C# and it does not support the Disassembly Debug Window. When I can I'll check Visual Studio 2010 Professional and update this answer again. If you have Visual Studio Ultimate then the Intellitrace suggestion by #Hans is maybe a better bet.

Possible to delete a breakpoint for good when debugging?

When debugging, changes to breakpoints are only persisted for that debugging session. Once the debugger detaches the breakpoints are restored to their 'pre-debug' state.
I can appreciate this is sometimes useful, and understand why it defaults this way.
However - does anyone know if there is an option to disable this functionality (in VS2010) such that if I delete/disable/add a breakpoint during debugging the changes will persist the next time I start debugging?
You can remove the breakpoint whilst debugging by using the Breakpoint Management Window (Debug -> Windows -> Breakpoints).
From there you'll be able to remove the breakpoint in question by right clicking the relevant breakpoint and hitting 'delete'.
During debugging hit F9 on active breakpoint.

Categories

Resources