From 6239c7c1b602282a74b207a5516393f9abf591df Mon Sep 17 00:00:00 2001 From: Pablo Torregrosa Paez Date: Thu, 15 Oct 2015 10:57:52 +0200 Subject: Target Explorer: Added getEntryPoints method to ElfUtils. Change-Id: Ie9fd35b002836a3eb609b53a106d9ea05193a935 Signed-off-by: Pablo Torregrosa Paez --- .../org/eclipse/tcf/te/core/cdt/elf/ElfUtils.java | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'target_explorer/plugins') diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core.cdt/src/org/eclipse/tcf/te/core/cdt/elf/ElfUtils.java b/target_explorer/plugins/org.eclipse.tcf.te.core.cdt/src/org/eclipse/tcf/te/core/cdt/elf/ElfUtils.java index 98e74b385..76e1a9f43 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.core.cdt/src/org/eclipse/tcf/te/core/cdt/elf/ElfUtils.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.core.cdt/src/org/eclipse/tcf/te/core/cdt/elf/ElfUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2012, 2015 Wind River Systems, Inc. and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,9 +11,12 @@ package org.eclipse.tcf.te.core.cdt.elf; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.utils.elf.Elf; import org.eclipse.cdt.utils.elf.Elf.ELFhdr; +import org.eclipse.cdt.utils.elf.Elf.Symbol; /** * Provides ELF file utilities. @@ -94,4 +97,40 @@ public final class ElfUtils { } return elfclass; } + + /** + * Returns a list with the entry point names in this file. + * + * @param file The file representation of the physical file to get the entry points. + * Must not be null. + * @return + */ + public static String[] getEntryPoints(File file) throws IOException { + String[] entryPoints = null; + if (file!=null) { + Elf elfFile = null; + try { + elfFile = new Elf(file.getAbsolutePath()); + elfFile.loadSymbols(); + + Symbol[] symbols = elfFile.getSymbols(); + if (symbols != null) { + List entryPointList = new ArrayList(); + for(Symbol s:symbols) { + if (s.st_type() == Elf.Symbol.STT_FUNC) { + entryPointList.add(s.toString()); + } + } + entryPoints = entryPointList.toArray(new String[entryPointList.size()]); + } + } + finally { + if (elfFile != null) { + elfFile.dispose(); + } + elfFile = null; + } + } + return entryPoints; + } } -- cgit v1.2.3