不会命中此断点

This breakpoint will not be hit

本文关键字:断点      更新时间:2023-10-16

我查看了许多关于这个问题的帖子,但没有一个适用于我的情况。 我在一个文件中有一个C++类,它有 3 个方法。我可以在一种方法中设置断点。但是,我不能在其他两种方法中的任何代码行上设置断点。此类是作为具有 DEBUG 集的库构建的。所有优化都将关闭。 下面是此类中两个问题方法的代码。

块引用

#include "pch.h"
#include <stdio.h>
#include <afxwin.h>
#include <cstring>
#include <io.h>
#include <iostream>
#include <string>
#include "Log.h"

CLog::CLog()
{
ptLog = NULL;  // this is the file ptr
}
void CLog::Init()
{
int iFD;
DWORD iLength;
int iStat;
HMODULE hMod;
std::string sPath;
std::string sFile;
int i;
hMod = GetModuleHandle(NULL);  // handle to this execuatble
std::cout << "Module = " << hMod;
if(hMod)
{
// Use two bytes ASCII (UNICODE) if set by compiler
char acFile[120];
// Full path name of exe file
GetModuleFileName(hMod, acFile, sizeof(acFile));
std::cout << "File Name = " << acFile<<"n";
// extract file name from full path and append .log
sPath = acFile;
i = sPath.find_last_of("\/");
sFile = sPath.substr(i + 1);
sFile.copy(acFile, 120);
std::cout << " File Name Trunc = " << sFile;
sFile.append(".log");
iStat = fopen_s(&ptLog, sFile.data(), "a+");  // append log data to file
std::cout << "fopen stat = " << iStat;
if (iStat != 0)    // failed to open error log
{
return;
}
iFD = _fileno(ptLog);
iLength = _filelength(iFD);
// Check length. If too large rename and create new file.
if (iLength > MAX_LOG_SIZE)
{
fclose(ptLog);
char acBakFile[80];
strcpy_s(acBakFile, 80, acFile);
strcat_s(acBakFile, ".bak");   // new name of old log file
remove(acBakFile);  // remove previous bak file if it exists
rename(acFile, acBakFile);
fopen_s(&ptLog, acFile, "a+");   // Create new log file
}
}// end if (hMod)
}

,,,

ptLog 被声明为文件 * 此类使用以下代码调用:

#include <iostream>
#include "..LogLog.h"
int main()
{
CLog Logger;
Logger.Init();
Logger.vLog((char *) "Hello n");
}

块引用 此代码也编译为调试。如果在"Loggger.Init(("上设置断点 调试器将命中断点。如果选择"步入",则不会进入 Init(( 方法中的代码。代码确实执行,因为我可以在控制台上看到文本。如果我在 Init(( 方法中的任何位置放置断点,它们不会中断。

我做了以下操作: 从链接器的输入中删除了 log.lib。 显然,链路由于未解析的外部而失败。 放回 log.lib 并重建。 关闭了"要求与原始版本完全匹配的源文件"选项 调试和断点有效。 已启用该选项。 重试调试,断点仍然有效。 是否进行了完全重建和断点工作。

我真的不明白,因为我已经进行了多次清洁和重建 以前。

我确实发现了另一个问题。我打开了"/clr"选项。 这适用于 .lib 的公共语言运行时支持。 链接到它的模块没有打开公共语言运行库。在这种情况下, 断点被忽略。当我关闭"/clr"时,断点 功能正常