8263670: pmap and pstack in jhsdb do not work on debug server
Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
parent
38e0a58f6c
commit
a209ed01ba
@ -444,16 +444,12 @@ public class HotSpotAgent {
|
||||
db.getJShortType().getSize());
|
||||
}
|
||||
|
||||
if (!isServer) {
|
||||
// Do not initialize the VM on the server (unnecessary, since it's
|
||||
// instantiated on the client)
|
||||
try {
|
||||
VM.initialize(db, debugger);
|
||||
} catch (DebuggerException e) {
|
||||
throw (e);
|
||||
} catch (Exception e) {
|
||||
throw new DebuggerException(e);
|
||||
}
|
||||
try {
|
||||
VM.initialize(db, debugger);
|
||||
} catch (DebuggerException e) {
|
||||
throw (e);
|
||||
} catch (Exception e) {
|
||||
throw new DebuggerException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,6 +25,7 @@
|
||||
package sun.jvm.hotspot.debugger.remote;
|
||||
|
||||
import java.rmi.*;
|
||||
import java.util.*;
|
||||
|
||||
import sun.jvm.hotspot.debugger.*;
|
||||
|
||||
@ -76,4 +77,8 @@ public interface RemoteDebugger extends Remote {
|
||||
long addrOrId2, boolean isAddress2) throws RemoteException;
|
||||
public int getThreadHashCode(long addrOrId, boolean isAddress) throws RemoteException;
|
||||
public long[] getThreadIntegerRegisterSet(long addrOrId, boolean isAddress) throws RemoteException;
|
||||
|
||||
public default String execCommandOnServer(String command, Map<String, Object> options) throws RemoteException {
|
||||
throw new DebuggerException("Command execution is not supported");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -415,4 +415,12 @@ public class RemoteDebuggerClient extends DebuggerBase implements JVMDebugger {
|
||||
public void writeBytesToProcess(long a, long b, byte[] c) {
|
||||
throw new DebuggerException("Unimplemented!");
|
||||
}
|
||||
|
||||
public String execCommandOnServer(String command, Map<String, Object> options) {
|
||||
try {
|
||||
return remoteDebugger.execCommandOnServer(command, options);
|
||||
} catch (RemoteException e) {
|
||||
throw new DebuggerException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,10 +24,13 @@
|
||||
|
||||
package sun.jvm.hotspot.debugger.remote;
|
||||
|
||||
import java.io.*;
|
||||
import java.rmi.*;
|
||||
import java.rmi.server.*;
|
||||
import java.util.*;
|
||||
|
||||
import sun.jvm.hotspot.debugger.*;
|
||||
import sun.jvm.hotspot.tools.*;
|
||||
|
||||
/** The implementation of the RemoteDebugger interface. This
|
||||
delegates to a local debugger */
|
||||
@ -35,7 +38,7 @@ import sun.jvm.hotspot.debugger.*;
|
||||
public class RemoteDebuggerServer extends UnicastRemoteObject
|
||||
implements RemoteDebugger {
|
||||
|
||||
private transient Debugger debugger;
|
||||
private transient JVMDebugger debugger;
|
||||
|
||||
/** This is the required no-arg constructor */
|
||||
public RemoteDebuggerServer() throws RemoteException {
|
||||
@ -44,14 +47,14 @@ public class RemoteDebuggerServer extends UnicastRemoteObject
|
||||
|
||||
/** This is the constructor used on the machine where the debuggee
|
||||
process lies that accepts an RMI connector port */
|
||||
public RemoteDebuggerServer(Debugger debugger, int port) throws RemoteException {
|
||||
public RemoteDebuggerServer(JVMDebugger debugger, int port) throws RemoteException {
|
||||
super(port);
|
||||
this.debugger = debugger;
|
||||
}
|
||||
|
||||
/** This is the constructor used on the machine where the debuggee
|
||||
process lies */
|
||||
public RemoteDebuggerServer(Debugger debugger) throws RemoteException {
|
||||
public RemoteDebuggerServer(JVMDebugger debugger) throws RemoteException {
|
||||
this(debugger, 0);
|
||||
}
|
||||
|
||||
@ -175,4 +178,23 @@ public class RemoteDebuggerServer extends UnicastRemoteObject
|
||||
return debugger.getThreadForThreadId(addrOrId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execCommandOnServer(String command, Map<String, Object> options) throws RemoteException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
try (var out = new PrintStream(bout)) {
|
||||
if (command.equals("pmap")) {
|
||||
(new PMap(debugger)).run(out, debugger);
|
||||
} else if (command.equals("pstack")) {
|
||||
PStack pstack = new PStack(debugger);
|
||||
pstack.setVerbose(false);
|
||||
pstack.setConcurrentLocks((boolean)options.get("concurrentLocks"));
|
||||
pstack.run(out, debugger);
|
||||
} else {
|
||||
throw new DebuggerException(command + " is not supported in this debugger");
|
||||
}
|
||||
}
|
||||
|
||||
return bout.toString();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import java.util.*;
|
||||
import sun.jvm.hotspot.*;
|
||||
import sun.jvm.hotspot.debugger.*;
|
||||
import sun.jvm.hotspot.debugger.cdbg.*;
|
||||
import sun.jvm.hotspot.debugger.remote.*;
|
||||
import sun.jvm.hotspot.utilities.PlatformInfo;
|
||||
|
||||
public class PMap extends Tool {
|
||||
@ -77,7 +78,7 @@ public class PMap extends Tool {
|
||||
}
|
||||
} else {
|
||||
if (getDebugeeType() == DEBUGEE_REMOTE) {
|
||||
out.println("remote configuration is not yet implemented");
|
||||
out.print(((RemoteDebuggerClient)dbg).execCommandOnServer("pmap", null));
|
||||
} else {
|
||||
out.println("not yet implemented (debugger does not support CDebugger)!");
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import sun.jvm.hotspot.code.*;
|
||||
import sun.jvm.hotspot.interpreter.*;
|
||||
import sun.jvm.hotspot.debugger.*;
|
||||
import sun.jvm.hotspot.debugger.cdbg.*;
|
||||
import sun.jvm.hotspot.debugger.remote.*;
|
||||
import sun.jvm.hotspot.oops.*;
|
||||
import sun.jvm.hotspot.runtime.*;
|
||||
import sun.jvm.hotspot.utilities.PlatformInfo;
|
||||
@ -197,7 +198,7 @@ public class PStack extends Tool {
|
||||
} // for threads
|
||||
} else {
|
||||
if (getDebugeeType() == DEBUGEE_REMOTE) {
|
||||
out.println("remote configuration is not yet implemented");
|
||||
out.print(((RemoteDebuggerClient)dbg).execCommandOnServer("pstack", Map.of("concurrentLocks", concurrentLocks)));
|
||||
} else {
|
||||
out.println("not yet implemented (debugger does not support CDebugger)!");
|
||||
}
|
||||
@ -289,4 +290,12 @@ public class PStack extends Tool {
|
||||
System.arraycopy(names.toArray(), 0, res, 0, res.length);
|
||||
return res;
|
||||
}
|
||||
|
||||
public void setVerbose(boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public void setConcurrentLocks(boolean concurrentLocks) {
|
||||
this.concurrentLocks = concurrentLocks;
|
||||
}
|
||||
}
|
||||
|
@ -45,18 +45,7 @@ public class ClhsdbAttachToDebugServer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
|
||||
|
||||
if (SATestUtils.needsPrivileges()) {
|
||||
// This tests has issues if you try adding privileges on OSX. The debugd process cannot
|
||||
// be killed if you do this (because it is a root process and the test is not), so the destroy()
|
||||
// call fails to do anything, and then waitFor() will time out. If you try to manually kill it with
|
||||
// a "sudo kill" command, that seems to work, but then leaves the LingeredApp it was
|
||||
// attached to in a stuck state for some unknown reason, causing the stopApp() call
|
||||
// to timeout. For that reason we don't run this test when privileges are needed. Note
|
||||
// it does appear to run fine as root, so we still allow it to run on OSX when privileges
|
||||
// are not required.
|
||||
throw new SkippedException("Cannot run this test on OSX if adding privileges is required.");
|
||||
}
|
||||
SATestUtils.validateSADebugDPrivileges();
|
||||
|
||||
System.out.println("Starting ClhsdbAttachToDebugServer test");
|
||||
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021 NTT DATA.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.apps.LingeredApp;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.SA.SATestUtils;
|
||||
|
||||
import jtreg.SkippedException;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8263670
|
||||
* @requires vm.hasSA
|
||||
* @requires (os.family != "windows") & (os.family != "mac")
|
||||
* @library /test/lib
|
||||
* @run main/othervm PmapOnDebugdTest
|
||||
*/
|
||||
|
||||
public class PmapOnDebugdTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
|
||||
SATestUtils.validateSADebugDPrivileges();
|
||||
|
||||
LingeredApp theApp = null;
|
||||
DebugdUtils debugd = null;
|
||||
try {
|
||||
theApp = LingeredApp.startApp();
|
||||
System.out.println("Started LingeredApp with pid " + theApp.getPid());
|
||||
debugd = new DebugdUtils(null);
|
||||
debugd.attach(theApp.getPid());
|
||||
|
||||
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
|
||||
jhsdbLauncher.addToolArg("jmap");
|
||||
jhsdbLauncher.addToolArg("--connect");
|
||||
jhsdbLauncher.addToolArg("localhost");
|
||||
|
||||
Process jhsdb = (SATestUtils.createProcessBuilder(jhsdbLauncher)).start();
|
||||
OutputAnalyzer out = new OutputAnalyzer(jhsdb);
|
||||
|
||||
jhsdb.waitFor();
|
||||
System.out.println(out.getStdout());
|
||||
System.err.println(out.getStderr());
|
||||
|
||||
out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();
|
||||
out.shouldMatch("^0x[0-9a-f]+.+libjvm\\.so$"); // Find libjvm from output
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
// This will detect most SA failures, including during the attach.
|
||||
out.shouldNotMatch("^sun.jvm.hotspot.debugger.DebuggerException:.*$");
|
||||
} catch (SkippedException se) {
|
||||
throw se;
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Test ERROR " + ex, ex);
|
||||
} finally {
|
||||
if (debugd != null) {
|
||||
debugd.detach();
|
||||
}
|
||||
LingeredApp.stopApp(theApp);
|
||||
}
|
||||
System.out.println("Test PASSED");
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -56,18 +56,7 @@ public class SADebugDTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
|
||||
|
||||
if (SATestUtils.needsPrivileges()) {
|
||||
// This tests has issues if you try adding privileges on OSX. The debugd process cannot
|
||||
// be killed if you do this (because it is a root process and the test is not), so the destroy()
|
||||
// call fails to do anything, and then waitFor() will time out. If you try to manually kill it with
|
||||
// a "sudo kill" command, that seems to work, but then leaves the LingeredApp it was
|
||||
// attached to in a stuck state for some unknown reason, causing the stopApp() call
|
||||
// to timeout. For that reason we don't run this test when privileges are needed. Note
|
||||
// it does appear to run fine as root, so we still allow it to run on OSX when privileges
|
||||
// are not required.
|
||||
throw new SkippedException("Cannot run this test on OSX if adding privileges is required.");
|
||||
}
|
||||
SATestUtils.validateSADebugDPrivileges();
|
||||
runTests();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -207,4 +207,20 @@ public class SATestUtils {
|
||||
// Otherwise expect to be permitted:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests has issues if you try adding privileges on OSX. The debugd process cannot
|
||||
* be killed if you do this (because it is a root process and the test is not), so the destroy()
|
||||
* call fails to do anything, and then waitFor() will time out. If you try to manually kill it with
|
||||
* a "sudo kill" command, that seems to work, but then leaves the LingeredApp it was
|
||||
* attached to in a stuck state for some unknown reason, causing the stopApp() call
|
||||
* to timeout. For that reason we don't run this test when privileges are needed. Note
|
||||
* it does appear to run fine as root, so we still allow it to run on OSX when privileges
|
||||
* are not required.
|
||||
*/
|
||||
public static void validateSADebugDPrivileges() {
|
||||
if (needsPrivileges()) {
|
||||
throw new SkippedException("Cannot run this test on OSX if adding privileges is required.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user