Skip to content

Commit 60a01fc

Browse files
[GR-68387] Update and validate options for run-time debug info.
PullRequest: graal/21754
2 parents 4f683e3 + a4d3457 commit 60a01fc

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.oracle.svm.core.c.libc.LibCBase;
5353
import com.oracle.svm.core.c.libc.MuslLibC;
5454
import com.oracle.svm.core.config.ConfigurationValues;
55+
import com.oracle.svm.core.graal.RuntimeCompilation;
5556
import com.oracle.svm.core.heap.ReferenceHandler;
5657
import com.oracle.svm.core.jdk.VectorAPIEnabled;
5758
import com.oracle.svm.core.option.APIOption;
@@ -528,7 +529,19 @@ public static void setImageLayerCreateEnabledHandler(OptionEnabledHandler<Boolea
528529
public static final HostedOptionKey<Boolean> IncludeNodeSourcePositions = new HostedOptionKey<>(false);
529530

530531
@Option(help = "Provide debuginfo for runtime-compiled code.")//
531-
public static final HostedOptionKey<Boolean> RuntimeDebugInfo = new HostedOptionKey<>(false);
532+
public static final HostedOptionKey<Boolean> RuntimeDebugInfo = new HostedOptionKey<>(false, SubstrateOptions::validateRuntimeDebugInfo);
533+
534+
private static void validateRuntimeDebugInfo(HostedOptionKey<Boolean> optionKey) {
535+
if (optionKey.getValue()) {
536+
if (!useDebugInfoGeneration()) {
537+
throw UserError.invalidOptionValue(optionKey, optionKey.getValue(), "The option can only be enabled if debug info generation is enabled ('-g')");
538+
} else if (!OS.LINUX.isCurrent()) {
539+
throw UserError.invalidOptionValue(optionKey, optionKey.getValue(), "The option is only supported on Linux.");
540+
} else if (!RuntimeCompilation.isEnabled()) {
541+
throw UserError.invalidOptionValue(optionKey, optionKey.getValue(), "The option only works if run-time compilation support is enabled.");
542+
}
543+
}
544+
}
532545

533546
@Option(help = "Search path for C libraries passed to the linker (list of comma-separated directories)", stability = OptionStability.STABLE)//
534547
@BundleMember(role = BundleMember.Role.Input)//

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/debug/SubstrateDebugInfoProvider.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.stream.Stream;
3131

3232
import org.graalvm.collections.Pair;
33-
import org.graalvm.nativeimage.ProcessProperties;
3433

3534
import com.oracle.objectfile.debugentry.ArrayTypeEntry;
3635
import com.oracle.objectfile.debugentry.ClassEntry;
@@ -39,12 +38,14 @@
3938
import com.oracle.objectfile.debugentry.PointerToTypeEntry;
4039
import com.oracle.objectfile.debugentry.PrimitiveTypeEntry;
4140
import com.oracle.objectfile.debugentry.TypeEntry;
41+
import com.oracle.svm.core.SubstrateOptions;
4242
import com.oracle.svm.core.SubstrateUtil;
4343
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
4444
import com.oracle.svm.core.meta.SharedMethod;
4545
import com.oracle.svm.core.meta.SharedType;
4646
import com.oracle.svm.core.option.RuntimeOptionKey;
4747

48+
import jdk.graal.compiler.api.replacements.Fold;
4849
import jdk.graal.compiler.code.CompilationResult;
4950
import jdk.graal.compiler.debug.DebugContext;
5051
import jdk.graal.compiler.options.Option;
@@ -73,18 +74,19 @@ public static class Options {
7374

7475
public static Path getRuntimeSourceDestDir() {
7576
String sourceDestDir = RuntimeSourceDestDir.getValue();
76-
if (sourceDestDir != null) {
77-
return Path.of(sourceDestDir);
78-
}
79-
Path result = Path.of("sources");
80-
Path exeDir = Path.of(ProcessProperties.getExecutableName()).getParent();
81-
if (exeDir != null) {
82-
result = exeDir.resolve(result);
83-
}
84-
return result;
77+
/*
78+
* If not set, use source cache root from the native image debug info. This makes sure
79+
* the cachePath is the same as in the native image debug info.
80+
*/
81+
return sourceDestDir != null ? Path.of(sourceDestDir) : getHostedSourceCacheRoot();
8582
}
8683
}
8784

85+
@Fold
86+
static Path getHostedSourceCacheRoot() {
87+
return SubstrateOptions.getDebugInfoSourceCacheRoot();
88+
}
89+
8890
private final SharedMethod sharedMethod;
8991
private final CompilationResult compilation;
9092
private final long codeAddress;

0 commit comments

Comments
 (0)