Skip to content

Commit 9abb992

Browse files
committed
add debugInfo for MacOS
1 parent ac3547c commit 9abb992

22 files changed

+7432
-29
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/DwarfDebugInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ public byte getHeapbaseRegister() {
109109
return heapbaseRegister;
110110
}
111111

112+
@Override
113+
public boolean isAarch64() {
114+
return elfMachine == ELFMachine.AArch64;
115+
}
116+
117+
@Override
118+
public boolean isX86_64() {
119+
return elfMachine == ELFMachine.X86_64;
120+
}
121+
112122
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,7 @@ private DwarfTypeProperties addTypeProperties(TypeEntry typeEntry) {
607607

608608
public abstract byte getHeapbaseRegister();
609609

610+
public abstract boolean isAarch64();
611+
public abstract boolean isX86_64();
612+
610613
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfTag;
4949
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfVersion;
5050
import com.oracle.objectfile.debuginfo.dwarf.DwarfDebugInfoBase.AbbrevCode;
51-
import com.oracle.objectfile.elf.ELFMachine;
5251
import com.oracle.objectfile.elf.ELFObjectFile;
5352
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfExpressionOpcode;
5453
import com.oracle.objectfile.debuginfo.dwarf.constants.DwarfFlag;
@@ -135,7 +134,7 @@ public DwarfSectionImpl(DwarfDebugInfo dwarfSections, DwarfSectionName sectionNa
135134
}
136135

137136
public boolean isAArch64() {
138-
return dwarfSections.elfMachine == ELFMachine.AArch64;
137+
return dwarfSections.isAarch64();
139138
}
140139

141140
/**

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/dwarf/constants/DwarfSectionName.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
package com.oracle.objectfile.debuginfo.dwarf.constants;
2828

29+
import com.oracle.objectfile.macho.dsym.constants.DSYMSectionName;
30+
31+
import java.util.Arrays;
32+
import java.util.List;
33+
import java.util.stream.Collectors;
34+
2935
/**
3036
* Various ELF sections created by GraalVM including all debug info sections. The enum sequence
3137
* starts with the text section (not defined in the DWARF spec and not created by debug info code).
@@ -50,4 +56,6 @@ public enum DwarfSectionName {
5056
public String value() {
5157
return value;
5258
}
59+
60+
public static final List<String> debugSections = Arrays.stream(DSYMSectionName.values()).filter(e -> e != DSYMSectionName.TEXT_SECTION).map(e -> e.value()).collect(Collectors.toList());
5361
}

0 commit comments

Comments
 (0)