简体   繁体   English

在调试器中运行时,程序会触发一个断点,但是如果在没有调试器的情况下运行,则程序可以工作

[英]Program triggers a breakpoint when run in debugger but works if run without debugger

I created a dll and it is getting attached with a server application. 我创建了一个dll,并将其与服务器应用程序连接在一起。 Now the problem is, if I run the server from the command prompt then the dll will be running fine. 现在的问题是,如果我从命令提示符下运行服务器,则dll将运行正常。 But if I debug the server in visual studio then the server will crash because of dll. 但是,如果我在Visual Studio中调试服务器,则服务器将由于dll而崩溃。 Then I debugged it thoroughly and got to know that it is crashing while assigning the memory. 然后我对其进行了彻底的调试,并在分配内存时知道它崩溃了。 I checked evry possible thing, memory overwrite, memory leak, but everything seems to be fine. 我检查了可能的问题,内存覆盖,内存泄漏,但是一切似乎都很好。

Anyone encountered this type of problem before. 任何人以前都遇到过此类问题。 Why is this happening? 为什么会这样呢? I searched on the internet also but all I am getting is " crashing in release mode and not in debug mode". 我也在互联网上进行搜索,但我得到的只是“在发布模式下崩溃,而不是在调试模式下崩溃”。

EDIT: 编辑:

I am getting the following message on the window: 我在窗口上收到以下消息:

Windows has triggered a breakpoint in tcas.exe. Windows已在tcas.exe中触发了一个断点。 This may be due to a corruption of the heap, which indicates a bug in tcas.exe or any of the DLLs it has loaded. 这可能是由于堆损坏所致,这表明tcas.exe或其已加载的任何DLL中存在错误。 This may also be due to the user pressing F12 while tcas.exe has focus. 这也可能是由于tcas.exe具有焦点时用户按下F12所致。 The output window may have more diagnostic information. 输出窗口可能包含更多诊断信息。

If I click on continue, then their wont be any problem. 如果我单击继续,那么他们不会有任何问题。

Edit: 编辑:

Sorry I forgot to mention that it is the debug build I am using and not the release build. 抱歉,我忘了提到它是我正在使用的调试版本,而不是发行版本。

After trying everything, using all the permutation-combination and spending so much amount of my time on this, forcefully, I changed the logic of the function. 在尝试了所有方法之后,使用所有排列组合并在此上花费了大量时间,然后强行更改了函数的逻辑。 And now it is working, finally. 现在终于可以了。 But still, I am searching the answer for my original problem. 但是,我仍在寻找我的原始问题的答案。

One thing I also didn't understand is that I read about the same problem, as mine, here http://www.debuginfo.com/tips/userbpntdll.html and when I enable full pageheap for my application, as mentioned in the blog, my application works fine. 我还不了解的一件事是,我在http://www.debuginfo.com/tips/userbpntdll.html上阅读了与我相同的问题,以及当我为应用程序启用完整的pageheap时,如博客,我的应用程序运行正常。 It doesn't get crash while debugging. 调试时不会崩溃。 And I enabled it, in first place, so that I can get a detailed information about heap corruption. 首先,我启用了它,以便获得有关堆损坏的详细信息。 I hope this blog will help others having the similar issue. 我希望这个博客可以帮助其他遇到类似问题的人。

Your program likely has a bug that's causing heap corruption. 您的程序可能存在导致堆损坏的错误。

When you run in the debugger , your program uses a special version of the heap designed to help find these types of bugs. 当您在调试器中运行时 ,您的程序将使用特殊版本的堆,旨在帮助查找这些类型的错误。

When you run from the command prompt, your program (even a debug build) doesn't get (all) the same help in finding heap corruption. 当您从命令提示符运行时,您的程序(甚至是调试版本)在查找堆损坏方面不会得到(全部)相同的帮助。 Your program still has a bug, but you're just getting "lucky" that you don't notice any problem in the test run. 您的程序仍然存在错误,但是您只是“幸运”地发现自己在测试运行中没有发现任何问题。

Read up on the debug heap and use it (in the debugger) to find and fix your bug. 阅读调试堆,并在调试器中使用它来查找和修复错误。

If you have pointers in your code you most likely are accesing somewhere unallocated memory using one of the pointers, so when the destructor runs, it crashes your program. 如果代码中有指针,则很可能使用指针之一访问未分配的内存,因此当析构函数运行时,它将使程序崩溃。

