How to go back to a break point during debugging? - c#

I am working in asp.net and debugging an application.
Sometimes there are scenarios in which I need to go back to a break point that I have passed. Is there any way to go back to that break point? I am debugging using F5 and F10 and press SHIFT+F5 to stop debugging.
I searched on google, but not finding the required answer.
Please guide me regarding this. I'll be thankful.

At least in Visual Studio 2010 you can drag the yellow arrow showing your current line you're debugging. It doesn't work all the times though.
I've used that if I had accidently passed a function I should have debugged.

If you have VS 2010 Ultimate IntelliTrace, by default, records breakpoint state. You can go back an examine the state at the breakpoint.

you can drag the yellow arrow which line u want debugging .

Related

Visual Studio 2012/C# breaks code execution, no breakpoint set

I'm having a problem in Visual Studio 2012/C# which is driving me crazy. I have a particular line of code in a C# file with NO breakpoint set. Every time this line should be executed the debugger interrupts the execution of my code like a breakpoint was set. The only difference i noticed is the arrow on the left hand side, indicating the current step. Usually this arrow is yellow (when a breakpoint is set). In my case it is grey.
I have been searching for a solution but did not find anything useful to this. I tried deleting all breakpoints, build project, rebuild project, clean project and it still appears.
Does anyone have the same problems and found a solution this?
normal arrow:
arrow in my case:
This line of code is currently executing, it calls something else, e.g. native code or .NET internal code and an exception happens there. You can see both arrows in the call stack window:
Perhaps you need to turn on "Show external code".
If you can't see the exception dialog, usually you can show it like this:

C# Step Into variable list

There usually is a variable list at the bottom of the screen that helps me follow the value of different variables in my app while using the f11 'step into' function, but since I updated to web developer 2012 I can't seem to find this list. Was it removed? or is there a way to open it? thanks!
Set a break point in the project, start debugging your application, once you hit the break point, go to Visual web developer, Under Deubg-> Windows, see if you find Locals option. That will show the local variables during debugging.

Step Through Visual Studio On Click

I am trying to work on this website and I am a bit new to Visual Studio and whatnot. I would like to have a step through action whenever I click on certain icons on the website. Basically it is a lot of code, most of which I am learning, and I need to know where I am sending control when I click certian icons.
Any tips?
Insert break points in your code (click the left margin in the code windows). Your application will then stop, and you'll be sent to Visual Studio to do stuff when the code hits the break points. You also have functions to go through the app line by line from a break point when VS is in debug mode.
Well, the Button that you click must have a Click Event Handler in the code behind file. You can go to that code and add a break point by pressing F9 key or use Debug > Toggle Breakpoint, which makes debugger break when that line of code is executed, after which you can use F10 key or use Debug > Step Over to move debugger to next line after executing the current line. While debugging, you can use mouse hover to know values of variables.

Debugging C# applications

I´m coming from a PHP background where my debugging "tools" are basically echo, var_dump and exit. While I know the importance of debugging, I never tried to use/learn a debugging tool.
Now I´m learning C# and I think I can´t really program without an extensive knowledge of this area.
So my question is: where can I learn what is and how to do debugging? I know what is a breakpoint (conceptually), but how to use it? How to use Step into and Step over? Basic things like that.
As a related question, there is anything like var_dump in C# (Visual Studio), where I can inspect any object.
I find very difficult and painful to do a foreach for every array/list to see the contents, specially now that I´m still learning the language.
Microsoft has an extensive guide on C# debugging in Visual Studio that might be helpful. VS has a lot of powerful debugging functionality; for example, rather than doing a foreach to see the contents of an array as you were describing, you could set a breakpoint (pausing the execution of the program) and select the variable you wish to see the contents of (array or list or whatever) and see what it contains, without having to write any extra code. Step Into and Step Over can be used to continue execution of the program but only incrementally so that you can continue to see how variables change, where the flow of execution currently is, etc.
This has been covered earlier on StackOverflow:
Best Visual Studio 2008 Debugging Tutorial?
So, your compiled applications can be run in a "debug" mode from which visual studio can monitor the internal workings of the application and even control it.
A break point can be placed just about anywhere in your code by clicking to the far left of the line (kinda in the margin of the visual studio text editor). When that line of code has been reached, the visual studio debugger will actually pause the execution of your program and bring you back to the editor where you can literally hover over a variable or object or whatever and see everything about it.
There is also a "Locals" window available that will give you the break down of all of your locally scoped items - this should pop up by default at the bottom of your screen when debugging.
In debug mode you can navigate the execution of your code line-by-line
F10 will continue with the next line of code.
F11 will attempt to drill down into what ever functions are on the current line of code
Ctrl-D will bring up a "Quick Watch" window giving you all information about the currently selected variable/object.
Once you are in debug mode there are tons of things you can do - in some cases you can even edit the code as you go.
The easiest way to get into debug mode is to use the little "play" button up at the top of visual studio - and when a break point is reached it will enter debug mode and highlight the currently executing line of code.
You can also hit F10 from the editor and your application will be started and paused on the very first line of code.
By comparison, in PHP, you had to actually write "debugging code" into your application - using Visual Studio you can actually monitor the execution of your code without adding a thing to your existing code.
I hope that gets you started.
You might want to also read up on your IDE a bit to. There is a metric ton of stuff in visual studio that will help you navigate your code in ways you never imagined in most PHP editors.
If you've already downloaded Microsoft Visual Studio, you'd might want to check out the Visual C# Express Library available for free over at: http://msdn.com/express/
It's located down the bottom of the page and is very useful. It contains pretty much every answer you might be looking for as a beginner to the C# Language. ...Welcome to C#, my friend :-D

C# program quitting/crashing suddenly, how to break it?

So my C# program is quitting/disapearing/closing/crashing suddenly even in debug mode.
How can I make it break/pause/stop so as to find out where caused it?
Set a breakpoint (by clicking the left of the line numbers--it's a red circle) that you know is before the point where it crashes and then step through it (using F8). The last statement that you're on is the one that it's crashing at.
If you're in Visual Studio you can enable "Stop when an exception is thrown" - go Debug->Exceptions. This is often quite useful for detecting the exact source of the problem.
You may be able to learn more by using an unhandled exception handler. However, if you're in debug mode you should be able to see it by default. Check your Debug: Exceptions settings to make sure you haven't accidentally stopped reporting them in debug mode.
as Eric suggested try going through step through it... also always place try/catch in your end caller apps in order to manage exceptions.
Also, it may be worth checking your code for occurrences of Environment.FailFast, just in case someone tried to be (too) smart.
You can hit F10 to start debugging your project. This will put a breakpoint right at the beginning of your Main method, then you can go from there stepping through the code with F11 to see at which points it crashes.

Categories