|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
24 | 24 | */
|
25 | 25 | package com.oracle.svm.hosted.image;
|
26 | 26 |
|
| 27 | +import java.nio.file.Files; |
| 28 | +import java.nio.file.Path; |
27 | 29 | import java.util.List;
|
28 | 30 | import java.util.function.Function;
|
| 31 | +import java.util.function.Supplier; |
29 | 32 |
|
| 33 | +import com.oracle.svm.core.c.CGlobalData; |
| 34 | +import com.oracle.svm.core.c.CGlobalDataFactory; |
| 35 | +import com.oracle.svm.core.config.ConfigurationValues; |
| 36 | +import com.oracle.svm.core.heap.Heap; |
| 37 | +import com.oracle.svm.hosted.c.CGlobalDataFeature; |
| 38 | +import com.oracle.svm.util.ReflectionUtil; |
| 39 | +import jdk.graal.compiler.core.common.CompressEncoding; |
30 | 40 | import jdk.graal.compiler.debug.DebugContext;
|
31 | 41 | import jdk.graal.compiler.printer.GraalDebugHandlersFactory;
|
32 | 42 | import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
|
|
49 | 59 | import com.oracle.svm.hosted.ProgressReporter;
|
50 | 60 | import com.oracle.svm.hosted.image.sources.SourceManager;
|
51 | 61 | import com.oracle.svm.hosted.util.DiagnosticUtils;
|
| 62 | +import org.graalvm.word.PointerBase; |
| 63 | +import org.graalvm.word.WordFactory; |
52 | 64 |
|
53 | 65 | @AutomaticallyRegisteredFeature
|
54 | 66 | @SuppressWarnings("unused")
|
@@ -97,6 +109,21 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
|
97 | 109 | var accessImpl = (FeatureImpl.BeforeAnalysisAccessImpl) access;
|
98 | 110 | bfdNameProvider.setNativeLibs(accessImpl.getNativeLibraries());
|
99 | 111 | }
|
| 112 | + |
| 113 | + /* |
| 114 | + * Ensure ClassLoader.nameAndId is available at runtime for type lookup from gdb |
| 115 | + */ |
| 116 | + access.registerAsAccessed(ReflectionUtil.lookupField(ClassLoader.class, "nameAndId")); |
| 117 | + |
| 118 | + CompressEncoding compressEncoding = ImageSingletons.lookup(CompressEncoding.class); |
| 119 | + CGlobalData<PointerBase> compressedShift = CGlobalDataFactory.createWord(WordFactory.signed(compressEncoding.getShift()), "__svm_compressed_shift"); |
| 120 | + CGlobalData<PointerBase> useHeapBase = CGlobalDataFactory.createWord(WordFactory.unsigned(compressEncoding.hasBase() ? 1 : 0), "__svm_use_heap_base"); |
| 121 | + CGlobalData<PointerBase> oopTagsMask = CGlobalDataFactory.createWord(WordFactory.unsigned(Heap.getHeap().getObjectHeader().getReservedBitsMask()), "__svm_oop_tags_mask"); |
| 122 | + CGlobalData<PointerBase> objectAlignment = CGlobalDataFactory.createWord(WordFactory.unsigned(ConfigurationValues.getObjectLayout().getAlignment()), "__svm_object_alignment"); |
| 123 | + CGlobalDataFeature.singleton().registerWithGlobalHiddenSymbol(compressedShift); |
| 124 | + CGlobalDataFeature.singleton().registerWithGlobalHiddenSymbol(useHeapBase); |
| 125 | + CGlobalDataFeature.singleton().registerWithGlobalHiddenSymbol(oopTagsMask); |
| 126 | + CGlobalDataFeature.singleton().registerWithGlobalHiddenSymbol(objectAlignment); |
100 | 127 | }
|
101 | 128 |
|
102 | 129 | @Override
|
@@ -134,11 +161,29 @@ public boolean isLoadable() {
|
134 | 161 | };
|
135 | 162 | };
|
136 | 163 |
|
| 164 | + Supplier<BasicProgbitsSectionImpl> makeGDBSectionImpl = () -> { |
| 165 | + var content = AssemblyBuffer.createOutputAssembler(objectFile.getByteOrder()); |
| 166 | + // 1 -> python file |
| 167 | + content.writeByte((byte) 1); |
| 168 | + content.writeString("./svmhelpers.py"); |
| 169 | + return new BasicProgbitsSectionImpl(content.getBlob()) { |
| 170 | + @Override |
| 171 | + public boolean isLoadable() { |
| 172 | + return false; |
| 173 | + } |
| 174 | + }; |
| 175 | + }; |
| 176 | + |
137 | 177 | var imageClassLoader = accessImpl.getImageClassLoader();
|
138 | 178 | objectFile.newUserDefinedSection(".debug.svm.imagebuild.classpath", makeSectionImpl.apply(DiagnosticUtils.getClassPath(imageClassLoader)));
|
139 | 179 | objectFile.newUserDefinedSection(".debug.svm.imagebuild.modulepath", makeSectionImpl.apply(DiagnosticUtils.getModulePath(imageClassLoader)));
|
140 | 180 | objectFile.newUserDefinedSection(".debug.svm.imagebuild.arguments", makeSectionImpl.apply(DiagnosticUtils.getBuilderArguments(imageClassLoader)));
|
141 | 181 | objectFile.newUserDefinedSection(".debug.svm.imagebuild.java.properties", makeSectionImpl.apply(DiagnosticUtils.getBuilderProperties()));
|
| 182 | + |
| 183 | + Path svmDebugHelper = Path.of(System.getProperty("java.home"), "lib/svm/debug/svmhelpers.py"); |
| 184 | + if (Files.exists(svmDebugHelper)) { |
| 185 | + objectFile.newUserDefinedSection(".debug_gdb_scripts", makeGDBSectionImpl.get()); |
| 186 | + } |
142 | 187 | }
|
143 | 188 | }
|
144 | 189 | ProgressReporter.singleton().setDebugInfoTimer(timer);
|
|
0 commit comments