diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/DebugInfoProvider.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/DebugInfoProvider.java index b7af9cc7f695..36ad53fb7126 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/DebugInfoProvider.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/DebugInfoProvider.java @@ -82,8 +82,10 @@ interface DebugFileInfo { Path filePath(); /** - * @return a relative path to the source cache containing the cached source file of a file - * element or {@code null} if sources are not available. + * @return the path to the source cache containing the cached source file of a file element + * or {@code null} if sources are not available. Relative paths to the target + * directory are preferred over absolute paths, to make it easier to move the binary + * and the cache directory around. */ Path cachePath(); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index cd99fbebf10f..a6e7da9c6356 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -476,7 +476,13 @@ public static void defaultDebugInfoValueUpdateHandler(EconomicMap, @Option(help = "Directory under which to create source file cache for Application or GraalVM classes")// public static final HostedOptionKey DebugInfoSourceCacheRoot = new HostedOptionKey<>("sources"); - public static Path getDebugInfoSourceCacheRoot() { + /** + * Returns {@link SubstrateOptions#DebugInfoSourceCacheRoot} as an absolute path, by resolving + * it on {@link SubstrateOptions#Path} if it's not already an absolute path. + * + * @return the source cache root as an absolute path + */ + public static Path getDebugInfoSourceCacheRootAsAbsolutePath() { try { return Paths.get(Path.getValue()).resolve(DebugInfoSourceCacheRoot.getValue()); } catch (InvalidPathException ipe) { @@ -484,6 +490,14 @@ public static Path getDebugInfoSourceCacheRoot() { } } + public static Path getDebugInfoSourceCacheRoot() { + try { + return Paths.get(DebugInfoSourceCacheRoot.getValue()); + } catch (InvalidPathException ipe) { + throw UserError.abort("Invalid path provided for option DebugInfoSourceCacheRoot %s", DebugInfoSourceCacheRoot.getValue()); + } + } + @Option(help = "Omit generation of DebugLineInfo originating from inlined methods") // public static final HostedOptionKey OmitInlinedMethodDebugLineInfo = new HostedOptionKey<>(true); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java index 4997385e88af..a661d9ac466e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java @@ -87,6 +87,7 @@ class NativeImageDebugInfoProvider implements DebugInfoProvider { private final DebugContext debugContext; private final NativeImageCodeCache codeCache; + private final Path cachePath; @SuppressWarnings("unused") private final NativeImageHeap heap; boolean useHeapBase; int compressShift; @@ -101,6 +102,7 @@ class NativeImageDebugInfoProvider implements DebugInfoProvider { super(); this.debugContext = debugContext; this.codeCache = codeCache; + this.cachePath = SubstrateOptions.getDebugInfoSourceCacheRoot(); this.heap = heap; ObjectHeader objectHeader = Heap.getHeap().getObjectHeader(); ObjectInfo primitiveFields = heap.getObjectInfo(StaticFieldsSupport.getStaticPrimitiveFields()); @@ -236,8 +238,6 @@ private static String toJavaName(JavaType javaType) { return javaType.toJavaName(); } - private final Path cachePath = SubstrateOptions.getDebugInfoSourceCacheRoot(); - private abstract class NativeImageDebugFileInfo implements DebugFileInfo { private Path fullFilePath; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java index daebe68b7de2..3d8d496f3d90 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java @@ -461,7 +461,7 @@ public LinkerInvocation write(DebugContext debug, Path outputDirectory, Path tem } if (SubstrateOptions.GenerateDebugInfo.getValue() > 0) { - BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, SubstrateOptions.getDebugInfoSourceCacheRoot()); + BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, SubstrateOptions.getDebugInfoSourceCacheRootAsAbsolutePath()); if (OS.getCurrent() == OS.WINDOWS) { BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, imagePath.resolveSibling(imageName + ".pdb")); } else { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java index 8fcbce1b5ca8..190529e11c37 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java @@ -94,7 +94,7 @@ public class SourceCache { * Create the source cache. */ protected SourceCache() { - basePath = SubstrateOptions.getDebugInfoSourceCacheRoot(); + basePath = SubstrateOptions.getDebugInfoSourceCacheRootAsAbsolutePath(); srcRoots = new ArrayList<>(); specialSrcRoots = new HashMap<>(); addJDKSources();