src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java
author hseigel
Wed, 20 Feb 2019 13:21:36 -0500
changeset 53853 7ca9e625d6b2
parent 53782 37c12515c30f
child 58074 6eca527d3689
permissions -rw-r--r--
8214719: Deprecate -Xverify:none option Summary: Deprecate -Xverify:none and -noverify and remove them from tests Reviewed-by: dholmes, mikael
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53782
37c12515c30f 8218941: jdb should support a dbgtrace command that acts the same as the dbgtrace command line option
cjplummer
parents: 52366
diff changeset
     2
 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    26
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    27
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    28
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    29
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    30
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    31
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    32
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    33
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    34
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
package com.sun.tools.example.debug.tty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.jdi.connect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class TTY implements EventNotifier {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    EventHandler handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * List of Strings to execute at each stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private List<String> monitorCommands = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private int monitorCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * The name of this tool.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final String progname = "jdb";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
38348
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    59
    private volatile boolean shuttingDown = false;
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    60
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    61
    public void setShuttingDown(boolean s) {
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    62
       shuttingDown = s;
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    63
    }
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    64
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    65
    public boolean isShuttingDown() {
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    66
        return shuttingDown;
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    67
    }
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
    68
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    69
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public void vmStartEvent(VMStartEvent se)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        MessageOutput.lnprint("VM Started:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    75
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void vmDeathEvent(VMDeathEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    79
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void vmDisconnectEvent(VMDisconnectEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    83
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void threadStartEvent(ThreadStartEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    87
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void threadDeathEvent(ThreadDeathEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    91
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void classPrepareEvent(ClassPrepareEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    95
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public void classUnloadEvent(ClassUnloadEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    99
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void breakpointEvent(BreakpointEvent be)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        MessageOutput.lnprint("Breakpoint hit:");
52228
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   103
        // Print breakpoint location and prompt if suspend policy is
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   104
        // SUSPEND_NONE or SUSPEND_EVENT_THREAD. In case of SUSPEND_ALL
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   105
        // policy this is handled by vmInterrupted() method.
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   106
        int suspendPolicy = be.request().suspendPolicy();
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   107
        switch (suspendPolicy) {
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   108
            case EventRequest.SUSPEND_EVENT_THREAD:
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   109
            case EventRequest.SUSPEND_NONE:
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   110
                printBreakpointLocation(be);
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   111
                MessageOutput.printPrompt();
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   112
                break;
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   113
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   116
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void fieldWatchEvent(WatchpointEvent fwe)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        Field field = fwe.field();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        ObjectReference obj = fwe.object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (fwe instanceof ModificationWatchpointEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            MessageOutput.lnprint("Field access encountered before after",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                  new Object [] {field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                                 fwe.valueCurrent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                                 ((ModificationWatchpointEvent)fwe).valueToBe()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            MessageOutput.lnprint("Field access encountered", field.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   132
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void stepEvent(StepEvent se)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        MessageOutput.lnprint("Step completed:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   138
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void exceptionEvent(ExceptionEvent ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Location catchLocation = ee.catchLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (catchLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            MessageOutput.lnprint("Exception occurred uncaught",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                  ee.exception().referenceType().name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            MessageOutput.lnprint("Exception occurred caught",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                  new Object [] {ee.exception().referenceType().name(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                                 Commands.locationString(catchLocation)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   152
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void methodEntryEvent(MethodEntryEvent me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         * These can be very numerous, so be as efficient as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * If we are stopping here, then we will see the normal location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         * info printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            // We are stopping; the name will be shown by the normal mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            MessageOutput.lnprint("Method entered:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // We aren't stopping, show the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            MessageOutput.print("Method entered:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            printLocationOfEvent(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   170
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public boolean methodExitEvent(MethodExitEvent me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         * These can be very numerous, so be as efficient as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        Method mmm = Env.atExitMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        Method meMethod = me.method();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (mmm == null || mmm.equals(meMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // Either we are not tracing a specific method, or we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            // and we are exitting that method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                // We will be stopping here, so do a newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                MessageOutput.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (Env.vm().canGetMethodReturnValues()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                MessageOutput.print("Method exitedValue:", me.returnValue() + "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                MessageOutput.print("Method exited:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (me.request().suspendPolicy() == EventRequest.SUSPEND_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                // We won't be stopping here, so show the method name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                printLocationOfEvent(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // In case we want to have a one shot trace exit some day, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // code disables the request so we don't hit it again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                // This is a one shot deal; we don't want to stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                // here the next time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                Env.setAtExitMethod(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                EventRequestManager erm = Env.vm().eventRequestManager();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   206
                for (EventRequest eReq : erm.methodExitRequests()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    if (eReq.equals(me.request())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        eReq.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // We are tracing a specific method, and this isn't it.  Keep going.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   219
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public void vmInterrupted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        Thread.yield();  // fetch output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        printCurrentLocation();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   223
        for (String cmd : monitorCommands) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   224
            StringTokenizer t = new StringTokenizer(cmd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            t.nextToken();  // get rid of monitor number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            executeCommand(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        MessageOutput.printPrompt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   231
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public void receivedEvent(Event event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private void printBaseLocation(String threadName, Location loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        MessageOutput.println("location",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                              new Object [] {threadName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                             Commands.locationString(loc)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
52228
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   241
    private void printBreakpointLocation(BreakpointEvent be) {
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   242
        printLocationWithSourceLine(be.thread().name(), be.location());
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   243
    }
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   244
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private void printCurrentLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        StackFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            frame = threadInfo.getCurrentFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } catch (IncompatibleThreadStateException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            MessageOutput.println("<location unavailable>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (frame == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            MessageOutput.println("No frames on the current call stack");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } else {
52228
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   257
            printLocationWithSourceLine(threadInfo.getThread().name(), frame.location());
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   258
        }
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   259
        MessageOutput.println();
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   260
    }
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   261
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   262
    private void printLocationWithSourceLine(String threadName, Location loc) {
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   263
        printBaseLocation(threadName, loc);
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   264
        // Output the current source line, if possible
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   265
        if (loc.lineNumber() != -1) {
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   266
            String line;
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   267
            try {
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   268
                line = Env.sourceLine(loc, loc.lineNumber());
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   269
            } catch (java.io.IOException e) {
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   270
                line = null;
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   271
            }
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   272
            if (line != null) {
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   273
                MessageOutput.println("source line number and line",
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   274
                                           new Object [] {loc.lineNumber(),
0ca91992dd8e 8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
dtitov
parents: 52006
diff changeset
   275
                                                          line});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private void printLocationOfEvent(LocatableEvent theEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        printBaseLocation(theEvent.thread().name(), theEvent.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    void help() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        MessageOutput.println("zz help text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private static final String[][] commandList = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         * NOTE: this list must be kept sorted in ascending ASCII
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         *       order by element [0].  Ref: isCommand() below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         *Command      OK when        OK when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * name      disconnected?   readonly?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         *------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        {"!!",           "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        {"?",            "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        {"bytecodes",    "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        {"catch",        "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        {"class",        "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        {"classes",      "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        {"classpath",    "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        {"clear",        "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        {"connectors",   "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        {"cont",         "n",         "n"},
53782
37c12515c30f 8218941: jdb should support a dbgtrace command that acts the same as the dbgtrace command line option
cjplummer
parents: 52366
diff changeset
   307
        {"dbgtrace",     "y",         "y"},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        {"disablegc",    "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        {"down",         "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        {"dump",         "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        {"enablegc",     "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        {"eval",         "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        {"exclude",      "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        {"exit",         "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        {"extension",    "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        {"fields",       "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        {"gc",           "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        {"help",         "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        {"ignore",       "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        {"interrupt",    "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        {"kill",         "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        {"lines",        "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        {"list",         "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        {"load",         "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        {"locals",       "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        {"lock",         "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        {"memory",       "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        {"methods",      "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        {"monitor",      "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        {"next",         "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        {"pop",          "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        {"print",        "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        {"quit",         "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        {"read",         "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        {"redefine",     "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        {"reenter",      "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        {"resume",       "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        {"run",          "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        {"save",         "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        {"set",          "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        {"sourcepath",   "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        {"step",         "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        {"stepi",        "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        {"stop",         "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        {"suspend",      "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        {"thread",       "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        {"threadgroup",  "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        {"threadgroups", "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        {"threadlocks",  "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        {"threads",      "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        {"trace",        "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        {"unmonitor",    "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        {"untrace",      "n",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        {"unwatch",      "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        {"up",           "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        {"use",          "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        {"version",      "y",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        {"watch",        "y",         "n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        {"where",        "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        {"wherei",       "n",         "y"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Look up the command string in commandList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * If found, return the index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * If not found, return index < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    private int isCommand(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        //Reference: binarySearch() in java/util/Arrays.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        //           Adapted for use with String[][0].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        int low = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        int high = commandList.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        while (low <= high) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            int mid = (low + high) >>> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            String midVal = commandList[mid][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            int compare = midVal.compareTo(key);
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   377
            if (compare < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                low = mid + 1;
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   379
            } else if (compare > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                high = mid - 1;
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   381
            }
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   382
            else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                return mid; // key found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   385
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return -(low + 1);  // key not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Return true if the command is OK when disconnected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    private boolean isDisconnectCmd(int ii) {
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   393
        if (ii < 0 || ii >= commandList.length) {
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   394
            return false;
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   395
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return (commandList[ii][1].equals("y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Return true if the command is OK when readonly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    private boolean isReadOnlyCmd(int ii) {
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   403
        if (ii < 0 || ii >= commandList.length) {
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   404
            return false;
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   405
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return (commandList[ii][2].equals("y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    void executeCommand(StringTokenizer t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        String cmd = t.nextToken().toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // Normally, prompt for the next command after this one is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        boolean showPrompt = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         * Anything starting with # is discarded as a no-op or 'comment'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (!cmd.startsWith("#")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
             * Next check for an integer repetition prefix.  If found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
             * recursively execute cmd that number of times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (Character.isDigit(cmd.charAt(0)) && t.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    int repeat = Integer.parseInt(cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    String subcom = t.nextToken("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    while (repeat-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        executeCommand(new StringTokenizer(subcom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        showPrompt = false; // Bypass the printPrompt() below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                } catch (NumberFormatException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    MessageOutput.println("Unrecognized command.  Try help...", cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                int commandNumber = isCommand(cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                 * Check for an unknown command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                if (commandNumber < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    MessageOutput.println("Unrecognized command.  Try help...", cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                } else if (!Env.connection().isOpen() && !isDisconnectCmd(commandNumber)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    MessageOutput.println("Command not valid until the VM is started with the run command",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                          cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                } else if (Env.connection().isOpen() && !Env.vm().canBeModified() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                           !isReadOnlyCmd(commandNumber)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    MessageOutput.println("Command is not supported on a read-only VM connection",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                          cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    Commands evaluator = new Commands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        if (cmd.equals("print")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                            evaluator.commandPrint(t, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                        } else if (cmd.equals("eval")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                            evaluator.commandPrint(t, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                        } else if (cmd.equals("set")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                            evaluator.commandSet(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        } else if (cmd.equals("dump")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                            evaluator.commandPrint(t, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        } else if (cmd.equals("locals")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                            evaluator.commandLocals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        } else if (cmd.equals("classes")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                            evaluator.commandClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        } else if (cmd.equals("class")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                            evaluator.commandClass(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        } else if (cmd.equals("connectors")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                            evaluator.commandConnectors(Bootstrap.virtualMachineManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        } else if (cmd.equals("methods")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                            evaluator.commandMethods(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        } else if (cmd.equals("fields")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                            evaluator.commandFields(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        } else if (cmd.equals("threads")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                            evaluator.commandThreads(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        } else if (cmd.equals("thread")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                            evaluator.commandThread(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        } else if (cmd.equals("suspend")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                            evaluator.commandSuspend(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        } else if (cmd.equals("resume")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                            evaluator.commandResume(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        } else if (cmd.equals("cont")) {
52006
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   486
                            MessageOutput.printPrompt(true);
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   487
                            showPrompt = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                            evaluator.commandCont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        } else if (cmd.equals("threadgroups")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                            evaluator.commandThreadGroups();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        } else if (cmd.equals("threadgroup")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                            evaluator.commandThreadGroup(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        } else if (cmd.equals("catch")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                            evaluator.commandCatchException(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        } else if (cmd.equals("ignore")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                            evaluator.commandIgnoreException(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        } else if (cmd.equals("step")) {
52006
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   498
                            MessageOutput.printPrompt(true);
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   499
                            showPrompt = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                            evaluator.commandStep(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                        } else if (cmd.equals("stepi")) {
52006
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   502
                            MessageOutput.printPrompt(true);
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   503
                            showPrompt = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                            evaluator.commandStepi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        } else if (cmd.equals("next")) {
52006
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   506
                            MessageOutput.printPrompt(true);
82dc590fa586 8169718: nsk/jdb/locals/locals002: ERROR: Cannot find boolVar with expected value: false
gadams
parents: 48543
diff changeset
   507
                            showPrompt = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                            evaluator.commandNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        } else if (cmd.equals("kill")) {
52366
8f543813b402 8211013: [TESTBUG] nsk/jdb/kill/kill002 wait for message and prompt
gadams
parents: 52228
diff changeset
   510
                            showPrompt = false;        // asynchronous command
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                            evaluator.commandKill(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        } else if (cmd.equals("interrupt")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                            evaluator.commandInterrupt(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                        } else if (cmd.equals("trace")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                            evaluator.commandTrace(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        } else if (cmd.equals("untrace")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                            evaluator.commandUntrace(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                        } else if (cmd.equals("where")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                            evaluator.commandWhere(t, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                        } else if (cmd.equals("wherei")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                            evaluator.commandWhere(t, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                        } else if (cmd.equals("up")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                            evaluator.commandUp(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                        } else if (cmd.equals("down")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                            evaluator.commandDown(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        } else if (cmd.equals("load")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                            evaluator.commandLoad(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                        } else if (cmd.equals("run")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                            evaluator.commandRun(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                             * Fire up an event handler, if the connection was just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                             * opened. Since this was done from the run command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                             * we don't stop the VM on its VM start event (so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                             * arg 2 is false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                            if ((handler == null) && Env.connection().isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                handler = new EventHandler(this, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        } else if (cmd.equals("memory")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                            evaluator.commandMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                        } else if (cmd.equals("gc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                            evaluator.commandGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                        } else if (cmd.equals("stop")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                            evaluator.commandStop(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        } else if (cmd.equals("clear")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                            evaluator.commandClear(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        } else if (cmd.equals("watch")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                            evaluator.commandWatch(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        } else if (cmd.equals("unwatch")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                            evaluator.commandUnwatch(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        } else if (cmd.equals("list")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                            evaluator.commandList(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                        } else if (cmd.equals("lines")) { // Undocumented command: useful for testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                            evaluator.commandLines(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        } else if (cmd.equals("classpath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                            evaluator.commandClasspath(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        } else if (cmd.equals("use") || cmd.equals("sourcepath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                            evaluator.commandUse(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                        } else if (cmd.equals("monitor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                            monitorCommand(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        } else if (cmd.equals("unmonitor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                            unmonitorCommand(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                        } else if (cmd.equals("lock")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                            evaluator.commandLock(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                        } else if (cmd.equals("threadlocks")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                            evaluator.commandThreadlocks(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                        } else if (cmd.equals("disablegc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                            evaluator.commandDisableGC(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                        } else if (cmd.equals("enablegc")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                            evaluator.commandEnableGC(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                        } else if (cmd.equals("save")) { // Undocumented command: useful for testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                            evaluator.commandSave(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                            showPrompt = false;        // asynchronous command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                        } else if (cmd.equals("bytecodes")) { // Undocumented command: useful for testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                            evaluator.commandBytecodes(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                        } else if (cmd.equals("redefine")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                            evaluator.commandRedefine(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        } else if (cmd.equals("pop")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                            evaluator.commandPopFrames(t, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                        } else if (cmd.equals("reenter")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                            evaluator.commandPopFrames(t, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        } else if (cmd.equals("extension")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                            evaluator.commandExtension(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        } else if (cmd.equals("exclude")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                            evaluator.commandExclude(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        } else if (cmd.equals("read")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                            readCommand(t);
53782
37c12515c30f 8218941: jdb should support a dbgtrace command that acts the same as the dbgtrace command line option
cjplummer
parents: 52366
diff changeset
   591
                        } else if (cmd.equals("dbgtrace")) {
37c12515c30f 8218941: jdb should support a dbgtrace command that acts the same as the dbgtrace command line option
cjplummer
parents: 52366
diff changeset
   592
                            evaluator.commandDbgTrace(t);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        } else if (cmd.equals("help") || cmd.equals("?")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                            help();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        } else if (cmd.equals("version")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                            evaluator.commandVersion(progname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                                     Bootstrap.virtualMachineManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                        } else if (cmd.equals("quit") || cmd.equals("exit")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                            if (handler != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                handler.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                            Env.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                            MessageOutput.println("Unrecognized command.  Try help...", cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    } catch (VMCannotBeModifiedException rovm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        MessageOutput.println("Command is not supported on a read-only VM connection", cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    } catch (UnsupportedOperationException uoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        MessageOutput.println("Command is not supported on the target VM", cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    } catch (VMNotConnectedException vmnse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        MessageOutput.println("Command not valid until the VM is started with the run command",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                              cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                        MessageOutput.printException("Internal exception:", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (showPrompt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            MessageOutput.printPrompt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Maintain a list of commands to execute each time the VM is suspended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    void monitorCommand(StringTokenizer t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (t.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            ++monitorCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            monitorCommands.add(monitorCount + ": " + t.nextToken(""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        } else {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   632
            for (String cmd : monitorCommands) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   633
                MessageOutput.printDirectln(cmd);// Special case: use printDirectln()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    void unmonitorCommand(StringTokenizer t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if (t.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            String monTok = t.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            int monNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                monNum = Integer.parseInt(monTok);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            } catch (NumberFormatException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                MessageOutput.println("Not a monitor number:", monTok);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            String monStr = monTok + ":";
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   649
            for (String cmd : monitorCommands) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                StringTokenizer ct = new StringTokenizer(cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                if (ct.nextToken().equals(monStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    monitorCommands.remove(cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                    MessageOutput.println("Unmonitoring", cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            MessageOutput.println("No monitor numbered:", monTok);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            MessageOutput.println("Usage: unmonitor <monitor#>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    void readCommand(StringTokenizer t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (t.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            String cmdfname = t.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            if (!readCommandFile(new File(cmdfname))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                MessageOutput.println("Could not open:", cmdfname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            MessageOutput.println("Usage: read <command-filename>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * Read and execute a command file.  Return true if the file was read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * else false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    boolean readCommandFile(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        BufferedReader inFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            if (f.canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                // Process initial commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                MessageOutput.println("*** Reading commands from", f.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                inFile = new BufferedReader(new FileReader(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                String ln;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                while ((ln = inFile.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    StringTokenizer t = new StringTokenizer(ln);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    if (t.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        executeCommand(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            if (inFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    inFile.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        return inFile != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * Try to read commands from dir/fname, unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * the canonical path passed in is the same as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * for dir/fname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * Return null if that file doesn't exist,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * else return the canonical path of that file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    String readStartupCommandFile(String dir, String fname, String canonPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        File dotInitFile = new File(dir, fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if (!dotInitFile.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        String myCanonFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            myCanonFile = dotInitFile.getCanonicalPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            MessageOutput.println("Could not open:", dotInitFile.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if (canonPath == null || !canonPath.equals(myCanonFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (!readCommandFile(dotInitFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                MessageOutput.println("Could not open:", dotInitFile.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return myCanonFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    public TTY() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        MessageOutput.println("Initializing progname", progname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (Env.connection().isOpen() && Env.vm().canBeModified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
             * Connection opened on startup. Start event handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
             * immediately, telling it (through arg 2) to stop on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
             * VM start event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            this.handler = new EventHandler(this, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            BufferedReader in =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    new BufferedReader(new InputStreamReader(System.in));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            String lastLine = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
             * Read start up files.  This mimics the behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
             * of gdb which will read both ~/.gdbinit and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
             * ./.gdbinit if they exist.  We have the twist that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
             * we allow two different names, so we do this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
             *  if ~/jdb.ini exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
             *      read it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
             *  else if ~/.jdbrc exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
             *      read it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
             *  if ./jdb.ini exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
             *      if it hasn't been read, read it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
             *      It could have been read above because ~ == .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
             *      or because of symlinks, ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
             *  else if ./jdbrx exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
             *      if it hasn't been read, read it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                String userHome = System.getProperty("user.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                String canonPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                if ((canonPath = readStartupCommandFile(userHome, "jdb.ini", null)) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    // Doesn't exist, try alternate spelling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    canonPath = readStartupCommandFile(userHome, ".jdbrc", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                String userDir = System.getProperty("user.dir");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                if (readStartupCommandFile(userDir, "jdb.ini", canonPath) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    // Doesn't exist, try alternate spelling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    readStartupCommandFile(userDir, ".jdbrc", canonPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            // Process interactive commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            MessageOutput.printPrompt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                String ln = in.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                if (ln == null) {
38348
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
   793
                    /*
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
   794
                     *  Jdb is being shutdown because debuggee exited, ignore any 'null'
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
   795
                     *  returned by readLine() during shutdown. JDK-8154144.
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
   796
                     */
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
   797
                    if (!isShuttingDown()) {
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
   798
                        MessageOutput.println("Input stream closed.");
bd578f1c54b6 8154144: Tests in com/sun/jdi fails intermittently with &quot;jdb input stream closed prematurely&quot;
dsamersoff
parents: 25859
diff changeset
   799
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    ln = "quit";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                if (ln.startsWith("!!") && lastLine != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    ln = lastLine + ln.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    MessageOutput.printDirectln(ln);// Special case: use printDirectln()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                StringTokenizer t = new StringTokenizer(ln);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                if (t.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    lastLine = ln;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    executeCommand(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    MessageOutput.printPrompt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        } catch (VMDisconnectedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            handler.handleDisconnectedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    private static void usage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        MessageOutput.println("zz usage text", new Object [] {progname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                                                     File.pathSeparator});
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
   824
        System.exit(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    static void usageError(String messageKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        MessageOutput.println(messageKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        MessageOutput.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    static void usageError(String messageKey, String argument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        MessageOutput.println(messageKey, argument);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        MessageOutput.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    private static boolean supportsSharedMemory() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   840
        for (Connector connector :
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   841
                 Bootstrap.virtualMachineManager().allConnectors()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (connector.transport() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            if ("dt_shmem".equals(connector.transport().name())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    private static String addressToSocketArgs(String address) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        int index = address.indexOf(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            String hostString = address.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            String portString = address.substring(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            return "hostname=" + hostString + ",port=" + portString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            return "port=" + address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    private static boolean hasWhitespace(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        int length = string.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            if (Character.isWhitespace(string.charAt(i))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    private static String addArgument(String string, String argument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if (hasWhitespace(argument) || argument.indexOf(',') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            // Quotes were stripped out for this argument, add 'em back.
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   876
            StringBuilder sb = new StringBuilder(string);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   877
            sb.append('"');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            for (int i = 0; i < argument.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                char c = argument.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                if (c == '"') {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   881
                    sb.append('\\');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   883
                sb.append(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   885
            sb.append("\" ");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   886
            return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            return string + argument + ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public static void main(String argv[]) throws MissingResourceException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        String cmdLine = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        String javaArgs = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        int traceFlags = VirtualMachine.TRACE_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        boolean launchImmediately = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        String connectSpec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        MessageOutput.textResources = ResourceBundle.getBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            ("com.sun.tools.example.debug.tty.TTYResources",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
             Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        for (int i = 0; i < argv.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            String token = argv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            if (token.equals("-dbgtrace")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                if ((i == argv.length - 1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                    ! Character.isDigit(argv[i+1].charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    traceFlags = VirtualMachine.TRACE_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                    String flagStr = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                        flagStr = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        traceFlags = Integer.decode(flagStr).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                    } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        usageError("dbgtrace flag value must be an integer:",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                                   flagStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            } else if (token.equals("-X")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                usageError("Use java minus X to see");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            } else if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                   // Standard VM options passed on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                   token.equals("-v") || token.startsWith("-v:") ||  // -v[:...]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                   token.startsWith("-verbose") ||                  // -verbose[:...]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                   token.startsWith("-D") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                   // -classpath handled below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                   // NonStandard options passed on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                   token.startsWith("-X") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                   // Old-style options (These should remain in place as long as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                   //  the standard VM accepts them)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                   token.equals("-noasyncgc") || token.equals("-prof") ||
53853
7ca9e625d6b2 8214719: Deprecate -Xverify:none option
hseigel
parents: 53782
diff changeset
   934
                   token.equals("-verify") ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                   token.equals("-verifyremote") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                   token.equals("-verbosegc") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                   token.startsWith("-ms") || token.startsWith("-mx") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                   token.startsWith("-ss") || token.startsWith("-oss") ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                javaArgs = addArgument(javaArgs, token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            } else if (token.equals("-tclassic")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                usageError("Classic VM no longer supported.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            } else if (token.equals("-tclient")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                // -client must be the first one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                javaArgs = "-client " + javaArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            } else if (token.equals("-tserver")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                // -server must be the first one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                javaArgs = "-server " + javaArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            } else if (token.equals("-sourcepath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                if (i == (argv.length - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                    usageError("No sourcepath specified.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                Env.setSourcePath(argv[++i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            } else if (token.equals("-classpath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                if (i == (argv.length - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                    usageError("No classpath specified.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                javaArgs = addArgument(javaArgs, token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                javaArgs = addArgument(javaArgs, argv[++i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            } else if (token.equals("-attach")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                if (connectSpec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                    usageError("cannot redefine existing connection", token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                if (i == (argv.length - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    usageError("No attach address specified.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                String address = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                 * -attach is shorthand for one of the reference implementation's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                 * attaching connectors. Use the shared memory attach if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                 * available; otherwise, use sockets. Build a connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                 * specification string based on this decision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                if (supportsSharedMemory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    connectSpec = "com.sun.jdi.SharedMemoryAttach:name=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                                   address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    String suboptions = addressToSocketArgs(address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                    connectSpec = "com.sun.jdi.SocketAttach:" + suboptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            } else if (token.equals("-listen") || token.equals("-listenany")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                if (connectSpec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    usageError("cannot redefine existing connection", token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                String address = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                if (token.equals("-listen")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    if (i == (argv.length - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                        usageError("No attach address specified.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    address = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                 * -listen[any] is shorthand for one of the reference implementation's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                 * listening connectors. Use the shared memory listen if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                 * available; otherwise, use sockets. Build a connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                 * specification string based on this decision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                if (supportsSharedMemory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                    connectSpec = "com.sun.jdi.SharedMemoryListen:";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    if (address != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                        connectSpec += ("name=" + address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                    connectSpec = "com.sun.jdi.SocketListen:";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                    if (address != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                        connectSpec += addressToSocketArgs(address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            } else if (token.equals("-launch")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                launchImmediately = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            } else if (token.equals("-listconnectors")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                Commands evaluator = new Commands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                evaluator.commandConnectors(Bootstrap.virtualMachineManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            } else if (token.equals("-connect")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                 * -connect allows the user to pick the connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                 * used in bringing up the target VM. This allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                 * use of connectors other than those in the reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                 * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                if (connectSpec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                    usageError("cannot redefine existing connection", token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                if (i == (argv.length - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                    usageError("No connect specification.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                connectSpec = argv[++i];
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
  1040
            } else if (token.equals("-?") ||
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
  1041
                       token.equals("-h") ||
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
  1042
                       token.equals("--help") ||
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
  1043
                       // -help: legacy.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
  1044
                       token.equals("-help")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            } else if (token.equals("-version")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                Commands evaluator = new Commands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                evaluator.commandVersion(progname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                         Bootstrap.virtualMachineManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            } else if (token.startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                usageError("invalid option", token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                // Everything from here is part of the command line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                cmdLine = addArgument("", token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                for (i++; i < argv.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    cmdLine = addArgument(cmdLine, argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
         * Unless otherwise specified, set the default connect spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
         * Here are examples of jdb command lines and how the options
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
         * are interpreted as arguments to the program being debugged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
         * arg1       arg2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
         * ----       ----
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
         * jdb hello a b       a          b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
         * jdb hello "a b"     a b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         * jdb hello a,b       a,b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
         * jdb hello a, b      a,         b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
         * jdb hello "a, b"    a, b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
         * jdb -connect "com.sun.jdi.CommandLineLaunch:main=hello  a,b"   illegal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
         * jdb -connect  com.sun.jdi.CommandLineLaunch:main=hello "a,b"   illegal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
         * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello "a,b"'  arg1 = a,b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
         * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello "a b"'  arg1 = a b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
         * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello  a b'   arg1 = a  arg2 = b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
         * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello "a," b' arg1 = a, arg2 = b
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (connectSpec == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            connectSpec = "com.sun.jdi.CommandLineLaunch:";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        } else if (!connectSpec.endsWith(",") && !connectSpec.endsWith(":")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            connectSpec += ","; // (Bug ID 4285874)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        cmdLine = cmdLine.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        javaArgs = javaArgs.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        if (cmdLine.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            if (!connectSpec.startsWith("com.sun.jdi.CommandLineLaunch:")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                usageError("Cannot specify command line with connector:",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                           connectSpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            connectSpec += "main=" + cmdLine + ",";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        if (javaArgs.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            if (!connectSpec.startsWith("com.sun.jdi.CommandLineLaunch:")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                usageError("Cannot specify target vm arguments with connector:",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                           connectSpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            connectSpec += "options=" + javaArgs + ",";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            if (! connectSpec.endsWith(",")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                connectSpec += ","; // (Bug ID 4285874)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            Env.init(connectSpec, launchImmediately, traceFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            new TTY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            MessageOutput.printException("Internal exception:", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
}