📄 crashfinderdoc.cpp
字号:
(PSTR)(LPCSTR)pImage->GetFullName() ,
NULL ,
pImage->GetLoadAddress ( ) ,
0 );
// Watch out. SymLoadModule returns the load address of the
// image, not TRUE.
ASSERT ( FALSE != bRet ) ;
if ( FALSE == bRet )
{
TRACE ( "m_cSymEng.SymLoadModule failed!!\n" ) ;
iState = STATE_NOTVALID ;
}
else
{
CImageHlp_Module cModInfo ;
BOOL bRet =
m_cSymEng.SymGetModuleInfo ( pImage->GetLoadAddress(),
&cModInfo );
ASSERT ( TRUE == bRet ) ;
if ( TRUE == bRet )
{
// Check if the symbols type is not SymNone.
if ( SymNone != cModInfo.SymType )
{
iState = STATE_VALIDATED ;
// Set the image symbol information.
pImage->SetSymbolInformation ( cModInfo ) ;
}
else
{
iState = STATE_NOTVALID ;
// Unload the module. The symbol engine loads a
// module even without symbols so I need to unload
// them here. I only want good loads to happen.
m_cSymEng.SymUnloadModule (
pImage->GetLoadAddress());
pImage->SetBinaryError ( eNoSymbolsAtAll ) ;
}
}
else
{
iState = STATE_NOTVALID ;
}
}
}
// Set the extra data value for pImage to the state of the symbol
// load.
if ( STATE_VALIDATED == iState )
{
pImage->SetExtraData ( TRUE ) ;
}
else
{
pImage->SetExtraData ( FALSE ) ;
}
// Put this item into the array.
m_cDataArray.Add ( pImage ) ;
// Does adding the item modify the document?
if ( TRUE == bModifiesDoc )
{
SetModifiedFlag ( ) ;
}
// Get the image into the tree.
bRet = m_cTreeDisplay.InsertImageInTree ( pImage ,
iState ) ;
ASSERT ( bRet ) ;
// All OK, Jumpmaster!!
return ( bRet ) ;
}
// A helper to check if a load address is already in the project. This
// returns TRUE if the address is a conflicting address and iIndex is
// the one that it conflicts with.
BOOL CCrashFinderDoc :: IsConflictingLoadAddress ( DWORD dwAddr ,
int & iIndex )
{
ASSERT ( this ) ;
CBinaryImage * pImage ;
int iCount = m_cDataArray.GetSize ( ) ;
for ( iIndex = 0 ; iIndex < iCount ; iIndex++ )
{
pImage = (CBinaryImage*)m_cDataArray[ iIndex ] ;
if ( dwAddr == pImage->GetLoadAddress ( ) )
{
return ( TRUE ) ;
}
}
return ( FALSE ) ;
}
int CCrashFinderDoc :: LookUpAddress ( DWORD dwAddr ,
CString & sModule ,
IMAGEHLP_SYMBOL & stIHSym ,
DWORD & dwFnDispl ,
IMAGEHLP_LINE & stIHLine ,
DWORD & dwSrcDispl )
{
ASSERT ( this ) ;
// Check that there there are things in the symbol engine.
if ( 0 == m_cDataArray.GetSize ( ) )
{
CString sMsg ;
VERIFY ( sMsg.LoadString ( IDS_NOMODULESLOADED ) ) ;
AfxMessageBox ( sMsg ) ;
return ( -1 ) ;
}
BOOL bSymFound = TRUE ;
BOOL bLineFound = TRUE ;
BOOL bModFound = TRUE ;
// Try and find the module. If this cannot be found, then it is no
// use looking anything else up.
CImageHlp_Module cMod ;
bModFound = m_cSymEng.SymGetModuleInfo ( dwAddr , &cMod ) ;
if ( FALSE == bModFound )
{
bSymFound = FALSE ;
bLineFound = FALSE ;
}
else
{
// Pull out the module.
sModule = cMod.ImageName ;
// Look up the symbol information.
BOOL bRet = m_cSymEng.SymGetSymFromAddr ( dwAddr ,
&dwFnDispl ,
&stIHSym ) ;
if ( FALSE == bRet )
{
bSymFound = FALSE ;
}
// Look up the line stuff.
bRet = m_cSymEng.SymGetLineFromAddr ( dwAddr ,
&dwSrcDispl ,
&stIHLine ) ;
if ( FALSE == bRet )
{
bLineFound = FALSE ;
}
}
int iRet = 0 ;
if ( TRUE == bSymFound )
{
iRet |= eLUSYM ;
}
if ( TRUE == bLineFound )
{
iRet |= eLULINE ;
}
if ( TRUE == bModFound )
{
iRet |= eLUMOD ;
}
return ( iRet ) ;
}
// Called when the global application options change.
void CCrashFinderDoc :: ShowFullPaths ( BOOL bShowFull )
{
ASSERT ( this ) ;
ASSERT ( NULL != m_pcTreeControl ) ;
// Here I will just loop through each item in the tree control and
// using the CBinaryImage pointer stored in each tree item's extra
// data, just change the node.
HTREEITEM hItem = m_pcTreeControl->GetRootItem ( ) ;
while ( NULL != hItem )
{
CBinaryImage * pImage =
(CBinaryImage *)m_pcTreeControl->GetItemData ( hItem ) ;
ASSERT ( NULL != pImage ) ;
m_pcTreeControl->SetItemText ( hItem ,
bShowFull
? pImage->GetFullName()
: pImage->GetName() );
hItem = m_pcTreeControl->GetNextItem ( hItem , TVGN_NEXT ) ;
}
}
void CCrashFinderDoc :: RedoFind ( void )
{
m_pFormView->RedoFind ( ) ;
}
void CCrashFinderDoc :: Serialize ( CArchive & ar )
{
ASSERT ( this ) ;
int iCount ;
CBinaryImage * pImage ;
if ( ar.IsStoring ( ) )
{
// Write out the count of items.
iCount = m_cDataArray.GetSize ( ) ;
ar << iCount ;
// Now loop through and write out each item in the array.
for ( int i = 0 ; i < iCount ; i++ )
{
pImage = (CBinaryImage*)m_cDataArray[ i ] ;
ar << pImage ;
}
}
else
{
ar >> iCount ;
for ( int i = 0 ; i < iCount ; i++ )
{
ar >> pImage ;
LoadAndShowImage ( pImage , FALSE ) ;
}
// Force the selection to the first item, if possible.
HTREEITEM hItem = m_pcTreeControl->GetRootItem ( ) ;
if ( NULL != hItem )
{
m_pcTreeControl->SelectItem ( hItem ) ;
}
}
}
CView * CCrashFinderDoc :: GetCurrentView ( void )
{
CMDIFrameWnd * pFrame = (CMDIFrameWnd*)AfxGetApp( )->m_pMainWnd ;
ASSERT ( NULL != pFrame ) ;
if ( NULL == pFrame )
{
return ( NULL ) ;
}
// Get the active MDI child window.
CMDIChildWnd * pChild = (CMDIChildWnd *)pFrame->GetActiveFrame ( ) ;
ASSERT ( NULL != pChild ) ;
if ( NULL == pChild )
{
return ( NULL ) ;
}
// Get the active view attached to the active MDI child window.
CView * pView = pChild->GetActiveView ( ) ;
return ( pView ) ;
}
#ifdef _DEBUG
void CCrashFinderDoc :: AssertValid ( ) const
{
ASSERT ( this ) ;
CDocument::AssertValid ( ) ;
}
void CCrashFinderDoc :: Dump ( CDumpContext & dc ) const
{
ASSERT ( this ) ;
// Dump the basic stuff.
CDocument::Dump ( dc ) ;
// Now dump this document's specific stuff.
dc << _T ( "m_pcTreeControl " ) << m_pcTreeControl ;
dc << _T ( "m_cDataArray " ) << m_cDataArray ;
}
#endif //_DEBUG
void CCrashFinderDoc :: OnEditFindCrash ( )
{
ASSERT ( this ) ;
m_pEditControl->SetFocus ( ) ;
/*
CFindCrashDlg cDlg ( this ) ;
cDlg.m_strAddresses = m_strAddresses;
cDlg.m_bAddress = ((CCrashFinderApp *)AfxGetApp( ))->m_bAddress;
cDlg.m_bModule = ((CCrashFinderApp *)AfxGetApp( ))->m_bModule;
cDlg.m_bFunction = ((CCrashFinderApp *)AfxGetApp( ))->m_bFunction;
cDlg.m_bFnDisplacement = ((CCrashFinderApp *)AfxGetApp( ))->m_bFnDisplacement;
cDlg.m_bSourceFile = ((CCrashFinderApp *)AfxGetApp( ))->m_bSourceFile;
cDlg.m_bSourceLine = ((CCrashFinderApp *)AfxGetApp( ))->m_bSourceLine;
cDlg.m_bSrcDisplacement = ((CCrashFinderApp *)AfxGetApp( ))->m_bSrcDisplacement;
cDlg.m_bOneLine = ((CCrashFinderApp *)AfxGetApp( ))->m_bOneLine;
cDlg.DoModal ( ) ;
m_strAddresses = cDlg.m_strAddresses;
((CCrashFinderApp *)AfxGetApp( ))->m_bAddress = cDlg.m_bAddress;
((CCrashFinderApp *)AfxGetApp( ))->m_bModule = cDlg.m_bModule;
((CCrashFinderApp *)AfxGetApp( ))->m_bFunction = cDlg.m_bFunction;
((CCrashFinderApp *)AfxGetApp( ))->m_bFnDisplacement = cDlg.m_bFnDisplacement;
((CCrashFinderApp *)AfxGetApp( ))->m_bSourceFile = cDlg.m_bSourceFile;
((CCrashFinderApp *)AfxGetApp( ))->m_bSourceLine = cDlg.m_bSourceLine;
((CCrashFinderApp *)AfxGetApp( ))->m_bSrcDisplacement = cDlg.m_bSrcDisplacement;
((CCrashFinderApp *)AfxGetApp( ))->m_bOneLine = cDlg.m_bOneLine;
*/
}
void CCrashFinderDoc :: OnEditAddImage ( void )
{
AddAnImage ( ) ;
}
BOOL CCrashFinderDoc :: AddAnImage ( void )
{
ASSERT ( this ) ;
BOOL bRet = TRUE ;
CString szFilter ;
CString szTitle ;
// Get the filter list and the title of the dialog.
VERIFY ( szFilter.LoadString ( IDS_ADDFILTER ) ) ;
VERIFY ( szTitle.LoadString ( IDS_ADDTITLE ) ) ;
// The open file dialog.
CFileDialog cFD ( TRUE ,
NULL ,
NULL ,
OFN_ALLOWMULTISELECT |
OFN_FILEMUSTEXIST |
OFN_NOCHANGEDIR |
OFN_PATHMUSTEXIST |
OFN_HIDEREADONLY ,
szFilter ,
AfxGetApp()->m_pMainWnd ) ;
cFD.m_ofn.lpstrTitle = (LPCTSTR)szTitle ;
// Set up the buffers that will be used to return the file
// information. Since the dialog allows multple selection, I make
// sure to allocate a big enough buffer to handle a good number
// of files.
#define MAXFILEOPENSIZE 16384
LPTSTR szFileName = new TCHAR[ MAXFILEOPENSIZE ] ;
szFileName[ 0 ] = _T ( '\0' ) ;
cFD.m_ofn.lpstrFile = szFileName ;
cFD.m_ofn.nMaxFile = MAXFILEOPENSIZE ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -