diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java index c6334470ccc..42f67a68947 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java @@ -1029,6 +1029,9 @@ public class Elf implements AutoCloseable { return slist.toArray(new Section[0]); } + /** + * @throws ElfClassNoneException if {@link ELFhdr#ELFCLASSNONE} header is read + */ public Section[] getSections() throws IOException { if (sections == null) { if (ehdr.e_shoff == 0) { @@ -1063,7 +1066,7 @@ public class Elf implements AutoCloseable { break; case ELFhdr.ELFCLASSNONE: default: - throw new IOException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); //$NON-NLS-1$ + throw new ElfClassNoneException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); //$NON-NLS-1$ } sections[i].sh_link = efile.readIntE(); @@ -1081,7 +1084,7 @@ public class Elf implements AutoCloseable { break; case ELFhdr.ELFCLASSNONE: default: - throw new IOException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); //$NON-NLS-1$ + throw new ElfClassNoneException("Unknown ELF class " + ehdr.e_ident[ELFhdr.EI_CLASS]); //$NON-NLS-1$ } } } @@ -1316,4 +1319,16 @@ public class Elf implements AutoCloseable { } return result; } + + /** + * Exception indicating that {@link ELFhdr#ELFCLASSNONE} header is read. + * + * @since 7.1 + */ + public static class ElfClassNoneException extends IOException { + + ElfClassNoneException(String message) { + super(message); + } + } } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java index c1c245a1f3b..0e4da98b046 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.utils.AR; import org.eclipse.cdt.utils.elf.Elf; import org.eclipse.cdt.utils.elf.Elf.Attribute; import org.eclipse.cdt.utils.elf.Elf.ELFhdr; +import org.eclipse.cdt.utils.elf.Elf.ElfClassNoneException; import org.eclipse.cdt.utils.elf.Elf.PHdr; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; @@ -177,7 +178,7 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser { try { /* No PHdr.PT_INTERP found in the hints meaning we need to read the file itself */ return Arrays.stream(getPHdrs(path)).anyMatch(phdr -> phdr.p_type == PHdr.PT_INTERP); - } catch (IOException e) { + } catch (ElfClassNoneException e) { CCorePlugin.log(e); } return false;