C++ single step in debugger throws an exception

2020-06-21 10:20发布

问题:

I have a C++ app that will throw an exception when I try to single step from a breakpoint. For example:

1) Start app from VS2010 0 debugger is attached.

2) Set a breakpoint. It doesn't seem to matter where.

3) Do something in the app so that it hits the break point.

** VS2010 hits the break point

4) Single step the debugger to the next line of code.

VS2010 pops up a message box with this exception:

"Unhandled exception at 0x087df66f in SimpleGraphSDI.exe: 0xC0000005: Access violation."

Note that if I set a breakpoint on two consecutive lines of code, and press run to advance from one line to another, the app "runs" to the next line of code with no issues. The access violation is only when I use the single step command from VS2010.

Some code in the app has been around since VC6 and maybe earlier. However do not know if this is relevant.

UPDATE: The exception when single stepping the debugger does not occur if I start the app, and then attach the debugger after the app has started.

回答1:

I had this exact same issue. I was able to solve it by starting VS from the command line telling it to reset the UI to default (/ResetSettings) Details on the command line arguments are here

I did not need to reboot after resetting VS, but I did a full rebuild of the project after completing the reset of the environment.



回答2:

A work around for this problem is to disable RPC debugging.

In the Visual Studio 2010, Visual Studio 2010 SP1 toolbar select below steps -

Tools->Options->Debugging->Native and deselect "Enable RPC debugging"



回答3:

There maybe exist a thread that somehow detects that the code is being debugged step by step and pagefaults in response to prevent you from debugging. Try to locate that thread by suspending threads one by one.

Also, is address 0x087df66f always the same? If it is then you can set a breakpoint there and look around when the breakpoint is hit.