【问题标题】:Why Visual Studio's debug mode Step Into (F11) sometimes doesn't enter inside some functions?为什么 Visual Studio 的调试模式 Step Into (F11) 有时无法进入某些函数?
【发布时间】:2016-10-12 17:46:59
【问题描述】:

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

我的意思是,如果我从 main 方法中调用一个函数,并且该函数是在另一个 .cpp 中定义的,我希望 F11 调试模式可以逐步进入在函数内部以分析变量的变化。大多数时候它会这样做,但在某些情况下它只是执行函数而不进入它,并跳转到 main 方法中的下一行。

为什么会这样?

示例:

这是 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   
}

【问题讨论】:

    标签: c++ visual-studio-2008 visual-studio-debugging


    【解决方案1】:

    值得快速检查..

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

    点击左侧的调试

    在左侧查找 Enable Just my Code (Managed),如果选中,取消选中,点击“OK

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

    【讨论】:

    • 我没有被选中,但还是谢谢你。我的意思是,我希望当 F11 到达 glutMainLoop() 行时,也会进入函数显示,但只有当我在 display(void) 内设置断点时才会这样做。
    【解决方案2】:

    您需要调试信息才能进入 glutMainLoop。当 glutMainLoop 没有可用的源代码或调试信息时,调试器无法显示源代码。当您想单步执行此功能时,您需要同时添加两者。

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

    【讨论】:

      【解决方案3】:

      当单步执行CameraMain 中的代码时,您是否希望能够在调用glutDisplayFunc(display); 时单步执行display

      在这种情况下,它不会发生,因为 display 函数当时没有被调用。相反,它由 GLUT 保存,以便从 GLUT 主循环内部调用。您必须在 display 函数中设置断点才能单步执行。

      【讨论】:

      • 我希望能够进入显示到glutMainLoop,但正如你所说,断点是必要的。这是为什么?循环是否总是发生?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-13
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多