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