13

In some of the files, debugger is pointing at the wrong line, while stepping through the code. To be precise, it is off by exectly one line (always)

What I have already tried:

1) normlized line-endings in all of the files
2) wiped out all of the PDB files
3) wiped out the entire debug folder
4) rebuilt the entire project
5)ensured that optimisation for the entire solution and projects within it it is turned-off (/Od switch enabled)
6)ensured that libraries (*.LIB) to which source code I have access to, have had their optimisation disabled and use the same threading mode as the main executable.
7) rebooted PC / VS

project is set to x64 Debug,takes use of SQLite3 LIB and DLL, OpenCL.lib

example in the faulty file:

   int a = 0;
   a++;
=> a++; //debugger points at this line, though the value of 'a' is already equal to 2
   a++;

One file has the issue, while another might not have it. I haven't found any corelation between affected files and their content.

Vega4
  • 969
  • 1
  • 11
  • 25
  • Have you tried restarting visual studio? – Cratebox99 Aug 25 '17 at 17:02
  • 1
    just did , and the entire machine, to no avail – Vega4 Aug 25 '17 at 17:17
  • 3
    Is it off by one statement? VS will often point to the *next* statement to be executed, especially when you have switched to a higher call in the call stack. – Aerom Xundes Aug 25 '17 at 17:18
  • it is off by one statement,but in the sense that it points one line above where it is supposed to point at (which can happen and often does happen to be an empty line). When I add artificial empty lines to the code, it seems to take these into account and still is off only by one line (so the PDB files are updated) – Vega4 Aug 25 '17 at 17:26
  • Does it happen for all code or just some library or section of code? I think you need to narrow down the scope of the issue. – Aerom Xundes Aug 25 '17 at 17:28
  • I am trying to narrow down the problem. It happens (as far as I am aware of right now,- it is sort of a large project). In one of the CPP files. some other files are fine – Vega4 Aug 25 '17 at 17:32
  • What about a new project with a hello world? – rustyx Aug 25 '17 at 17:33
  • @RustyX new 'hello world' project debugs perfectly fine – Vega4 Aug 25 '17 at 17:37
  • I've removed references to other libraries from the problematic cpp file (includes) the problem persists. – Vega4 Aug 25 '17 at 17:44
  • 1
    The optimizer might fold several source lines into a single machine code. Then there is just one possible stop for the debugger. – Bo Persson Aug 25 '17 at 18:08
  • @Bo Persson; like I said, I've already disabled code optimisation /Od – Vega4 Aug 25 '17 at 18:42
  • Try cleaning and rebuilding the project. What is the debug information settings? – tambre Aug 25 '17 at 19:32
  • @tambre, like I said, I've already tried cleaning the entire project multiple times, to no avail. Which Debug info settings do you mean? the format is "Program Database for Edit And Continue (/ZI)". It's killing me:) – Vega4 Aug 25 '17 at 19:37
  • In case this helps someone, if your cpp file gets more than 64000 lines, at some point you might have to split up the file into 2 files to get the debugger using correct lines again. Its happened to me a few times and splitting the file into 2 resolved. – Robert Feb 26 '21 at 16:48

2 Answers2

13

Turns out I've used the most upvoted method described in stack post to 'normalize' line endings in the entire project. Seems like it did not work. After normalising line endings with Visual Studio everything works fine.

So for anyone else with this problem, just re-enable automatic line-ending fix-up ,if disabled, by going to Tools=>Options=>Environment=>Documents and enable 'check for consistient line endings on load'. Then repen problematic file.

Vega4
  • 969
  • 1
  • 11
  • 25
  • Thanks for sharing your solution here, since it was resolved, you could mark your reply as the answer, so it could help other community members who get the same issue. Have a nice day:) – Jack Zhai Aug 28 '17 at 06:57
  • Didn't fix it, I have the option on to start with, and yet, it still points to the wrong line. – kovarex Jun 14 '21 at 15:52
0

In my case I have found that I actually need to close the project then delete both the bin and obj folders in the main exe project folder and any dll project folders. Visual Studio will auto-recreate empty bin and obj folders on next open of the solution. At that point, rebuilding the project will fix this.

amonroejj
  • 573
  • 4
  • 16