Skip to content

Commit afec45d

Browse files
committed
[GR-46169] Remove SubstrateOptions.UseOldDebugInfo.
PullRequest: graal/14606
2 parents 397a0bb + 5b3e7d6 commit afec45d

File tree

9 files changed

+35
-40
lines changed

9 files changed

+35
-40
lines changed

docs/reference-manual/native-image/DebugInfo.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,15 @@ When `callgrind` is used in combination with a viewer like
991991
information about native image execution aand relate it back to
992992
specific source code lines.
993993

994-
### Related Documentation
994+
### Call-graph recording with `perf record`
995+
996+
Normally when perf does stack frame recording (i.e. when `--call-graph` is used), it uses frame pointers to recognize the individual stack frames.
997+
This assumes that the executable that gets profiled actually preserves frame pointers whenever a function gets called.
998+
For native images, this can be achieved by using `-H:+PreserveFramePointer` as an image build argument.
999+
1000+
An alternative solution is to make perf use dwarf debug info (specifically debug_frame data) to help unwind stack frames.
1001+
To make this work, the image needs to be built with `-g` (to generate debuginfo), and `perf record` needs to use the argument `--call-graph dwarf` to make sure dwarf debug info (instead of frame pointers) is used for stack unwinding.
1002+
1003+
## Related Documentation
9951004

