diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/elf/ElfTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/elf/ElfTest.java index ba525d7db01..6bc84e7e2f2 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/elf/ElfTest.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/elf/ElfTest.java @@ -40,25 +40,41 @@ public class ElfTest { private static final String SYMTAB_NAME = ".symtab"; - @Parameters(name = "{0}") - public static Collection elfArchitectures() { - return Arrays.asList(new Object[][] { - { "BE32", "ppc", "resources/elf/unit_test/simple-be32.elf", 35, "0x00000000", "0x100001a8", 75, - "0x10000518" }, - { "BE64", "ppc64", "resources/elf/unit_test/simple-be64.elf", 34, "0x0000000000000000", - "0x0000000010000240", 69, "0x000000001001fea0" }, - { "LE32", "x86", "resources/elf/unit_test/simple-le32.elf", 36, "0x00000000", "0x080481cc", 70, - "0x080483e5" }, - { "LE64", "x86_64", "resources/elf/unit_test/simple-le64.elf", 36, "0x0000000000000000", - "0x00000000004002b8", 68, "0x00000000004004e4" }, }); - } - - private static final Collection functions = Arrays.asList("", "crtstuff.c", "simple.c", "crtstuff.c", + /** + * Different elfs, being built on different architectures, etc may have different + * contents in their symbol tables. + * + * See {@link #elfArchitectures()} for the mapping of which elf files contain which + * sets of functions + */ + private static final Collection functions1 = Arrays.asList("", "crtstuff.c", "simple.c", "crtstuff.c", "_ITM_deregisterTMCloneTable", "__gmon_start__", "_Jv_RegisterClasses", "_ITM_registerTMCloneTable", "_init", "_start", "deregister_tm_clones", "register_tm_clones", "__do_global_dtors_aux", "frame_dummy", "function", "main", "__libc_csu_init", "__libc_csu_fini", "_fini", "_IO_stdin_used", "__FRAME_END__", "__JCR_LIST__", "__JCR_END__", "_DYNAMIC", "data_start", "__data_start", "__dso_handle", "_edata", "__bss_start", "__TMC_END__", "_end"); + private static final Collection functions2 = Arrays.asList("", "crtstuff.c", "simple.c", "crtstuff.c", + "_ITM_deregisterTMCloneTable", "__gmon_start__", "_ITM_registerTMCloneTable", "_init", "_start", + "deregister_tm_clones", "register_tm_clones", "__do_global_dtors_aux", "frame_dummy", "function", "main", + "_fini", "_IO_stdin_used", "__FRAME_END__", "_DYNAMIC", "data_start", "__data_start", "__dso_handle", + "_edata", "__bss_start", "__TMC_END__", "_end"); + + @Parameters(name = "{0}") + public static Collection elfArchitectures() { + return Arrays.asList(new Object[][] { + { "BE32", "BE32", "ppc", "resources/elf/unit_test/simple-be32.elf", 35, "0x00000000", "0x100001a8", 75, + "0x10000518", Attribute.ELF_TYPE_EXE, functions1 }, + { "BE64", "BE64", "ppc64", "resources/elf/unit_test/simple-be64.elf", 34, "0x0000000000000000", + "0x0000000010000240", 69, "0x000000001001fea0", Attribute.ELF_TYPE_EXE, functions1 }, + { "LE32", "LE32", "x86", "resources/elf/unit_test/simple-le32.elf", 36, "0x00000000", "0x080481cc", 70, + "0x080483e5", Attribute.ELF_TYPE_EXE, functions1 }, + { "LE64", "LE64", "x86_64", "resources/elf/unit_test/simple-le64.elf", 36, "0x0000000000000000", + "0x00000000004002b8", 68, "0x00000000004004e4", Attribute.ELF_TYPE_EXE, functions1 }, + { "DWARF4", "LE64", "x86_64", "resources/elf/unit_test/simple-dwarf4.elf", 34, "0x0000000000000000", + "0x00000000000003d8", 34, "0x000000000000113b", Attribute.ELF_TYPE_SHLIB, functions2 }, + { "DWARF5", "LE64", "x86_64", "resources/elf/unit_test/simple-dwarf5.elf", 35, "0x0000000000000000", + "0x00000000000003d8", 34, "0x000000000000113b", Attribute.ELF_TYPE_SHLIB, functions2 }, }); + } private final String memoryArchitecture; private final String arch; @@ -68,9 +84,12 @@ public static Collection elfArchitectures() { private final String dynsymBaseAddress; private final int nbSymbols; private final String mainAddress; + private final int elfType; + private final Collection functions; - public ElfTest(String mArch, String architecture, String path, int sections, String symBaseAddress, - String dynBaseAddress, int symbolCount, String mainAddr) throws IOException { + public ElfTest(String testName, String mArch, String architecture, String path, int sections, String symBaseAddress, + String dynBaseAddress, int symbolCount, String mainAddr, int elfType, Collection functions) + throws IOException { memoryArchitecture = mArch; nbSections = sections; elf = new Elf(path); @@ -79,6 +98,8 @@ public ElfTest(String mArch, String architecture, String path, int sections, Str dynsymBaseAddress = dynBaseAddress; nbSymbols = symbolCount; mainAddress = mainAddr; + this.elfType = elfType; + this.functions = functions; } /** @@ -92,12 +113,10 @@ public void testGetSections() throws IOException { assertNotNull(sectionByName); assertEquals(arch + ": " + "symbol table", SYMTAB_NAME, sectionByName.toString()); assertEquals(arch + ": " + "binary address", symtabBaseAddress, sectionByName.sh_addr.toHexAddressString()); - assertEquals(arch + ": " + "sh_name", 1, sectionByName.sh_name); sectionByName = elf.getSectionByName(".dynsym"); assertNotNull(sectionByName); assertEquals(arch + ": " + "dynamic symbols", ".dynsym", sectionByName.toString()); assertEquals(arch + ": " + "binary address", dynsymBaseAddress, sectionByName.sh_addr.toHexAddressString()); - assertEquals(arch + ": " + "sh_name", 78L, sectionByName.sh_name); } /** @@ -150,7 +169,7 @@ public void testGetAttributes() throws IOException { memoryArchitecture.endsWith("32") ? unsigned32BitAddress : unsigned64BitAddress, attributes.getAddressFactory().getMax().getValue()); assertEquals(arch + ": " + "debug type", Attribute.DEBUG_TYPE_DWARF, attributes.getDebugType()); - assertEquals(arch + ": " + "elf type", Attribute.ELF_TYPE_EXE, attributes.getType()); + assertEquals(arch + ": " + "elf type", elfType, attributes.getType()); } @Test diff --git a/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/Makefile b/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/Makefile index 3bf7cf61345..54f4f89646a 100644 --- a/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/Makefile +++ b/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/Makefile @@ -1,2 +1,11 @@ #just an example -gcc simple.c -g -o simple.elf \ No newline at end of file +# gcc simple.c -g -o simple.elf + +simple-dwarf4.elf: + gcc simple.c -g -gdwarf-4 -o simple-dwarf4.elf + +# This needs to run on a GCC that fully supports DWARF v5, e.g. Ubuntu 22.04 +# e.g. docker run --rm -it -v $PWD:/work -w /work ubuntu:22.04 /bin/bash +# apt-get update && apt-get install -y --no-install-recommends build-essential +simple-dwarf5.elf: + gcc simple.c -g -gdwarf-5 -o simple-dwarf5.elf diff --git a/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf4.elf b/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf4.elf new file mode 100755 index 00000000000..021d2ab7ed1 Binary files /dev/null and b/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf4.elf differ diff --git a/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf5.elf b/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf5.elf new file mode 100755 index 00000000000..ee01be12478 Binary files /dev/null and b/core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf5.elf differ diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index c0e55984241..27b238fe1ac 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true -Bundle-Version: 8.0.0.qualifier +Bundle-Version: 8.0.100.qualifier Bundle-Activator: org.eclipse.cdt.core.CCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/Dwarf.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/Dwarf.java index 78fea6a9629..d6100e30597 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/Dwarf.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/Dwarf.java @@ -460,11 +460,22 @@ void parseDebugInfo(IDebugEntryRequestor requestor) { header.offsetSize = sectionLength.offsetSize; header.version = read_2_bytes(data); - if (header.offsetSize == 8) - header.abbreviationOffset = (int) read_8_bytes(data); - else - header.abbreviationOffset = read_4_bytes(data); - header.addressSize = data.get(); + if (header.version >= 5) { + // XXX: We don't use this new field in DWARF v5 yet + var unit_type = data.get(); + header.addressSize = data.get(); + + if (header.offsetSize == 8) + header.abbreviationOffset = (int) read_8_bytes(data); + else + header.abbreviationOffset = read_4_bytes(data); + } else { + if (header.offsetSize == 8) + header.abbreviationOffset = (int) read_8_bytes(data); + else + header.abbreviationOffset = read_4_bytes(data); + header.addressSize = data.get(); + } if (printEnabled) { System.out.println("Compilation Unit @ " + Long.toHexString(data.position())); //$NON-NLS-1$ @@ -476,10 +487,20 @@ void parseDebugInfo(IDebugEntryRequestor requestor) { // A 4-byte or 12-byte unsigned integer representing the length of the .debug_info // contribution for that compilation unit, not including the length field itself. ByteBuffer entryBuffer = data.slice(); - entryBuffer.limit(((int) header.length) - (header.offsetSize == 8 ? 11 : 7)); + int newLimit = ((int) header.length) - (header.offsetSize == 8 ? 11 : 7); + if (header.version >= 5) { + // account for new field in DWARF v5 + newLimit -= 1; + } + entryBuffer.limit(newLimit); parseDebugInfoEntry(requestor, entryBuffer, abbrevs, header); - data.position(data.position() + ((int) header.length) - (header.offsetSize == 8 ? 11 : 7)); + int newLimit2 = ((int) header.length) - (header.offsetSize == 8 ? 11 : 7); + if (header.version >= 5) { + // account for new field in DWARF v5 + newLimit2 -= 1; + } + data.position(data.position() + newLimit2); if (printEnabled) System.out.println();