"One or more breakpoints cannot be set and have been disabled. Execution will stop at the beginning of the program." - debugging

I set a breakpoint in my code in Visual-C++, but when I run, I see the error mentioned in the title.
I know this question has been asked before on Stack Overflow (Breakpoints cannot be set and have been disabled), but none of the answers there fully explained the problem I'm seeing. The closest I can see is something about the linker, but I don't understand that - so if someone could explain in more detail that would be great.
In my case, I have 2 projects in Visual C++ - the production dsw, and the test code dsw. I have loaded and rebuilt both dsws in debug mode. I want a breakpoint in the production code, which is run via the test scripts. My issue is I get the error message when I run the test code, because the break point is in the production code, which isn't loaded up when the test starts.
Near the beginning of the test script there is a mytest_initialize() command. I imagine this goes off and loads up the production dll. Once this line has executed, I can put the breakpoint in my production code and run until I hit it. But it's quite annoying to have to run to this line, set the breakpoint and continue every time I want to run the test.
So I think the problem is Visual C++ doesn't realise the two projects are related. Is this a linker issue? What does the linker do and what settings should I change to make this work?
Thanks in advance. Apologies if instead I should be appending this question to the existing one, this is my first post so not quite sure how this should work.
[Update 1] I think Chris O has identified the problem. I'll add a further update if I'm able to work out how to use the project settings to make this work.

It sounds like you are using VC6, since you mention dsw files. I think that is as good as it gets in VC6, you have to manually add the breakpoint after your module is loaded from LoadLibrary. Actually, there might be a project debug setting, so you can specify which DLLs to load when debugging your project, that will keep your breakpoints enabled when hitting F5.
You can also try attaching the debugger after you know the mytest_initialize() has been called, that might keep your breakpoints enabled.

I had this issue sometimes, but always pass this with some code replacement actions.
Here is some guy post, how he had fixed it.
Hope it helps.

In my case i solved this by setting the DLL project containing the breakpoint as Active Project and changed Debug settings for this project (right-click project>>settings>>Debug tab) to point to the project that actually runs and accesses the DLL. "Executable for debug session:" and "Working directory:" should be set to the executable that you actually want to run and its corresponding directory.
Hope this is of any help.

right-click project>>settings>>Link tab
check on Generate debug info
check on Link incrementally

Related

Visual Studio 2015 debugging: Symbols cannot be loaded until I restart my computer

Recently, whenever I change something in my code, rebuild, and attempt to debug, I get the error "This breakpoint will not currently be hit, No symbols have been loaded for this document."
But then as soon as I restart my computer, everything is fine and I can debug properly. Why is this happening? It's really frustrating having to restart my desktop every time I try to debug my code. I've looked all over stack overflow and MSDN and can't find any solution to my particular problem. Any help is appreciated
"This breakpoint will not currently be hit, No symbols have been loaded
for this document."
(As for this error message, it's common error which has different causes. I can't give the most direct correct answer for this issue, I can only give you some tips for trouble-shooting. In order to avoid losing contact in the round-trip comments, I post those content as answer instead of comments.)
Since VS2015 have been released for long time, I would think this issue is a particular one, not found similar issues online.
First of all, please create a new simple project to check if this issue occurs in new project when debugging.
If it persists in new project, I think this issue has something to do outside environment like VS settings, VS config files or Debug options.
You can try:
1.Go Tools=>Import and Export Settings=>Reset all settings =>No,just reset settings=>Finish
2.Repair VS IDE since it seems to work well in the past, and just got the issue recently, so maybe something is broken for your IDE(In Control Panel find VS2015, right-click=>change=>repair). Also, make sure you have the latest VS2015 Update3 instead of earlier versions.
And if it works well in new project, then maybe the issue is about the whole project or solution itself. You can try:
1.Navigate to solution folder, close all vs instance, delete the .vs, bin and obj folders and restart VS to check if it helps.
2.Make sure you've loaded the required symbols, check the content in your Modules window during debugging, there's possibility you don't load necessary symbols successfully.
3.Check the output folder after your rebuild, check in folder like bin\debug folder if you have both the .exe and .pdb files. And make sure the .exe and .pdb files are up-to-date after your rebuild by checking their Date Modified.
Hope it helps and more info about the project type, dependencies would be better:)

VisualStudio 2017 - Debugger skips over code when using step into

What could cause VS 2017's debugger to skip stepping in to code? I've verified that the build is set to Debug and that the project's Properties->Build->Optimize code is unchecked. I've tried deleting all the source and output files from my computer and checked it out again from TFS, yet the issue still remains. I've tried logging in as a different account and uninstalling/reinstalling VS and neither resolved the issue. The debugger works fine if I set manual breakpoints and will hit them in portions it would otherwise not step into, but using Step into will often skip portions of my own code for no discernible reason.
Edit
So disabling Just My Code fixed it which I dont understand at all the code is in the same solution, although in two projects/assemblies. So I guess my answer would now be, why does VisualStudio think the middle/end of a method is not "My Code"
why does VisualStudio think the middle/end of a method is not "My Code"
According to msdn document:
Enable Just My Code
The debugger displays and steps into user code
("My Code") only, ignoring system code and other code that is
optimized or that does not have debugging symbols.
Even if all the code is in the same solution, although in two projects/assemblies, you still need make sure if it is optimized and have debugging symbols.
Note: Don't miss copy .PDB file to the compiling directory.

Visual Studio does not recognize local variables or objects while debugging

