gpt4 book ai didi

c++ - boost 文件系统 : recursive_directory_iterator constructor causes SIGTRAPS and debug problems

转载 作者:搜寻专家 更新时间:2023-10-31 01:59:03 25 4
gpt4 key购买 nike

我想使用 boost::filesystem 提供的 recursive_directory_iterator 来删除一个目录。但是在构造时,调试器会停止并显示消息 Signal Received: Sigtrap 。我可以选择继续(必须多次执行,因为捕获了多个 Sigtraps)并且程序将按预期工作,但使用自定义断点进行调试不再有效。 “fs::path dir”指向的路径是有效的,我也尝试使用像 fs::... dirIter( "D:/validPath") 这样的字符串,但是问题依然存在。

#include <boost/filesystem.hpp> 
namespace boost::filesystem = fs;
void recursiveDeleteDir( fs::path dir )
fs::recursive_directory_iterator endIter;
//At this point debugging is stopped with the message
//Signal Received: SIGTRAP
fs::recursive_directory_iterator dirIter( dir );
for(;dirIter != endIter ; ++dirIter)
{
// do something
}
}

当我试图找出 Sigtrap 的确切来源时,我迷失在 boost::filesystem 实现细节的深处。

有没有人知道为什么这些 Sigtraps 存在或者它们是如何被激活的更重要的是:有没有办法摆脱它们

(当然,它们只出现在 Debug模式下,程序在 Release模式下运行良好,但我必须能够以某种方式继续调试)

感谢您的帮助!


编辑:我正在使用 NetBeans IDE,但无权访问完整的调用堆栈。但这是接收到 sigtrap 信号时包含的内容:

01: ntdll!RtlpNtMakeTemporaryKey()
02: ntdll!RtlpNtMakeTemporaryKey()
03: ntdll!RtlpNtMakeTemporaryKey()
04: ntdll!LdrFindEntryForAddress()
05:地址:[@0x003e0000]
06:地址:[@0x50000061]
07: std::basic_string, std::allocator>::_Rep::_S_empty_rep_storage()
08:地址:[@0x003e0000]
09: std::basic_string, std::allocator>::_Rep::_S_empty_rep_storage()
10:地址:[@0x40000060]
11:地址:[@0x0022f968]
12:地址:[@0x00000000]

最佳答案

经过大量的搜索和询问,我解决了这个问题。这个问题(或者更确切地说是答案)给了我一个提示:
Does getting random SIGTRAP signals (in MinGW-gdb) is a sign of memory corruption?

这似乎是试图访问损坏的内存的问题,这是由使用未初始化的动态库引起的。

通过使用 boost::filesystem 和 boost::system 库的静态(调试)版本,并激活链接器的 -static 开关,可以解决这个问题。

关于c++ - boost 文件系统 : recursive_directory_iterator constructor causes SIGTRAPS and debug problems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3469463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com