在调试模式下访问冲突,但在发布模式下正常

发布于 2025-01-05 10:48:53 字数 1102 浏览 4 评论 0原文

我花了两天的时间来解决这个问题,这让我很生气,因为我对 C++ 仍然很陌生。这个违规访问问题对您来说可能很容易,并且可能会被回答数千次。但我缺乏 C++ 知识,甚至无法识别曾经回答过的相同问题。

好的,这是我的问题:

1. 主要代码位于 DLL 中。我使用的是 Visual Studio 2008

2. 这个 DLL 调用了 3 个外部库:boost、tinyXML 和 SRILM(一个 NLP 工具包)。

3. 错误显示: tester.exe 中 0x5f4f068f (TextNormalizerAPI.dll) 处未处理的异常:0xC0000005:读取位置 0x00000000 时发生访问冲突。 仅在调试模式下发生。错误行是由我的代码中 boost::regex 对象 (patUsername = regex("^\\W*@[A-Za-z]");) 的初始化引起的,但实际位置在boost库的深处,如下图所示:

错误发生在boost lib中,而不是在我的代码中

**在大多数情况下,我是不应该更改 Boost lib 的源代码,不是吗? **

4. 该错误仅在 Debug 版本中出现,在 Release 版本中不会出现。

5. 我用旧的但无故障的版本替换了整个解决方案,该版本在调试模式下正常工作。然而,在我生成该解决方案的发布版本后,在调试模式下立即发生错误!

更新:

6. 谢谢你们!我刚刚尝试了一下,发现即使是在DLL入口的第一行简单地定义一个正则表达式对象也会引发这个错误!有什么想法吗?

7. 但在该 dll 调用者的 main() 的第一行中初始化正则表达式对象不会出现此问题。

希望这个描述能帮助你回忆起一些事情并给我一些提示。

我想问:

缩小范围并发现问题的通常策略是什么?谢谢你!

I am working on this problem for two days and this is driving me mad as I am still quite new to C++. This violation access problem may be quite easy to you and may be answered thousands of times. But my lack of C++ knowledge make me even unable to identify the same problem ever answered.

OK here is my problem:

1. The major code is in a DLL. I am using Visual Studio 2008

2. This DLL called 3 external libraries: boost, tinyXML and SRILM (a NLP toolkit).

3. The error says: Unhandled exception at 0x5f4f068f (TextNormalizerAPI.dll) in tester.exe: 0xC0000005: Access violation reading location 0x00000000. , occurred only in Debug mode. And the error line was caused by an initialization of a boost::regex object (patUsername = regex("^\\W*@[A-Za-z]");) in my code, but the actual position was deeply inside the boost library, as shown in below figure:

The error occurred in boost lib, not in my code

**in most cases, I am not supposed to change the source code of Boost lib, isn't it? **

4. This error occurred only in Debug version, not in Release version.

5. I replace the whole solution with a old but fault-free version which worked properly in Debug mode. Yet immediately after I generating a Release version of this solution, error occurred in Debug mode!

UPDATE:

6. Thank you guys! I just tried something and found out that even a simple define a regex object in the first line of the entry of DLL will incurred this error! Any ideas?

7. yet initialize a regex object in the first line in the main() of the caller of this dll will not incur this problem.

Hope this description will help you recall something and give me some hint.

I want to ask:

what's the usual strategy to narrow down and spot the problem? thank you!

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

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

发布评论

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

评论(2

挽手叙旧 2025-01-12 10:48:53

查看您的代码,您可能需要验证您的 m_position 值是否有效...我在代码中看到 escape_type_class_jump 标签,因此 goto 或您用来跳转到该标签的任何机制(我无法从屏幕截图中看出)可能会绕过为验证您的位置增量是否仍然有效而进行的任何检查。

Looking at your code, you may want to verify that your m_position values are valid ... I'm seeing a escape_type_class_jump label in your code, so the goto or whatever mechanism you're using to jump to that label (I can't tell from the screen-shot) may be bypassing whatever checks are being done to verify that your position increments are still valid.

平安喜乐 2025-01-12 10:48:53

在我看来,“this”(即 basic_regex_parser)是 NULL,并且它试图调用 NULL 对象上的方法,这显然不能很好地工作。如果“this”确实是 NULL(您可以通过查看“Locals”选项卡来判断,那么我会将调用堆栈上升到“basic_regex_implementation”级别,看看那里发生了什么 - 这个 NULL 值来自哪里?一般来说,查看调用堆栈的不同级别以及这些级别中的变量值会很有帮助。

It looks to me like "this" (i.e., the basic_regex_parser) is NULL, and it's trying to call a method on a NULL object, which obviously doesn't work well. If "this" is indeed NULL (you can tell by looking in the "Locals" tab, then I would go up the call stack to the "basic_regex_implementation" level and see what's going on there -- where is this NULL value coming from? In general, looking at different levels of the call stack, and at the variables' values in those levels, will be helpful.

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