sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.instr/src/com/nokia/carbide/cpp/pi/instr/MapFile.java
changeset 12 ae255c9aa552
parent 5 844b047e260d
equal deleted inserted replaced
11:5b9d4d8641ce 12:ae255c9aa552
    40 	private File mapFile;
    40 	private File mapFile;
    41 	private String referencePath;
    41 	private String referencePath;
    42 	private long referenceLineNumber;
    42 	private long referenceLineNumber;
    43 	private LinkedList<Function> functionData;
    43 	private LinkedList<Function> functionData;
    44 	private ArrayList<Function> sortedFunctionData;
    44 	private ArrayList<Function> sortedFunctionData;
    45 	private Long currentGccLibEndingOffset = new Long(0);
    45 	private Long currentGccLibEndingOffset = Long.valueOf(0);
    46 	private Function lastGccFunction = null;
    46 	private Function lastGccFunction = null;
    47 	
    47 	
    48 	// RVCT/RVDS map file line
    48 	// RVCT/RVDS map file line
    49 	private static final Pattern rvctLinePattern = Pattern.compile("^\\p{Blank}*((?!\\d)\\S.+)\\p{Blank}+(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+(?:ARM Code|Thumb Code)\\p{Blank}+(0x\\p{XDigit}+|\\d+)\\p{Blank}.*\\(\\.text\\)$");	//$NON-NLS-1$
    49 	private static final Pattern RVCT_LINE_PATTERN = Pattern.compile("^\\p{Blank}*((?!\\d)\\S.+)\\p{Blank}+(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+(?:ARM Code|Thumb Code)\\p{Blank}+(0x\\p{XDigit}+|\\d+)\\p{Blank}.*\\(\\.text\\)$");	//$NON-NLS-1$
    50 
    50 
    51 	// a GCC map file line looks like this:
    51 	// a GCC map file line looks like this:
    52 	// <%x|%d> <symbol name> for function symbols
    52 	// <%x|%d> <symbol name> for function symbols
    53 	// symbol name cannot be number (e.g. first non space is not a digit)
    53 	// symbol name cannot be number (e.g. first non space is not a digit)
    54 	private static final Pattern gccFuncLinePattern  = Pattern.compile("\\p{Blank}*(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+((?!\\d)\\S.+)");	//$NON-NLS-1$
    54 	private static final Pattern GCC_FUNC_LINE_PATTERN  = Pattern.compile("\\p{Blank}*(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+((?!\\d)\\S.+)");	//$NON-NLS-1$
    55 
    55 
    56 	// <section> <%x|%d> <%x|%d> <symbol name>	for whole library
    56 	// <section> <%x|%d> <%x|%d> <symbol name>	for whole library
    57 	// *fill* <%x|%d> <%x|%d> 00000000 for filler
    57 	// *fill* <%x|%d> <%x|%d> 00000000 for filler
    58 	private static final Pattern gccLibOrFillerLinePattern = Pattern.compile("\\p{Blank}*(?:\\S*)\\p{Blank}*(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+(\\S.+)"); //$NON-NLS-1$
    58 	private static final Pattern GCC_LIB_OR_FILLER_LINE_PATTERN = Pattern.compile("\\p{Blank}*(?:\\S*)\\p{Blank}*(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+(0[x|X]\\p{XDigit}+|\\d+)\\p{Blank}+(\\S.+)"); //$NON-NLS-1$
    59 
    59 
    60 	private static final String EXPORTED = " (EXPORTED)";
    60 	private static final String EXPORTED = " (EXPORTED)";
    61 
    61 
    62 	public MapFile(File file, String referencePath, long referenceLineNumber)
    62 	public MapFile(File file, String referencePath, long referenceLineNumber)
    63 	{
    63 	{
   193 			}
   193 			}
   194 		}
   194 		}
   195 		return -1;
   195 		return -1;
   196 	}
   196 	}
   197 	
   197 	
   198 	private Function FunctionFromTokens(String funcNameToken, String funcOffsetToken, String funcLengthToken)
   198 	private Function functionFromTokens(String funcNameToken, String funcOffsetToken, String funcLengthToken)
   199 	{	
   199 	{	
   200 		Function f = new Function(funcNameToken,Long.valueOf(0),null);
   200 		Function f = new Function(funcNameToken,Long.valueOf(0),null);
   201 		// look for length, set it tentatively
   201 		// look for length, set it tentatively
   202 		// we may adjust it later
   202 		// we may adjust it later
   203 		f.setLength(Long.decode(funcLengthToken));
   203 		f.setLength(Long.decode(funcLengthToken));
   287 	private void processLineRVCT(String line)
   287 	private void processLineRVCT(String line)
   288 	{
   288 	{
   289 		// a RVCT symbol line looks like this:
   289 		// a RVCT symbol line looks like this:
   290 		// <symbol name> <%x|%d> <ARM Code|Thumb Code> <%x|%d> <object>
   290 		// <symbol name> <%x|%d> <ARM Code|Thumb Code> <%x|%d> <object>
   291 		// symbol name cannot be number (e.g. first non space is not a digit)
   291 		// symbol name cannot be number (e.g. first non space is not a digit)
   292 		Matcher rvctLineMatcher = rvctLinePattern.matcher(line);
   292 		Matcher rvctLineMatcher = RVCT_LINE_PATTERN.matcher(line);
   293 		
   293 		
   294 		if (rvctLineMatcher.matches())
   294 		if (rvctLineMatcher.matches())
   295 		{
   295 		{
   296 			String funcNameToken = rvctLineMatcher.group(1).trim();
   296 			String funcNameToken = rvctLineMatcher.group(1).trim();
   297 			// internal symbol, not a function
   297 			// internal symbol, not a function
   306 			if (funcOffsetToken.equalsIgnoreCase("0x00000001") && line.contains("Thumb Code")) //$NON-NLS-1$ //$NON-NLS-2$
   306 			if (funcOffsetToken.equalsIgnoreCase("0x00000001") && line.contains("Thumb Code")) //$NON-NLS-1$ //$NON-NLS-2$
   307 				return;
   307 				return;
   308 			
   308 			
   309 			String funcLengthToken = rvctLineMatcher.group(3).trim();
   309 			String funcLengthToken = rvctLineMatcher.group(3).trim();
   310 			
   310 			
   311 			Function f = FunctionFromTokens(funcNameToken, funcOffsetToken, funcLengthToken);
   311 			Function f = functionFromTokens(funcNameToken, funcOffsetToken, funcLengthToken);
   312 			
   312 			
   313 			this.insertToFunctionData(f);
   313 			this.insertToFunctionData(f);
   314 		}
   314 		}
   315 	}
   315 	}
   316 		
   316 		
   348 	private void processLineGCC(String line)
   348 	private void processLineGCC(String line)
   349 	{	
   349 	{	
   350 		// a GCC symbol line looks like this:
   350 		// a GCC symbol line looks like this:
   351 		// <%x|%d> <symbol name> for function symbols
   351 		// <%x|%d> <symbol name> for function symbols
   352 		// symbol name cannot be number (e.g. first non space is not a digit)
   352 		// symbol name cannot be number (e.g. first non space is not a digit)
   353 		Matcher gccFuncLineMatcher  = gccFuncLinePattern.matcher(line);	//$NON-NLS-1$
   353 		Matcher gccFuncLineMatcher  = GCC_FUNC_LINE_PATTERN.matcher(line);	//$NON-NLS-1$
   354 		// <section> <%x|%d> <%x|%d> <symbol name>	for whole library
   354 		// <section> <%x|%d> <%x|%d> <symbol name>	for whole library
   355 		// *fill* <%x|%d> <%x|%d> 00000000 for filler
   355 		// *fill* <%x|%d> <%x|%d> 00000000 for filler
   356 		Matcher gccLibOrFillerLineMatcher = gccLibOrFillerLinePattern.matcher(line); //$NON-NLS-1$
   356 		Matcher gccLibOrFillerLineMatcher = GCC_LIB_OR_FILLER_LINE_PATTERN.matcher(line); //$NON-NLS-1$
   357 		
   357 		
   358 		Function f = null;
   358 		Function f = null;
   359 		Long currentLineOffset = currentGccLibEndingOffset;
   359 		Long currentLineOffset = currentGccLibEndingOffset;
   360 		
   360 		
   361 
   361 
   363 		{
   363 		{
   364 			String funcNameToken = gccFuncLineMatcher.group(2).trim();
   364 			String funcNameToken = gccFuncLineMatcher.group(2).trim();
   365 			String funcOffsetToken = gccFuncLineMatcher.group(1).trim();
   365 			String funcOffsetToken = gccFuncLineMatcher.group(1).trim();
   366 			String funcLengthToken = Messages.getString("MapFile.zero"); //$NON-NLS-1$
   366 			String funcLengthToken = Messages.getString("MapFile.zero"); //$NON-NLS-1$
   367 			
   367 			
   368 			f = FunctionFromTokens(funcNameToken, funcOffsetToken, funcLengthToken);
   368 			f = functionFromTokens(funcNameToken, funcOffsetToken, funcLengthToken);
   369 			
   369 			
   370 			// Some GCC symbol may be bogus
   370 			// Some GCC symbol may be bogus
   371 			if (qualifyGCCSymbol(f.getOffsetFromBinaryStart(), funcNameToken)) {
   371 			if (qualifyGCCSymbol(f.getOffsetFromBinaryStart(), funcNameToken)) {
   372 				this.insertToFunctionData(f);
   372 				this.insertToFunctionData(f);
   373 			} 
   373 			} 
   385 			String libLengthToken = gccLibOrFillerLineMatcher.group(2).trim();
   385 			String libLengthToken = gccLibOrFillerLineMatcher.group(2).trim();
   386 			// next time around we will use the new library offset
   386 			// next time around we will use the new library offset
   387 			currentGccLibEndingOffset = Long.decode(libLengthToken) + Long.decode(libOffsetToken);				
   387 			currentGccLibEndingOffset = Long.decode(libLengthToken) + Long.decode(libOffsetToken);				
   388 		} else {
   388 		} else {
   389 			// next time around we will use the new library offset
   389 			// next time around we will use the new library offset
   390 			currentGccLibEndingOffset = new Long(0);
   390 			currentGccLibEndingOffset = Long.valueOf(0);
   391 		}
   391 		}
   392 		
   392 		
   393 		// update last function's size if needed
   393 		// update last function's size if needed
   394 		if (lastGccFunction != null)
   394 		if (lastGccFunction != null)
   395 		{
   395 		{
   506 		  }
   506 		  }
   507 		  if (referenceLineNumber > 0) {
   507 		  if (referenceLineNumber > 0) {
   508 			  myMessage += Messages.getString("MapFile.line.number") + referenceLineNumber; //$NON-NLS-1$
   508 			  myMessage += Messages.getString("MapFile.line.number") + referenceLineNumber; //$NON-NLS-1$
   509 		  }
   509 		  }
   510 		  
   510 		  
   511     	  GeneralMessages.PiLog(myMessage, GeneralMessages.WARNING);
   511     	  GeneralMessages.piLog(myMessage, GeneralMessages.WARNING);
   512 	}
   512 	}
   513 
   513 
   514 	private void flagIOException(File file, String referencePath, long referenceLineNumber) {
   514 	private void flagIOException(File file, String referencePath, long referenceLineNumber) {
   515 		  String myMessage = Messages.getString("MapFile.map.file") + file.getAbsoluteFile().getName() + Messages.getString("MapFile.ioexception"); //$NON-NLS-1$ //$NON-NLS-2$
   515 		  String myMessage = Messages.getString("MapFile.map.file") + file.getAbsoluteFile().getName() + Messages.getString("MapFile.ioexception"); //$NON-NLS-1$ //$NON-NLS-2$
   516 		  if (referencePath != null && referencePath.length() > 0) {
   516 		  if (referencePath != null && referencePath.length() > 0) {
   519 		  if (referenceLineNumber > 0) {
   519 		  if (referenceLineNumber > 0) {
   520 			  myMessage += Messages.getString("MapFile.line.number") + referenceLineNumber; //$NON-NLS-1$
   520 			  myMessage += Messages.getString("MapFile.line.number") + referenceLineNumber; //$NON-NLS-1$
   521 		  }
   521 		  }
   522 
   522 
   523 		  GeneralMessages.showErrorMessage(myMessage);
   523 		  GeneralMessages.showErrorMessage(myMessage);
   524 		  GeneralMessages.PiLog(myMessage, GeneralMessages.ERROR);
   524 		  GeneralMessages.piLog(myMessage, GeneralMessages.ERROR);
   525 	}
   525 	}
   526 }
   526 }