创建 stl 字符串时应用程序崩溃

发布于 2024-11-05 19:04:37 字数 5904 浏览 0 评论 0原文

我的应用程序的两个位置发生应用程序崩溃。其中一个位置是下面给出的方法的以下声明。在为传递给 LogMessage 方法的字符串创建 stl 字符串对象时,应用程序崩溃。

EMCoreLogger::GetLoggerInstance()->LogMessage("Sending message completed successfully",
                            "CGEMCustomMessageService",Information);

下面给出了调用堆栈

    msvcr90.dll!_crt_debugger_hook(int _Reserved=101180712)  Line 65    C
    msvcr90.dll!_invalid_parameter(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=0)  Line 112 + 0x7 bytes  C++
    msvcr90.dll!memcpy_s(void * dst=0x0607e5d8, unsigned int sizeInBytes=0, const void * src=0x084beac8, unsigned int count=38)  Line 55 + 0x19 bytes   C
    msvcp90.dll!std::char_traits<char>::_Copy_s(char * _First1=0x0607e5d8, unsigned int _Size_in_bytes=0, const char * _First2=0x084beac8, unsigned int _Count=38)  Line 583    C++
    msvcp90.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char * _First1=0x0607e5d8, unsigned int _Size=0, const char * _First2=0x084beac8, unsigned int _Count=38, std::_Secure_char_traits_tag __formal={...})  Line 714 + 0x11 bytes  C++
    msvcp90.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char * _First1=0x0607e5d8, unsigned int _Size=0, const char * _First2=0x084beac8, unsigned int _Count=38)  Line 706 + 0x14 bytes   C++
    msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr=0x084beac8, unsigned int _Count=38)  Line 1086 + 0x1b bytes  C++
    msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr=0x084beac8)  Line 1095 + 0x16 bytes  C++
    msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const char * _Ptr=0x084beac8)  Line 664   C++
>   GemCore.dll!CGEMCustomMessageService::SendProcessMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 566 + 0x34 bytes  C++
    GemCore.dll!CCustomMessageRouter::PA_ProcessPrimaryMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 54 + 0x1d bytes C++
    PAL.dll!CPALProtocolPlugin::PA_ProcessPrimaryMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 50 + 0x2c bytes   C++
    CustomSECSII_R.dll!CCustomMessageTransportPlugin::ProcessPrmryMsg(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned char byStream='', unsigned char byFunction='', unsigned short tkt=167, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 85 + 0x20 bytes C++
    TAL.dll!CMessageHandler::HandleCustomMessage(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwTransID=2839, unsigned long dwTransTwoID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pHeader=0x478f8ff0, unsigned char byPType=0, int nScanFuncId=-1, int nProcessFuncId=4, std::vector<int,std::allocator<int> > pVecClientId=[1](1))  Line 2949 + 0x4b bytes   C++
    TAL.dll!CMessageHandler::ReceiveMessage(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwTransID=2839, unsigned long dwTransTwoID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pHeader=0x478f8ff0, unsigned char byPType=0)  Line 1220 + 0x6c bytes C++
    TAL.dll!CTALTransportObject::ReceiveMessage(char * szBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwSECS1TRID=2839, unsigned long dwSECS2TRID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pbyHeader=0x478f8ff0, unsigned char byPType=0)  Line 199 + 0x30 bytes  C++
    HSMS.dll!CDataMessageMngr::RespondToMessage(CMessage * pMessage=0x0607ff28)  Line 392   C++
    HSMS.dll!CLowerRouter::RecieveData()  Line 820  C++
    HSMS.dll!CLowerRouter::RecievingThread(void * pVoid=0x036f9fa0)  Line 566   C++
    kernel32.dll!7c80b729()     
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]

我启用了 pageheap 来检测堆损坏。我还启用了运行时错误检查/RTC来检测堆栈损坏。我无法检测根本原因。

我如何才能找到问题的原因?