So this just started: When I'm debugging a method, VS debugger does not recognize variables or objects that have been declared within the method I am debugging. When I hover over them, it does not give any pop-up intellisense. If I add it to the watch, it says:
'FooBar' is not declared. It may be inaccessible due to its protection level.
It can be something simple, like:
Dim MyString String = "this is a test"
But after moving past that line in dubugger, it won't recognize MyString. BUT, if I then use MyString, like save it to the DB or output it to the screen, it works fine. So it's really there, but debugger is not recognizing it.
Variables and objects that are passed into the method work just fine, as expected.
The first time I saw this, I did a clean & rebuild, and that solved the problem. But a few debugs later, it started up again. A clean & rebuild did not work. So I closed VS, deleted the solutions .suo file. After starting VS back up again, debug now worked as normal, for a while.
But now it's doing it again, and nothing I try seems to get it back working again.
I spent time on Google and have found people who have asked the same question, but I've not seen any thread anywhere with a definitive answer.
Anyone ever seen this before and whooped it?
EDIT AFTER:
Pretty sure I am doing this in debug mode. But let me know if there is some other place I should be looking.
My guess is that you are debugging a 'Release' configuration. Release configurations optimize the code by, among the many other optimizations, removing code that it knows for sure is never going to be used. So, for example, Dim MyString String = "this is a test" will be optimized out of the solution if it is never used but if you add a line of code to commit it to a database it is then being used and will not be optimized out. Switch to the 'Debug' configuration to prevent these types of optimizations.

Debug.WriteLine malfunctions in Visual Studio. How to fix it?

The text sent is not seen in the Output window.
Solution Configuration is Debug.
Output window is showing output from Debug.
It's a simple command: Debug.WriteLine("abc");
Setting a Breakpoint on it succeeds, but the program breaks on the line after it, moving the Breakpoint!
Changing Platform from Any CPU to x86 solves the issue. But going back, it returns.
Creating a new solution, it does work. Even in Any CPU.
I removed the .suo file for the solution.
I emptied the %temp% folder.
Is there any solution for this?
1) Go to Build -> Configuration manager and make sure you are in Debug mode, not Release.
2) Right-click on the project that you're having trouble with and choose properties.
3) Check the Build tab and make sure Define DEBUG constant and Define TRACE constant are both checked.
Note, most people make the mistake corrected by Step #1. But in my case it was steps #2 and #3 that fixed the problem. Despite being in DEBUG mode, for some reason those two constants were not being defined! I think the IDE may have turned them off when I had some of the projects in a solution using one platform target, and the rest of them using a different one, because by default, they are both enabled (checked) when you are in Debug mode.

"No symbols have been loaded for this document." But they have!

As you can notice
Symbols are been correctly loaded.
I just created a view GetCompanies.cshtml using the AddView shortlink
But, no matter what I do, I can't debug in the View.
What I did so far:
Close and Open Solution
Close and open Visual Studio
Shutdown all ASP.NET Development Server's
Deleted all Symbol Libraries .pdb
Clean Solution
Re-Build Solution
did not (yet) shutdown Windows 7 x64 :-/
Sometimes if you have a hard stop, Visual Studio temp cache will be screwed.
Clear the cache by deleting these folders:
C:\Windows\Microsoft.NET\Framework\<.net version>\Temporary ASP.NET Files\(ApplicationName)
C:\Windows\Microsoft.NET\Framework64\<.net version>\Temporary ASP.NET Files\(ApplicationName)
I am finding the same behavior from time to time when debugging silverlight. My solution is to clean the browser's cache (on latest IE click on the wheel button, Developer tools), as it sometimes will cache the binary files and not load the new ones.
Perhaps is could be the same with your views?
Been messing with this problem for a couple hours trying everything above. I finally changed my Target Framework to .NET Framework4.5 and it all started magically working.
This is always weird. I just had this problem and solved it with a full rebuild of the entire solution.
There was also another strange symptom, though: a new unit test that I had written using NUnit, mocking with NSubstitute, wouldn't pass because NSubstitute wasn't returning what I wanted it to return. I lost a few minutes trying to figure out if I did something wrong programming NSubstitute, then when I tried to attach the debugger to the NUnit GUI I saw that warning.
That's when I decided to do a full rebuild of the solution, and that worked for me.
So I guess the lesson to be learned is "before smashing your head against the wall, try a full rebuild".
For me, I somehow switched my target build to Release instead of Debug
Remember that views are actually compiled when you request the page (by default).
This means when you set a breakpoint in a view:
It shows the "No Symbols" error. This just means the view isn't
compiled yet.
It shows the breakpoint fine. This just means
that it found SOME compiled version of the page. Like the LAST working version...
So basically its not meaningful information to look at what it says when you mouseover the breakpoint in a view (at least in this regard)
If you are trying to debug this page, then you have a problem. Look at what the debugger is outputting to your BROWSER instead and fix that first. I think we'll be surprised about how many people are going to facepalm at this.
I had this problem with SL5 project (VS2012). And to fix this, I was needed to set "Silverlight" option enabled in %MyProjectName%.Web project properties, under Web tab.
In my case, the .PDB file was hosed (from which the symbols are loaded) in VS 2012, so performing a Clean and Build reconstructed the .PDB file and everything started workign again.
I was attempting to debug a deployed WCF windows services (compiled in Release mode) and had the exact same issue. Give this a shot...
Save All. You may even want to try to clean the solution
Rebuild all and install or deploy
BEFORE starting the service (or exe) I copied the .pdb files over to the install folder
Start the service (or exe) and attach the debugger to the process
Worked like a charm (finally) for me.
delete bin and obj directories
run solution again.
Note: Unless that cshtml loads at runtime the symbols are not loaded. On page load that breakpoint will be hit. So wait till control goes to that page

Resources