Skip to content

Commit 09dd697

Browse files
committed
add debuginfo for MacOS
1 parent 726a45d commit 09dd697

22 files changed

+1280
-671
lines changed

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

Lines changed: 20 additions & 3 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
@@ -529,7 +529,11 @@ public Section newUserDefinedSection(String name, ElementImpl impl) {
529529
}
530530

531531
public Section newDebugSection(String name, ElementImpl impl) {
532-
final Segment segment = getOrCreateSegment(null, name, false, false);
532+
return newDebugSection(null, name, impl);
533+
}
534+
535+
public Section newDebugSection(String segmentName, String name, ElementImpl impl) {
536+
final Segment segment = getOrCreateSegment(segmentName, name, false, false);
533537
final int alignment = 1; // debugging information is mostly unaligned; padding can result in
534538
// corrupted data when the linker merges multiple debugging
535539
// sections from different inputs
@@ -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();
@@ -1294,6 +1302,10 @@ public Element getOffsetBootstrapElement() {
12941302
private final Map<Element, List<BuildDependency>> dependenciesByDependingElement = new IdentityHashMap<>();
12951303
private final Map<Element, List<BuildDependency>> dependenciesByDependedOnElement = new IdentityHashMap<>();
12961304

1305+
protected Object getLayoutDecisionValue(Element e, LayoutDecision.Kind k) {
1306+
return decisionsTaken.get(e).getDecidedValue(k);
1307+
}
1308+
12971309
public void write(DebugContext context, Path outputFile) throws IOException {
12981310
try (FileChannel channel = FileChannel.open(outputFile, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) {
12991311
withDebugContext(context, "ObjectFile.write", () -> {
@@ -1303,7 +1315,7 @@ public void write(DebugContext context, Path outputFile) throws IOException {
13031315
}
13041316

13051317
@SuppressWarnings("try")
1306-
public final void write(FileChannel outputChannel) {
1318+
public List<Element> write(FileChannel outputChannel) {
13071319
List<Element> sortedObjectFileElements = new ArrayList<>();
13081320
int totalSize = bake(sortedObjectFileElements);
13091321
try {
@@ -1317,6 +1329,7 @@ public final void write(FileChannel outputChannel) {
13171329
} catch (IOException e) {
13181330
throw new RuntimeException(e);
13191331
}
1332+
return sortedObjectFileElements;
13201333
}
13211334

13221335
/*
@@ -1861,4 +1874,8 @@ public void debugContext(String scopeName, Consumer<DebugContext> action) {
18611874
throw debugContext.handle(e);
18621875
}
18631876
}
1877+
1878+
public long getCodeBaseAddress() {
1879+
return 0;
1880+
}
18641881
}

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugLocalValueInfo;
4848
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugLocationInfo;
4949
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo.DebugTypeKind;
50-
import com.oracle.objectfile.dwarf.DwarfDebugInfo;
5150

5251
import jdk.vm.ci.meta.ResolvedJavaType;
5352

@@ -88,6 +87,11 @@
8887
* units.
8988
*/
9089
public abstract class DebugInfoBase {
90+
/*
91+
* The name of the type for header field hub which needs special case processing to remove tag
92+
* bits
93+
*/
94+
public static final String HUB_TYPE_NAME = "java.lang.Class";
9195
protected ByteOrder byteOrder;
9296
/**
9397
* A table listing all known strings, some of which may be marked for insertion into the
@@ -223,13 +227,17 @@ public int compiledCodeMax() {
223227
return compiledCodeMax;
224228
}
225229

230+
public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
231+
installDebugInfo(debugInfoProvider, 0);
232+
}
233+
226234
/**
227235
* Entry point allowing ELFObjectFile to pass on information about types, code and heap data.
228236
*
229237
* @param debugInfoProvider provider instance passed by ObjectFile client.
230238
*/
231239
@SuppressWarnings("try")
232-
public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
240+
public void installDebugInfo(DebugInfoProvider debugInfoProvider, long debugAddressOffset) {
233241
/*
234242
* This will be needed once we add support for type info:
235243
*
@@ -332,7 +340,7 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
332340
/* Search for a method defining this primary range. */
333341
ClassEntry classEntry = lookupClassEntry(ownerType);
334342
MethodEntry methodEntry = classEntry.ensureMethodEntryForDebugRangeInfo(debugCodeInfo, this, debugContext);
335-
PrimaryRange primaryRange = Range.createPrimary(methodEntry, lo, hi, primaryLine);
343+
PrimaryRange primaryRange = Range.createPrimary(methodEntry, lo + debugAddressOffset, hi + debugAddressOffset, primaryLine);
336344
if (debugContext.isLogEnabled(DebugContext.INFO_LEVEL)) {
337345
debugContext.log(DebugContext.INFO_LEVEL, "PrimaryRange %s.%s %s %s:%d [0x%x, 0x%x]", ownerType.toJavaName(), methodName, filePath, fileName, primaryLine, lo, hi);
338346
}
@@ -369,7 +377,7 @@ private TypeEntry createTypeEntry(String typeName, String fileName, Path filePat
369377
case INSTANCE: {
370378
FileEntry fileEntry = addFileEntry(fileName, filePath);
371379
typeEntry = new ClassEntry(typeName, fileEntry, size);
372-
if (typeEntry.getTypeName().equals(DwarfDebugInfo.HUB_TYPE_NAME)) {
380+
if (typeEntry.getTypeName().equals(HUB_TYPE_NAME)) {
373381
hubClassEntry = (ClassEntry) typeEntry;
374382
}
375383
break;
@@ -735,7 +743,7 @@ public String getCachePath() {
735743
}
736744

737745
public boolean isHubClassEntry(ClassEntry classEntry) {
738-
return classEntry.getTypeName().equals(DwarfDebugInfo.HUB_TYPE_NAME);
746+
return classEntry.getTypeName().equals(HUB_TYPE_NAME);
739747
}
740748

741749
public ClassEntry getHubClassEntry() {
@@ -780,7 +788,7 @@ private static void collectFilesAndDirs(ClassEntry classEntry) {
780788
/**
781789
* Ensure the supplied file entry and associated directory entry are included, but only once, in
782790
* a class entry's file and dir list.
783-
*
791+
*
784792
* @param classEntry the class entry whose file and dir list may need to be updated
785793
* @param fileEntry a file entry which may need to be added to the class entry's file list or
786794
* whose dir may need adding to the class entry's dir list

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@
2828

2929
import java.util.Map;
3030

31-
import com.oracle.objectfile.debugentry.ClassEntry;
32-
import com.oracle.objectfile.dwarf.constants.DwarfSectionName;
33-
import com.oracle.objectfile.dwarf.constants.DwarfVersion;
3431
import jdk.graal.compiler.debug.DebugContext;
3532

33+
import com.oracle.objectfile.debugentry.ClassEntry;
34+
import com.oracle.objectfile.debugentry.CompiledMethodEntry;
35+
import com.oracle.objectfile.debugentry.range.Range;
36+
import com.oracle.objectfile.dwarf.constants.DwarfVersion;
3637
import com.oracle.objectfile.LayoutDecision;
3738
import com.oracle.objectfile.LayoutDecisionMap;
3839
import com.oracle.objectfile.ObjectFile;
39-
import com.oracle.objectfile.debugentry.CompiledMethodEntry;
40-
import com.oracle.objectfile.debugentry.range.Range;
4140

4241
/**
4342
* Section generator for debug_aranges section.
@@ -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/dwarf/DwarfAbbrevSectionImpl.java

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

2727
package com.oracle.objectfile.dwarf;
2828

29+
import com.oracle.objectfile.dwarf.constants.DwarfAttribute;
2930
import com.oracle.objectfile.dwarf.constants.DwarfForm;
30-
import com.oracle.objectfile.dwarf.constants.DwarfHasChildren;
31-
import com.oracle.objectfile.dwarf.constants.DwarfSectionName;
3231
import com.oracle.objectfile.dwarf.constants.DwarfTag;
33-
import com.oracle.objectfile.dwarf.constants.DwarfAttribute;
32+
import com.oracle.objectfile.dwarf.constants.DwarfHasChildren;
33+
import com.oracle.objectfile.dwarf.DwarfDebugInfoBase.AbbrevCode;
3434
import jdk.graal.compiler.debug.DebugContext;
35-
import com.oracle.objectfile.dwarf.DwarfDebugInfo.AbbrevCode;
3635

3736
/**
3837
* Section generator for <code>debug_abbrev</code> section. That section defines the layout of the
@@ -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

0 commit comments

Comments
 (0)