|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2023, Red Hat, Inc. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | + * accompanied this code). |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License version |
| 17 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + * |
| 20 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | + * or visit www.oracle.com if you need additional information or have any |
| 22 | + * questions. |
| 23 | + */ |
| 24 | + |
| 25 | + |
| 26 | +/* |
| 27 | + * @test symbolsHsErr |
| 28 | + * @summary Test that function names are present in native frames of hs-err file as a proof that symbols are available. |
| 29 | + * @library /test/lib |
| 30 | + * @requires vm.flagless |
| 31 | + * @requires vm.debug |
| 32 | + * @requires os.family == "windows" |
| 33 | + * @modules java.base/jdk.internal.misc |
| 34 | + * java.management |
| 35 | + * @run driver TestSymbolsInHsErrFile |
| 36 | + */ |
| 37 | + |
| 38 | +import jdk.test.lib.process.OutputAnalyzer; |
| 39 | +import jdk.test.lib.process.ProcessTools; |
| 40 | + |
| 41 | +public class TestSymbolsInHsErrFile { |
| 42 | + |
| 43 | + public static void main(String[] args) throws Exception { |
| 44 | + |
| 45 | + // Start a jvm and cause a SIGSEGV / ACCESS_VIOLATION |
| 46 | + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
| 47 | + "-XX:+UnlockDiagnosticVMOptions", |
| 48 | + "-Xmx100M", |
| 49 | + "-XX:-CreateCoredumpOnCrash", |
| 50 | + "-XX:ErrorHandlerTest=14", |
| 51 | + "-version"); |
| 52 | + |
| 53 | + OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
| 54 | + output.shouldNotHaveExitValue(0); |
| 55 | + |
| 56 | + // Verify that the hs_err problematic frame contains a function name that points to origin of the crash; |
| 57 | + // on Windows/MSVC, if symbols are present and loaded, we should see a ref to either 'crash_with_segfault' |
| 58 | + // 'VMError::controlled_crash' depending on whether the compile optimizations (i.e. crash_with_segfault |
| 59 | + // was inlined or not): |
| 60 | + // # Problematic frame: |
| 61 | + // # V [jvm.dll+0x.....] crash_with_segfault+0x10 |
| 62 | + // or |
| 63 | + // # V [jvm.dll+0x.....] VMError::controlled_crash+0x99 |
| 64 | + // |
| 65 | + // If symbols could not be loaded, however, then the frame will contain not function name at all, i.e. |
| 66 | + // # Problematic frame: |
| 67 | + // # V [jvm.dll+0x.....] |
| 68 | + // NB: this is not true for other OS/Compilers, where the functions names are present even with no symbols, |
| 69 | + // hence this test being restricted to Windows only. |
| 70 | + output.shouldMatch(("# V \\[jvm.dll.*\\].*(crash_with_segfault|controlled_crash).*")); |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | + |
0 commit comments