src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/windbg/WindbgDebuggerLocal.java
author jgeorge
Thu, 30 Nov 2017 21:24:52 +0530
changeset 48166 2659c4fe8ea7
parent 47216 71c04702a3d5
child 49274 9f3ce373370a
permissions -rw-r--r--
8191324: SA cleanup -- part 2 Summary: Avoid redefinition of hotspot constants and ia64 code vestiges removal Reviewed-by: sspitsyn, dholmes, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
48166
2659c4fe8ea7 8191324: SA cleanup -- part 2
jgeorge
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.debugger.windbg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.net.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.debugger.amd64.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.debugger.x86.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.debugger.windbg.amd64.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.debugger.windbg.x86.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.debugger.win32.coff.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.debugger.cdbg.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import sun.jvm.hotspot.debugger.cdbg.basic.BasicDebugEvent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
import sun.jvm.hotspot.utilities.memo.*;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    40
import sun.jvm.hotspot.runtime.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
/** <P> An implementation of the JVMDebugger interface which talks to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    windbg and symbol table management is done in Java. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    <P> <B>NOTE</B> that since we have the notion of fetching "Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    primitive types" from the remote process (which might have
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    different sizes than we expect) we have a bootstrapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    problem. We need to know the sizes of these types before we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    fetch them. The current implementation solves this problem by
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    requiring that it be configured with these type sizes before they
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    can be fetched. The readJ(Type) routines here will throw a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    RuntimeException if they are called before the debugger is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    configured with the Java primitive type sizes. </P> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
public class WindbgDebuggerLocal extends DebuggerBase implements WindbgDebugger {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  private PageCache cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  private boolean   attached;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private boolean   isCore;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Symbol lookup support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // This is a map of library names to DLLs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private Map nameToDllMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // C/C++ debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private List/*<LoadObject>*/ loadObjects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  private CDebugger cdbg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // thread access
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  private Map threadIntegerRegisterSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  private List threadList;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // windbg native interface pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  private long ptrIDebugClient;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  private long ptrIDebugControl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  private long ptrIDebugDataSpaces;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  private long ptrIDebugOutputCallbacks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  private long ptrIDebugAdvanced;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  private long ptrIDebugSymbols;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  private long ptrIDebugSystemObjects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  private WindbgThreadFactory threadFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Implementation of Debugger interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  /** <P> machDesc may not be null. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      <P> useCache should be set to true if debugging is being done
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      locally, and to false if the debugger is being created for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      purpose of supporting remote debugging. </P> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  public WindbgDebuggerLocal(MachineDescription machDesc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                            boolean useCache) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    this.machDesc = machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    utils = new DebuggerUtilities(machDesc.getAddressSize(), machDesc.isBigEndian()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
           public void checkAlignment(long address, long alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
             // Need to override default checkAlignment because we need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
             // relax alignment constraints on Windows/x86
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
             if ( (address % alignment != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                &&(alignment != 8 || address % 4 != 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                throw new UnalignedAddressException(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                        "Trying to read at address: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                      + addressValueToString(address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                      + " with alignment: " + alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                        address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    String cpu = PlatformInfo.getCPU();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
       threadFactory = new WindbgX86ThreadFactory(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
       threadFactory = new WindbgAMD64ThreadFactory(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    if (useCache) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      // Cache portion of the remote process's address space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      // Fetching data over the socket connection to dbx is slow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      // Might be faster if we were using a binary protocol to talk to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      // dbx, but would have to test. For now, this cache works best
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      // if it covers the entire heap of the remote process. FIXME: at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      // least should make this tunable from the outside, i.e., via
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      // the UI. This is a cache of 4096 4K pages, or 16 MB. The page
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      // size must be adjusted to be the hardware's page size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      // (FIXME: should pick this up from the debugger.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      initCache(4096, 4096);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // FIXME: add instantiation of thread factory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  public boolean hasProcessList() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  public List getProcessList() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  public synchronized void attach(int processID) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    attachInit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    attach0(processID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    attached = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    isCore = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  public synchronized void attach(String executableName, String coreFileName) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    attachInit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    attach0(executableName, coreFileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    attached = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    isCore = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  public List getLoadObjectList() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    return loadObjects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  public synchronized boolean detach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    if ( ! attached)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
       return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    // Close all open DLLs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    if (nameToDllMap != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      for (Iterator iter = nameToDllMap.values().iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        DLL dll = (DLL) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        dll.close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      nameToDllMap = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      loadObjects = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    cdbg = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    clearCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    threadIntegerRegisterSet = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    threadList = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
       detach0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    } finally {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
       attached = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
       resetNativePointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  public Address parseAddress(String addressString) throws NumberFormatException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    return newAddress(utils.scanAddress(addressString));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  public String getOS() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    return PlatformInfo.getOS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  public String getCPU() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    return PlatformInfo.getCPU();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  public boolean hasConsole() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  public synchronized String consoleExecuteCommand(String cmd) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    if (! attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
       throw new DebuggerException("debugger not yet attached to a Dr. Watson dump!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    return consoleExecuteCommand0(cmd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  public String getConsolePrompt() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    return "(windbg)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  public CDebugger getCDebugger() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    if (cdbg == null) {
48166
2659c4fe8ea7 8191324: SA cleanup -- part 2
jgeorge
parents: 47216
diff changeset
   230
      cdbg = new WindbgCDebugger(this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    return cdbg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  /** From the SymbolLookup interface via Debugger and JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  public synchronized Address lookup(String objectName, String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    return newAddress(lookupByName(objectName, symbol));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  /** From the SymbolLookup interface via Debugger and JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  public synchronized OopHandle lookupOop(String objectName, String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    Address addr = lookup(objectName, symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    return addr.addOffsetToAsOopHandle(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  public synchronized ClosestSymbol lookup(long address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    return lookupByAddress0(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  /** From the Debugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  public MachineDescription getMachineDescription() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    return machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // Implementation of ThreadAccess interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  /** From the ThreadAccess interface via Debugger and JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  public ThreadProxy getThreadForIdentifierAddress(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    return threadFactory.createThreadWrapper(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  public ThreadProxy getThreadForThreadId(long handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    // with windbg we can't make out using handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    throw new DebuggerException("Unimplemented!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  public long getThreadIdFromSysId(long sysId) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    return getThreadIdFromSysId0(sysId);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // Overridden from DebuggerBase because we need to relax alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  // constraints on x86
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  public long readJLong(long address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    throws UnmappedAddressException, UnalignedAddressException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    checkJavaConfigured();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    // FIXME: allow this to be configurable. Undesirable to add a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    // dependency on the runtime package here, though, since this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    // package should be strictly underneath it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    //    utils.checkAlignment(address, jlongSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    utils.checkAlignment(address, jintSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    byte[] data = readBytes(address, jlongSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    return utils.dataToJLong(data, jlongSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // Internal routines (for implementation of WindbgAddress).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // These must not be called until the MachineDescription has been set up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  /** From the WindbgDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  public String addressValueToString(long address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    return utils.addressValueToString(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  /** From the WindbgDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  public WindbgAddress readAddress(long address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    throws UnmappedAddressException, UnalignedAddressException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    return (WindbgAddress) newAddress(readAddressValue(address));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   311
  public WindbgAddress readCompOopAddress(long address)
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   312
    throws UnmappedAddressException, UnalignedAddressException {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   313
    return (WindbgAddress) newAddress(readCompOopAddressValue(address));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   314
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   315
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 7696
diff changeset
   316
  public WindbgAddress readCompKlassAddress(long address)
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 7696
diff changeset
   317
    throws UnmappedAddressException, UnalignedAddressException {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 7696
diff changeset
   318
    return (WindbgAddress) newAddress(readCompKlassAddressValue(address));
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 7696
diff changeset
   319
  }
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 7696
diff changeset
   320
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  /** From the WindbgDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  public WindbgOopHandle readOopHandle(long address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    throws UnmappedAddressException, UnalignedAddressException, NotInHeapException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    long value = readAddressValue(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    return (value == 0 ? null : new WindbgOopHandle(this, value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   327
  public WindbgOopHandle readCompOopHandle(long address)
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   328
    throws UnmappedAddressException, UnalignedAddressException, NotInHeapException {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   329
    long value = readCompOopAddressValue(address);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   330
    return (value == 0 ? null : new WindbgOopHandle(this, value));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   331
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  /** From the WindbgDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  public int getAddressSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    return (int) machDesc.getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  // Thread context access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  private synchronized void setThreadIntegerRegisterSet(long threadId,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
                                               long[] regs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    threadIntegerRegisterSet.put(new Long(threadId), regs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  private synchronized void addThread(long sysId) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    threadList.add(threadFactory.createThreadWrapper(sysId));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  public synchronized long[] getThreadIntegerRegisterSet(long threadId)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    return (long[]) threadIntegerRegisterSet.get(new Long(threadId));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  public synchronized List getThreadList() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    return threadList;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  private String findFullPath(String file) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    File f = new File(file);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    if (f.exists()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
       return file;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
       // remove path part, if any.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
       file = f.getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
       StringTokenizer st = new StringTokenizer(imagePath, File.pathSeparator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
       while (st.hasMoreTokens()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
          f = new File(st.nextToken(), file);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
          if (f.exists()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
             return f.getPath();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  private synchronized void addLoadObject(String file, long size, long base) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    String path = findFullPath(file);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    if (path != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
       DLL dll = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
       if (useNativeLookup) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
          dll = new DLL(this, path, size,newAddress(base)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
                 public ClosestSymbol  closestSymbolToPC(Address pcAsAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                   long pc = getAddressValue(pcAsAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
                   ClosestSymbol sym = lookupByAddress0(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
                   if (sym == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
                     return super.closestSymbolToPC(pcAsAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                   } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
                     return sym;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
                   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
                 }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
              };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
       } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
         dll = new DLL(this, path, size, newAddress(base));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
       loadObjects.add(dll);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
       nameToDllMap.put(new File(file).getName(), dll);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // Address access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  /** From the Debugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  public long getAddressValue(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    if (addr == null) return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    return ((WindbgAddress) addr).getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  /** From the WindbgDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  public Address newAddress(long value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    if (value == 0) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    return new WindbgAddress(this, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  // attach/detach helpers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  private void checkAttached() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    if (attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
       String msg = (isCore)? "already attached to a Dr. Watson dump!" :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
                              "already attached to a process!";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
       throw new DebuggerException(msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  private void requireAttach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    if (!attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
       throw new RuntimeException("not attached to a process or Dr Watson dump");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  private void attachInit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    checkAttached();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    loadObjects = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    nameToDllMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    threadIntegerRegisterSet = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    threadList = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  private void resetNativePointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    ptrIDebugClient          = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    ptrIDebugControl         = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    ptrIDebugDataSpaces      = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    ptrIDebugOutputCallbacks = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    ptrIDebugAdvanced        = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    ptrIDebugSymbols         = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    ptrIDebugSystemObjects   = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  synchronized long lookupByName(String objectName, String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    long res = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    if (useNativeLookup) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
      res = lookupByName0(objectName, symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
      if (res != 0L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
        return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      } // else fallthru...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    DLL dll = (DLL) nameToDllMap.get(objectName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    // The DLL can be null because we use this to search through known
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    // DLLs in HotSpotTypeDataBase (for example)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    if (dll != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      WindbgAddress addr = (WindbgAddress) dll.lookupSymbol(symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      if (addr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
        return addr.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    return 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  /** This reads bytes from the remote process. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  public synchronized ReadResult readBytesFromProcess(long address, long numBytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    throws UnmappedAddressException, DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    byte[] res = readBytesFromProcess0(address, numBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    if(res != null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
       return new ReadResult(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
       return new ReadResult(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  private DLL findDLLByName(String fullPathName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    for (Iterator iter = loadObjects.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
      DLL dll = (DLL) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
      if (dll.getName().equals(fullPathName)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
        return dll;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  public void writeBytesToProcess(long address, long numBytes, byte[] data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    throws UnmappedAddressException, DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    throw new DebuggerException("Unimplemented");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  private static String  imagePath;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  private static String  symbolPath;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  private static boolean useNativeLookup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
     /*
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   513
      * sawindbg.dll depends on dbgeng.dll which itself depends on
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   514
      * dbghelp.dll. We have to make sure that the dbgeng.dll and
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   515
      * dbghelp.dll that we load are compatible with each other. We
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   516
      * load both of those libraries from the same directory based
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   517
      * on the theory that co-located libraries are compatible.
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   518
      *
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   519
      * On Windows 2000 and earlier, dbgeng.dll and dbghelp.dll were
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   520
      * not included as part of the standard system directory. On
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   521
      * systems newer than Windows 2000, dbgeng.dll and dbghelp.dll
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   522
      * are included in the standard system directory. However, the
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   523
      * versions included in the standard system directory may not
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   524
      * be able to handle symbol information for the newer compilers.
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   525
      *
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   526
      * We search for and explicitly load the libraries using the
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   527
      * following directory search order:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      *
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   529
      * - java.home/bin (same as $JAVA_HOME/jre/bin)
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   530
      * - dir named by DEBUGGINGTOOLSFORWINDOWS environment variable
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   531
      * - various "Debugging Tools For Windows" program directories
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   532
      * - the system directory ($SYSROOT/system32)
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   533
      *
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   534
      * If SA is invoked with -Dsun.jvm.hotspot.loadLibrary.DEBUG=1,
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   535
      * then debug messages about library loading are printed to
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   536
      * System.err.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   539
    String dbgengPath   = null;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   540
    String dbghelpPath  = null;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   541
    String sawindbgPath = null;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   542
    List   searchList   = new ArrayList();
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   543
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   544
    boolean loadLibraryDEBUG =
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   545
        System.getProperty("sun.jvm.hotspot.loadLibrary.DEBUG") != null;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    {
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   548
      // First place to search is co-located with sawindbg.dll in
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   549
      // $JAVA_HOME/jre/bin (java.home property is set to $JAVA_HOME/jre):
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   550
      searchList.add(System.getProperty("java.home") + File.separator + "bin");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   551
      sawindbgPath = (String) searchList.get(0) + File.separator +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   552
          "sawindbg.dll";
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   553
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   554
      // second place to search is specified by an environment variable:
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   555
      String DTFWHome = System.getenv("DEBUGGINGTOOLSFORWINDOWS");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   556
      if (DTFWHome != null) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   557
        searchList.add(DTFWHome);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   560
      // The third place to search is the install directory for the
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   561
      // "Debugging Tools For Windows" package; so far there are three
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   562
      // name variations that we know of:
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   563
      String sysRoot = System.getenv("SYSTEMROOT");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   564
      DTFWHome = sysRoot + File.separator + ".." + File.separator +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   565
          "Program Files" + File.separator + "Debugging Tools For Windows";
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   566
      searchList.add(DTFWHome);
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   567
16600
a841e8d2362a 8002118: WindbgDebuggerLocal should not try to load 64-bit debug libraries for 32-bit JVM
sla
parents: 13969
diff changeset
   568
      // Only add the search path for the current CPU architecture:
a841e8d2362a 8002118: WindbgDebuggerLocal should not try to load 64-bit debug libraries for 32-bit JVM
sla
parents: 13969
diff changeset
   569
      String cpu = PlatformInfo.getCPU();
a841e8d2362a 8002118: WindbgDebuggerLocal should not try to load 64-bit debug libraries for 32-bit JVM
sla
parents: 13969
diff changeset
   570
      if (cpu.equals("x86")) {
a841e8d2362a 8002118: WindbgDebuggerLocal should not try to load 64-bit debug libraries for 32-bit JVM
sla
parents: 13969
diff changeset
   571
          searchList.add(DTFWHome + " (x86)");
a841e8d2362a 8002118: WindbgDebuggerLocal should not try to load 64-bit debug libraries for 32-bit JVM
sla
parents: 13969
diff changeset
   572
      } else if (cpu.equals("amd64")) {
a841e8d2362a 8002118: WindbgDebuggerLocal should not try to load 64-bit debug libraries for 32-bit JVM
sla
parents: 13969
diff changeset
   573
          searchList.add(DTFWHome + " (x64)");
a841e8d2362a 8002118: WindbgDebuggerLocal should not try to load 64-bit debug libraries for 32-bit JVM
sla
parents: 13969
diff changeset
   574
      }
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   575
      // The last place to search is the system directory:
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   576
      searchList.add(sysRoot + File.separator + "system32");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   579
    for (int i = 0; i < searchList.size(); i++) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   580
      File dir = new File((String) searchList.get(i));
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   581
      if (!dir.exists()) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   582
        if (loadLibraryDEBUG) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   583
          System.err.println("DEBUG: '" + searchList.get(i) +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   584
              "': directory does not exist.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   585
        }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   586
        // this search directory doesn't exist so skip it
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   587
        continue;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   588
      }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   589
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   590
      dbgengPath = (String) searchList.get(i) + File.separator + "dbgeng.dll";
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   591
      dbghelpPath = (String) searchList.get(i) + File.separator + "dbghelp.dll";
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   592
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   593
      File feng = new File(dbgengPath);
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   594
      File fhelp = new File(dbghelpPath);
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   595
      if (feng.exists() && fhelp.exists()) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   596
        // both files exist so we have a match
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   597
        break;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   598
      }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   599
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   600
      // At least one of the files does not exist; no warning if both
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   601
      // don't exist. If just one doesn't exist then we don't check
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   602
      // loadLibraryDEBUG because we have a mis-configured system.
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   603
      if (feng.exists()) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   604
        System.err.println("WARNING: found '" + dbgengPath +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   605
            "' but did not find '" + dbghelpPath + "'; ignoring '" +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   606
            dbgengPath + "'.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   607
      } else if (fhelp.exists()) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   608
        System.err.println("WARNING: found '" + dbghelpPath +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   609
            "' but did not find '" + dbgengPath + "'; ignoring '" +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   610
            dbghelpPath + "'.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   611
      } else if (loadLibraryDEBUG) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   612
        System.err.println("DEBUG: searched '" + searchList.get(i) +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   613
          "': dbgeng.dll and dbghelp.dll were not found.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   614
      }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   615
      dbgengPath = null;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   616
      dbghelpPath = null;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   617
    }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   618
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   619
    if (dbgengPath == null || dbghelpPath == null) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   620
      // at least one of the files wasn't found anywhere we searched
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   621
      String mesg = null;
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   622
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   623
      if (dbgengPath == null && dbghelpPath == null) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   624
        mesg = "dbgeng.dll and dbghelp.dll cannot be found. ";
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   625
      } else if (dbgengPath == null) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   626
        mesg = "dbgeng.dll cannot be found (dbghelp.dll was found). ";
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   627
      } else {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   628
        mesg = "dbghelp.dll cannot be found (dbgeng.dll was found). ";
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   629
      }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   630
      throw new UnsatisfiedLinkError(mesg +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   631
          "Please search microsoft.com for 'Debugging Tools For Windows', " +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   632
          "and either download it to the default location, or download it " +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   633
          "to a custom location and set environment variable " +
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   634
          "'DEBUGGINGTOOLSFORWINDOWS' to the pathname of that location.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   635
    }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   636
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   637
    // NOTE: The order of loads is important! If we load dbgeng.dll
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   638
    // first, then the dependency - dbghelp.dll - will be loaded
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   639
    // from usual DLL search thereby defeating the purpose!
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   640
    if (loadLibraryDEBUG) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   641
      System.err.println("DEBUG: loading '" + dbghelpPath + "'.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   642
    }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   643
    System.load(dbghelpPath);
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   644
    if (loadLibraryDEBUG) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   645
      System.err.println("DEBUG: loading '" + dbgengPath + "'.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   646
    }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   647
    System.load(dbgengPath);
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   648
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    // Now, load sawindbg.dll
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   650
    if (loadLibraryDEBUG) {
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   651
      System.err.println("DEBUG: loading '" + sawindbgPath + "'.");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   652
    }
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   653
    System.load(sawindbgPath);
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   654
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    // where do I find '.exe', '.dll' files?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    imagePath = System.getProperty("sun.jvm.hotspot.debugger.windbg.imagePath");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    if (imagePath == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
      imagePath = System.getenv("PATH");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    // where do I find '.pdb', '.dbg' files?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    symbolPath = System.getProperty("sun.jvm.hotspot.debugger.windbg.symbolPath");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    // mostly, debug files would be find where .dll's, .exe's are found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    if (symbolPath == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
      symbolPath = imagePath;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    // should we parse DLL symbol table in Java code or use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    // Windbg's native lookup facility? By default, we use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    // native lookup so that we can take advantage of '.pdb'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    // files, if available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    useNativeLookup = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    String str = System.getProperty("sun.jvm.hotspot.debugger.windbg.disableNativeLookup");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    if (str != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
      useNativeLookup = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    initIDs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  // native methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  private static native void initIDs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  private native void attach0(String executableName, String coreFileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  private native void attach0(int processID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  private native void detach0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  private native byte[] readBytesFromProcess0(long address, long numBytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    throws UnmappedAddressException, DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  private native long getThreadIdFromSysId0(long sysId);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  private native String consoleExecuteCommand0(String cmd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  private native long lookupByName0(String objName, String symName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  private native ClosestSymbol lookupByAddress0(long address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  // helper called lookupByAddress0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  private ClosestSymbol createClosestSymbol(String symbol, long diff) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
    return new ClosestSymbol(symbol, diff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
}