At least that is what I had when the problem was the same. 至少那是我在问题相同的时候拥有的东西。

I am obviously very late to the party but I thought I would share my experience with this issue in an attempt to shed some light. 我参加聚会显然很晚,但是我想我将在这个问题上分享我的经验,以期阐明一些观点。

I am currently developing a lightweight windowing library wrapping Windows API functionality. 我目前正在开发包装Windows API功能的轻量级窗口库。

The declaration of my top most Window class includes a pointer to the base address of an CHAR array representing both the WNDCLASSEX class name and the corresponding window's title. 我最顶层的Window类的声明包括一个指向CHAR数组的基地址的指针,该数组既代表WNDCLASSEX类名,又代表相应的窗口标题。 This string is allocated on the Heap and always copied in Window's constructor to avoid unregistering a NULL class name when a Window object is destroyed for instance. 该字符串在堆上分配,并且始终复制到Window的构造函数中,以避免在例如销毁Window对象时取消注册NULL类名。 Window's destructor also calls delete[] on the CHAR buffer. Window的析构函数还调用CHAR缓冲区上的delete []。

The problem first occurred when I started implemented a free-standing message processing function for use with one or more Window (or derived class) instances. 当我开始实现独立的消息处理功能以与一个或多个Window(或派生类)实例一起使用时,首先出现了该问题。 The loop is as follows: 循环如下:

DWORD win_api::BeginQueueingMessages
(
    Window const *  windowList,
    UINT            length,
    INT             showCommandIndex
)
{
    BOOL processMessages    = TRUE;
    BOOL isFirstIteration   = TRUE;

    while (processMessages)
    {
        for (UINT i = 0; i < length; ++i)
        {
            Window  window  = windowList[i];
            HWND    handle  = window.getHandle();
            MSG     message = {};

            if (isFirstIteration)
            {
                ShowWindow(handle, showCommandIndex);
                UpdateWindow(handle);

                isFirstIteration = FALSE;
            }

            if (GetMessage(&message, handle, NULL, NULL))
            {
                TranslateMessage(&message);
                DispatchMessage(&message);
            }

            else
            {
                processMessages = FALSE;
            }
        }
    }

    return 0;
}

I have eventually identified the following line of code as the culprit: 我最终确定了以下代码行为罪魁祸首:

Window window = windowList[i];

I made the mistake of invoking an automatically implemented copy constructor triggered by the use of the assignment operator. 我犯了一个错误,即调用由赋值运算符触发的自动实现的副本构造函数。 Thus the internal CHAR pointer of the left-hand side operator now points to the same location as windowList[i]'s member without allocating new heap memory. 因此,左侧运算符的内部CHAR指针现在指向与windowList [i]的成员相同的位置,而无需分配新的堆内存。

Later, during program termination delete[] is called on an uninitialised block of memory and throws a C run time exception. 稍后,在程序终止期间,在未初始化的内存块上调用delete []并引发C运行时异常。

I hope this helps. 我希望这有帮助。

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

相关问题 调试不在调试器中运行且不会崩溃的程序 - Dubugging a program not run within the debugger and without a crash 当我运行程序时出现运行时错误,但在使用调试器时却没有 - Runtime error when I run the program but not when i use debugger 程序触发断点; 不运行 - Program triggers breakpoint; doesn't run XCode调试器lldb中断,没有错误输出,但程序运行正常 - XCode debugger lldb breaks without error output but program works fine 代码在调试器中工作,但不在可执行程序中 - Code works in debugger but not in executable program Visual Studio c++ - 程序在没有调试器的情况下失败,与调试器一起工作正常 - Visual Studio c++ - program fails without debugger, works fine with debugger Vscode 运行时出现调试器错误“启动程序 *文件/路径* 不存在” - Vscode Run with debugger error "Launch program *file/path* does not exist 本地Windows调试器已替换为Attach,并且无法运行和调试我的程序 - Local windows debugger replaced with attach and cannot run and debug my program 断点陷阱是否总是意味着程序是从调试器运行的? - Does break point trap always mean program was run from the debugger? 多项式类在调试器中运行良好,但在尝试构建和运行时却无法运行 - Polynomial Class runs fine in debugger but not when trying to build&run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM