Skip to content

Commit c78b623

Browse files
committed
add debugInfo for MacOS
1 parent b7f9fdc commit c78b623

22 files changed

+642
-113
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/ObjectFile.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -528,15 +528,19 @@ public Section newUserDefinedSection(String name, ElementImpl impl) {
528528
return result;
529529
}
530530

531-
public Section newDebugSection(String name, ElementImpl impl) {
532-
final Segment segment = getOrCreateSegment(null, name, false, false);
531+
public Section newDebugSection(String segmentName, String name, ElementImpl impl) {
532+
final Segment segment = getOrCreateSegment(segmentName, name, false, false);
533533
final int alignment = 1; // debugging information is mostly unaligned; padding can result in
534534
// corrupted data when the linker merges multiple debugging
535535
// sections from different inputs
536536
final Section result = newUserDefinedSection(segment, name, alignment, impl);
537537
return result;
538538
}
539539

540+
public Section newDebugSection(String name, ElementImpl impl) {
541+
return newDebugSection(null, name, impl);
542+
}
543+
540544
// Convenience that does not specify a segment name.
541545
public Section newProgbitsSection(String name, int alignment, boolean writable, boolean executable, ProgbitsSectionImpl impl) {
542546
assert impl != null;
@@ -1172,6 +1176,10 @@ public void installDebugInfo(@SuppressWarnings("unused") DebugInfoProvider debug
11721176
// do nothing by default
11731177
}
11741178

1179+
public List<String> getDebugSectionNames() {
1180+
return Collections.emptyList();
1181+
}
1182+
11751183
protected static Iterable<LayoutDecision> allDecisions(final Map<Element, LayoutDecisionMap> decisions) {
11761184
return () -> StreamSupport.stream(decisions.values().spliterator(), false)
11771185
.flatMap(layoutDecisionMap -> StreamSupport.stream(layoutDecisionMap.spliterator(), false)).iterator();
@@ -1289,7 +1297,7 @@ public Element getOffsetBootstrapElement() {
12891297

12901298
private final HashSet<LayoutDecision> allDecisions = new HashSet<>();
12911299
private final Map<Element, LayoutDecisionMap> decisionsByElement = new IdentityHashMap<>();
1292-
private final Map<Element, LayoutDecisionMap> decisionsTaken = new IdentityHashMap<>();
1300+
public final Map<Element, LayoutDecisionMap> decisionsTaken = new IdentityHashMap<>();
12931301

12941302
private final Map<Element, List<BuildDependency>> dependenciesByDependingElement = new IdentityHashMap<>();
12951303
private final Map<Element, List<BuildDependency>> dependenciesByDependedOnElement = new IdentityHashMap<>();
@@ -1303,7 +1311,7 @@ public void write(DebugContext context, Path outputFile) throws IOException {
13031311
}
13041312

13051313
@SuppressWarnings("try")
1306-
public final void write(FileChannel outputChannel) {
1314+
public List<Element> write(FileChannel outputChannel) {
13071315
List<Element> sortedObjectFileElements = new ArrayList<>();
13081316
int totalSize = bake(sortedObjectFileElements);
13091317
try {
@@ -1317,6 +1325,7 @@ public final void write(FileChannel outputChannel) {
13171325
} catch (IOException e) {
13181326
throw new RuntimeException(e);
13191327
}
1328+
return sortedObjectFileElements;
13201329
}
13211330

13221331
/*
@@ -1861,4 +1870,8 @@ public void debugContext(String scopeName, Consumer<DebugContext> action) {
18611870
throw debugContext.handle(e);
18621871
}
18631872
}
1873+
1874+
public long getCodeBaseAddress() {
1875+
return 0;
1876+
}
18641877
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/DebugInfoBase.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,17 @@ public int compiledCodeMax() {
223223
return compiledCodeMax;
224224
}
225225

226+
public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
227+
installDebugInfo(debugInfoProvider, 0);
228+
}
229+
226230
/**
227231
* Entry point allowing ELFObjectFile to pass on information about types, code and heap data.
228232
*
229233
* @param debugInfoProvider provider instance passed by ObjectFile client.
230234
*/
231235
@SuppressWarnings("try")
232-
public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
236+
public void installDebugInfo(DebugInfoProvider debugInfoProvider, long debugAddressOffset) {
233237
/*
234238
* This will be needed once we add support for type info:
235239
*
@@ -332,7 +336,7 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
332336
/* Search for a method defining this primary range. */
333337
ClassEntry classEntry = lookupClassEntry(ownerType);
334338
MethodEntry methodEntry = classEntry.ensureMethodEntryForDebugRangeInfo(debugCodeInfo, this, debugContext);
335-
PrimaryRange primaryRange = Range.createPrimary(methodEntry, lo, hi, primaryLine);
339+
PrimaryRange primaryRange = Range.createPrimary(methodEntry, lo + debugAddressOffset, hi + debugAddressOffset, primaryLine);
336340
if (debugContext.isLogEnabled(DebugContext.INFO_LEVEL)) {
337341
debugContext.log(DebugContext.INFO_LEVEL, "PrimaryRange %s.%s %s %s:%d [0x%x, 0x%x]", ownerType.toJavaName(), methodName, filePath, fileName, primaryLine, lo, hi);
338342
}
@@ -780,7 +784,7 @@ private static void collectFilesAndDirs(ClassEntry classEntry) {
780784
/**
781785
* Ensure the supplied file entry and associated directory entry are included, but only once, in
782786
* a class entry's file and dir list.
783-
*
787+
*
784788
* @param classEntry the class entry whose file and dir list may need to be updated
785789
* @param fileEntry a file entry which may need to be added to the class entry's file list or
786790
* whose dir may need adding to the class entry's dir list

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfARangesSectionImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Map;
3030

3131
import com.oracle.objectfile.debugentry.ClassEntry;
32-
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfSectionName;
3332
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfVersion;
3433
import jdk.graal.compiler.debug.DebugContext;
3534

@@ -47,8 +46,8 @@ public class DwarfARangesSectionImpl extends DwarfSectionImpl {
4746
private static final int AR_HEADER_SIZE = 12;
4847
private static final int AR_HEADER_PAD_SIZE = 4;
4948

50-
public DwarfARangesSectionImpl(DwarfDebugInfo dwarfSections) {
51-
super(dwarfSections, DwarfSectionName.DW_ARANGES_SECTION, DwarfSectionName.DW_FRAME_SECTION);
49+
public DwarfARangesSectionImpl(DwarfDebugInfoBase dwarfSections) {
50+
super(dwarfSections, dwarfSections.arangesSectionName(), dwarfSections.frameSectionName());
5251
}
5352

5453
@Override
@@ -113,7 +112,7 @@ private static int entrySize(int methodCount) {
113112

114113
@Override
115114
public byte[] getOrDecideContent(Map<ObjectFile.Element, LayoutDecisionMap> alreadyDecided, byte[] contentHint) {
116-
ObjectFile.Element textElement = getElement().getOwner().elementForName(".text");
115+
ObjectFile.Element textElement = getElement().getOwner().elementForName(dwarfSections.textSectionName().value());
117116
LayoutDecisionMap decisionMap = alreadyDecided.get(textElement);
118117
if (decisionMap != null) {
119118
Object valueObj = decisionMap.getDecidedValue(LayoutDecision.Kind.VADDR);

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfAbbrevSectionImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfAttribute;
3030
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfForm;
31-
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfSectionName;
3231
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfTag;
3332
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfHasChildren;
3433
import com.oracle.objectfile.debuginfo.dwarf.DwarfDebugInfoBase.AbbrevCode;
@@ -832,9 +831,9 @@
832831
*/
833832
public class DwarfAbbrevSectionImpl extends DwarfSectionImpl {
834833

835-
public DwarfAbbrevSectionImpl(DwarfDebugInfo dwarfSections) {
834+
public DwarfAbbrevSectionImpl(DwarfDebugInfoBase dwarfSections) {
836835
// abbrev section depends on ranges section
837-
super(dwarfSections, DwarfSectionName.DW_ABBREV_SECTION, DwarfSectionName.DW_RANGES_SECTION);
836+
super(dwarfSections, dwarfSections.abbrevSectionName(), dwarfSections.rangesSectionName());
838837
}
839838

840839
@Override

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfDebugInfo.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.nio.ByteOrder;
3030

31+
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfSectionNameBase;
3132
import com.oracle.objectfile.elf.ELFMachine;
3233

3334
/**
@@ -109,4 +110,85 @@ public byte getHeapbaseRegister() {
109110
return heapbaseRegister;
110111
}
111112

113+
@Override
114+
public boolean isAarch64() {
115+
return elfMachine == ELFMachine.AArch64;
116+
}
117+
118+
@Override
119+
public boolean isAMD64() {
120+
return elfMachine == ELFMachine.X86_64;
121+
}
122+
123+
@Override
124+
public DwarfSectionNameBase textSectionName() {
125+
return DwarfSectionName.TEXT_SECTION;
126+
}
127+
128+
@Override
129+
public DwarfSectionNameBase lineSectionName() {
130+
return DwarfSectionName.DW_LINE_SECTION;
131+
}
132+
133+
@Override
134+
public DwarfSectionNameBase strSectionName() {
135+
return DwarfSectionName.DW_STR_SECTION;
136+
}
137+
138+
@Override
139+
public DwarfSectionNameBase locSectionName() {
140+
return DwarfSectionName.DW_LOC_SECTION;
141+
}
142+
143+
@Override
144+
public DwarfSectionNameBase rangesSectionName() {
145+
return DwarfSectionName.DW_RANGES_SECTION;
146+
}
147+
148+
@Override
149+
public DwarfSectionNameBase arangesSectionName() {
150+
return DwarfSectionName.DW_ARANGES_SECTION;
151+
}
152+
153+
@Override
154+
public DwarfSectionNameBase frameSectionName() {
155+
return DwarfSectionName.DW_FRAME_SECTION;
156+
}
157+
158+
@Override
159+
public DwarfSectionNameBase abbrevSectionName() {
160+
return DwarfSectionName.DW_ABBREV_SECTION;
161+
}
162+
163+
@Override
164+
public DwarfSectionNameBase infoSectionName() {
165+
return DwarfSectionName.DW_INFO_SECTION;
166+
}
167+
168+
/**
169+
* Various ELF sections created by GraalVM including all debug info sections. The enum sequence
170+
* starts with the text section (not defined in the DWARF spec and not created by debug info
171+
* code).
172+
*/
173+
enum DwarfSectionName implements DwarfSectionNameBase {
174+
TEXT_SECTION(".text"),
175+
DW_STR_SECTION(".debug_str"),
176+
DW_LINE_SECTION(".debug_line"),
177+
DW_FRAME_SECTION(".debug_frame"),
178+
DW_ABBREV_SECTION(".debug_abbrev"),
179+
DW_INFO_SECTION(".debug_info"),
180+
DW_LOC_SECTION(".debug_loc"),
181+
DW_ARANGES_SECTION(".debug_aranges"),
182+
DW_RANGES_SECTION(".debug_ranges");
183+
184+
private final String value;
185+
186+
DwarfSectionName(String s) {
187+
value = s;
188+
}
189+
190+
public String value() {
191+
return value;
192+
}
193+
}
112194
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfDebugInfoBase.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.oracle.objectfile.debugentry.range.Range;
3636
import com.oracle.objectfile.debuginfo.DebugInfoProvider;
3737
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfLanguage;
38+
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfSectionNameBase;
3839
import org.graalvm.collections.EconomicMap;
3940

4041
import java.nio.ByteOrder;
@@ -607,4 +608,42 @@ private DwarfTypeProperties addTypeProperties(TypeEntry typeEntry) {
607608

608609
public abstract byte getHeapbaseRegister();
609610

611+
public abstract boolean isAarch64();
612+
613+
public abstract boolean isAMD64();
614+
615+
public abstract DwarfSectionNameBase textSectionName();
616+
617+
public abstract DwarfSectionNameBase lineSectionName();
618+
619+
public abstract DwarfSectionNameBase strSectionName();
620+
621+
public abstract DwarfSectionNameBase locSectionName();
622+
623+
public abstract DwarfSectionNameBase rangesSectionName();
624+
625+
public abstract DwarfSectionNameBase arangesSectionName();
626+
627+
public abstract DwarfSectionNameBase frameSectionName();
628+
629+
public abstract DwarfSectionNameBase abbrevSectionName();
630+
631+
public abstract DwarfSectionNameBase infoSectionName();
632+
633+
public boolean layoutDependsOnVaddr() {
634+
return false;
635+
}
636+
637+
public boolean isDebugSectionName(String name) {
638+
return name.startsWith(".debug");
639+
}
640+
641+
public long relocatableLong(long l) {
642+
return 0l;
643+
}
644+
645+
public int relocatableInt(int l) {
646+
return 0;
647+
}
648+
610649
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfFrameSectionImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.oracle.objectfile.debugentry.range.Range;
3131
import com.oracle.objectfile.debuginfo.DebugInfoProvider;
3232
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfFrameValue;
33-
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfSectionName;
3433
import jdk.graal.compiler.debug.DebugContext;
3534

3635
import java.util.List;
@@ -44,9 +43,9 @@ public abstract class DwarfFrameSectionImpl extends DwarfSectionImpl {
4443

4544
private static final int CFA_CIE_id_default = -1;
4645

47-
public DwarfFrameSectionImpl(DwarfDebugInfo dwarfSections) {
46+
public DwarfFrameSectionImpl(DwarfDebugInfoBase dwarfSections) {
4847
// debug_frame section depends on debug_line section
49-
super(dwarfSections, DwarfSectionName.DW_FRAME_SECTION, DwarfSectionName.DW_LINE_SECTION);
48+
super(dwarfSections, dwarfSections.frameSectionName(), dwarfSections.lineSectionName());
5049
}
5150

5251
@Override

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfFrameSectionImplAArch64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class DwarfFrameSectionImplAArch64 extends DwarfFrameSectionImpl {
4040
private static final int CFA_SP_IDX = 31;
4141
@SuppressWarnings("unused") private static final int CFA_PC_IDX = 32;
4242

43-
public DwarfFrameSectionImplAArch64(DwarfDebugInfo dwarfSections) {
43+
public DwarfFrameSectionImplAArch64(DwarfDebugInfoBase dwarfSections) {
4444
super(dwarfSections);
4545
}
4646

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfFrameSectionImplX86_64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class DwarfFrameSectionImplX86_64 extends DwarfFrameSectionImpl {
3838
private static final int CFA_RSP_IDX = 7;
3939
private static final int CFA_RIP_IDX = 16;
4040

41-
public DwarfFrameSectionImplX86_64(DwarfDebugInfo dwarfSections) {
41+
public DwarfFrameSectionImplX86_64(DwarfDebugInfoBase dwarfSections) {
4242
super(dwarfSections);
4343
}
4444

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/DwarfInfoSectionImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfFlag;
4040
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfInline;
4141
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfLanguage;
42-
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfSectionName;
4342
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfVersion;
4443
import com.oracle.objectfile.debuginfo.dwarf.DwarfDebugInfoBase.AbbrevCode;
4544
import org.graalvm.collections.EconomicSet;
@@ -90,9 +89,9 @@ public class DwarfInfoSectionImpl extends DwarfSectionImpl {
9089
private int voidOffset;
9190
private int cuStart;
9291

93-
public DwarfInfoSectionImpl(DwarfDebugInfo dwarfSections) {
92+
public DwarfInfoSectionImpl(DwarfDebugInfoBase dwarfSections) {
9493
// debug_info section depends on loc section
95-
super(dwarfSections, DwarfSectionName.DW_INFO_SECTION, DwarfSectionName.DW_LOC_SECTION);
94+
super(dwarfSections, dwarfSections.infoSectionName(), dwarfSections.locSectionName());
9695
// initialize to an invalid value
9796
voidOffset = -1;
9897
// initialize CU start to an invalid value
@@ -399,8 +398,8 @@ private int writeInstanceClassInfo(DebugContext context, ClassEntry classEntry,
399398
if (name == null) {
400399
name = classEntry.getTypeName().replace('.', '/') + ".java";
401400
}
402-
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(name), name);
403401
pos = writeStrSectionOffset(uniqueDebugString(name), buffer, pos);
402+
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(name), name);
404403
String compilationDirectory = dwarfSections.getCachePath();
405404
log(context, " [0x%08x] comp_dir 0x%x (%s)", pos, debugStringIndex(compilationDirectory), compilationDirectory);
406405
pos = writeStrSectionOffset(compilationDirectory, buffer, pos);

0 commit comments

Comments
 (0)