C++ 当前不会命中断点。没有与此行关联的可执行代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15205750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Breakpoint will not currently be hit. No executable code associated with this line
提问by xcdemon05
I have a class in a .h file:
我在 .h 文件中有一个类:
class Blah
{
public:
Blah(){}
virtual ~Blah(){}
void WriteMessage( bool MessageReceived )
{
if(MessageReceived)
{
cout << "Message Recieved\n";
}
}
};
I was trying to figure out why my code isn't working, so I set a breakpoint on the conditional inside the WriteMessage()
funcition, but as soon as I started running the project in debug mode the breakpoint faded out and the tooltip for it said:
我试图弄清楚为什么我的代码不起作用,所以我在函数内部的条件上设置了一个断点WriteMessage()
,但是一旦我开始在调试模式下运行项目,断点就消失了,它的工具提示说:
Breakpoint will not currently be hit.
No executable code associated with this line.
当前不会命中断点。
没有与此行关联的可执行代码。
I have no idea why this is happening, because all of my other member functions for other classes work just fine when implemented in the .h file. What is causing this?
我不知道为什么会发生这种情况,因为其他类的所有其他成员函数在 .h 文件中实现时都可以正常工作。这是什么原因造成的?
Edit:Okay as requested, here's a stripped down version of the real code I'm working with:
编辑:好的,按照要求,这是我正在使用的真实代码的精简版本:
VimbaBridgeAPI.h(header file for .dll)
VimbaBridgeAPI.h(.dll 的头文件)
#pragma once
#ifdef VIMBABRIDGEAPI_EXPORTS
#define VIMBABRIDGEAPI_API __declspec(dllexport)
#else
#define VIMBABRIDGEAPI_API __declspec(dllimport)
#endif
#include "AlCamIncludes.h"
#include "VimbaSystem.h"
////////////////////////////////////////////
// Global Variables ///////////////////////
////////////////////////////////////////////
extern HBITMAP hbit;
extern CEdit* global_filenamehandle;
////////////////////////////////////////////
// Global Flags ///////////////////////////
////////////////////////////////////////////
extern bool imageReady;
extern bool take_picture;
using namespace AVT::VmbAPI;
VIMBABRIDGEAPI_API void BridgedGetImage(FramePtr framepoint, VmbUchar_t** imgDat);
VIMBABRIDGEAPI_API HBITMAP ExternalFrameRecieved( const FramePtr pFrame );
//////////////////////////////////////////////////////////////////////////
////////// MyObserver class ///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
class VIMBABRIDGEAPI_API MyObserver : public IFrameObserver
{
private:
MyObserver( MyObserver& );
MyObserver& operator=( const MyObserver& );
//class member variables
//BITMAPINFO* pbmi;
CEdit* m_filenameedit;
public:
MyObserver(CameraPtr pCamera) : IFrameObserver(pCamera) {}
virtual ~MyObserver() {}
void FrameReceived ( const FramePtr pFrame );
};
NOTE:IFrameObserver is not written by me, but the FrameReceived function is a pure virtual declared in the IFrameObserver class. Their documentation says that FrameRecieved gets called by their API whenever a frame comes in, and I had to implement the function. I have tested this functions and it works, but only when defined outside the class (inside I get the error I'm getting now)
注意:IFrameObserver 不是我写的,但是 FrameReceived 函数是在 IFrameObserver 类中声明的纯虚拟函数。他们的文档说 FrameRecieved 会在帧进入时被他们的 API 调用,我必须实现该功能。我已经测试了这个函数并且它可以工作,但只有在类外部定义时(在内部我得到了我现在得到的错误)
VimbaBridgeAPI.cpp(code hidden from user)
VimbaBridgeAPI.cpp(对用户隐藏的代码)
void FrameRecieved( const FramePtr pFrame )
{
DbgMsg(L"Frame Received\n");
////////////////////////////////////////////////////////////////////////
////////// Setup Bitmap ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//// FILEHEADER ////
BITMAPFILEHEADER* bf = new BITMAPFILEHEADER;
bf->bfType = 0x4d42;
bf->bfSize = 6054400 + 54 + sizeof(BITMAPINFO);
bf->bfOffBits = 54;
//// INFOHEADER ////
BITMAPINFOHEADER* bih = new BITMAPINFOHEADER;
bih->biSize = 40;
bih->biWidth = 2752;
bih->biHeight = -2200;
bih->biPlanes = 1;
bih->biBitCount = 32;
bih->biCompression = 0;
//bi->biSizeImage = 6054400; //not required
bih->biXPelsPerMeter = 2835;
bih->biYPelsPerMeter = 2835;
bih->biClrUsed = 0;
bih->biClrImportant = 0;
//// INFO ////
BITMAPINFO* pbmi = (BITMAPINFO*)alloca( sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
pbmi->bmiHeader.biSize = sizeof (pbmi->bmiHeader);
pbmi->bmiHeader.biWidth = 2752;
pbmi->bmiHeader.biHeight = -2200;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = 8;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = 0;
pbmi->bmiHeader.biXPelsPerMeter = 14173;
pbmi->bmiHeader.biYPelsPerMeter = 14173;
pbmi->bmiHeader.biClrUsed = 0;
pbmi->bmiHeader.biClrImportant = 0;
//create grayscale color palette
for(int i=0; i<256; i++)
{
pbmi->bmiColors[i].rgbRed = BYTE(i);
pbmi->bmiColors[i].rgbGreen = BYTE(i);
pbmi->bmiColors[i].rgbBlue = BYTE(i);
pbmi->bmiColors[i].rgbReserved = BYTE(0);
}
//// IMAGE DATA ////
VmbUchar_t* imageData = NULL;
BridgedGetImage(pFrame, &imageData);
//////////////////////////////////////////////////////////////////////////
////// Create image that's printed to dialog box /////////////////////////
//////////////////////////////////////////////////////////////////////////
HDC hdc = ::GetDC(NULL);
hbit = CreateDIBitmap(hdc, bih, CBM_INIT, imageData, pbmi, DIB_RGB_COLORS);
//clean up
DeleteObject(bf);
DeleteObject(bih);
DeleteObject(hdc);
}
采纳答案by swaps
I would suggest you firstly Delete the output files: Physically delete all generated DLLs, PDBs and EXEs. Then compile (rebuild) again to generate the files. Sometimes Visual Studio can "get lost" and "forget" to overwrite the output files when you build your solution.
我建议您首先删除输出文件:物理删除所有生成的 DLL、PDB 和 EXE。然后再次编译(重建)以生成文件。有时,在构建解决方案时,Visual Studio 可能会“迷失”和“忘记”覆盖输出文件。
This can happen for a few other reasons:
发生这种情况的原因可能有以下几个:
- The code the debugger is using is different from the code that the application is running
- The pdb file that the debugger is using is different from the code that the application is running
- The code the application is running has been optimized and debug information has been stripped out.
- The code in which you have breakpoints on hasn't been loaded into the process yet
- 调试器使用的代码与应用程序运行的代码不同
- 调试器使用的 pdb 文件与应用程序运行的代码不同
- 应用程序运行的代码已经过优化,调试信息已被删除。
- 设置断点的代码尚未加载到进程中
回答by jxramos
I wound up having this issue too, the context of my app was a main app in C# which used unmanaged C++ code in a lower layer that I wanted to step into from the debugger. From the C# project properties I went into the Debug tab and under the Enable Debuggers section checked the "Enable unmanaged code debugging".
我最终也遇到了这个问题,我的应用程序的上下文是 C# 中的一个主应用程序,它在我想从调试器进入的较低层中使用非托管 C++ 代码。从 C# 项目属性中,我进入了调试选项卡,在启用调试器部分下选中了“启用非托管代码调试”。
回答by IVSoftware
Wanted to mention that I experienced the "Breakpoint will not be hit..."
error when porting some of my older MFC (managed--using clr support)
projects into VS2015
.
想提一下我"Breakpoint will not be hit..."
在将一些旧MFC (managed--using clr support)
项目移植到VS2015
.
What fixed the issue for me was setting this:
对我来说解决这个问题的是设置这个:
Configuration Properties\Linker\Debugging\Debuggable Assembly
Configuration Properties\Linker\Debugging\Debuggable Assembly
... to this:
...到这个:
Yes (/ASSEMBLYDEBUG)
Yes (/ASSEMBLYDEBUG)
回答by Phillip
I also wanted to chime in with my own solution. I had a C++ project loading a dll that consisted of C++/CLR code. Turns out, I had to set the startup project's debugger type to "Mixed". "Auto" wasn't detecting that it needed managed support because the dll was loaded manually after the program started.
我也想加入我自己的解决方案。我有一个 C++ 项目加载了一个由 C++/CLR 代码组成的 dll。结果,我不得不将启动项目的调试器类型设置为“混合”。“自动”没有检测到它需要托管支持,因为在程序启动后手动加载了 dll。
回答by muhammad tayyab
I was trying to press Ctrl+F5
which gives same as the error you received in Visual Studio Code. However, once I just go to Debug
section and pressed Green buttonwhich initialisesDebugging helped me solve this error.
我试图按Ctrl+F5
它给出的错误与您在 Visual Studio Code 中收到的错误相同。但是,一旦我转到Debug
部分并按下初始化调试的绿色按钮,就可以帮助我解决此错误。
回答by Hassan
For me, the answer was:
对我来说,答案是:
Project Properties->C/C++->Optimization
Project Properties->C/C++->Optimization
Set Optimization to : "Disabled (/Od)"
将优化设置为:“禁用 (/Od)”
回答by Uduse
回答by zar
I had the same issue but the accepted solution of cleaning up files didn't work for me. I have my issue resolved and it had to do with my code. Here are the details of my fix, hope it gives some clues to your fix.
我有同样的问题,但清理文件的公认解决方案对我不起作用。我已经解决了我的问题,它与我的代码有关。这是我修复的详细信息,希望它为您的修复提供一些线索。
What I was doing is overloading CArchive
<<
operator for my structure but the code never steps into it. I would set the break point and I got the solid red symbol. As soon as I start debugger the symbol becomes outlined and the warning message on it says:
我所做的是CArchive
<<
为我的结构重载运算符,但代码从未介入其中。我会设置断点,我得到了实心的红色符号。一旦我启动调试器,符号就会被勾勒出来,上面的警告消息说:
The breakpoint will not currently be hit. no executable code is associated with this line
当前不会命中断点。没有可执行代码与此行相关联
My relevant code is below where the break point doesn't break.
我的相关代码在断点没有中断的地方。
class Book
{
friend CArchive& operator << (CArchive& ar, const Book & book )
{
ar << book.title;
ar << "\r\n";
ar << book.price;
ar << "\r\n";
}
}
Now there is an obvious problem with this code is that it doesn't have a return statement return ar
but the compiler never complained. The reason compiler didn't complain was I was using the operator incorrectly (and rather never using it)
现在这段代码有一个明显的问题是它没有 return 语句return ar
但编译器从未抱怨过。编译器没有抱怨的原因是我错误地使用了操作符(而是从不使用它)
book *mybook = new Book(...);
ar << mybook;
Because mistakenly I am accessing the operator via pointer, my object's <<
operator was never really invoked and that's why compiler didn't complain either because it was never being used.
因为我错误地通过指针访问了操作符,所以我的对象的<<
操作符从未真正被调用过,这就是编译器没有抱怨的原因,因为它从未被使用过。
So first I fixed the calling code
所以首先我修复了调用代码
book *mybook = new Book(...);
ar << *mybook;
Now the operator overloading method complains about the return
statement and I fixed that too.
现在运算符重载方法抱怨该return
语句,我也修复了它。
I can now step into the function. So the bottom line was that the break point was not being set because this code was essentially sidelined by compiler (correctly) because it was never used in the code.
我现在可以进入这个函数了。所以最重要的是没有设置断点,因为这段代码基本上被编译器(正确地)排除在外,因为它从未在代码中使用过。