Skip to content

Commit 6c53fd8

Browse files
committed
Support DWARF attribute form DW_FORM_strx1
1 parent 4f39107 commit 6c53fd8

File tree

5 files changed

+76
-45
lines changed

5 files changed

+76
-45
lines changed

core/org.eclipse.cdt.core/.settings/.api_filters

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<component id="org.eclipse.cdt.core" version="2">
3-
<resource path="utils/org/eclipse/cdt/utils/coff/Coff64.java" type="org.eclipse.cdt.utils.coff.Coff64$SectionHeader">
3+
<resource path="utils/org/eclipse/cdt/utils/debug/dwarf/DwarfConstants.java" type="org.eclipse.cdt.utils.debug.dwarf.DwarfConstants">
44
<filter id="336658481">
55
<message_arguments>
6-
<message_argument value="org.eclipse.cdt.utils.coff.Coff64.SectionHeader"/>
7-
<message_argument value="STYP_MEM_DISCARDABLE"/>
6+
<message_argument value="org.eclipse.cdt.utils.debug.dwarf.DwarfConstants"/>
7+
<message_argument value="DW_AT_str_offsets_base"/>
88
</message_arguments>
99
</filter>
1010
<filter id="336658481">
1111
<message_arguments>
12-
<message_argument value="org.eclipse.cdt.utils.coff.Coff64.SectionHeader"/>
13-
<message_argument value="STYP_MEM_WRITE"/>
14-
</message_arguments>
15-
</filter>
16-
</resource>
17-
<resource path="utils/org/eclipse/cdt/utils/coff/Coff64.java" type="org.eclipse.cdt.utils.coff.Coff64$Symbol">
18-
<filter id="336658481">
19-
<message_arguments>
20-
<message_argument value="org.eclipse.cdt.utils.coff.Coff64.Symbol"/>
21-
<message_argument value="SC_EXTERNAL"/>
22-
</message_arguments>
23-
</filter>
24-
</resource>
25-
<resource path="utils/org/eclipse/cdt/utils/elf/Elf.java" type="org.eclipse.cdt.utils.elf.Elf$ELFhdr">
26-
<filter id="336658481">
27-
<message_arguments>
28-
<message_argument value="org.eclipse.cdt.utils.elf.Elf.ELFhdr"/>
29-
<message_argument value="EM_AVR32"/>
12+
<message_argument value="org.eclipse.cdt.utils.debug.dwarf.DwarfConstants"/>
13+
<message_argument value="DW_FORM_data16"/>
3014
</message_arguments>
3115
</filter>
3216
<filter id="336658481">
3317
<message_arguments>
34-
<message_argument value="org.eclipse.cdt.utils.elf.Elf.ELFhdr"/>
35-
<message_argument value="EM_MICROBLAZE"/>
18+
<message_argument value="org.eclipse.cdt.utils.debug.dwarf.DwarfConstants"/>
19+
<message_argument value="DW_FORM_strx1"/>
3620
</message_arguments>
3721
</filter>
3822
<filter id="336658481">
3923
<message_arguments>
40-
<message_argument value="org.eclipse.cdt.utils.elf.Elf.ELFhdr"/>
41-
<message_argument value="EM_V800"/>
24+
<message_argument value="org.eclipse.cdt.utils.debug.dwarf.DwarfConstants"/>
25+
<message_argument value="DW_LNCT_MD5"/>
4226
</message_arguments>
4327
</filter>
4428
</resource>

