From 0e95220a055ae0887e53bf0efae03e8ef1bd5999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Tue, 24 May 2022 16:08:23 +0200 Subject: [PATCH 1/2] Add hosted options SourceLevelDebug and SourceLevelDebugFilter --- .../com/oracle/svm/core/SubstrateOptions.java | 36 +++++++++++++++++++ .../src/com/oracle/svm/hosted/SVMHost.java | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) 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 94e44eadb007..bf6baeb97668 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 @@ -35,6 +35,8 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; +import java.util.function.Predicate; import org.graalvm.collections.EconomicMap; import org.graalvm.collections.UnmodifiableEconomicMap; @@ -47,6 +49,8 @@ import org.graalvm.compiler.options.OptionValues; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; import com.oracle.svm.core.deopt.DeoptimizationSupport; import com.oracle.svm.core.heap.ReferenceHandler; @@ -56,6 +60,7 @@ import com.oracle.svm.core.option.HostedOptionValues; import com.oracle.svm.core.option.ImmutableRuntimeOptionKey; import com.oracle.svm.core.option.LocatableMultiOptionValue; +import com.oracle.svm.core.option.OptionUtils; import com.oracle.svm.core.option.RuntimeOptionKey; import com.oracle.svm.core.thread.VMOperationControl; import com.oracle.svm.core.util.UserError; @@ -66,6 +71,10 @@ public class SubstrateOptions { @Option(help = "When true, compiler graphs are parsed only once before static analysis. When false, compiler graphs are parsed for static analysis and again for AOT compilation.")// public static final HostedOptionKey ParseOnce = new HostedOptionKey<>(true); + @Option(help = "Preserve the local variable information for every Java source line to allow line-by-line stepping in the debugger. Allow the lookup of Java-level method information, e.g., in stack traces.")// + public static final HostedOptionKey SourceLevelDebug = new HostedOptionKey<>(false); + @Option(help = "Constrain debug info generation to the comma-separated list of package prefixes given to this option.")// + public static final HostedOptionKey SourceLevelDebugFilter = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings()); public static boolean parseOnce() { /* @@ -154,6 +163,32 @@ protected void onValueUpdate(EconomicMap, Object> values, Boolean o private static ValueUpdateHandler optimizeValueUpdateHandler; private static ValueUpdateHandler debugInfoValueUpdateHandler = SubstrateOptions::defaultDebugInfoValueUpdateHandler; + @Fold + public static boolean getSourceLevelDebug() { + return SourceLevelDebug.getValue(); + } + + @Fold + public static Predicate getSourceLevelDebugFilter() { + return makeFilter(SourceLevelDebugFilter.getValue().values()); + } + + @Platforms(Platform.HOSTED_ONLY.class) + private static Predicate makeFilter(List definedFilters) { + if (definedFilters.isEmpty()) { + return javaName -> true; + } + List wildCardList = OptionUtils.flatten(",", definedFilters); + return javaName -> { + for (String wildCard : wildCardList) { + if (javaName.startsWith(wildCard)) { + return true; + } + } + return false; + }; + } + /** * The currently supported optimization levels. See the option description of {@link #Optimize} * for a description of the levels. @@ -171,6 +206,7 @@ public enum OptimizationLevel { protected void onValueUpdate(EconomicMap, Object> values, String oldValue, String newValue) { OptimizationLevel newLevel = parseOptimizationLevel(newValue); SubstrateOptions.IncludeNodeSourcePositions.update(values, newLevel == OptimizationLevel.O0); + SubstrateOptions.SourceLevelDebug.update(values, newLevel == OptimizationLevel.O0); SubstrateOptions.AOTTrivialInline.update(values, newLevel != OptimizationLevel.O0); if (optimizeValueUpdateHandler != null) { optimizeValueUpdateHandler.onValueUpdate(values, newLevel); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index f76c91f0c7b8..3ca2e0f3607b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -298,7 +298,7 @@ public boolean isInitialized(AnalysisType type) { public GraphBuilderConfiguration updateGraphBuilderConfiguration(GraphBuilderConfiguration config, AnalysisMethod method) { return config.withRetainLocalVariables(retainLocalVariables()) .withUnresolvedIsError(linkAtBuildTimeSupport.linkAtBuildTime(method.getDeclaringClass())) - .withFullInfopoints(SubstrateOptions.GenerateDebugInfo.getValue() > 0); + .withFullInfopoints(SubstrateOptions.getSourceLevelDebug() && SubstrateOptions.getSourceLevelDebugFilter().test(method.getDeclaringClass().toJavaName())); } private boolean retainLocalVariables() { From a2cb56a01e5d4543493995379299c25b5882a629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Tue, 24 May 2022 18:11:57 +0200 Subject: [PATCH 2/2] Run debuginfotest with -H:+SourceLevelDebug --- substratevm/mx.substratevm/mx_substratevm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index daa90028c037..4bc07176efef 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -833,6 +833,7 @@ def _debuginfotest(native_image, path, build_only, args): '-Dgraal.LogFile=graal.log', '-g', '-H:-OmitInlinedMethodDebugLineInfo', + '-H:+SourceLevelDebug', '-H:DebugInfoSourceSearchPath=' + sourcepath, '-H:DebugInfoSourceCacheRoot=' + join(path, 'sources'), 'hello.Hello'] + args