From: Joseph M. Newcomer on
There are enough bugs in the memory display logic that I would not trust that message
unless I knew the exact value that was shown. I find that sometimes it just gratuitously
issues that message, because it has a symbol-table lookup problem (the error can arise
from symbol table lookup or a bad pointer)
joe

On Fri, 27 Jul 2007 18:45:02 -0000, VT <thomasinov(a)gmail.com> wrote:

>This is valid but m_nSlot is undefined. I get a "m_nSlot CXX0030:
>Error: expression cannot be evaluated" message in the watch window.
>
>
>On Jul 25, 1:39 pm, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> The problem I had was that I could find no documentation on this class. However, the most
>> likely cause is that some memory damage has occurred. When you get the crash, what is the
>> value of 'this', for example?
>> joe
>>
>>
>>
>>
>>
>> On Tue, 24 Jul 2007 23:00:02 -0000, VT <thomasi...(a)gmail.com> wrote:
>> >CNoTrackObject* CThreadLocalObject::GetData(
>> > CNoTrackObject* (AFXAPI* pfnCreateObject)())
>> >{
>> > ENSURE(pfnCreateObject);
>>
>> > if (m_nSlot == 0)
>> > {
>> > if (_afxThreadData == NULL)
>> > {
>> > _afxThreadData = new(__afxThreadData) CThreadSlotData;
>> > ENSURE(_afxThreadData != NULL);
>> > }
>> > m_nSlot = _afxThreadData->AllocSlot();
>> > ENSURE(m_nSlot != 0);
>> > }
>> > CNoTrackObject* pValue = static_cast<CNoTrackObject*>(_afxThreadData-
>> >>GetThreadValue(m_nSlot));
>> > if (pValue == NULL)
>> > {
>> > // allocate zero-init object
>> > pValue = (*pfnCreateObject)();
>>
>> > // set tls data to newly created object
>> > _afxThreadData->SetValue(m_nSlot, pValue);
>> > ASSERT(_afxThreadData->GetThreadValue(m_nSlot) == pValue);
>> > }
>> > return pValue;
>> >}
>>
>> >Here is the surrounding code. It breaks at the line if (m_nSlot ==
>> >0).
>>
>> >On Jul 24, 8:39 am, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> >> Without seeing the code, and especially the code of CThreadLocalObject, it is hard to even
>> >> begin to guess what might be going on there.
>> >> joe
>>
>> >> On Tue, 24 Jul 2007 00:39:34 -0000, "thomasi...(a)gmail.com" <thomasi...(a)gmail.com> wrote:
>> >> >I recently ported an app from VC2003 to VC2005. My app now crashes on
>> >> >exit. The following is the stack trace from the app.
>>
>> >> >mfc80d.dll!CThreadLocalObject::GetData(CNoTrackObject * (void)*
>> >> >pfnCreateObject=0x78245650) Line 409 + 0x3 bytes C++
>>
>> >> > mfc80d.dll!CThreadLocal<AFX_MODULE_THREAD_STATE>::GetData() Line 177
>> >> >+ 0xd bytes C++
>> >> > mfc80d.dll!AfxGetModuleThreadState() Line 464 + 0x11 bytes C++
>> >> > mfc80d.dll!AfxWinTerm() Line 47 + 0x5 bytes C++
>>
>> >> > mfc80d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__
>> >> >* hPrevInstance=0x00000000, char * lpCmdLine=0x0015233a, int
>> >> >nCmdShow=1) Line 62 C++
>>
>> >> > SzSimTool.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__
>> >> >* hPrevInstance=0x00000000, char * lpCmdLine=0x0015233a, int
>> >> >nCmdShow=1) Line 29 C++
>>
>> >> >SzSimTool.exe!__tmainCRTStartup() Line 578 + 0x35 bytes C
>> >> > SzSimTool.exe!WinMainCRTStartup() Line 403 C
>> >> > kernel32.dll!7c816fd7()
>> >> > [Frames below may be incorrect and/or missing, no symbols loaded for
>> >> >kernel32.dll]
>>
>> >> >It appears that AfxGetModuleThreadState() returns a seemingly valid
>> >> >AFX_MODULE_THREAD_STATE* object.
>>
>> >> >However, the memory under it is inaccessible. So, when it gets to
>> >> >the
>> >> >GetData() call inside of the CThreadLocalObject, the this pointer is
>> >> >pointing to memory it has no access to. Therefore, as soon as it
>> >> >attempts
>> >> >to execute if (m_nSlot == 0), it crashes with the following
>> >> >exception:
>> >> >Unhandled exception at 0x78246d10 (mfc80d.dll) in SzSimTool.exe:
>> >> >0xC0000005: Access violation reading location 0x05878b48.
>>
>> >> >Anyone have any ideas as to what is causing this? If not how can I go
>> >> >about debugging this problem.
>>
>> >> >Thanks,
>> >> >V
>>
>> >> Joseph M. Newcomer [MVP]
>> >> email: newco...(a)flounder.com
>> >> Web:http://www.flounder.com
>> >> MVP Tips:http://www.flounder.com/mvp_tips.htm-Hide quoted text -
>>
>> >> - Show quoted text -
>>
>> Joseph M. Newcomer [MVP]
>> email: newco...(a)flounder.com
>> Web:http://www.flounder.com
>> MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
>>
>> - Show quoted text -
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
Note that 'this' might be a valid pointer to storage that is already freed, or storage
that has been accidentally overwritten, in which case the error message *is* legitimate.
So EXACT content is required. m_nSlot has an actual value. If nothing else, you can use
a memory window to examine the conents, but the report as it stands is insufficient.
joe

