Fixed the bug that symbol address is wrongly fixed up. With this we can correctly set breakpoint at a symbol, e.g. for any symbol specified in stop-at-main preference UI.
authorl12wang
Thu, 08 Oct 2009 17:43:28 -0500
changeset 99 83ae0d82da3b
parent 96 defec9d2b40a
child 100 6e8bead0f126
Fixed the bug that symbol address is wrongly fixed up. With this we can correctly set breakpoint at a symbol, e.g. for any symbol specified in stop-at-main preference UI.
cdt/cdt_6_0_x/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE.java
--- a/cdt/cdt_6_0_x/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE.java	Tue Sep 15 10:25:52 2009 -0500
+++ b/cdt/cdt_6_0_x/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE.java	Thu Oct 08 17:43:28 2009 -0500
@@ -644,15 +644,24 @@
 
 	public Symbol[] getSymbols() throws IOException {
 		if (symbolTable == null) {
+			SectionHeader[] secHeaders = getSectionHeaders();
+			NTOptionalHeader ntHeader = getNTOptionalHeader();
+
 			RandomAccessFile accessFile = getRandomAccessFile();
 			long offset = fileHeader.f_symptr;
 			symbolTable = new Symbol[fileHeader.f_nsyms];
 			for (int i = 0; i < symbolTable.length; i++, offset += Symbol.SYMSZ) {
-				symbolTable[i] = new Symbol(accessFile, offset);
-				NTOptionalHeader ntHeader = getNTOptionalHeader();
-				// FIXME: What is this again ?
+				Symbol newSym = new Symbol(accessFile, offset);
+				
+				// Now convert section offset of the symbol to image offset.
+				if (newSym.n_scnum >= 1 && newSym.n_scnum <= secHeaders.length)	// valid section #
+					newSym.n_value += secHeaders[newSym.n_scnum-1].s_vaddr;
+				
+				// convert to absolute address.
 				if (ntHeader != null)
-					symbolTable[i].n_value += ntHeader.ImageBase + ntHeader.FileAlignment;
+					newSym.n_value += ntHeader.ImageBase;
+				
+				symbolTable[i] = newSym;
 			}				
 		}
 		return symbolTable;