9961005
- [Debug Native Executables with GDB](guides/debug-native-executables-with-gdb.md)

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ class SvmSupport(object):
11401140
def __init__(self):
11411141
self._svm_supported = has_component('svm', stage1=True)
11421142
self._svm_ee_supported = self._svm_supported and has_component('svmee', stage1=True)
1143-
self._debug_supported = self._svm_supported and (mx.is_linux() or mx.is_windows() or (mx.is_darwin() and has_component('svmee', stage1=True)))
1143+
self._debug_supported = self._svm_supported and (mx.is_linux() or mx.is_windows())
11441144
self._separate_debuginfo_ext = {
11451145
'linux': '.debug',
11461146
'windows': '.pdb',
@@ -1182,8 +1182,6 @@ def separate_debuginfo_ext(self):
11821182
def get_debug_flags(self, image_config):
11831183
assert self.is_debug_supported()
11841184
flags = ['-g']
1185-
if mx.is_darwin():
1186-
flags += ['-H:+UseOldDebugInfo']
11871185
if self.generate_separate_debug_info(image_config):
11881186
flags += ['-H:+StripDebugInfo']
11891187
return flags

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public static int codeAlignment() {
631631

632632
@APIOption(name = "-g", fixedValue = "2", customHelp = "generate debugging information")//
633633
@Option(help = "Insert debug info into the generated native image or library")//
634-
public static final HostedOptionKey<Integer> GenerateDebugInfo = new HostedOptionKey<>(0, SubstrateOptions::validateGenerateDebugInfo) {
634+
static final HostedOptionKey<Integer> GenerateDebugInfo = new HostedOptionKey<>(0, SubstrateOptions::validateGenerateDebugInfo) {
635635
@Override
636636
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer oldValue, Integer newValue) {
637637
if (OS.WINDOWS.isCurrent()) {
@@ -642,39 +642,17 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer o
642642
};
643643

644644
private static void validateGenerateDebugInfo(HostedOptionKey<Integer> optionKey) {
645-
if (OS.getCurrent() == OS.DARWIN && optionKey.hasBeenSet() && optionKey.getValue() > 0 && !SubstrateOptions.UseOldDebugInfo.getValue()) {
645+
if (OS.getCurrent() == OS.DARWIN && optionKey.hasBeenSet() && optionKey.getValue() > 0) {
646646
LogUtils.warning("Using %s is not supported on macOS", SubstrateOptionsParser.commandArgument(optionKey, optionKey.getValue().toString()));
647647
}
648648
}
649649

650-
@Option(help = "Control debug information output: 0 - no debuginfo, 1 - AOT code debuginfo, 2 - AOT and runtime code debuginfo (runtime code support only with -H:+UseOldDebugInfo).", //
651-
deprecated = true, deprecationMessage = "Please use the -g option.")//
652-
public static final HostedOptionKey<Integer> Debug = new HostedOptionKey<>(0) {
653-
@Override
654-
public void update(EconomicMap<OptionKey<?>, Object> values, Object newValue) {
655-
GenerateDebugInfo.update(values, newValue);
656-
}
657-
};
658-
659-
@Option(help = "Use old debuginfo", deprecated = true, deprecationMessage = "Please use the -g option.")//
660-
public static final HostedOptionKey<Boolean> UseOldDebugInfo = new HostedOptionKey<>(false, SubstrateOptions::validateUseOldDebugInfo);
661-
662650
public static boolean useDebugInfoGeneration() {
663-
return useLIRBackend() && GenerateDebugInfo.getValue() > 0 && !UseOldDebugInfo.getValue();
651+
return useLIRBackend() && GenerateDebugInfo.getValue() > 0;
664652
}
665653

666-
private static void validateUseOldDebugInfo(HostedOptionKey<Boolean> optionKey) {
667-
if (optionKey.getValue() && SubstrateOptions.GenerateDebugInfo.getValue() < 1) {
668-
throw UserError.abort("The option '%s' can only be used together with '%s'.",
669-
SubstrateOptionsParser.commandArgument(optionKey, "+"), SubstrateOptionsParser.commandArgument(SubstrateOptions.GenerateDebugInfo, "2"));
670-
}
671-
}
672-
673-
@Option(help = "Search path for source files for Application or GraalVM classes (list of comma-separated directories or jar files)")//
674-
public static final HostedOptionKey<LocatableMultiOptionValue.Paths> DebugInfoSourceSearchPath = new HostedOptionKey<>(LocatableMultiOptionValue.Paths.buildWithCommaDelimiter());
675-
676654
@Option(help = "Directory under which to create source file cache for Application or GraalVM classes")//
677-
public static final HostedOptionKey<String> DebugInfoSourceCacheRoot = new HostedOptionKey<>("sources");
655+
static final HostedOptionKey<String> DebugInfoSourceCacheRoot = new HostedOptionKey<>("sources");
678656

679657
@Option(help = "Temporary option to disable checking of image builder module dependencies or increasing its verbosity", type = OptionType.Debug)//
680658
public static final HostedOptionKey<Integer> CheckBootModuleDependencies = new HostedOptionKey<>(ModuleSupport.modulePathBuild ? 1 : 0);

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,6 @@ private static void deprecatedSanitizeJVMEnvironment(Map<String, String> environ
15251525

15261526
private static void sanitizeJVMEnvironment(Map<String, String> environment, Map<String, String> imageBuilderEnvironment) {
15271527
Set<String> requiredKeys = new HashSet<>(List.of("PATH", "PWD", "HOME", "LANG", "LC_ALL"));
1528-
requiredKeys.add("SRCHOME"); /* Remove once GR-44676 is fixed */
15291528
Function<String, String> keyMapper;
15301529
if (OS.WINDOWS.isCurrent()) {
15311530
requiredKeys.addAll(List.of("TEMP", "INCLUDE", "LIB"));

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/codegen/CCompilerInvoker.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,11 @@ protected boolean detectError(String line) {
516516
}
517517

518518
public static Optional<Path> lookupSearchPath(String name) {
519-
return Arrays.stream(System.getenv("PATH").split(File.pathSeparator))
519+
String envPath = System.getenv("PATH");
520+
if (envPath == null) {
521+
return Optional.empty();
522+
}
523+
return Arrays.stream(envPath.split(File.pathSeparator))
520524
.map(entry -> Paths.get(entry, name))
521525
.filter(p -> Files.isExecutable(p) && !Files.isDirectory(p))
522526
.findFirst();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public void addNativeLinkerOption(String option) {
242242

243243
protected List<String> getNativeLinkerOptions() {
244244
return Stream.of(nativeLinkerOptions, Options.NativeLinkerOption.getValue().values())
245-
.flatMap(Collection::stream).collect(Collectors.toList());
245+
.flatMap(Collection::stream)
246+
.collect(Collectors.toList());
246247
}
247248

248249
private static class BinutilsCCLinkerInvocation extends CCLinkerInvocation {
@@ -484,7 +485,7 @@ public List<String> getCommand() {
484485
/* Put .lib and .exp files in a temp dir as we don't usually need them. */
485486
cmd.add("/IMPLIB:" + getTempDirectory().resolve(imageName + ".lib"));
486487

487-
if (SubstrateOptions.GenerateDebugInfo.getValue() > 0) {
488+
if (SubstrateOptions.useDebugInfoGeneration()) {
488489
cmd.add("/DEBUG");
489490

490491
if (SubstrateOptions.DeleteLocalSymbols.getValue()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class NativeImageDebugInfoStripFeature implements InternalFeature {
5252

5353
@Override
5454
public boolean isInConfiguration(IsInConfigurationAccess access) {
55-
return SubstrateOptions.useDebugInfoGeneration() || SubstrateOptions.UseOldDebugInfo.getValue();
55+
return SubstrateOptions.useDebugInfoGeneration() && SubstrateOptions.StripDebugInfo.getValue();
5656
}
5757

5858
@SuppressWarnings("try")

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ private void runLinkerCommand(String imageName, LinkerInvocation inv, List<Strin
163163
BuildArtifacts.singleton().add(ArtifactType.IMPORT_LIBRARY, importLibCopy);
164164
}
165165

166-
if (SubstrateOptions.GenerateDebugInfo.getValue() > 0) {
167-
if (SubstrateOptions.UseOldDebugInfo.getValue()) {
168-
return;
169-
}
166+
if (SubstrateOptions.useDebugInfoGeneration()) {
170167
BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, SubstrateOptions.getDebugInfoSourceCacheRoot());
171168
if (Platform.includedIn(Platform.WINDOWS.class)) {
172169
BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, imagePath.resolveSibling(imageName + ".pdb"));

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@
3939
import java.util.HashMap;
4040
import java.util.List;
4141

42+
import org.graalvm.compiler.options.Option;
4243
import org.graalvm.nativeimage.ImageSingletons;
4344

4445
import com.oracle.svm.core.SubstrateOptions;
4546
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4647
import com.oracle.svm.core.feature.InternalFeature;
48+
import com.oracle.svm.core.option.HostedOptionKey;
49+
import com.oracle.svm.core.option.LocatableMultiOptionValue;
4750
import com.oracle.svm.core.util.VMError;
4851
import com.oracle.svm.hosted.FeatureImpl;
4952
import com.oracle.svm.hosted.ImageClassLoader;
@@ -504,6 +507,12 @@ protected static void ensureTargetDirs(Path targetDir) {
504507
@AutomaticallyRegisteredFeature
505508
@SuppressWarnings("unused")
506509
class SourceCacheFeature implements InternalFeature {
510+
511+
public static class Options {
512+
@Option(help = "Search path for source files for application or GraalVM classes (list of comma-separated directories or jar files)")//
513+
static final HostedOptionKey<LocatableMultiOptionValue.Paths> DebugInfoSourceSearchPath = new HostedOptionKey<>(LocatableMultiOptionValue.Paths.buildWithCommaDelimiter());
514+
}
515+
507516
ImageClassLoader imageClassLoader;
508517

509518
@Override
@@ -520,7 +529,7 @@ static List<Path> getModulePath() {
520529
}
521530

522531
static List<Path> getSourceSearchPath() {
523-
return SubstrateOptions.DebugInfoSourceSearchPath.getValue().values();
532+
return Options.DebugInfoSourceSearchPath.getValue().values();
524533
}
525534
}
526535

0 commit comments

Comments
 (0)