8218941: jdb should support a dbgtrace command that acts the same as the dbgtrace command line option
authorcjplummer
Fri, 15 Feb 2019 12:33:11 -0800
changeset 53782 37c12515c30f
parent 53781 940046624bf8
child 53783 72709e703abd
8218941: jdb should support a dbgtrace command that acts the same as the dbgtrace command line option Summary: added dbgtrace command. Reviewed-by: sspitsyn, amenkov, gadams
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Commands.java
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Env.java
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources.java
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/VMConnection.java
--- a/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Commands.java	Fri Feb 15 11:18:01 2019 -0800
+++ b/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Commands.java	Fri Feb 15 12:33:11 2019 -0800
@@ -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 @@
         }
     }
 
+    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;
--- a/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Env.java	Fri Feb 15 11:18:01 2019 -0800
+++ b/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Env.java	Fri Feb 15 12:33:11 2019 -0800
@@ -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 @@
         }
     }
 
+    static void setTraceFlags(int flags) {
+        connection.setTraceFlags(flags);
+    }
+
     static VMConnection connection() {
         return connection;
     }
--- a/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java	Fri Feb 15 11:18:01 2019 -0800
+++ b/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java	Fri Feb 15 12:33:11 2019 -0800
@@ -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 @@
         {"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 @@
                             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")) {
--- a/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources.java	Fri Feb 15 11:18:01 2019 -0800
+++ b/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources.java	Fri Feb 15 12:33:11 2019 -0800
@@ -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 @@
         {"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 @@
              "<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" +
--- a/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/VMConnection.java	Fri Feb 15 11:18:01 2019 -0800
+++ b/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/VMConnection.java	Fri Feb 15 12:33:11 2019 -0800
@@ -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 @@
 
     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 @@
         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();