2

When I run on my working machine (win7 VS2010 ultimate sp1)

int main()
{
    unsigned i = 5;
    i %= 0;
    return 0;
}

or

int main()
{
    int * ip = 0;
    *ip = 4;

    return 0;
}

and I get Integer division by zero unhandled exception. When I hit break button, to see the problem, my Call stack contains only msvcrt100d and ntdll and Visual studio breaks me inside file mlock.c on the LeaveCriticalSection( _locktable[locknum].lock ); line.

When I run this code on another machine(win7 VS2010 proff sp1), VS breaks it exactly on the problematic line i %= 0; od *ip = 4.

This mistake was hidden somewhere within my project and I wasn't able to find it till I run it on another machine. How can I fix this behavior? I need to see it on my working machine.

I have a clean installation of Windows 7, clean installation Visual Studio 2010 and VS-SP1. My project should not be ruined. I generate it using CMake and same project working fine on non-working machine.

Any advice would be greatly appreciated.

relaxxx
  • 7,566
  • 8
  • 37
  • 64
  • Have just realized that you have issues with debug information and not trying to divide by zero :) If the setup is screwed, it is hard to guess what exactly is wrong. I'd make sure to have all of the debug information. It seems like VS simply shows different place for the same code location. –  Feb 20 '13 at 14:56
  • Did you try to **manualy** delete all *.ncb, *.ilk, *.pdb, *.obj, *.idb files on your working machine ? – borisbn Feb 20 '13 at 15:09
  • yes. I create totally new clean project, add only one cpp file, fill it with example code and run. – relaxxx Feb 20 '13 at 15:14

2 Answers2

1

Ok, I have found a solution.

In VS go to exceptions settings (ctrl + alt + e) and check Thrown in required Win32 Exceptions.

More info can be found here and here.

SO related question here.

Community
  • 1
  • 1
relaxxx
  • 7,566
  • 8
  • 37
  • 64
0

When you compile a program with VS it creates the EXE file and a PDB file with all the relevant debugging information of the program. Also, the absolute path of the PDB if embedded into the EXE.

When the EXE crashes and you use VS to debug it, it tries to find the corresponding PDB, both in the same folder than the EXE and in the absolute path embedded in the file. If you want it to be able to debug the program, then you must copy the PDB along with the EXE. Note that these two files must come from exactly the same compilation, or else it will not work.

Then, the VS debugger will try to show you the sources of the program, again using the absolute path of the *.c or *.cpp files embedded in the PDB. Obviously, if you want it to stop in the relevant line, you need a copy of the sources! If you copy the sources to the very same path than in the original machine it should work without problems. If not, you have to open the Call stack window, double-click over the main function and it will ask you to browse for the actual sources.

Or maybe your setup is screwed...

rodrigo
  • 94,151
  • 12
  • 143
  • 190