From 1c7aa967a0cff9b1eba4620e80d4b40749ea29e0 Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Sat, 14 Jan 2023 16:18:04 +0000 Subject: [PATCH] Add support for DW_FORM_line_strp --- .../resources/elf/unit_test/simple-dwarf4.elf | Bin .../resources/elf/unit_test/simple-dwarf5.elf | Bin .../.settings/.api_filters | 11 +++++++ .../eclipse/cdt/utils/debug/dwarf/Dwarf.java | 31 +++++++++++++++++- .../cdt/utils/debug/dwarf/DwarfConstants.java | 7 +++- .../cdt/utils/debug/dwarf/DwarfReader.java | 7 ++-- 6 files changed, 52 insertions(+), 4 deletions(-) mode change 100755 => 100644 core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf4.elf mode change 100755 => 100644 core/org.eclipse.cdt.core.tests/resources/elf/unit_test/simple-dwarf5.elf create mode 100644 core/org.eclipse.cdt.core/.settings/.api_filters 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 diff --git a/core/org.eclipse.cdt.core/.settings/.api_filters b/core/org.eclipse.cdt.core/.settings/.api_filters new file mode 100644 index 00000000000..dda81c3a1bc --- /dev/null +++ b/core/org.eclipse.cdt.core/.settings/.api_filters @@ -0,0 +1,11 @@ + + + + + + + + + + + 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 d6100e30597..8750f348af2 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 QNX Software Systems and others. + * Copyright (c) 2000, 2023 QNX Software Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,6 +12,7 @@ * QNX Software Systems - Initial API and implementation * Salvatore Culcasi - Bug 322475 * Serge Beauchamp - Bug 409916 + * John Dallaway - Support DW_FORM_line_strp (#198) *******************************************************************************/ package org.eclipse.cdt.utils.debug.dwarf; @@ -56,6 +57,7 @@ public class Dwarf implements AutoCloseable { final static String DWARF_DEBUG_MACINFO = ".debug_macinfo"; //$NON-NLS-1$ final static String DWARF_DEBUG_MACRO = ".debug_macro"; //$NON-NLS-1$ final static String DWARF_DEBUG_TYPES = ".debug_types"; //$NON-NLS-1$ + final static String DWARF_DEBUG_LINE_STR = ".debug_line_str"; //$NON-NLS-1$ final static String DWARF_GNU_DEBUGLINK = ".gnu_debuglink"; //$NON-NLS-1$ final static String DWARF_GNU_DEBUGALTLINK = ".gnu_debugaltlink"; //$NON-NLS-1$ @@ -724,6 +726,33 @@ Object readAttribute(int form, ByteBuffer in, CompilationUnitHeader header) thro } break; + case DwarfConstants.DW_FORM_line_strp: { + long offset; + if (header.offsetSize == 8) + offset = read_8_bytes(in); + else + offset = read_4_bytes(in) & 0xffffffffL; + + ByteBuffer data = dwarfSections.get(DWARF_DEBUG_LINE_STR); + if (data == null) { + obj = ""; //$NON-NLS-1$ + } else if (offset < 0 || offset > data.capacity()) { + obj = ""; //$NON-NLS-1$ + } else { + StringBuilder sb = new StringBuilder(); + data.position((int) offset); + while (data.hasRemaining()) { + byte c = data.get(); + if (c == 0) { + break; + } + sb.append((char) c); + } + obj = sb.toString(); + } + } + break; + case DwarfConstants.DW_FORM_GNU_strp_alt: { long offset; if (header.offsetSize == 8) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfConstants.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfConstants.java index 673e5bb8882..f38a8c80106 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfConstants.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 QNX Software Systems and others. + * Copyright (c) 2000, 2023 QNX Software Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * John Dallaway - Add DW_FORM_line_strp (#198) *******************************************************************************/ package org.eclipse.cdt.utils.debug.dwarf; @@ -207,6 +208,10 @@ public class DwarfConstants { * @since 5.7 */ public final static int DW_FORM_flag_present = 0x19; + /** + * @since 8.0 + */ + public final static int DW_FORM_line_strp = 0x1f; /** * @since 5.7 */ diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java index d040fbe1112..7eb90327d5e 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2019 Nokia and others. + * Copyright (c) 2007, 2023 Nokia and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -49,7 +49,7 @@ public class DwarfReader extends Dwarf implements ISymbolReader, ICompileOptions // These are sections that need be parsed to get the source file list. final static String[] DWARF_SectionsToParse = { DWARF_DEBUG_INFO, DWARF_DEBUG_LINE, DWARF_DEBUG_ABBREV, DWARF_DEBUG_STR, // this is optional. Some compilers don't generate it. - DWARF_DEBUG_MACRO, }; + DWARF_DEBUG_MACRO, DWARF_DEBUG_LINE_STR }; final static String[] DWARF_ALT_SectionsToParse = { DWARF_DEBUG_STR, DWARF_DEBUG_MACRO }; @@ -335,6 +335,9 @@ void parseSourceInCULineInfo(String cuCompDir, // compilation directory of the C short version = read_2_bytes(data); // Skip the following till "opcode_base" short skip_bytes = 8; + if (version >= 5) { + skip_bytes += 2; // see address_size and segment_selector_size + } if (version >= 4) skip_bytes += 1; // see maximum_operations_per_instruction if (dwarf64Bit)