hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/proc/ProcDebuggerLocal.java
author coleenp
Sun, 13 Apr 2008 17:43:42 -0400
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 670 ddf3e9583f2f
permissions -rw-r--r--
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2004 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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.proc;
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.cdbg.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.debugger.proc.amd64.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.debugger.proc.sparc.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.debugger.proc.x86.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.debugger.amd64.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.debugger.sparc.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import sun.jvm.hotspot.debugger.x86.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
/** <P> An implementation of the JVMDebugger interface which sits on
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
 * top of proc and relies on the SA's proc import module for
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
 * communication with the debugger. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
 * <P> <B>NOTE</B> that since we have the notion of fetching "Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
 * primitive types" from the remote process (which might have
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
 * different sizes than we expect) we have a bootstrapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
 * problem. We need to know the sizes of these types before we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
 * fetch them. The current implementation solves this problem by
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 * requiring that it be configured with these type sizes before they
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 * can be fetched. The readJ(Type) routines here will throw a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
 * RuntimeException if they are called before the debugger is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
 * configured with the Java primitive type sizes. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
public class ProcDebuggerLocal extends DebuggerBase implements ProcDebugger {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    protected static final int cacheSize = 16 * 1024 * 1024; // 16 MB
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    //------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    // Implementation of Debugger interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    /** <P> machDesc may be null if it couldn't be determined yet; i.e.,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
     * if we're on SPARC, we need to ask the remote process whether
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
     * we're in 32- or 64-bit mode. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
     *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
     * <P> useCache should be set to true if debugging is being done
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
     * locally, and to false if the debugger is being created for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
     * purpose of supporting remote debugging. </P> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    public ProcDebuggerLocal(MachineDescription machDesc, boolean useCache) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        this.machDesc = machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        int cacheNumPages;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
        int cachePageSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        final String cpu = PlatformInfo.getCPU();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        if (cpu.equals("sparc")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
            threadFactory = new ProcSPARCThreadFactory(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
            pcRegIndex = SPARCThreadContext.R_PC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
            fpRegIndex = SPARCThreadContext.R_I6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        } else if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
            threadFactory = new ProcX86ThreadFactory(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
            pcRegIndex = X86ThreadContext.EIP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
            fpRegIndex = X86ThreadContext.EBP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
            unalignedAccessesOkay = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
        } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
            threadFactory = new ProcAMD64ThreadFactory(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
            pcRegIndex = AMD64ThreadContext.RIP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
            fpRegIndex = AMD64ThreadContext.RBP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
            throw new RuntimeException("Thread access for CPU architecture " + PlatformInfo.getCPU() + " not yet supported");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        if (useCache) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
            // Cache portion of the remote process's address space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
            // For now, this cache works best if it covers the entire
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
            // heap of the remote process. FIXME: at least should make this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
            // tunable from the outside, i.e., via the UI. This is a 16 MB
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
            // cache divided on SPARC into 2048 8K pages and on x86 into
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
            // 4096 4K pages; the page size must be adjusted to be the OS's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
            // page size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
            cachePageSize = getPageSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
            cacheNumPages = parseCacheNumPagesProperty(cacheSize / cachePageSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
            initCache(cachePageSize, cacheNumPages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        resetNativePointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        clearCacheFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    /** FIXME: implement this with a Runtime.exec() of ps followed by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
     * parsing of its output */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    public boolean hasProcessList() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    public List getProcessList() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        throw new DebuggerException("Not yet supported");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    public synchronized void attach(int processID) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
        checkAttached();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
        isCore = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
        attach0(new Integer(processID).toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        attached = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        suspended = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    public synchronized void attach
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    (String executableName, String coreFileName) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        checkAttached();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        isCore = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
        topFrameCache = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        attach0(executableName, coreFileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        attached = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
        suspended = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    public synchronized boolean detach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        if (! attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
            return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
            if (p_ps_prochandle == 0L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
                return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
            detach0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
            clearCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
            return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
            e.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
            return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        } finally {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
            resetNativePointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
            clearCacheFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
            suspended = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
            attached = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    public synchronized void suspend() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        if (suspended) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
            throw new DebuggerException("Process already suspended");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        suspend0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        suspended = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        enableCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
        reresolveLoadObjects();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    public synchronized void resume() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        if (!suspended) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
            throw new DebuggerException("Process not suspended");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        resume0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        disableCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        suspended = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    public synchronized boolean isSuspended() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        return suspended;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    public Address parseAddress(String addressString) throws NumberFormatException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        long addr = utils.scanAddress(addressString);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        if (addr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
            return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        return new ProcAddress(this, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    public String getOS() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
        return PlatformInfo.getOS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    /** From the Debugger interface via JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    public String getCPU() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        return PlatformInfo.getCPU();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    public boolean hasConsole() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    public String consoleExecuteCommand(String cmd) throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        throw new DebuggerException("Can't execute console commands");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    public String getConsolePrompt() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        return "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    public CDebugger getCDebugger() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
        if (cdbg == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
            cdbg = new ProcCDebugger(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        return cdbg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    /** From the SymbolLookup interface via Debugger and JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    public synchronized Address lookup(String objectName, String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        long addr = lookupByName0(objectName, symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        if (addr == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
            return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        return new ProcAddress(this, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    /** From the SymbolLookup interface via Debugger and JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    public synchronized OopHandle lookupOop(String objectName, String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        Address addr = lookup(objectName, symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
            return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        return addr.addOffsetToAsOopHandle(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    public MachineDescription getMachineDescription() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        return machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    /** Internal routine supporting lazy setting of MachineDescription,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
     * since on SPARC we will need to query the remote process to ask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
     * it what its data model is (32- or 64-bit).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
     */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    public void setMachineDescription(MachineDescription machDesc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        this.machDesc = machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        setBigEndian(machDesc.isBigEndian());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        utils = new DebuggerUtilities(machDesc.getAddressSize(), machDesc.isBigEndian());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    public synchronized int getRemoteProcessAddressSize()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
        return getRemoteProcessAddressSize0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    // Implementation of ThreadAccess interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    /** From the ThreadAccess interface via Debugger and JVMDebugger */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    public ThreadProxy getThreadForIdentifierAddress(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        return threadFactory.createThreadWrapper(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    public ThreadProxy getThreadForThreadId(long id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
        return threadFactory.createThreadWrapper(id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    // Overridden from DebuggerBase because we need to relax alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    // constraints on x86
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    public long readJLong(long address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    throws UnmappedAddressException, UnalignedAddressException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
        checkJavaConfigured();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
        // FIXME: allow this to be configurable. Undesirable to add a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
        // dependency on the runtime package here, though, since this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
        // package should be strictly underneath it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
        if (unalignedAccessesOkay) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
            utils.checkAlignment(address, jintSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
            utils.checkAlignment(address, jlongSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
        byte[] data = readBytes(address, jlongSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
        return utils.dataToJLong(data, jlongSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    // Internal routines (for implementation of ProcAddress).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    // These must not be called until the MachineDescription has been set up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    public String addressValueToString(long address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
        return utils.addressValueToString(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    /** Need to override this to relax alignment checks on Solaris/x86. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    public long readCInteger(long address, long numBytes, boolean isUnsigned)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    throws UnmappedAddressException, UnalignedAddressException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
        checkConfigured();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
        if (!unalignedAccessesOkay) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
            utils.checkAlignment(address, numBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
            // Only slightly relaxed semantics -- this is a hack, but is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
            // necessary on Solaris/x86 where it seems the compiler is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
            // putting some global 64-bit data on 32-bit boundaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
            if (numBytes == 8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
                utils.checkAlignment(address, 4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
                utils.checkAlignment(address, numBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
        byte[] data = readBytes(address, numBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
        return utils.dataToCInteger(data, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    public ProcAddress readAddress(long address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    throws UnmappedAddressException, UnalignedAddressException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
        long value = readAddressValue(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
        return (value == 0 ? null : new ProcAddress(this, value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   338
    public ProcAddress readCompOopAddress(long address)
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   339
    throws UnmappedAddressException, UnalignedAddressException {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   340
        long value = readCompOopAddressValue(address);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   341
        return (value == 0 ? null : new ProcAddress(this, value));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   342
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   343
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    public ProcOopHandle readOopHandle(long address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    throws UnmappedAddressException, UnalignedAddressException, NotInHeapException {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   347
        long   value = readAddressValue(address);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   348
        return (value == 0 ? null : new ProcOopHandle(this, value));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   349
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   350
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   351
    public ProcOopHandle readCompOopHandle(long address) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   352
        long value = readCompOopAddressValue(address);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
        return (value == 0 ? null : new ProcOopHandle(this, value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    public void writeBytesToProcess(long address, long numBytes, byte[] data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    throws UnmappedAddressException, DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
        if (isCore) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
            throw new DebuggerException("Attached to a core file!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
        writeBytesToProcess0(address, numBytes, data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    public synchronized ReadResult readBytesFromProcess(long address, long numBytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
        byte[] res = readBytesFromProcess0(address, numBytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
        if(res != null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
            return new ReadResult(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
        else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
            return new ReadResult(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    protected int getPageSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
        int pagesize = getPageSize0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
        if (pagesize == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
            // return the hard coded default value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
            pagesize = (PlatformInfo.getCPU().equals("x86"))? 4096 : 8192;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
        return pagesize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    // Thread context access. Can not be package private, but should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    // only be accessed by the architecture-specific subpackages.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    /** From the ProcDebugger interface. May have to redefine this later. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    public synchronized long[] getThreadIntegerRegisterSet(int tid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
        return getThreadIntegerRegisterSet0(tid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    // Address access. Can not be package private, but should only be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    // accessed by the architecture-specific subpackages.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    public long getAddressValue(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
        if (addr == null) return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
        return ((ProcAddress) addr).getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    public Address newAddress(long value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
        if (value == 0) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
        return new ProcAddress(this, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    public synchronized List getThreadList() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
        List res = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
        if (isCore && (threadListCache != null)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
            res = threadListCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
            res = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
            fillThreadList0(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
            if (isCore) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
                threadListCache = res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
        return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    public synchronized List getLoadObjectList() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
        if (!suspended) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
            throw new DebuggerException("Process not suspended");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
        if (loadObjectCache == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
            updateLoadObjectCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
        return loadObjectCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    public synchronized CFrame topFrameForThread(ThreadProxy thread)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
        CFrame res = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
        if (isCore && ((res = (CFrame) topFrameCache.get(thread)) != null)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
            return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
            ThreadContext context = thread.getContext();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
            int numRegs = context.getNumRegisters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
            long[] regs = new long[numRegs];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
            for (int i = 0; i < numRegs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
                regs[i] = context.getRegister(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
            res = fillCFrameList0(regs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
            if (isCore) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
                topFrameCache.put(thread, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
            return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    public synchronized ClosestSymbol lookup(long address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
        requireAttach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
        return lookupByAddress0(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    /** From the ProcDebugger interface */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    public String demangle(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
        return demangle0(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    //------------- Internals only below this point --------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    private void updateLoadObjectCache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
        List res = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
        nameToDsoMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
        fillLoadObjectList0(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
        loadObjectCache = sortLoadObjects(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    // sort load objects by base address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    private static List sortLoadObjects(List in) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
        // sort the list by base address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
        Object[] arr = in.toArray();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
        Arrays.sort(arr, loadObjectComparator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
        return Arrays.asList(arr);
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 long lookupByName(String objectName, String symbolName)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
        // NOTE: this assumes that process is suspended (which is probably
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
        // necessary assumption given that DSOs can be loaded/unloaded as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
        // process runs). Should update documentation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
        if (nameToDsoMap == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
            getLoadObjectList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
        SharedObject dso = (SharedObject) nameToDsoMap.get(objectName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
        // The DSO can be null because we use this to search through known
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
        // DSOs in HotSpotTypeDataBase (for example)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
        if (dso != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
            ProcAddress addr = (ProcAddress) dso.lookupSymbol(symbolName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
            if (addr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
                return addr.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
        return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    private SharedObject findDSOByName(String fullPathName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
        if (loadObjectCache == null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
            return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
        for (Iterator iter = loadObjectCache.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
            SharedObject dso = (SharedObject) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
            if (dso.getName().equals(fullPathName)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
                return dso;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
        return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    private void reresolveLoadObjects() throws DebuggerException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
        if (loadObjectCache == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
        updateLoadObjectCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    private void checkAttached() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
        if (attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
            if (isCore) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
                throw new DebuggerException("already attached to a core file!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
                throw new DebuggerException("already attached to a process!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    private void requireAttach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
        if (! attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
            throw new RuntimeException("not attached to a process or core file!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    private void clearCacheFields() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
        loadObjectCache = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
        nameToDsoMap    = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
        threadListCache = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
        topFrameCache   = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    private void resetNativePointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
        p_ps_prochandle          = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
        // reset thread_db pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
        libthread_db_handle    = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
        p_td_thragent_t        = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
        p_td_init              = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
        p_td_ta_new            = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
        p_td_ta_delete         = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
        p_td_ta_thr_iter       = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
        p_td_thr_get_info      = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
        p_td_ta_map_id2thr     = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
        p_td_thr_getgregs      = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
        // part of class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
        classes_jsa_fd         = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
        p_file_map_header      = 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    // native methods and native helpers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    // attach, detach
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    private native void attach0(String pid) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    private native void attach0(String executableFile, String coreFileName) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    private native void detach0() throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    // address size, page size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    private native int getRemoteProcessAddressSize0() throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    private native int getPageSize0() throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    // threads, stacks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    private native long[] getThreadIntegerRegisterSet0(long tid) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    private native void   fillThreadList0(List l) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    // fills stack frame list given reg set of the top frame and top frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    private native ProcCFrame fillCFrameList0(long[] regs) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    // helper called by fillCFrameList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    private ProcCFrame createSenderFrame(ProcCFrame f, long pc, long fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
        ProcCFrame sender = new ProcCFrame(this, newAddress(pc), newAddress(fp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
        if (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
            f.setSender(sender);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
        return sender;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    // shared objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    private native void fillLoadObjectList0(List l) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    // helper called by fillLoadObjectList0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    private LoadObject createLoadObject(String fileName, long textsize, long base) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
        File f = new File(fileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
        Address baseAddr = newAddress(base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
        SharedObject res = findDSOByName(fileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
        if (res != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
            // already in cache. just change the base, if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
            Address oldBase = res.getBase();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
            if (! baseAddr.equals(oldBase)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
                res.setBase(baseAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
            // new shared object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
            res = new SharedObject(this, fileName, f.length(), baseAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
        nameToDsoMap.put(f.getName(), res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
        return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    // symbol-to-pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    private native long lookupByName0(String objectName, String symbolName) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    private native ClosestSymbol lookupByAddress0(long address) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    // helper called by lookupByAddress0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    private ClosestSymbol createClosestSymbol(String name, long offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
        return new ClosestSymbol(name, offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    // process read/write
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    private native byte[] readBytesFromProcess0(long address, long numBytes) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    private native void writeBytesToProcess0(long address, long numBytes, byte[] data) throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    // process control
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    private native void suspend0() throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    private native void resume0() throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    // demangle a C++ name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    private native String demangle0(String name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    // init JNI ids to fields, methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    private native static void initIDs() throws DebuggerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    private static LoadObjectComparator loadObjectComparator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
        System.loadLibrary("saproc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
        initIDs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
        loadObjectComparator = new LoadObjectComparator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    private boolean unalignedAccessesOkay;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    private ProcThreadFactory threadFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    // indices of PC and FP registers in gregset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    private int pcRegIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    private int fpRegIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    // Symbol lookup support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    // This is a map of library names to DSOs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    private Map nameToDsoMap;  // Map<String, SharedObject>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    // C/C++ debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    private List/*<LoadObject>*/ loadObjects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    private CDebugger cdbg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    // ProcessControl support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    private boolean suspended;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    // libproc handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    private long p_ps_prochandle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    // libthread.so's dlopen handle, thread agent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    // and function pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    private long libthread_db_handle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    private long p_td_thragent_t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    private long p_td_init;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    private long p_td_ta_new;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    private long p_td_ta_delete;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    private long p_td_ta_thr_iter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    private long p_td_thr_get_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    private long p_td_ta_map_id2thr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    private long p_td_thr_getgregs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
    // part of class sharing workaround
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    private int classes_jsa_fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    private long p_file_map_header;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    private boolean attached = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    private boolean isCore;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    // for core files, we cache load object list, thread list, top frames etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    // for processes we cache load object list and sync. it during suspend.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    private List threadListCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
    private List loadObjectCache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
    private Map  topFrameCache;      // Map<ThreadProxy, CFrame>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
}