On Fri, 27 Jul 2007 18:45:02 -0000, VT <thomasinov(a)gmail.com> wrote:

>This is valid but m_nSlot is undefined. I get a "m_nSlot CXX0030:
>Error: expression cannot be evaluated" message in the watch window.
>
>
>On Jul 25, 1:39 pm, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> The problem I had was that I could find no documentation on this class. However, the most
>> likely cause is that some memory damage has occurred. When you get the crash, what is the
>> value of 'this', for example?
>> joe
>>
>>
>>
>>
>>
>> On Tue, 24 Jul 2007 23:00:02 -0000, VT <thomasi...(a)gmail.com> wrote:
>> >CNoTrackObject* CThreadLocalObject::GetData(
>> > CNoTrackObject* (AFXAPI* pfnCreateObject)())
>> >{
>> > ENSURE(pfnCreateObject);
>>
>> > if (m_nSlot == 0)
>> > {
>> > if (_afxThreadData == NULL)
>> > {
>> > _afxThreadData = new(__afxThreadData) CThreadSlotData;
>> > ENSURE(_afxThreadData != NULL);
>> > }
>> > m_nSlot = _afxThreadData->AllocSlot();
>> > ENSURE(m_nSlot != 0);
>> > }
>> > CNoTrackObject* pValue = static_cast<CNoTrackObject*>(_afxThreadData-
>> >>GetThreadValue(m_nSlot));
>> > if (pValue == NULL)
>> > {
>> > // allocate zero-init object
>> > pValue = (*pfnCreateObject)();
>>
>> > // set tls data to newly created object
>> > _afxThreadData->SetValue(m_nSlot, pValue);
>> > ASSERT(_afxThreadData->GetThreadValue(m_nSlot) == pValue);
>> > }
>> > return pValue;
>> >}
>>
>> >Here is the surrounding code. It breaks at the line if (m_nSlot ==
>> >0).
>>
>> >On Jul 24, 8:39 am, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> >> Without seeing the code, and especially the code of CThreadLocalObject, it is hard to even
>> >> begin to guess what might be going on there.
>> >> joe
>>
>> >> On Tue, 24 Jul 2007 00:39:34 -0000, "thomasi...(a)gmail.com" <thomasi...(a)gmail.com> wrote:
>> >> >I recently ported an app from VC2003 to VC2005. My app now crashes on
>> >> >exit. The following is the stack trace from the app.
>>
>> >> >mfc80d.dll!CThreadLocalObject::GetData(CNoTrackObject * (void)*
>> >> >pfnCreateObject=0x78245650) Line 409 + 0x3 bytes C++
>>
>> >> > mfc80d.dll!CThreadLocal<AFX_MODULE_THREAD_STATE>::GetData() Line 177
>> >> >+ 0xd bytes C++
>> >> > mfc80d.dll!AfxGetModuleThreadState() Line 464 + 0x11 bytes C++
>> >> > mfc80d.dll!AfxWinTerm() Line 47 + 0x5 bytes C++
>>
>> >> > mfc80d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__
>> >> >* hPrevInstance=0x00000000, char * lpCmdLine=0x0015233a, int
>> >> >nCmdShow=1) Line 62 C++
>>
>> >> > SzSimTool.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__
>> >> >* hPrevInstance=0x00000000, char * lpCmdLine=0x0015233a, int
>> >> >nCmdShow=1) Line 29 C++
>>
>> >> >SzSimTool.exe!__tmainCRTStartup() Line 578 + 0x35 bytes C
>> >> > SzSimTool.exe!WinMainCRTStartup() Line 403 C
>> >> > kernel32.dll!7c816fd7()
>> >> > [Frames below may be incorrect and/or missing, no symbols loaded for
>> >> >kernel32.dll]
>>
>> >> >It appears that AfxGetModuleThreadState() returns a seemingly valid
>> >> >AFX_MODULE_THREAD_STATE* object.
>>
>> >> >However, the memory under it is inaccessible. So, when it gets to
>> >> >the
>> >> >GetData() call inside of the CThreadLocalObject, the this pointer is
>> >> >pointing to memory it has no access to. Therefore, as soon as it
>> >> >attempts
>> >> >to execute if (m_nSlot == 0), it crashes with the following
>> >> >exception:
>> >> >Unhandled exception at 0x78246d10 (mfc80d.dll) in SzSimTool.exe:
>> >> >0xC0000005: Access violation reading location 0x05878b48.
>>
>> >> >Anyone have any ideas as to what is causing this? If not how can I go
>> >> >about debugging this problem.
>>
>> >> >Thanks,
>> >> >V
>>
>> >> Joseph M. Newcomer [MVP]
>> >> email: newco...(a)flounder.com
>> >> Web:http://www.flounder.com
>> >> MVP Tips:http://www.flounder.com/mvp_tips.htm-Hide quoted text -
>>
>> >> - Show quoted text -
>>
>> Joseph M. Newcomer [MVP]
>> email: newco...(a)flounder.com
>> Web:http://www.flounder.com
>> MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
>>
>> - Show quoted text -
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm