简体   繁体   English

为什么Visual C ++没有遇到断点,或者单步执行某个特定的函数?

[英]Why does Visual C++ not hit a breakpoint in, or step through a specific function?

I have the following: 我有以下内容:

classA::FuncA()
{
 ... code
   FuncB();
 ... code
}

classA::FuncB(const char *pText)
{
    SelectObject(m_hDC, GetStockObject (  SYSTEM_FONT)); 
    wglUseFontBitmaps(m_hDC, 0, 255, 1000); 
    glListBase(1000); 
    glCallLists(static_cast<GLsizei>(strlen(pText)), GL_UNSIGNED_BYTE, pText); 
}

I can hit breakpoints anywhere in FuncA. 我可以在FuncA的任何地方点击断点。 If I try to step into FuncB, it steps over. 如果我尝试进入FuncB,它会跳过。 It will accept a breakpoint in FuncB, but never hits it. 它将接受FuncB中的断点,但永远不会命中它。 I know it is executing FuncB, because I can put a MessagBox() call in FuncB and get the message box. 我知道它正在执行FuncB,因为我可以在FuncB中调用MessagBox()并获取消息框。

I'm new to VS2005 after a few years away from extensive VC6 usage. 在远离广泛的VC6使用几年后,我是VS2005的新手。 The one situation like this I recall from my VC6 days, is if symbol information is not available. 我记得VC6时代的这种情况是,如果没有符号信息。 However, in this case both functions are in the same file, so the symbol information must be correct. 但是,在这种情况下,两个函数都在同一个文件中,因此符号信息必须正确。 Also in that case I think you couldn't even set the breakpoint. 同样在那种情况下,我认为你甚至无法设置断点。

I've tried all the silly voodoo like rebuilding the whole solution. 我尝试过所有愚蠢的伏都教,就像重建整个解决方案一样。

What stupid thing am I overlooking? 我忽略了什么愚蠢的事情?

EDIT: Added code for FuncB in response to comment about it possibly being essentially inline-able. 编辑:添加了FuncB的代码,以回应关于它可能基本上是内联的评论。 (It's just the exact sample code from MSDN for wglUseFontBitmaps [minus comments here]). (这只是来自MSDN的wglUseFontBitmaps的确切示例代码[减去这里的评论])。 I don't see how inlining that would impede stepping through each call. 我不知道内联是如何妨碍逐步完成每次通话的。

Make sure all compiler optimizations are disabled (/Od). 确保禁用所有编译器优化(/ Od)。 Compiler optimization can cause problems with debugger breakpoints. 编译器优化可能会导致调试器断点出现问题。

Not sure what the problem is, but one thing you might try is to look at the disassembled code. 不确定问题是什么,但您可能尝试的一件事是查看反汇编代码。 You can switch betwen the source code and disassbled view with VS. 你可以用VS切换源代码和disassbled视图。 I do not have the IDE in front of me at work, so the terms might be slightly off. 我工作时没有IDE,所以这些条款可能略有偏差。

If you put the debugger into this mode, you can see what the assembly instructions that are executing. 如果将调试器置于此模式,则可以查看正在执行的汇编指令。 This helps sometimes to determine these kinds of problems. 这有助于确定这些问题。 Sometimes, although not usually with a debug build, calls are optimized out by the compiler. 有时,尽管通常不使用调试版本,但编译器会优化调用。

If everything fails try updating to VS2005 SP1 if you don't already have it... 如果一切都失败,请尝试更新到VS2005 SP1,如果您还没有...

Sounds strange indeed! 听起来很奇怪!

Thanks for posting the code. 感谢您发布代码。 This is clearly not what I had guessed. 这显然不是我猜到的。


For posterity's sake, and to clear things up, my guess was that if (1) the function was one line and (2) the compiler inlined the function, then (3) the debugger might not know how to step into it. 为了后人的目的,为了清理,我的猜测是,如果(1)函数是一行,(2)编译器内联函数,那么(3)调试器可能不知道如何进入它。 This guess relies on the fact that some debuggers do have trouble with inlined code and other compiler optimizations . 这种猜测依赖于一些调试器在内联代码和其他编译器优化方面遇到问题的事实。 I'm not familiar enough with Visual Studio's debugger to say whether it is on that list. 我对Visual Studio的调试器不够熟悉,不知道它是否在该列表中。

On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; 在大多数使用stabs格式的系统上,-g允许使用只有GDB才能使用的额外调试信息; this extra information makes debugging work better in GDB but will probably make other debuggers crash or refuse to read the program. 这些额外的信息使得调试在GDB中工作得更好,但可能会使其他调试器崩溃或拒绝读取程序。 ... ...

GCC allows you to use -g with -O. GCC允许您使用-g和-O。 The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; 优化代码所采用的快捷方式有时会产生令人惊讶的结果:您声明的某些变量可能根本不存在; flow of control may briefly move where you did not expect it; 控制流可能会短暂地移动到你没想到的地方; some statements may not be executed because they compute constant results or their values were already at hand; 某些陈述可能无法执行,因为它们会计算出不变的结果,或者它们的值已经存在; some statements may execute in different places because they were moved out of loops. 一些语句可能在不同的地方执行,因为它们被移出循环。

The GCC manual used to have a statement that some compilers would refuse to emit debugging symbols in optimized code because their debuggers couldn't follow it. GCC手册过去曾声明某些编译器会拒绝在优化代码中发出调试符号,因为他们的调试器无法遵循它。

实际上我有一个类似的问题,发现当我运行程序时代码没有被编译,所以在尝试运行它之前确保你'编译'程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM