8218941: jdb should support a dbgtrace command that acts the same as the dbgtrace command line option

Added dbgtrace command.

Reviewed-by: sspitsyn, amenkov, gadams
This commit is contained in:
Chris Plummer 2019-02-15 12:33:11 -08:00
parent ff97b60fde
commit e4dc17c354
5 changed files with 42 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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
@ -1128,6 +1128,22 @@ class Commands {
}
}
void commandDbgTrace(StringTokenizer t) {
int traceFlags;
if (t.hasMoreTokens()) {
String flagStr = t.nextToken();
try {
traceFlags = Integer.decode(flagStr).intValue();
} catch (NumberFormatException nfe) {
MessageOutput.println("dbgtrace command value must be an integer:", flagStr);
return;
}
} else {
traceFlags = VirtualMachine.TRACE_ALL;
}
Env.setTraceFlags(traceFlags);
}
void commandStop(StringTokenizer t) {
String atIn;
byte suspendPolicy = EventRequest.SUSPEND_ALL;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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
@ -64,6 +64,10 @@ class Env {
}
}
static void setTraceFlags(int flags) {
connection.setTraceFlags(flags);
}
static VMConnection connection() {
return connection;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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
@ -304,6 +304,7 @@ public class TTY implements EventNotifier {
{"clear", "y", "n"},
{"connectors", "y", "y"},
{"cont", "n", "n"},
{"dbgtrace", "y", "y"},
{"disablegc", "n", "n"},
{"down", "n", "y"},
{"dump", "n", "y"},
@ -587,6 +588,8 @@ public class TTY implements EventNotifier {
evaluator.commandExclude(t);
} else if (cmd.equals("read")) {
readCommand(t);
} else if (cmd.equals("dbgtrace")) {
evaluator.commandDbgTrace(t);
} else if (cmd.equals("help") || cmd.equals("?")) {
help();
} else if (cmd.equals("version")) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, 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
@ -107,6 +107,7 @@ public class TTYResources extends java.util.ListResourceBundle {
{"Current thread isnt suspended.", "Current thread isn't suspended."},
{"Current thread not set.", "Current thread not set."},
{"dbgtrace flag value must be an integer:", "dbgtrace flag value must be an integer: {0}"},
{"dbgtrace command value must be an integer:", "dbgtrace command value must be an integer: {0}"},
{"Deferring.", "Deferring {0}.\nIt will be set after the class is loaded."},
{"End of stack.", "End of stack."},
{"Error popping frame", "Error popping frame - {0}"},
@ -411,6 +412,7 @@ public class TTYResources extends java.util.ListResourceBundle {
"<n> <command> -- repeat command n times\n" +
"# <command> -- discard (no-op)\n" +
"help (or ?) -- list commands\n" +
"dbgtrace [flag] -- same as dbgtrace command line option" +
"version -- print version information\n" +
"exit (or quit) -- exit debugger\n" +
"\n" +

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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
@ -52,7 +52,7 @@ class VMConnection {
private final Connector connector;
private final Map<String, com.sun.jdi.connect.Connector.Argument> connectorArgs;
private final int traceFlags;
private int traceFlags;
synchronized void notifyOutputComplete() {
outputCompleteCount++;
@ -321,6 +321,17 @@ class VMConnection {
this.traceFlags = traceFlags;
}
public void setTraceFlags(int flags) {
this.traceFlags = flags;
/*
* If vm is not connected now, then vm.setDebugTraceMode() will
* be called when it is connected.
*/
if (vm != null) {
vm.setDebugTraceMode(flags);
}
}
synchronized VirtualMachine open() {
if (connector instanceof LaunchingConnector) {
vm = launchTarget();