Skip to content

Commit 75a2a27

Browse files
committed
find all known targets of pointer types
1 parent 59ed1cb commit 75a2a27

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ private int writeStructField(DebugContext context, FieldEntry fieldEntry, byte[]
344344
pos = writeEmbeddedArrayDataType(context, foreignValueType, valueSize, fieldSize / valueSize, buffer, pos);
345345
} else {
346346
if (foreignValueType.isPointer()) {
347+
TypeEntry pointerTo = foreignValueType.getPointerTo();
348+
assert pointerTo != null : "ADDRESS field pointer type must have a known target type";
347349
// type the array using the referent of the pointer type
348350
//
349351
// n.b it is critical for correctness to use the index of the referent rather
@@ -355,7 +357,7 @@ private int writeStructField(DebugContext context, FieldEntry fieldEntry, byte[]
355357
// of the referring type and the latter precedes the definition of the
356358
// referent type then the layout index of the referring type may still be unset
357359
// at this point.
358-
valueTypeIdx = getTypeIndex(foreignValueType.getPointerTo());
360+
valueTypeIdx = getTypeIndex(pointerTo);
359361
} else {
360362
valueTypeIdx = getIndirectLayoutIndex(foreignValueType);
361363
}
@@ -1354,6 +1356,8 @@ private int writeEmbeddedArrayDataType(DebugContext context, ForeignTypeEntry fo
13541356
String elementTypeName = foreignValueType.getTypeName();
13551357
int elementTypeIdx;
13561358
if (foreignValueType.isPointer()) {
1359+
TypeEntry pointerTo = foreignValueType.getPointerTo();
1360+
assert pointerTo != null : "ADDRESS field pointer type must have a known target type";
13571361
// type the array using the referent of the pointer type
13581362
//
13591363
// n.b it is critical for correctness to use the index of the referent rather than
@@ -1363,7 +1367,7 @@ private int writeEmbeddedArrayDataType(DebugContext context, ForeignTypeEntry fo
13631367
// However, if this embedded struct field definition precedes the definition of the
13641368
// referring type and the latter precedes the definition of the referent type then
13651369
// the layout index of the referring type may still be unset at this point.
1366-
elementTypeIdx = getTypeIndex(foreignValueType.getPointerTo());
1370+
elementTypeIdx = getTypeIndex(pointerTo);
13671371
} else {
13681372
// type the array using the layout type
13691373
elementTypeIdx = getIndirectLayoutIndex(foreignValueType);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
import jdk.vm.ci.meta.Signature;
126126
import jdk.vm.ci.meta.Value;
127127
import org.graalvm.nativeimage.c.struct.CPointerTo;
128+
import org.graalvm.nativeimage.c.struct.RawPointerTo;
128129
import org.graalvm.word.WordBase;
129130

130131
/**
@@ -969,11 +970,18 @@ public ResolvedJavaType parent() {
969970
@Override
970971
public ResolvedJavaType pointerTo() {
971972
if (isPointer()) {
973+
// any target type for the pointer will be defined by a CPointerTo or RawPointerTo
974+
// annotation
972975
CPointerTo cPointerTo = hostedType.getAnnotation(CPointerTo.class);
973976
if (cPointerTo != null) {
974977
HostedType pointerTo = heap.hMetaAccess.lookupJavaType(cPointerTo.value());
975978
return getOriginal(pointerTo);
976979
}
980+
RawPointerTo rawPointerTo = hostedType.getAnnotation(RawPointerTo.class);
981+
if (rawPointerTo != null) {
982+
HostedType pointerTo = heap.hMetaAccess.lookupJavaType(rawPointerTo.value());
983+
return getOriginal(pointerTo);
984+
}
977985
}
978986
return null;
979987
}

0 commit comments

Comments
 (0)