bool
CGEMCustomMessageService::SendProcessMessage(SECSTICKET tkt, PSECSMSG mb,int nFuncID, int* pnClientIds,int nClientCount)
{
    bool bRetCode = true;
    int nRetCode = 0;
    char chLog[1024] = {0};
    CEALCustomMessagePlugin *pCustomMessagePlugin = CEALCustomMessagePlugin::Instance();
    int nStream   = mb->nStream;
    int nFunction = mb->nFunction;
    int nTicket   = tkt;

        CGEMEqpmntService* pGEMEqpmntService = (CGEMEqpmntService *)CGEMEqpmntService::Instance();
        EQP_CTRL_STATE eControlState = STATE_HOSTOFFLINE;
        sprintf(chLog,"Sending S%d,F%d with ticket[%d]",mb->nStream, mb->nFunction,tkt);
        LogDataMessage(chLog,"CGEMCustomMessageService",Information);

        if (NULL != pCustomMessagePlugin)
        {  

                    GEMCoreLogger::GetLoggerInstance()->LogMessage("Control state is Online remote sending message to client",
                        "CGEMCustomMessageService",Debug);
                    nRetCode = pCustomMessagePlugin->GEMT_ProcessPrimaryMessage(tkt,mb,nFuncID,pnClientIds,nClientCount);

                    GEMCoreLogger::GetLoggerInstance()->LogMessage("Sending message completed successfully",
                        "CGEMCustomMessageService",Information);
        }

    return bRetCode;
}

I am getting an application crash in two locations of my application. One of the locations is the following statement of the method given below. The application crashes while creating an stl string object for the string pass to LogMessage method.

EMCoreLogger::GetLoggerInstance()->LogMessage("Sending message completed successfully",
                            "CGEMCustomMessageService",Information);

The callstack is given below

    msvcr90.dll!_crt_debugger_hook(int _Reserved=101180712)  Line 65    C
    msvcr90.dll!_invalid_parameter(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=0)  Line 112 + 0x7 bytes  C++
    msvcr90.dll!memcpy_s(void * dst=0x0607e5d8, unsigned int sizeInBytes=0, const void * src=0x084beac8, unsigned int count=38)  Line 55 + 0x19 bytes   C
    msvcp90.dll!std::char_traits<char>::_Copy_s(char * _First1=0x0607e5d8, unsigned int _Size_in_bytes=0, const char * _First2=0x084beac8, unsigned int _Count=38)  Line 583    C++
    msvcp90.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char * _First1=0x0607e5d8, unsigned int _Size=0, const char * _First2=0x084beac8, unsigned int _Count=38, std::_Secure_char_traits_tag __formal={...})  Line 714 + 0x11 bytes  C++
    msvcp90.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char * _First1=0x0607e5d8, unsigned int _Size=0, const char * _First2=0x084beac8, unsigned int _Count=38)  Line 706 + 0x14 bytes   C++
    msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr=0x084beac8, unsigned int _Count=38)  Line 1086 + 0x1b bytes  C++
    msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr=0x084beac8)  Line 1095 + 0x16 bytes  C++
    msvcp90.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const char * _Ptr=0x084beac8)  Line 664   C++
>   GemCore.dll!CGEMCustomMessageService::SendProcessMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 566 + 0x34 bytes  C++
    GemCore.dll!CCustomMessageRouter::PA_ProcessPrimaryMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 54 + 0x1d bytes C++
    PAL.dll!CPALProtocolPlugin::PA_ProcessPrimaryMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 50 + 0x2c bytes   C++
    CustomSECSII_R.dll!CCustomMessageTransportPlugin::ProcessPrmryMsg(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned char byStream='', unsigned char byFunction='', unsigned short tkt=167, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 85 + 0x20 bytes C++
    TAL.dll!CMessageHandler::HandleCustomMessage(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwTransID=2839, unsigned long dwTransTwoID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pHeader=0x478f8ff0, unsigned char byPType=0, int nScanFuncId=-1, int nProcessFuncId=4, std::vector<int,std::allocator<int> > pVecClientId=[1](1))  Line 2949 + 0x4b bytes   C++
    TAL.dll!CMessageHandler::ReceiveMessage(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwTransID=2839, unsigned long dwTransTwoID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pHeader=0x478f8ff0, unsigned char byPType=0)  Line 1220 + 0x6c bytes C++
    TAL.dll!CTALTransportObject::ReceiveMessage(char * szBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwSECS1TRID=2839, unsigned long dwSECS2TRID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pbyHeader=0x478f8ff0, unsigned char byPType=0)  Line 199 + 0x30 bytes  C++
    HSMS.dll!CDataMessageMngr::RespondToMessage(CMessage * pMessage=0x0607ff28)  Line 392   C++
    HSMS.dll!CLowerRouter::RecieveData()  Line 820  C++
    HSMS.dll!CLowerRouter::RecievingThread(void * pVoid=0x036f9fa0)  Line 566   C++
    kernel32.dll!7c80b729()     
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]

