为什么Visual Studio的调试模式Step Into(F11)有时无法进入某些函数内部?

11
我在调试一个给定的C++代码时,使用F11键(步进模式)以了解代码中函数被调用的精确顺序,并且我意识到在某些函数内部,除非我在函数定义中的某行设置断点,否则它永远不会进入这些函数
我的意思是,如果我从主方法调用一个在另一个.cpp文件中定义的函数,我希望F11调试模式逐步进入函数,以便分析变量的更改。大多数情况下是可以的,但在某些情况下,它只是执行函数而不进入它,并跳转到主方法中的下一行。
为什么会发生这种情况? 示例: 这是F11永远不会进入的函数:
void VirtualCamera::display (void) {
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear the background of the window
    glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on)
    glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations

    glTranslatef(0.0f, 0.0f, -5.0f);
    renderPrimitive(); // Render the primitive

    glFlush(); // Flush the OpenGL buffers to the window
}

这是主方法,F11会一步一步执行:

void VirtualCamera::CameraMain(int argc, char **argv){
    glutInit(&argc, argv); // Initialize GLUT
    glutInitDisplayMode (GLUT_SINGLE); 
    glutInitWindowSize (500, 500); // Set the width and height of the window
    glutInitWindowPosition (100, 100); // Set the position of the window
    glutCreateWindow ("OpenGL Window"); // Set the title for the window

    glutDisplayFunc(display); // Tell GLUT to use the method "display" for rendering
    glutReshapeFunc(reshape);

    glutMainLoop(); // Enter GLUT's main loop   
}
3个回答

7

值得快速检查...

在Visual Studio中,转到工具 > 选项...

点击左侧的调试

在左侧查找启用仅限我的代码(托管),如果已经选中,请取消选择,然后点击"确定"

为了保险起见,我总是退出VS并重新进入


我没有被选中,但还是谢谢。我的意思是,我期望当F11到达glutMainLoop()这一行时,也会进入display函数,但只有在我在display(void)内设置断点时才会进入。 - Jav_Rock

6

您需要调试信息才能进入glutMainLoop。当没有源代码或没有为glutMainLoop提供调试信息时,调试器无法显示源代码。如果您想单步执行此函数,您需要同时添加它们。

或者,您可以使用Shift-F11进入反汇编。但我不认为在这种情况下会有帮助。


4
当您在CameraMain代码中进行步进时,您是否期望能够在调用glutDisplayFunc(display);时步进到display中?
在这种情况下,不会发生这种情况,因为display函数在该点上并未被调用。相反,它被GLUT保存以便从GLUT主循环内部调用。您必须在display函数中设置断点才能逐步执行它。

我希望能够在glutMainLoop中进入显示,但正如你所说,需要一个断点。为什么?这种情况是否总是发生在循环中? - Jav_Rock

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接