Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Function Address Information for 1.0.1

Hi!

I needed address information for functions. The information was being parsed out of the elf file, but not being put anywhere in the higher level objects. This patch makes the st_value field from the elf entry available as the function address by passing it through ISymbol and onto the created IFunction.

Perhaps the address information is put in the wrong place by the way. I debated putting it in FunctionInfo rather than in Function, however since Function was creating it's FunctionInfo with every getInfo call it seemed that Function was going to have to store the information locally anyway.

I don't care too much if it goes in 1.0.1. It's not fixing a bug, but is something that I needed to hang some higher level navigation stuff on. I do really want this kind of information available in the head. I feel that IFunction children of the binaries should have their addresses available. It makes all sorts of cool things possible when you get to profiling data.

Thanks!
-Chris

diff -r -c xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IFunction.java xide/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IFunction.java *** xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IFunction.java Sat Feb 1 12:54:38 2003 --- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IFunction.java Tue Mar 18 09:15:19 2003
***************
*** 75,78 ****
--- 75,87 ----
  	 * @see Flags
  	 */
  	public int getAccessControl() throws CModelException;
+ 	
+ 	/**
+ 	 * Returns the address of the function. This method will only produce
+ 	 * valid addresses for symbols that are children of IBinaries.
+ 	 *
+ 	 * @exception CModelException if this element does not have address
+ 	 * information.
+ 	 */
+ 	public long getAddress() throws CModelException;
  }
diff -r -c xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java *** xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java Tue Mar 18 09:16:15 2003 --- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java Tue Mar 18 09:15:19 2003
***************
*** 220,230 ****
  				hash.put(path, tu);
  				addChild(tu);
  			}
! 			function = new Function(tu, symbol.getName());
  			function.setLines( symbol.getLineNumber(), symbol.getLineNumber());
  			tu.addChild(function);
  		} else {
! 			function = new Function(parent, symbol.getName());
  			addChild(function);
  		}
  		//		if (function != null) {
--- 220,230 ----
  				hash.put(path, tu);
  				addChild(tu);
  			}
! 			function = new Function(tu, symbol.getName(), symbol.getAddress());
  			function.setLines( symbol.getLineNumber(), symbol.getLineNumber());
  			tu.addChild(function);
  		} else {
! 			function = new Function(parent, symbol.getName(), symbol.getAddress());
  			addChild(function);
  		}
  		//		if (function != null) {
diff -r -c xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java *** xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java Sat Feb 1 12:54:39 2003 --- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java Tue Mar 18 09:15:19 2003
***************
*** 11,20 ****
--- 11,29 ----

  public class Function extends SourceManipulation implements IFunction {
  	
+ 	/** address of the function, only valid in certain cases */
+ 	long address;
+ 	
  	public Function(ICElement parent, String name) {
  		super(parent, name, CElement.C_FUNCTION);
+ 		this.address = -1;
  	}

+ 	public Function(ICElement parent, String name, long address) {
+ 		super(parent, name, CElement.C_FUNCTION);
+ 		this.address = address;
+ 	}
+ 	
  	public String[] getExceptions() throws CModelException {
  		return new String[] {};
  	}
***************
*** 46,49 ****
--- 55,63 ----
  	protected CElementInfo createElementInfo () {
  		return new FunctionInfo(this);
  	}
+ 	
+ 	public long getAddress()
+ 	{
+ 		return address;
+ 	}
  }
diff -r -c xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java *** xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java Tue Mar 11 13:51:39 2003 --- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/ElfBinaryFile.java Tue Mar 18 09:15:19 2003
***************
*** 365,370 ****
--- 365,371 ----
  			Symbol sym = new Symbol();
  			sym.type = type;
  			sym.name = array[i].toString();
+ 			sym.address = array[i].st_value;
  			try {
  				// This can fail if we use addr2line
  				// but we can safely ignore the error.
diff -r -c xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java *** xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java Sat Feb 1 12:54:39 2003 --- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/parser/Symbol.java Tue Mar 18 09:15:19 2003
***************
*** 13,18 ****
--- 13,19 ----
  	public int lineno;
  	public String name;
  	public int type;
+ 	public long address;

  	/**
  	 * @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getFilename()
***************
*** 41,45 ****
--- 42,54 ----
  	public int getType() {
  		return type;
  	}
+ 	
+ 	/**
+ 	 * @see org.eclipse.cdt.core.model.IBinaryParser.ISymbol#getAddress()
+ 	 */
+ 	public long getAddress()
+ 	{
+ 		return address;	
+ 	}

  }
diff -r -c xide_compare/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java xide/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java *** xide_compare/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java Sat Feb 1 12:54:39 2003 --- xide/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IBinaryParser.java Tue Mar 18 09:15:20 2003
***************
*** 82,87 ****
--- 82,88 ----
  		public int getLineNumber();
  		public String getFilename();
  		public int getType();
+ 		public long getAddress();
  	}

  	public IBinaryFile getBinary(IFile file) throws IOException;



Back to the top