core/org.eclipse.cdt.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
5-
Bundle-Version: 9.0.0.qualifier
5+
Bundle-Version: 9.1.0.qualifier
66
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/Dwarf.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 QNX Software Systems and others.
2+
* Copyright (c) 2000, 2025 QNX Software Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
1515
* John Dallaway - Support DW_FORM_line_strp (#198)
1616
* John Dallaway - Support DW_FORM_implicit_const (#443)
1717
* Alexander Fedorov (ArSysOp) - fix resource leak (#693)
18+
* John Dallaway - Support DW_FORM_strx1 (#1135)
1819
*******************************************************************************/
1920

2021
package org.eclipse.cdt.utils.debug.dwarf;
@@ -52,6 +53,7 @@ public class Dwarf implements AutoCloseable {
5253
final static String DWARF_DEBUG_LOC = ".debug_loc"; //$NON-NLS-1$
5354
final static String DWARF_DEBUG_PUBNAMES = ".debug_pubnames"; //$NON-NLS-1$
5455
final static String DWARF_DEBUG_STR = ".debug_str"; //$NON-NLS-1$
56+
final static String DWARF_DEBUG_STR_OFFSETS = ".debug_str_offsets"; //$NON-NLS-1$
5557
final static String DWARF_DEBUG_FUNCNAMES = ".debug_funcnames"; //$NON-NLS-1$
5658
final static String DWARF_DEBUG_TYPENAMES = ".debug_typenames"; //$NON-NLS-1$
5759
final static String DWARF_DEBUG_VARNAMES = ".debug_varnames"; //$NON-NLS-1$
@@ -797,6 +799,10 @@ Object readAttribute(int form, ByteBuffer in, CompilationUnitHeader header) thro
797799
}
798800
break;
799801

802+
case DwarfConstants.DW_FORM_strx1:
803+
obj = Integer.valueOf(Byte.toUnsignedInt(in.get()));
804+
break;
805+
800806
case DwarfConstants.DW_FORM_ref1:
801807
obj = Byte.valueOf(in.get());
802808
break;
@@ -859,7 +865,8 @@ Object readAttribute(int form, ByteBuffer in, CompilationUnitHeader header) thro
859865
return obj;
860866
}
861867

862-
void processDebugInfoEntry(IDebugEntryRequestor requestor, AbbreviationEntry entry, List<AttributeValue> list) {
868+
void processDebugInfoEntry(IDebugEntryRequestor requestor, AbbreviationEntry entry, List<AttributeValue> list)
869+
throws IOException {
863870
int len = list.size();
864871
int tag = (int) entry.tag;
865872
if (printEnabled)
@@ -1015,7 +1022,7 @@ void processSubProgram(IDebugEntryRequestor requestor, List<AttributeValue> list
10151022
requestor.exitFunction(highPC);
10161023
}
10171024

1018-
void processCompileUnit(IDebugEntryRequestor requestor, List<AttributeValue> list) {
1025+
void processCompileUnit(IDebugEntryRequestor requestor, List<AttributeValue> list) throws IOException {
10191026
if (currentCU != null) {
10201027
requestor.exitCompilationUnit(currentCU.highPC);
10211028
}

core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfConstants.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2023 QNX Software Systems and others.
2+
* Copyright (c) 2000, 2025 QNX Software Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -148,6 +148,8 @@ public class DwarfConstants {
148148
public final static int DW_AT_variable_parameter = 0x4b;
149149
public final static int DW_AT_virtuality = 0x4c;
150150
public final static int DW_AT_vtable_elem_location = 0x4d;
151+
/** @since 9.1 */
152+
public final static int DW_AT_str_offsets_base = 0x72;
151153
public final static int DW_AT_lo_user = 0x2000;
152154
public final static int DW_AT_MIPS_fde = 0x2001;
153155
public final static int DW_AT_MIPS_loop_begin = 0x2002;
@@ -209,6 +211,8 @@ public class DwarfConstants {
209211
* @since 5.7
210212
*/
211213
public final static int DW_FORM_flag_present = 0x19;
214+
/** @since 9.1 */
215+
public final static int DW_FORM_data16 = 0x1e;
212216
/**
213217
* @since 8.1
214218
*/
@@ -221,6 +225,8 @@ public class DwarfConstants {
221225
* @since 8.3
222226
*/
223227
public final static int DW_FORM_implicit_const = 0x21;
228+
/** @since 9.1 */
229+
public final static int DW_FORM_strx1 = 0x25;
224230
/* Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission. */
225231
/**
226232
* @since 5.7
@@ -250,6 +256,8 @@ public class DwarfConstants {
250256
* @since 8.3
251257
*/
252258
public final static int DW_LNCT_directory_index = 0x02; /* Index to directories entry */
259+
/** @since 9.1 */
260+
public final static int DW_LNCT_MD5 = 0x05; /* MD5 digest */
253261

254262
/* DWARF location operation encodings. */
255263
public final static int DW_OP_addr = 0x03; /* Constant address. */

core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2023 Nokia and others.
2+
* Copyright (c) 2007, 2025 Nokia and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,7 @@
1313
* Ling Wang (Nokia) bug 201000
1414
* Serge Beauchamp (Freescale Semiconductor) - Bug 421070
1515
* Red Hat Inc. - add debuginfo and macro section support
16-
* John Dallaway - support DWARF v5 content form data (#443)
16+
* John Dallaway - support DWARF v5 content form data (#443, #1135)
1717
*******************************************************************************/
1818

1919
package org.eclipse.cdt.utils.debug.dwarf;
@@ -37,6 +37,7 @@
3737
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
3838
import org.eclipse.cdt.utils.elf.Elf;
3939
import org.eclipse.cdt.utils.elf.Elf.Section;
40+
import org.eclipse.core.runtime.ILog;
4041
import org.eclipse.core.runtime.IPath;
4142
import org.eclipse.core.runtime.IProgressMonitor;
4243
import org.eclipse.core.runtime.Path;
@@ -50,7 +51,7 @@ public class DwarfReader extends Dwarf implements ISymbolReader, ICompileOptions
5051
// These are sections that need be parsed to get the source file list.
5152
final static String[] DWARF_SectionsToParse = { DWARF_DEBUG_INFO, DWARF_DEBUG_LINE, DWARF_DEBUG_ABBREV,
5253
DWARF_DEBUG_STR, // this is optional. Some compilers don't generate it.
53-
DWARF_DEBUG_MACRO, DWARF_DEBUG_LINE_STR };
54+
DWARF_DEBUG_MACRO, DWARF_DEBUG_LINE_STR, DWARF_DEBUG_STR_OFFSETS };
5455

5556
final static String[] DWARF_ALT_SectionsToParse = { DWARF_DEBUG_STR, DWARF_DEBUG_MACRO };
5657

@@ -368,8 +369,8 @@ private void addSourceFilesDwarf5(String cuCompDir, ByteBuffer data, byte offset
368369
data.get(dcf_count);
369370
List<ContentForm> directoryContentForms = new ArrayList<>();
370371
for (int fmt = 0; fmt < dcf_count[0]; fmt++) {
371-
ContentForm def = readContentForm(data);
372-
directoryContentForms.add(def);
372+
ContentForm dcf = readContentForm(data);
373+
directoryContentForms.add(dcf);
373374
}
374375

375376
// read directories
@@ -386,7 +387,10 @@ private void addSourceFilesDwarf5(String cuCompDir, ByteBuffer data, byte offset
386387
dir = new Path(cuCompDir).append(path);
387388
}
388389
directories.add(dir.toString());
389-
} // TODO: support other DW_LNCT_path forms
390+
} else {
391+
ILog.get().warn(String.format("DWARF directory content 0x%x form 0x%x not handled", //$NON-NLS-1$
392+
contentForm.lnct, contentForm.form));
393+
}
390394
}
391395
}
392396

@@ -395,8 +399,8 @@ private void addSourceFilesDwarf5(String cuCompDir, ByteBuffer data, byte offset
395399
data.get(fncf_count);
396400
List<ContentForm> fileNameContentForms = new ArrayList<>();
397401
for (int fmt = 0; fmt < fncf_count[0]; fmt++) {
398-
ContentForm fnef = readContentForm(data);
399-
fileNameContentForms.add(fnef);
402+
ContentForm fncf = readContentForm(data);
403+
fileNameContentForms.add(fncf);
400404
}
401405

402406
// read file names
@@ -409,12 +413,17 @@ private void addSourceFilesDwarf5(String cuCompDir, ByteBuffer data, byte offset
409413
&& (DwarfConstants.DW_LNCT_path == contentForm.lnct)) {
410414
long offset = readOffset(data, offsetSize);
411415
filename = getPathInLineStr(offset);
412-
} // TODO: support other DW_LNCT_path forms
413-
if ((DwarfConstants.DW_FORM_udata == contentForm.form)
416+
} else if ((DwarfConstants.DW_FORM_udata == contentForm.form)
414417
&& (DwarfConstants.DW_LNCT_directory_index == contentForm.lnct)) {
415418
long directory_index = read_unsigned_leb128(data);
416419
directory = directories.get((int) directory_index);
417-
} // TODO: support other DW_LNCT_directory_index forms
420+
} else if ((DwarfConstants.DW_FORM_data16 == contentForm.form)
421+
&& (DwarfConstants.DW_LNCT_MD5 == contentForm.lnct)) {
422+
data.get(new byte[16]); // skip MD5 digest
423+
} else {
424+
ILog.get().warn(String.format("DWARF file content 0x%x form 0x%x not handled", //$NON-NLS-1$
425+
contentForm.lnct, contentForm.form));
426+
}
418427
}
419428
if ((null != directory) && (null != filename)) {
420429
addSourceFile(directory, filename);
@@ -704,8 +713,8 @@ private String addSourceFile(String dir, String name) {
704713

705714
// Override parent: only handle TAG_Compile_Unit.
706715
@Override
707-
void processDebugInfoEntry(IDebugEntryRequestor requestor, AbbreviationEntry entry,
708-
List<Dwarf.AttributeValue> list) {
716+
void processDebugInfoEntry(IDebugEntryRequestor requestor, AbbreviationEntry entry, List<Dwarf.AttributeValue> list)
717+
throws IOException {
709718
int tag = (int) entry.tag;
710719
switch (tag) {
711720
case DwarfConstants.DW_TAG_compile_unit:
@@ -720,10 +729,14 @@ void processDebugInfoEntry(IDebugEntryRequestor requestor, AbbreviationEntry ent
720729
// Just get the file name of the CU.
721730
// Argument "requestor" is ignored.
722731
@Override
723-
void processCompileUnit(IDebugEntryRequestor requestor, List<AttributeValue> list) {
732+
void processCompileUnit(IDebugEntryRequestor requestor, List<AttributeValue> list) throws IOException {
724733

725734
String cuName, cuCompDir;
726735
int stmtList = -1;
736+
ByteBuffer strings = dwarfSections.get(DWARF_DEBUG_STR);
737+
ByteBuffer offsets = dwarfSections.get(DWARF_DEBUG_STR_OFFSETS);
738+
byte offsetSize = (offsets != null) ? readInitialLengthField(offsets).offsetSize : -1;
739+
long offsetsBase = -1L;
727740

728741
cuName = cuCompDir = ""; //$NON-NLS-1$
729742

@@ -736,11 +749,30 @@ void processCompileUnit(IDebugEntryRequestor requestor, List<AttributeValue> lis
736749
cuName = (String) av.value;
737750
break;
738751
case DwarfConstants.DW_AT_comp_dir:
739-
cuCompDir = (String) av.value;
752+
if ((av.attribute.form == DwarfConstants.DW_FORM_strp)
753+
|| (av.attribute.form == DwarfConstants.DW_FORM_line_strp)) {
754+
cuCompDir = (String) av.value;
755+
} else if ((av.attribute.form == DwarfConstants.DW_FORM_strx1) && (offsets != null)
756+
&& (offsetsBase != -1L)) {
757+
int index = ((Number) av.value).intValue();
758+
// read the pointer into .debug_str from .debug_str_offsets
759+
long offset = offsetsBase + (index * offsetSize);
760+
offsets.position((int) offset);
761+
long strp = readOffset(offsets, offsetSize);
762+
// read the string from .debug_str
763+
strings.position((int) strp);
764+
cuCompDir = readString(strings);
765+
} else {
766+
ILog.get().warn(String.format("DW_AT_comp_dir form 0x%x not handled", av.attribute.form)); //$NON-NLS-1$
767+
}
740768
break;
741769
case DwarfConstants.DW_AT_stmt_list:
742770
stmtList = ((Number) av.value).intValue();
743771
break;
772+
case DwarfConstants.DW_AT_str_offsets_base:
773+
// read the base of all offsets into .debug_str_offsets
774+
offsetsBase = (offsetSize == 8) ? ((Number) av.value).longValue() : ((Number) av.value).intValue();
775+
break;
744776
default:
745777
break;
746778
}

0 commit comments

Comments
 (0)