analyzetool/commandlineengine/src/catromsymbol.cpp
branchRCL_3
changeset 13 da2cedce4920
equal deleted inserted replaced
12:d27dfa8884ad 13:da2cedce4920
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Reads rom symbol file and provides interface to acquire
       
    15 *               binary and function information using memory addresss.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "../inc/ATCommonDefines.h"
       
    20 #include "../inc/catromsymbol.h"
       
    21 #include "../inc/catfilereader.h"
       
    22 #include "../inc/CATBase.h"
       
    23 #include "../inc/CATMemoryAddress.h"
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // RofsBinary::RofsBinary
       
    27 // Default construcor
       
    28 // -----------------------------------------------------------------------------
       
    29 RofsBinary::RofsBinary()
       
    30 {
       
    31 	LOG_LOW_FUNC_ENTRY("RofsBinary::RofsBinary");
       
    32 	m_sBinary = "";
       
    33 	vSymbols.clear();
       
    34 }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // RofsBinary::RofsBinary
       
    38 // Construcor
       
    39 // -----------------------------------------------------------------------------
       
    40 RofsBinary::RofsBinary( const string& sBinary )
       
    41 {
       
    42 	LOG_LOW_FUNC_ENTRY("RofsBinary::RofsBinary");
       
    43 	m_sBinary = sBinary;
       
    44 	vSymbols.clear();
       
    45 }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // RofsBinary::~RofsBinary
       
    49 // Destructor
       
    50 // -----------------------------------------------------------------------------
       
    51 RofsBinary::~RofsBinary()
       
    52 {
       
    53 	LOG_LOW_FUNC_ENTRY("RofsBinary::~RofsBinary");
       
    54 	for ( vector<Symbol*>::iterator it = vSymbols.begin() ; it != vSymbols.end() ; it++ )
       
    55 		delete *it;
       
    56 	vSymbols.clear();
       
    57 }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CATRomSymbol::CATRomSymbol
       
    61 // Constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 CATRomSymbol::CATRomSymbol()
       
    64 {
       
    65 	LOG_FUNC_ENTRY("CATRomSymbol::CATRomSymbol");
       
    66 	m_bSymbolsRead = false;
       
    67 	m_iRomEndAddress = 0;
       
    68 	m_iRomStartAddress = 0;
       
    69 	m_vRomFiles.clear();
       
    70 	m_sErrorMessage = "";
       
    71 	m_vRomCache.clear();
       
    72 	m_vRomSymbols.clear();
       
    73 	m_bShowProgressMessages = false;
       
    74 }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CATRomSymbol::~CATRomSymbol
       
    78 // Destructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 CATRomSymbol::~CATRomSymbol()
       
    81 {
       
    82 	LOG_FUNC_ENTRY("CATRomSymbol::~CATRomSymbol");
       
    83 	// Rom
       
    84 	for ( vector<Symbol*>::iterator it = m_vRomSymbols.begin() ; it != m_vRomSymbols.end() ; it++ )
       
    85 	{
       
    86 		delete *it;
       
    87 	}
       
    88 	m_vRomSymbols.clear();
       
    89 	// Rofs
       
    90 	for ( vector<RofsBinary*>::iterator it = m_vRofsBinaries.begin() ; it != m_vRofsBinaries.end() ; it++ )
       
    91 	{
       
    92 		delete *it;
       
    93 	}
       
    94 	m_vRofsBinaries.clear();
       
    95 }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CATRomSymbol::Open
       
    99 // This funtion should not be used anymore since
       
   100 // we support multiple rom/rofs files.
       
   101 // -----------------------------------------------------------------------------
       
   102 bool CATRomSymbol::Open( const string& /*sString*/, const unsigned long /*iLong*/)
       
   103 {
       
   104 	LOG_FUNC_ENTRY("CATRomSymbol::Open");
       
   105 	return false;
       
   106 }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CATRomSymbol::SetSymbols
       
   110 // Set symbol file(s) to be used.
       
   111 // This also checks that files exists and identifies them as rom/rofs.
       
   112 // -----------------------------------------------------------------------------
       
   113 bool CATRomSymbol::SetSymbols( const vector<string>& vSymbols )
       
   114 {
       
   115 	LOG_FUNC_ENTRY("CATRomSymbol::SetSymbols");
       
   116 	bool ok = true;
       
   117 	// Check no same symbol defined twice.
       
   118 	for( vector<string>::const_iterator it = vSymbols.begin() ;
       
   119 		it != vSymbols.end(); it++ )
       
   120 	{
       
   121 		for( vector<string>::const_iterator it2 = vSymbols.begin() ;
       
   122 			it2 != vSymbols.end(); it2++ )
       
   123 		{
       
   124 			if ( it == it2 )
       
   125 				continue;
       
   126 			if ( _stricmp( (*it).c_str(), (*it2).c_str() ) == 0 )
       
   127 			{
       
   128 				m_sErrorMessage.append( "Same symbol file defined twice (" );
       
   129 				m_sErrorMessage.append( (*it) );
       
   130 				m_sErrorMessage.append( ")\n" );
       
   131 				return false;
       
   132 			}
       
   133 		}
       
   134 	}
       
   135 	// Loop given symbol files.
       
   136 	for( vector<string>::const_iterator it = vSymbols.begin() ;
       
   137 		it != vSymbols.end(); it++ )
       
   138 	{
       
   139 		// Symbol file exists?
       
   140 		if ( ! CATBase::FileExists( (*it).c_str() ) )
       
   141 		{
       
   142 			ok = false;
       
   143 			m_sErrorMessage.append( "Symbol file does not exists (" );
       
   144 			m_sErrorMessage.append( *it );
       
   145 			m_sErrorMessage.append( ").\n");
       
   146 			continue;
       
   147 		}
       
   148 		// Identify symbol file.
       
   149 		int type = IdentifySymbolFile( *it );
       
   150 		// Depending on type move it correct vector.
       
   151 		switch( type )
       
   152 		{
       
   153 		case SYMBOL_FILE_INVALID:
       
   154 			ok = false;
       
   155 			m_sErrorMessage.append( "Symbol file with invalid content (" );
       
   156 			m_sErrorMessage.append( *it );
       
   157 			m_sErrorMessage.append( ").\n");
       
   158 			break;
       
   159 		case SYMBOL_FILE_ROM:
       
   160 			m_vRomFiles.push_back( *it );
       
   161 			break;
       
   162 		case SYMBOL_FILE_ROFS:
       
   163 			m_vRofsFiles.push_back( *it );
       
   164 			break;
       
   165 		default:
       
   166 			ok = false;
       
   167 			LOG_STRING("IdentifySymbolFile returned unknown type.");
       
   168 			break;
       
   169 		}
       
   170 	}
       
   171 	if ( ok )
       
   172 	{
       
   173 		// Read symbols.
       
   174 		if ( m_vRomFiles.size() > 0 )
       
   175 		{
       
   176 			if ( ! ReadRomFiles() )
       
   177 				ok = false;
       
   178 			else
       
   179 				m_bSymbolsRead = true;
       
   180 		}
       
   181 		if ( m_vRofsFiles.size() > 0 )
       
   182 		{
       
   183 			if ( ! ReadRofsFiles() )
       
   184 				ok = false;
       
   185 			else
       
   186 				m_bSymbolsRead = true;
       
   187 		}
       
   188 	}
       
   189 	return ok;
       
   190 }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CATRomSymbol::IdentifySymbolFile
       
   194 // Identify given file is it rom / rofs.
       
   195 // -----------------------------------------------------------------------------
       
   196 int CATRomSymbol::IdentifySymbolFile( const string& sFile )
       
   197 {
       
   198 	LOG_FUNC_ENTRY("CATRomSymbol::IdentifySymbolFile");
       
   199 	// Set type as invalid.
       
   200 	int iType = SYMBOL_FILE_INVALID;
       
   201 	// Line counter.
       
   202 	int iLineCount = 0;
       
   203 	// Minimun line length to identify it.
       
   204 	size_t iLineMinLength = MAX_LINE_LENGTH;
       
   205 	if ( ROFS_SYMBOL_IDENTIFY_STRING.length() > ROM_SYMBOL_IDENTIFY_STRING.length() )
       
   206 		iLineMinLength = ROFS_SYMBOL_IDENTIFY_STRING.length();
       
   207 	else
       
   208 		iLineMinLength = ROM_SYMBOL_IDENTIFY_STRING.length();
       
   209 	try {
       
   210 		ifstream in;
       
   211 		in.open( sFile.c_str(), ios::in );
       
   212 		if ( ! in.good() )
       
   213 			return SYMBOL_FILE_INVALID;
       
   214 		char cLine[MAX_LINE_LENGTH];
       
   215 		do {
       
   216 			// Dont read too many lines. (File might be contain invalid data).
       
   217 			iLineCount++;
       
   218 			if ( iLineCount > IDENTIFY_MAX_LINES_READ )
       
   219 				break;
       
   220 
       
   221 			// Get line -> string.
       
   222 			in.getline( cLine, MAX_LINE_LENGTH );
       
   223 			string sLine(cLine);
       
   224 			
       
   225 			// Check its not too short.
       
   226 			if( sLine.length() < iLineMinLength )
       
   227 				continue;
       
   228 
       
   229 			// Take substring from start of line to identify it to rofs/rom.
       
   230 			if ( ! sLine.substr( 0, ROFS_SYMBOL_IDENTIFY_STRING.length() ).compare( ROFS_SYMBOL_IDENTIFY_STRING ) )
       
   231 			{
       
   232 				iType = SYMBOL_FILE_ROFS;
       
   233 				break;
       
   234 			}
       
   235 			else if ( ! sLine.substr( 0, ROM_SYMBOL_IDENTIFY_STRING.length() ).compare( ROM_SYMBOL_IDENTIFY_STRING ) )
       
   236 			{
       
   237 				iType = SYMBOL_FILE_ROM;
       
   238 				break;
       
   239 			}
       
   240 		} while ( in.good() );
       
   241 		in.close();
       
   242 	}
       
   243 	catch(...)
       
   244 	{
       
   245 		LOG_STRING("CATRomSymbol::IdentifySymbolFile unhandled exception.");
       
   246 	}
       
   247 	return iType;
       
   248 }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CATRomSymbol::ReadRomFiles
       
   252 // Reads rom file(s) and creates symbols to vector.
       
   253 // -----------------------------------------------------------------------------
       
   254 bool CATRomSymbol::ReadRomFiles()
       
   255 {
       
   256 	LOG_FUNC_ENTRY("CATRomSymbol::ReadRomFile");
       
   257 
       
   258 	// Clear symbols.
       
   259 	for ( vector<Symbol*>::iterator it = m_vRomSymbols.begin() ; it != m_vRomSymbols.end() ; it++ )
       
   260 	{
       
   261 		delete *it;
       
   262 	}
       
   263 	m_vRomSymbols.clear();
       
   264 	
       
   265 	// Clear cache. note cache is just pointers dont delete them.
       
   266 	m_vRomCache.clear();
       
   267 
       
   268 	// Any errors?
       
   269 	bool ok = true;
       
   270 
       
   271 	for( vector<string>::iterator it = m_vRomFiles.begin();
       
   272 		it != m_vRomFiles.end() ; it++ )
       
   273 		ok = ReadRomFile( *it );
       
   274 	
       
   275 	// If size smaller than 1 it is not good rom file(s).
       
   276 	if ( m_vRomSymbols.size() < 1  || ok != true)
       
   277 		return false;
       
   278 
       
   279 	// Rom start and end addresses.
       
   280 	m_iRomStartAddress = (*m_vRomSymbols.begin())->iStartAddress;
       
   281 	m_iRomEndAddress = (*m_vRomSymbols.rbegin())->iEndAddress;
       
   282 	return true;
       
   283 }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CATRomSymbol::ReadRofsFiles
       
   287 // Read rofs files.
       
   288 // -----------------------------------------------------------------------------
       
   289 bool CATRomSymbol::ReadRofsFiles()
       
   290 {
       
   291 	LOG_FUNC_ENTRY("CATRomSymbol::ReadRofsFiles");
       
   292 	// Clear.
       
   293 	for ( vector<RofsBinary*>::iterator it = m_vRofsBinaries.begin() ; it != m_vRofsBinaries.end() ; it++ )
       
   294 	{
       
   295 		delete *it;
       
   296 	}
       
   297 	m_vRofsBinaries.clear();
       
   298 	
       
   299 	// Any errors?
       
   300 	bool ok = true;
       
   301 
       
   302 	for( vector<string>::iterator it = m_vRofsFiles.begin();
       
   303 		it != m_vRofsFiles.end() ; it++ )
       
   304 		ok = ReadRofsFile( *it );
       
   305 	
       
   306 	// If size smaller than 1 it is not good rofs file(s).
       
   307 	if ( m_vRofsBinaries.size() < 1  || ok != true)
       
   308 		return false;
       
   309 	return true;
       
   310 }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CATRomSymbol::ReadRomFile
       
   314 // Read given rom file
       
   315 // -----------------------------------------------------------------------------
       
   316 bool CATRomSymbol::ReadRomFile( const string& sFile )
       
   317 {
       
   318 	LOG_FUNC_ENTRY("CATRomSymbol::ReadRomfile");
       
   319 	// Open rom file.
       
   320 	CATFileReader* reader = new CATFileReader();
       
   321 	// Show progress message if flag set.
       
   322 	if ( m_bShowProgressMessages )
       
   323 		cout << AT_MSG << "Reading rom symbol file: " << sFile << "..." << endl;
       
   324 	if ( ! reader->Open( sFile.c_str() ) )
       
   325 	{
       
   326 		reader->Close();
       
   327 		delete reader;
       
   328 		return false;
       
   329 	}
       
   330 
       
   331 	// Show progress message if flag set.
       
   332 	if ( m_bShowProgressMessages )
       
   333 		cout << AT_MSG << "Parsing rom symbol file: " << sFile << "..." << endl;
       
   334 
       
   335 	// Loop thrue lines.
       
   336 	string sLine("");
       
   337 	string sBinary("");
       
   338 	while( reader->GetLine( sLine ) )
       
   339 	{
       
   340 		// From rom we just read symbols that have lenght, no need to separate them into diff binaries.
       
   341 		try {
       
   342 			if ( sLine.size() < 2 )
       
   343 			{
       
   344 				continue;
       
   345 			}
       
   346 			else if ( sLine.at(0) == '8' )
       
   347 			{
       
   348 				// Create new item.
       
   349 				Symbol* symbol = new Symbol();
       
   350 				ParseSymbolFromLine( sLine, symbol);
       
   351 				// Ignore symbols which have same start & end address (zero length).
       
   352 				if ( symbol->iStartAddress != symbol->iEndAddress )
       
   353 					m_vRomSymbols.push_back( symbol );
       
   354 				else
       
   355 					delete symbol;
       
   356 			}
       
   357 		} catch(...)
       
   358 		{
       
   359 			// Catch all possible exception here so analyze will succeed even rom file invalid.
       
   360 			m_sErrorMessage.append( "Unhandled exception parsing rom symbol file.\n" );
       
   361 			// Close and delete reader.
       
   362 			reader->Close();
       
   363 			delete reader;
       
   364 			return false;
       
   365 		}
       
   366 	}
       
   367 	// Close and delete reader.
       
   368 	reader->Close();
       
   369 	delete reader;
       
   370 	return true;
       
   371 }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CATRomSymbol::ReadRofsFile
       
   375 // Read given rofs file
       
   376 // -----------------------------------------------------------------------------
       
   377 bool CATRomSymbol::ReadRofsFile( const string& sFile )
       
   378 {
       
   379 	LOG_FUNC_ENTRY("CATRomSymbol::ReadRofsFile");
       
   380 	// open/read rofs file.
       
   381 	CATFileReader* reader = new CATFileReader();
       
   382 	// Show progress message if flag set.
       
   383 	if ( m_bShowProgressMessages )
       
   384 		cout << AT_MSG << "Reading rofs symbol file: " << sFile << "..." << endl;
       
   385 	if ( ! reader->Open( sFile.c_str() ) )
       
   386 	{
       
   387 		reader->Close();
       
   388 		delete reader;
       
   389 		return false;
       
   390 	}
       
   391 
       
   392 	// Show progress message if flag set.
       
   393 	if ( m_bShowProgressMessages )
       
   394 		cout << AT_MSG << "Parsing rofs symbol file: " << sFile << "..." << endl;
       
   395 
       
   396 	// Loop thrue lines.
       
   397 	string sLine("");
       
   398 	string sBinary("");
       
   399 	RofsBinary* rb = NULL;
       
   400 	while( reader->GetLine( sLine ) )
       
   401 	{
       
   402 		try {
       
   403 			if ( sLine.size() < 2 )
       
   404 			{
       
   405 				continue;
       
   406 			}
       
   407 			else if ( sLine.at(0) == 'F' )
       
   408 			{
       
   409 				if ( rb != NULL )
       
   410 				{
       
   411 					// Check last binary if no symbols in it dont add it.
       
   412 					if ( rb->vSymbols.size() == 0 )
       
   413 					{
       
   414 						delete rb;
       
   415 						rb = NULL;
       
   416 					}
       
   417 					else
       
   418 						m_vRofsBinaries.push_back( rb );
       
   419 				}
       
   420 				// new binary name.
       
   421 				size_t i = sLine.rfind("\\");
       
   422 				sLine.erase(0, i+1);
       
   423 				rb = new RofsBinary( sLine );
       
   424 
       
   425 			}
       
   426 			else if ( sLine.at(0) == '0' )
       
   427 			{
       
   428 				// Cannot pickup symbols if no binary defined.
       
   429 				if ( rb == NULL )
       
   430 					continue;
       
   431 				// Create new item.
       
   432 				Symbol* symbol = new Symbol();
       
   433 				ParseSymbolFromLine( sLine, symbol);
       
   434 				// Ignore symbols which have same start & end address (zero length).
       
   435 				if ( symbol->iStartAddress != symbol->iEndAddress )
       
   436 					rb->vSymbols.push_back( symbol );
       
   437 				else
       
   438 					delete symbol;
       
   439 			}
       
   440 		} catch(...)
       
   441 		{
       
   442 			// Catch all possible exception here so analyze will succeed even rofs file invalid.
       
   443 			m_sErrorMessage.append( "Unhandled exception parsing rofs symbol file.\n" );
       
   444 			// Close and delete reader.
       
   445 			reader->Close();
       
   446 			delete reader;
       
   447 			return false;
       
   448 		}
       
   449 	}
       
   450 	// Last added binary.
       
   451 	if ( rb != NULL )
       
   452 	{
       
   453 		if ( rb->vSymbols.size() == 0 )
       
   454 		{
       
   455 			delete rb;
       
   456 			rb = NULL;
       
   457 		}
       
   458 		else
       
   459 			m_vRofsBinaries.push_back( rb );
       
   460 	}
       
   461 	// Close and delete reader.
       
   462 	reader->Close();
       
   463 	delete reader;
       
   464 	return true;
       
   465 }
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CATRomSymbol::ParseSymbolFromLine
       
   469 // Parses given line into given symbol.
       
   470 // -----------------------------------------------------------------------------
       
   471 void CATRomSymbol::ParseSymbolFromLine( const string& sLine, Symbol* pSymbol )
       
   472 {
       
   473 	LOG_LOW_FUNC_ENTRY("CATRomSymbol::ParseSymbolFromLine");
       
   474 	if ( pSymbol == NULL )
       
   475 		return;
       
   476 	size_t s,x;
       
   477 	string temp;
       
   478 	// address.
       
   479 	x = sLine.find( ' ' );
       
   480 	temp = sLine.substr( 0, x );
       
   481 	pSymbol->iStartAddress = CATBase::_httoi( temp.c_str() );
       
   482 	// "Erase spaces" move starting point.
       
   483 	s = x;
       
   484 	s = sLine.find_first_not_of( ' ', s );
       
   485 	// length.
       
   486 	x = sLine.find( ' ', s );
       
   487 	temp = sLine.substr(s,x-s);
       
   488 	unsigned long length = CATBase::_httoi( temp.c_str() );
       
   489 	pSymbol->iEndAddress = pSymbol->iStartAddress + length;
       
   490 	// "Erase spaces" move starting point.
       
   491 	s = x;
       
   492 	s = sLine.find_first_not_of( ' ', s);
       
   493 	// function. Function might have spaces so we find 2 spaces which indicates end of it.
       
   494 	x = sLine.find( "  ", s );
       
   495 	temp = sLine.substr( s, x-s );
       
   496 	pSymbol->sFunction = temp;
       
   497 }
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // CATRomSymbol::GetError
       
   501 // Get error string if error occured in other methods.
       
   502 // -----------------------------------------------------------------------------
       
   503 string CATRomSymbol::GetError( void )
       
   504 {
       
   505 	LOG_FUNC_ENTRY("CATRomSymbol::GetError");
       
   506 	return m_sErrorMessage;
       
   507 }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // CATRomSymbol::Close
       
   511 // Close (stop using).
       
   512 // -----------------------------------------------------------------------------
       
   513 bool CATRomSymbol::Close( void )
       
   514 {
       
   515 	LOG_FUNC_ENTRY("CATRomSymbol::Close");
       
   516 	return true;
       
   517 }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CATRomSymbol::AddressToLine
       
   521 // Try locate binary and function name for given memory address.
       
   522 // -----------------------------------------------------------------------------
       
   523 bool CATRomSymbol::AddressToLine( CATMemoryAddress* result )
       
   524 {
       
   525 	LOG_LOW_FUNC_ENTRY("CATRomSymbol::AddressToLine");
       
   526 	// Have symbols been read.
       
   527 	if ( ! m_bSymbolsRead )
       
   528 		return false;
       
   529 	// check that its lenght > 2
       
   530 	if ( result->GetAddressString().size() < 2 )
       
   531 		return false;
       
   532 	/* Check first is address in range of rom */
       
   533 	if ( result->GetAddress() < m_iRomStartAddress
       
   534 		|| result->GetAddress() > m_iRomEndAddress )
       
   535 	{
       
   536 		return AddressToLineRofs( result );		
       
   537 	}
       
   538 	return AddressToLineRom( result );
       
   539 }
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CATRomSymbol::AddressToLineRom
       
   543 // Locate function from rom address range.
       
   544 // -----------------------------------------------------------------------------
       
   545 bool CATRomSymbol::AddressToLineRom( CATMemoryAddress* result )
       
   546 {
       
   547 	LOG_LOW_FUNC_ENTRY( "CATRomSymbol::AddressToLineRom" );
       
   548 	// Address to find in integer & string.
       
   549 	unsigned long iAddressToFind = result->GetAddress();
       
   550 	string sAddressToFind = result->GetAddressString();
       
   551 	
       
   552 	// Find symbol.
       
   553 	Symbol* pFound = NULL;
       
   554 
       
   555 	// Check from cache first.
       
   556 	vector<Symbol*>::iterator it;
       
   557 	for ( it = m_vRomCache.begin(); it != m_vRomCache.end(); it++ )
       
   558 	{
       
   559 		if ( iAddressToFind >= (*it)->iStartAddress
       
   560 			&& (*it)->iEndAddress > iAddressToFind )
       
   561 		{
       
   562 			pFound = *it;
       
   563 			break;
       
   564 		}
       
   565 	}
       
   566 	
       
   567 	if ( pFound == NULL )
       
   568 	{
       
   569 		// From all symbols.
       
   570 		bool reverse = false;
       
   571 		int offSetFromStart = iAddressToFind - m_iRomStartAddress;
       
   572 		int offSetFromEnd = m_iRomEndAddress - iAddressToFind;
       
   573 		if ( offSetFromEnd < offSetFromStart ) 
       
   574 			reverse = true;
       
   575 		
       
   576 		if ( reverse )
       
   577 		{
       
   578 			// Iterate vector in reverse.
       
   579 			vector<Symbol*>::reverse_iterator it;
       
   580 			for ( it = m_vRomSymbols.rbegin(); it != m_vRomSymbols.rend(); ++it )
       
   581 			{
       
   582 				if ( iAddressToFind >= (*it)->iStartAddress
       
   583 					&& (*it)->iEndAddress > iAddressToFind )
       
   584 				{
       
   585 					pFound = *it;
       
   586 					break;
       
   587 				}
       
   588 			}
       
   589 		}
       
   590 		else
       
   591 		{
       
   592 			// Iterate vector normal direction.
       
   593 			vector<Symbol*>::iterator it;
       
   594 			for ( it = m_vRomSymbols.begin(); it != m_vRomSymbols.end(); it++ )
       
   595 			{
       
   596 				if ( iAddressToFind >= (*it)->iStartAddress
       
   597 					&& (*it)->iEndAddress > iAddressToFind )
       
   598 				{
       
   599 					pFound = *it;
       
   600 					break;
       
   601 				}
       
   602 			}
       
   603 		}
       
   604 	}
       
   605 
       
   606 	// Set result if found.
       
   607 	if ( pFound != NULL )
       
   608 	{
       
   609 		result->SetFunctionName( pFound->sFunction );
       
   610 		result->SetAddressToLineState( CATMemoryAddress::SYMBOL );
       
   611 		// Add found symbols pointer to cache.
       
   612 		m_vRomCache.push_back( pFound );
       
   613 		return true;
       
   614 	}
       
   615 	return false;
       
   616 }
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // CATRomSymbol::AddressToLineRofs
       
   620 // Locate function from rofs address range.
       
   621 // -----------------------------------------------------------------------------
       
   622 bool CATRomSymbol::AddressToLineRofs( CATMemoryAddress* result)
       
   623 {
       
   624 	LOG_LOW_FUNC_ENTRY("CATRomSymbol::AddressToLineRofs");
       
   625 	// Check that binary name is defined in memory address.
       
   626 	string sBinary = result->GetModuleName();
       
   627 	if ( sBinary.empty() )
       
   628 		return false;
       
   629 	// Try find that named module.
       
   630 	vector<RofsBinary*>::iterator rofs = m_vRofsBinaries.begin();
       
   631 	while( rofs != m_vRofsBinaries.end() )
       
   632 	{
       
   633 		if ( (*rofs)->m_sBinary.compare( sBinary ) == 0 )
       
   634 			break;
       
   635 		rofs++;
       
   636 	}
       
   637 	if ( rofs == m_vRofsBinaries.end() )
       
   638 		return false;
       
   639 
       
   640 	// Offset what we are looking from binary
       
   641 	unsigned long offSet = result->GetAddress();
       
   642 	offSet -= result->GetModuleStartAddress();
       
   643 	for( vector<Symbol*>::iterator it = (*rofs)->vSymbols.begin() ;
       
   644 		it != (*rofs)->vSymbols.end(); it++ )
       
   645 	{
       
   646 		if ( (*it)->iStartAddress <= offSet && offSet < (*it)->iEndAddress )
       
   647 		{
       
   648 			result->SetFunctionName( (*it)->sFunction );
       
   649 			result->SetAddressToLineState( CATMemoryAddress::SYMBOL );
       
   650 			return true;
       
   651 		}
       
   652 	}
       
   653 	return false;
       
   654 }
       
   655 
       
   656 //EOF