为什么Visual Studio的调试模式Step In(F11)有时不会进入某些函数?

Why Visual Studio's debug mode Step Into (F11) sometimes doesn't enter inside some functions?

本文关键字:函数 调试 Studio Visual 模式 Step F11 In 为什么      更新时间:2023-10-16

我用F11键调试给定的C++代码(进入模式),以了解代码中函数的调用顺序,我意识到除非在函数定义的某行设置断点,否则它永远不会进入某些函数。

我的意思是,如果我从主方法调用一个函数,并且该函数是在另一个.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   
}

值得快速检查。。

在Visual Studio中,转到工具选项

单击左侧的调试

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

为了更好地衡量,我总是退出VS并返回

您需要调试信息才能进入glutMainLoop。当没有源代码或没有调试信息可用于glutMainLoop时,调试器无法显示源代码。当你想单步执行这个函数时,你需要同时添加这两个。

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

在执行CameraMain中的代码时,是否希望能够在调用glutDisplayFunc(display);时进入display

在这种情况下,不会发生这种情况,因为display函数是,而不是。相反,它由GLUT保存,以便从GLUT主循环内部调用。您必须在display函数中设置一个断点才能逐步通过它。