I enabled pageheap to detect heap corruption. I also enabled Run-Time Error Checks /RTCs to detect stack corruption. I am not able to detect the root cause.

How can I proceed to get the cause of the issue?

bool
CGEMCustomMessageService::SendProcessMessage(SECSTICKET tkt, PSECSMSG mb,int nFuncID, int* pnClientIds,int nClientCount)
{
    bool bRetCode = true;
    int nRetCode = 0;
    char chLog[1024] = {0};
    CEALCustomMessagePlugin *pCustomMessagePlugin = CEALCustomMessagePlugin::Instance();
    int nStream   = mb->nStream;
    int nFunction = mb->nFunction;
    int nTicket   = tkt;

        CGEMEqpmntService* pGEMEqpmntService = (CGEMEqpmntService *)CGEMEqpmntService::Instance();
        EQP_CTRL_STATE eControlState = STATE_HOSTOFFLINE;
        sprintf(chLog,"Sending S%d,F%d with ticket[%d]",mb->nStream, mb->nFunction,tkt);
        LogDataMessage(chLog,"CGEMCustomMessageService",Information);

        if (NULL != pCustomMessagePlugin)
        {  

                    GEMCoreLogger::GetLoggerInstance()->LogMessage("Control state is Online remote sending message to client",
                        "CGEMCustomMessageService",Debug);
                    nRetCode = pCustomMessagePlugin->GEMT_ProcessPrimaryMessage(tkt,mb,nFuncID,pnClientIds,nClientCount);

                    GEMCoreLogger::GetLoggerInstance()->LogMessage("Sending message completed successfully",
                        "CGEMCustomMessageService",Information);
        }

    return bRetCode;
}

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

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

发布评论

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

评论(2

流殇 2024-11-12 19:04:37

我认为你应该从放弃所有信仰开始。

接下来,查看调用堆栈:您所指责的函数调用甚至不存在。在 memcpy_s 之前,一切似乎都很顺利。然后再问一些问题,例如:dit memcpy_s 从哪里获取它的参数?谁填写的?为什么要这样填写?...

在​​故障排除中,您成为一名侦探。怀疑每个人(但从你自己的代码开始:))。警惕偏见,警惕“应该”、“认为……”、“永远、永远、永远……”等词语……只关注确凿的事实。

根据您对系统的了解以及通过调试收集的事实,尝试通过推理来减少嫌疑人的数量。

(顺便说一句,按照 这篇 Visual Studio 文章

如果这些都没有帮助,请询问 StackOverflow 上的人:)

I think you should start by giving up all your beliefs.

Next, take a look into the call stack: the function call you blame isn't even there. All seems go well up till the memcpy_s. Then work your way back by asking questions like: where dit memcpy_s get it's parameters from? Who filled them in? Why were they filled in that way?...

In troubleshooting, you become a detective. Suspect everybody (but start with your own code :) ). Be wary of prejudice, and of words like 'should', 'think that...', 'will never, ever, ever, ... ' etc... Go for hard facts only.

Try to diminish the number of suspects by reasoning, based on your knowledge of the system and on facts you gather by debugging.

(by the way, the call stack can become more helpful after loading the symbols for some of the kernel dlls, following the tips on this Visual Studio article)

And if all that doesn't help, ask someone on StackOverflow :)

半暖夏伤 2024-11-12 19:04:37

您是否尝试过在通话中使用此表单:

    EMCoreLogger::GetLoggerInstance()->LogMessage( string("Sending message completed successfully"), string("CGEMCustomMessageService"), Information);

Have you tried using this form in the call:

    EMCoreLogger::GetLoggerInstance()->LogMessage( string("Sending message completed successfully"), string("CGEMCustomMessageService"), Information);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文