Debugging in sharepoint is the same as any other web application like ASP.NET, the only thing that we should make sure before debugging is that the debugger is attached to the process.
Now,lets see one scenario where we need to debug the code.
To configure VS debugger one can follow these steps :
Go to VS Tools >Options menu
Make sure that you have unchecked the option and then click ‘OK’
Then,go to Debug > Attach to process menu to attach the code to the w3wp process as shown below
It can be noticed from the screenshot that there may be several instances of the process running, to know are you attached to the correct process, first attach to that process ,press Ctrl +Alt + U and check if your dll has been loaded or not(See below screenshot) .If its loaded then, you are attached to the correct process or else try attaching other instances till you could see your dll loaded properly.
CustomWebPart.dll is my dll that has been loaded, so my code has been attached to the right process.
Once,this is done on performing an operation your breakpoint should get hit ,something like this
This kind of technique can be used to debug the code that has its dll in GAC (like web parts and the custom aspx pages in the layouts folder )But, this technique cannot be used for the custom pages that uses the inline code approach ,since its dll won’t be in the GAC.