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

发布于 2024-12-31 21:17:47 字数 1400 浏览 1 评论 0原文

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

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

I was debugging a given C++ code with the F11 key (Step Into mode) in order to understand the precise order in which the functions in the code were called and I realized that it would never enter inside some functions unless I set a breakpoint at some line inside the function definition.

I mean, if I call a function from the main method, and the function is defined in another .cpp I expect the F11 debugging mode to enter step by step inside the function in order to analize the variable changes. Most of the times it does but in some cases it just execute the function without stepping into it, and jumps to the next line in the main method.

Why is this happening?

Example:

This is the function F11 would never step into:

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
}

This is the main method where F11 goes step by step:

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   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉生梦死 2025-01-07 21:17:47

值得快速检查一下..

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

单击左侧的调试

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

为了更好的措施,我总是退出 VS 并返回

Worth a quick check..

In Visual Studio, go to Tools > Options...

Click Debugging on left side

On the left look for Enable Just my Code (Managed) if it is checked, uncheck it, hit "OK"

For good measure I always exit VS and go back in

不气馁 2025-01-07 21:17:47

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

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

You need debugging information to enter the glutMainLoop. When no source code or no debugging info is available for glutMainLoop the debugger can't display source code. When you want to single step this function you need to add both.

Alternatively you can enter to disassembly using Shift-F11. But I dont't think that this will help in this case.

书间行客 2025-01-07 21:17:47

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

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

When stepping through the code in CameraMain, do you expect to be able to step into display on the call to glutDisplayFunc(display);?

In that case it doesn't happen because the display function is not called at that point. Instead it is saved by GLUT to be called from inside the GLUT main loop. You have to set a breakpoint in the display function to be able to step through it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文