sa-jdi

buggerException;
  
  public abstract Win32Address readAddress(long paramLong)
    throws DebuggerException;
  
  public abstract Win32Address readCompOopAddress(long paramLong)
    throws DebuggerException;
  
  public abstract Win32OopHandle readOopHandle(long paramLong)
    throws DebuggerException;
  
  public abstract Win32OopHandle readCompOopHandle(long paramLong)
    throws DebuggerException;
  
  public abstract void writeJBoolean(long paramLong, boolean paramBoolean)
    throws DebuggerException;
  
  public abstract void writeJByte(long paramLong, byte paramByte)
    throws DebuggerException;
  
  public abstract void writeJChar(long paramLong, char paramChar)
    throws DebuggerException;
  
  public abstract void writeJDouble(long paramLong, double paramDouble)
    throws DebuggerException;
  
  public abstract void writeJFloat(long paramLong, float paramFloat)
    throws DebuggerException;
  
  public abstract void writeJInt(long paramLong, int paramInt)
    throws DebuggerException;
  
  public abstract void writeJLong(long paramLong1, long paramLong2)
    throws DebuggerException;
  
  public abstract void writeJShort(long paramLong, short paramShort)
    throws DebuggerException;
  
  public abstract void writeCInteger(long paramLong1, long paramLong2, long paramLong3)
    throws DebuggerException;
  
  public abstract void writeAddress(long paramLong, Win32Address paramWin32Address)
    throws DebuggerException;
  
  public abstract void writeOopHandle(long paramLong, Win32OopHandle paramWin32OopHandle)
    throws DebuggerException;
  
  public abstract long[] getThreadIntegerRegisterSet(int paramInt, boolean paramBoolean)
    throws DebuggerException;
  
  public abstract void setThreadIntegerRegisterSet(int paramInt, boolean paramBoolean, long[] paramArrayOfLong)
    throws DebuggerException;
  
  public abstract Address newAddress(long paramLong)
    throws DebuggerException;
  
  public abstract Win32LDTEntry getThreadSelectorEntry(int paramInt1, boolean paramBoolean, int paramInt2)
    throws DebuggerException;
  
  public abstract List getThreadList()
    throws DebuggerException;
  
  public abstract List getLoadObjectList()
    throws DebuggerException;
  
  public abstract void writeBytesToProcess(long paramLong1, long paramLong2, byte[] paramArrayOfByte)
    throws UnmappedAddressException, DebuggerException;
  
  public abstract void suspend()
    throws DebuggerException;
  
  public abstract void resume()
    throws DebuggerException;
  
  public abstract boolean isSuspended()
    throws DebuggerException;
  
  public abstract void setBreakpoint(Address paramAddress)
    throws DebuggerException;
  
  public abstract void clearBreakpoint(Address paramAddress)
    throws DebuggerException;
  
  public abstract boolean isBreakpointSet(Address paramAddress)
    throws DebuggerException;
  
  public abstract DebugEvent debugEventPoll()
    throws DebuggerException;
  
  public abstract void debugEventContinue()
    throws DebuggerException;
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.debugger.win32.Win32Debugger
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.debugger.win32;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.DebuggerBase;
import sun.jvm.hotspot.debugger.DebuggerException;
import sun.jvm.hotspot.debugger.DebuggerUtilities;
import sun.jvm.hotspot.debugger.InputLexer;
import sun.jvm.hotspot.debugger.MachineDescription;
import sun.jvm.hotspot.debugger.NotInHeapException;
import sun.jvm.hotspot.debugger.OopHandle;
import sun.jvm.hotspot.debugger.PageCache;
import sun.jvm.hotspot.debugger.ProcessInfo;
import sun.jvm.hotspot.debugger.ReadResult;
import sun.jvm.hotspot.debugger.ThreadProxy;
import sun.jvm.hotspot.debugger.UnalignedAddressException;
import sun.jvm.hotspot.debugger.UnmappedAddressException;
import sun.jvm.hotspot.debugger.cdbg.CDebugger;
import sun.jvm.hotspot.debugger.cdbg.DebugEvent;
import sun.jvm.hotspot.debugger.cdbg.DebugEvent.Type;
import sun.jvm.hotspot.debugger.cdbg.basic.BasicDebugEvent;
import sun.jvm.hotspot.debugger.x86.X86ThreadContext;
import sun.jvm.hotspot.utilities.AddressOps;
import sun.jvm.hotspot.utilities.Assert;
import sun.jvm.hotspot.utilities.PlatformInfo;

public class Win32DebuggerLocal
  extends DebuggerBase
  implements Win32Debugger
{
  private Socket debuggerSocket;
  private boolean attached;
  private long pid;
  private PrintWriter out;
  private DataOutputStream rawOut;
  private InputLexer in;
  private static final int PORT = 27000;
  private PageCache cache;
  private static final long SHORT_TIMEOUT = 2000L;
  private static final long LONG_TIMEOUT = 20000L;
  private Map nameToDllMap;
  private List loadObjects;
  private CDebugger cdbg;
  private boolean suspended;
  private Map breakpoints;
  private DebugEvent curDebugEvent;
  private static final int EXCEPTION_DEBUG_EVENT = 1;
  private static final int LOAD_DLL_DEBUG_EVENT = 6;
  private static final int UNLOAD_DLL_DEBUG_EVENT = 7;
  private static final int EXCEPTION_ACCESS_VIOLATION = -1073741819;
  private static final int EXCEPTION_BREAKPOINT = -2147483645;
  private static final int EXCEPTION_SINGLE_STEP = -2147483644;
  
  public Win32DebuggerLocal(MachineDescription machDesc, boolean useCache)
    throws DebuggerException
  {
    this.machDesc = machDesc;
    utils = new DebuggerUtilities(machDesc.getAddressSize(), machDesc.isBigEndian());
    if (useCache) {
      initCache(4096L, parseCacheNumPagesProperty(4096));
    }
    try
    {
      connectToDebugServer();
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public boolean hasProcessList()
    throws DebuggerException
  {
    return true;
  }
  
  public List getProcessList()
    throws DebuggerException
  {
    List processes = new ArrayList();
    try
    {
      printlnToOutput("proclist");
      int num = in.parseInt();
      for (int i = 0; i < num; i++)
      {
        int pid = in.parseInt();
        String name = parseString();
        if (name.equals("")) {
          name = "System Idle Process";
        }
        processes.add(new ProcessInfo(name, pid));
      }
      return processes;
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized void attach(int processID)
    throws DebuggerException
  {
    if (attached) {
      throw new DebuggerException("Already attached to process " + pid);
    }
    try
    {
      printlnToOutput("attach " + processID);
      if (!in.parseBoolean()) {
        throw new DebuggerException("Error attaching to process, or no such process");
      }
      attached = true;
      pid = processID;
      suspended = true;
      breakpoints = new HashMap();
      curDebugEvent = null;
      nameToDllMap = null;
      loadObjects = null;
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized void attach(String executableName, String coreFileName)
    throws DebuggerException
  {
    throw new DebuggerException("Core files not yet supported on Win32");
  }
  
  public synchronized boolean detach()
  {
    if (!attached) {
      return false;
    }
    attached = false;
    suspended = false;
    breakpoints = null;
    if (nameToDllMap != null)
    {
      for (Iterator iter = nameToDllMap.values().iterator(); iter.hasNext();)
      {
        DLL dll = (DLL)iter.next();
        dll.close();
      }
      nameToDllMap = null;
      loadObjects = null;
    }
    cdbg = null;
    clearCache();
    try
    {
      printlnToOutput("detach");
      return in.parseBoolean();
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public Address parseAddress(String addressString)
    throws NumberFormatException
  {
    return newAddress(utils.scanAddress(addressString));
  }
  
  public String getOS()
  {
    return PlatformInfo.getOS();
  }
  
  public String getCPU()
  {
    return PlatformInfo.getCPU();
  }
  
  public boolean hasConsole()
    throws DebuggerException
  {
    return false;
  }
  
  public String consoleExecuteCommand(String cmd)
    throws DebuggerException
  {
    throw new DebuggerException("No debugger console available on Win32");
  }
  
  public String getConsolePrompt()
    throws DebuggerException
  {
    return null;
  }
  
  public CDebugger getCDebugger()
    throws DebuggerException
  {
    if (cdbg == null) {
      cdbg = new Win32CDebugger(this);
    }
    return cdbg;
  }
  
  public synchronized Address lookup(String objectName, String symbol)
  {
    if (!attached) {
      return null;
    }
    return newAddress(lookupInProcess(objectName, symbol));
  }
  
  public synchronized OopHandle lookupOop(String objectName, String symbol)
  {
    Address addr = lookup(objectName, symbol);
    if (addr == null) {
      return null;
    }
    return addr.addOffsetToAsOopHandle(0L);
  }
  
  public MachineDescription getMachineDescription()
  {
    return machDesc;
  }
  
  public ThreadProxy getThreadForIdentifierAddress(Address addr)
  {
    return new Win32Thread(this, addr);
  }
  
  public ThreadProxy getThreadForThreadId(long handle)
  {
    return new Win32Thread(this, handle);
  }
  
  public long readJLong(long address)
    throws UnmappedAddressException, UnalignedAddressException
  {
    checkJavaConfigured();
    
    utils.checkAlignment(address, jintSize);
    byte[] data = readBytes(address, jlongSize);
    return utils.dataToJLong(data, jlongSize);
  }
  
  public String addressValueToString(long address)
  {
    return utils.addressValueToString(address);
  }
  
  public Win32Address readAddress(long address)
    throws UnmappedAddressException, UnalignedAddressException
  {
    return (Win32Address)newAddress(readAddressValue(address));
  }
  
  public Win32Address readCompOopAddress(long address)
    throws UnmappedAddressException, UnalignedAddressException
  {
    return (Win32Address)newAddress(readCompOopAddressValue(address));
  }
  
  public Win32OopHandle readOopHandle(long address)
    throws UnmappedAddressException, UnalignedAddressException, NotInHeapException
  {
    long value = readAddressValue(address);
    return value == 0L ? null : new Win32OopHandle(this, value);
  }
  
  public Win32OopHandle readCompOopHandle(long address)
    throws UnmappedAddressException, UnalignedAddressException, NotInHeapException
  {
    long value = readCompOopAddressValue(address);
    return value == 0L ? null : new Win32OopHandle(this, value);
  }
  
  public void writeAddress(long address, Win32Address value)
  {
    writeAddressValue(address, getAddressValue(value));
  }
  
  public void writeOopHandle(long address, Win32OopHandle value)
  {
    writeAddressValue(address, getAddressValue(value));
  }
  
  public synchronized long[] getThreadIntegerRegisterSet(int threadHandleValue, boolean mustDuplicateHandle)
    throws DebuggerException
  {
    if (!suspended) {
      throw new DebuggerException("Process not suspended");
    }
    try
    {
      int handle = threadHandleValue;
      if (mustDuplicateHandle)
      {
        printlnToOutput("duphandle 0x" + Integer.toHexString(threadHandleValue));
        if (!in.parseBoolean()) {
          throw new DebuggerException("Error duplicating thread handle 0x" + threadHandleValue);
        }
        handle = (int)in.parseAddress();
      }
      printlnToOutput("getcontext 0x" + Integer.toHexString(handle));
      if (!in.parseBoolean())
      {
        if (mustDuplicateHandle) {
          printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
        }
        String failMessage = "GetThreadContext failed for thread handle 0x" + Integer.toHexString(handle);
        if (mustDuplicateHandle) {
          failMessage = failMessage + ", duplicated from thread handle " + Integer.toHexString(threadHandleValue);
        }
        throw new DebuggerException(failMessage);
      }
      int numRegs = 22;
      long[] winRegs = new long[numRegs];
      for (int i = 0; i < numRegs; i++) {
        winRegs[i] = in.parseAddress();
      }
      if (mustDuplicateHandle) {
        printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
      }
      long[] retval = new long[25];
      retval[11] = winRegs[0];
      retval[8] = winRegs[1];
      retval[10] = winRegs[2];
      retval[9] = winRegs[3];
      retval[5] = winRegs[4];
      retval[4] = winRegs[5];
      retval[6] = winRegs[6];
      retval[7] = winRegs[7];
      retval[14] = winRegs[8];
      retval[3] = winRegs[9];
      retval[2] = winRegs[10];
      retval[1] = winRegs[11];
      retval[0] = winRegs[12];
      retval[15] = winRegs[13];
      retval[18] = winRegs[14];
      retval[16] = winRegs[15];
      retval[19] = winRegs[16];
      retval[20] = winRegs[17];
      retval[21] = winRegs[18];
      retval[22] = winRegs[19];
      retval[23] = winRegs[20];
      retval[24] = winRegs[21];
      return retval;
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized void setThreadIntegerRegisterSet(int threadHandleValue, boolean mustDuplicateHandle, long[] context)
    throws DebuggerException
  {
    if (!suspended) {
      throw new DebuggerException("Process not suspended");
    }
    try
    {
      int handle = threadHandleValue;
      if (mustDuplicateHandle)
      {
        printlnToOutput("duphandle 0x" + Integer.toHexString(threadHandleValue));
        if (!in.parseBoolean()) {
          throw new DebuggerException("Error duplicating thread handle 0x" + threadHandleValue);
        }
        handle = (int)in.parseAddress();
      }
      long[] winRegs = new long[context.length];
      winRegs[0] = context[11];
      winRegs[1] = context[8];
      winRegs[2] = context[10];
      winRegs[3] = context[9];
      winRegs[4] = context[5];
      winRegs[5] = context[4];
      winRegs[6] = context[6];
      winRegs[7] = context[7];
      winRegs[8] = context[14];
      winRegs[9] = context[3];
      winRegs[10] = context[2];
      winRegs[11] = context[1];
      winRegs[12] = context[0];
      winRegs[13] = context[15];
      winRegs[14] = context[18];
      winRegs[15] = context[16];
      winRegs[16] = context[19];
      winRegs[17] = context[20];
      winRegs[18] = context[21];
      winRegs[19] = context[22];
      winRegs[20] = context[23];
      winRegs[21] = context[24];
      StringBuffer cmd = new StringBuffer();
      cmd.append("setcontext 0x");
      cmd.append(Integer.toHexString(threadHandleValue));
      for (int i = 0; i < context.length; i++)
      {
        cmd.append(" 0x");
        cmd.append(Long.toHexString(winRegs[i]));
      }
      printlnToOutput(cmd.toString());
      boolean res = in.parseBoolean();
      if (mustDuplicateHandle) {
        printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
      }
      if (!res)
      {
        String failMessage = "SetThreadContext failed for thread handle 0x" + Integer.toHexString(handle);
        if (mustDuplicateHandle) {
          failMessage = failMessage + ", duplicated from thread handle " + Integer.toHexString(threadHandleValue);
        }
        throw new DebuggerException(failMessage);
      }
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized Win32LDTEntry getThreadSelectorEntry(int threadHandleValue, boolean mustDuplicateHandle, int selector)
    throws DebuggerException
  {
    try
    {
      int handle = threadHandleValue;
      if (mustDuplicateHandle)
      {
        printlnToOutput("duphandle 0x" + Integer.toHexString(threadHandleValue));
        if (!in.parseBoolean()) {
          throw new DebuggerException("Error duplicating thread handle 0x" + threadHandleValue);
        }
        handle = (int)in.parseAddress();
      }
      printlnToOutput("selectorentry 0x" + Integer.toHexString(handle) + " " + selector);
      if (!in.parseBoolean())
      {
        if (mustDuplicateHandle) {
          printlnToOutput("closehandle 0x" + Integer.toHexString(handle));
        }
        throw new DebuggerException("GetThreadContext failed for thread handle 0x" + handle + ", duplicated from thread handle " + threadHandleValue);
      }
      short limitLow = (short)(int)in.parseAddress();
      short baseLow = (short)(int)in.parseAddress();
      byte baseMid = (byte)(int)in.parseAddress();
      byte flags1 = (byte)(int)in.parseAddress();
      byte flags2 = (byte)(int)in.parseAddress();
      byte baseHi = (byte)(int)in.parseAddress();
      return new Win32LDTEntry(limitLow, baseLow, baseMid, flags1, flags2, baseHi);
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized List getThreadList()
    throws DebuggerException
  {
    if (!suspended) {
      throw new DebuggerException("Process not suspended");
    }
    try
    {
      printlnToOutput("threadlist");
      List ret = new ArrayList();
      int numThreads = in.parseInt();
      for (int i = 0; i < numThreads; i++)
      {
        int handle = (int)in.parseAddress();
        ret.add(new Win32Thread(this, handle));
      }
      return ret;
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized List getLoadObjectList()
    throws DebuggerException
  {
    if (!suspended) {
      throw new DebuggerException("Process not suspended");
    }
    try
    {
      if (loadObjects == null)
      {
        loadObjects = new ArrayList();
        nameToDllMap = new HashMap();
        
        printlnToOutput("libinfo");
        int numInfo = in.parseInt();
        for (int i = 0; i < numInfo; i++)
        {
          String fullPathName = parseString().toLowerCase();
          Address base = newAddress(in.parseAddress());
          
          File file = new File(fullPathName);
          long size = file.length();
          DLL dll = new DLL(this, fullPathName, size, base);
          String name = file.getName();
          nameToDllMap.put(name, dll);
          loadObjects.add(dll);
        }
      }
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
    return loadObjects;
  }
  
  public synchronized void writeBytesToProcess(long startAddress, long numBytes, byte[] data)
    throws UnmappedAddressException, DebuggerException
  {
    try
    {
      printToOutput("poke 0x" + Long.toHexString(startAddress) + " |");
      
      writeIntToOutput((int)numBytes);
      writeToOutput(data, 0, (int)numBytes);
      printlnToOutput("");
      if (!in.parseBoolean()) {
        throw new UnmappedAddressException(startAddress);
      }
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized void suspend()
    throws DebuggerException
  {
    try
    {
      if (suspended) {
        throw new DebuggerException("Process already suspended");
      }
      printlnToOutput("suspend");
      suspended = true;
      enableCache();
      reresolveLoadObjects();
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized void resume()
    throws DebuggerException
  {
    try
    {
      if (!suspended) {
        throw new DebuggerException("Process not suspended");
      }
      disableCache();
      printlnToOutput("resume");
      suspended = false;
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public synchronized boolean isSuspended()
    throws DebuggerException
  {
    return suspended;
  }
  
  public synchronized void setBreakpoint(Address addr)
    throws DebuggerException
  {
    if (!suspended) {
      throw new DebuggerException("Process not suspended");
    }
    long addrVal = getAddressValue(addr);
    Long where = new Long(addrVal);
    if (breakpoints.get(where) != null) {
      throw new DebuggerException("Breakpoint already set at " + addr);
    }
    Byte what = new Byte(readBytes(addrVal, 1L)[0]);
    
    writeBytesToProcess(addrVal, 1L, new byte[] { -52 });
    
    breakpoints.put(where, what);
  }
  
  public synchronized void clearBreakpoint(Address addr)
    throws DebuggerException
  {
    if (!suspended) {
      throw new DebuggerException("Process not suspended");
    }
    long addrVal = getAddressValue(addr);
    Long where = new Long(addrVal);
    Byte what = (Byte)breakpoints.get(where);
    if (what == null) {
      throw new DebuggerException("Breakpoint not set at " + addr);
    }
    writeBytesToProcess(addrVal, 1L, new byte[] { what.byteValue() });
    
    breakpoints.remove(where);
  }
  
  public synchronized boolean isBreakpointSet(Address addr)
    throws DebuggerException
  {
    return breakpoints.get(new Long(getAddressValue(addr))) != null;
  }
  
  public synchronized DebugEvent debugEventPoll()
    throws DebuggerException
  {
    if (curDebugEvent != null) {
      return curDebugEvent;
    }
    try
    {
      printlnToOutput("pollevent");
      if (!in.parseBoolean()) {
        return null;
      }
      int handle = (int)in.parseAddress();
      ThreadProxy thread = new Win32Thread(this, handle);
      int code = in.parseInt();
      DebugEvent ev = null;
      switch (code)
      {
      case 6: 
        Address addr = newAddress(in.parseAddress());
        ev = BasicDebugEvent.newLoadObjectLoadEvent(thread, addr);
        break;
      case 7: 
        Address addr = newAddress(in.parseAddress());
        ev = BasicDebugEvent.newLoadObjectUnloadEvent(thread, addr);
        break;
      case 1: 
        int exceptionCode = in.parseInt();
        Address pc = newAddress(in.parseAddress());
        switch (exceptionCode)
        {
        case -1073741819: 
          boolean wasWrite = in.parseBoolean();
          Address addr = newAddress(in.parseAddress());
          ev = BasicDebugEvent.newAccessViolationEvent(thread, pc, wasWrite, addr);
          break;
        case -2147483645: 
          ev = BasicDebugEvent.newBreakpointEvent(thread, pc);
          break;
        case -2147483644: 
          ev = BasicDebugEvent.newSingleStepEvent(thread, pc);
          break;
        default: 
          ev = BasicDebugEvent.newUnknownEvent(thread, "Exception 0x" + Integer.toHexString(exceptionCode) + " at PC " + pc);
        }
        break;
      default: 
        ev = BasicDebugEvent.newUnknownEvent(thread, "Debug event " + code + " occurred");
      }
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(ev != null, "Must have created event");
      }
      curDebugEvent = ev;
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
    return curDebugEvent;
  }
  
  public synchronized void debugEventContinue()
    throws DebuggerException
  {
    if (curDebugEvent == null) {
      throw new DebuggerException("No debug event pending");
    }
    try
    {
      DebugEvent.Type t = curDebugEvent.getType();
      boolean shouldPassOn = true;
      if (t == DebugEvent.Type.BREAKPOINT)
      {
        Iterator iter;
        if (breakpoints.get(new Long(getAddressValue(curDebugEvent.getPC()))) != null)
        {
          System.err.println("Backing up PC due to breakpoint");
          X86ThreadContext ctx = (X86ThreadContext)curDebugEvent.getThread().getContext();
          ctx.setRegister(14, ctx.getRegister(14) - 1L);
          curDebugEvent.getThread().setContext(ctx);
        }
        else
        {
          System.err.println("Skipping back up of PC since I didn't know about this breakpoint");
          System.err.println("Known breakpoints:");
          for (iter = breakpoints.keySet().iterator(); iter.hasNext();) {
            System.err.println("  0x" + Long.toHexString(((Long)iter.next()).longValue()));
          }
        }
        shouldPassOn = false;
      }
      else if (t == DebugEvent.Type.SINGLE_STEP)
      {
        shouldPassOn = false;
      }
      int val = shouldPassOn ? 1 : 0;
      printlnToOutput("continueevent " + val);
      if (!in.parseBoolean()) {
        throw new DebuggerException("Unknown error while attempting to continue past debug event");
      }
      curDebugEvent = null;
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  public long getAddressValue(Address addr)
  {
    if (addr == null) {
      return 0L;
    }
    return ((Win32Address)addr).getValue();
  }
  
  public Address newAddress(long value)
  {
    if (value == 0L) {
      return null;
    }
    return new Win32Address(this, value);
  }
  
  private String parseString()
    throws IOException
  {
    int charSize = in.parseInt();
    int numChars = in.parseInt();
    in.skipByte();
    String str;
    String str;
    if (charSize == 1) {
      str = in.readByteString(numChars);
    } else {
      str = in.readCharString(numChars);
    }
    return str;
  }
  
  synchronized long lookupInProcess(String objectName, String symbol)
  {
    if (nameToDllMap == null) {
      getLoadObjectList();
    }
    DLL dll = (DLL)nameToDllMap.get(objectName);
    if (dll != null)
    {
      Win32Address addr = (Win32Address)dll.lookupSymbol(symbol);
      if (addr != null) {
        return addr.getValue();
      }
    }
    return 0L;
  }
  
  public synchronized ReadResult readBytesFromProcess(long address, long numBytes)
    throws UnmappedAddressException, DebuggerException
  {
    try
    {
      String cmd = "peek " + utils.addressValueToString(address) + " " + numBytes;
      printlnToOutput(cmd);
      while (in.readByte() != 66) {}
      byte res = in.readByte();
      if (res == 0)
      {
        System.err.println("Failing command: " + cmd);
        throw new DebuggerException("Read of remote process address space failed");
      }
      byte[] buf = new byte[(int)numBytes];
      boolean bailOut = false;
      long failureAddress = 0L;
      while (numBytes > 0L)
      {
        long len = in.readUnsignedInt();
        boolean isMapped = in.readByte() != 0;
        if (!isMapped)
        {
          if (!bailOut)
          {
            bailOut = true;
            failureAddress = address;
          }
        }
        else {
          in.readBytes(buf, 0, (int)len);
        }
        numBytes -= len;
        address += len;
      }
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(numBytes == 0L, "Bug in debug server's implementation of peek");
      }
      if (bailOut) {
        return new ReadResult(failureAddress);
      }
      return new ReadResult(buf);
    }
    catch (IOException e)
    {
      throw new DebuggerException(e);
    }
  }
  
  private void printlnToOutput(String s)
    throws IOException
  {
    out.println(s);
    if (out.checkError()) {
      throw new IOException("Error occurred while writing to debug server");
    }
  }
  
  private void printToOutput(String s)
    throws IOException
  {
    out.print(s);
    if (out.checkError()) {
      throw new IOException("Error occurred while writing to debug server");
    }
  }
  
  private void writeIntToOutput(int val)
    throws IOException
  {
    rawOut.writeInt(val);
    rawOut.flush();
  }
  
  private void writeToOutput(byte[] buf, int off, int len)
    throws IOException
  {
    rawOut.write(buf, off, len);
    rawOut.flush();
  }
  
  private void connectToDebugServer()
    throws IOException
  {
    debuggerSocket = null;
    long endTime = System.currentTimeMillis() + 2000L;
    while ((debuggerSocket == null) && (System.currentTimeMillis() < endTime)) {
      try
      {
        debuggerSocket = new Socket(InetAddress.getByName("127.0.0.1"), 27000);
        debuggerSocket.setTcpNoDelay(true);
      }
      catch (IOException e)
      {
        debuggerSocket = null;
        try
        {
          Thread.sleep(750L);
        }
        catch (InterruptedException ex) {}
      }
    }
    if (debuggerSocket == null) {
      throw new DebuggerException("Timed out while attempting to connect to debug server (please start SwDbgSrv.exe)");
    }
    out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(debuggerSocket.getOutputStream(), "US-ASCII")), true);
    rawOut = new DataOutputStream(new BufferedOutputStream(debuggerSocket.getOutputStream()));
    in = new InputLexer(new BufferedInputStream(debuggerSocket.getInputStream()));
  }
  
  private DLL findDLLByName(String fullPathName)
  {
    for (Iterator iter = loadObjects.iterator(); iter.hasNext();)
    {
      DLL dll = (DLL)iter.next();
      if (dll.getName().equals(fullPathName)) {
        return dll;
      }
    }
    return null;
  }
  
  private void reresolveLoadObjects()
    throws DebuggerException
  {
    try
    {
      if (loadObjects == null) {
        return;
      }
      List newLoadObjects = new ArrayList();
      
      printlnToOutput("libinfo");
      int numInfo = in.parseInt();
      for (int i = 0; i < numInfo; i++)
      {
        String fullPathName = parseString().toLowerCase();
        Address base = newAddress(in.parseAddress());
        
        DLL dll = findDLLByName(fullPathName);
        boolean mustLoad = true;
        if (dll != null)
        {
          loadObjects.remove(dll);
          if (AddressOps.equal(base, dll.getBase())) {
            mustLoad = false;
          }
        }
        if (mustLoad)
        {
          File file = new File(fullPathName);
          long size = file.length();
          String name = file.getName();
          dll = new DLL(this, fullPathName, size, base);
          nameToDllMap.put(name, dll);
        }
        newLoadObjects.add(dll);
      }
      for (Iterator dllIter = loadObjects.iterator(); dllIter.hasNext();)
      {
        dll = (DLL)dllIter.next();
        for (iter = nameToDllMap.keySet().iterator(); iter.hasNext();)
        {
          String name = (String)iter.next();
          if (nameToDllMap.get(name) == dll)
          {
            nameToDllMap.remove(name);
            break;
          }
        }
      }
      DLL dll;
      Iterator iter;
      loadObjects = newLoadObjects;
    }
    catch (IOException e)
    {
      loadObjects = null;
      nameToDllMap = null;
      throw new DebuggerException(e);
    }
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.debugger.win32.Win32DebuggerLocal
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.debugger.win32;

import java.io.Serializable;

class Win32LDTEntry
  implements Serializable
{
  private short limitLow;
  private short baseLow;
  private byte baseMid;
  private byte flags1;
  private byte flags2;
  private byte baseHi;
  
  private Win32LDTEntry() {}
  
  public Win32LDTEntry(short limitLow, short baseLow, byte baseMid, byte flags1, byte flags2, byte baseHi)
  {
    this.limitLow = limitLow;
    this.baseLow = baseLow;
    this.baseMid = baseMid;
    this.flags1 = flags1;
    this.flags2 = flags2;
    this.baseHi = baseHi;
  }
  
  public long getBase()
  {
    return (baseLow & 0xFFFF | (baseMid & 0xFF) << 16 | (baseHi & 0xFF) << 24) & 0xFFFFFFFF;
  }
  
  public short getLimitLow()
  {
    return limitLow;
  }
  
  public short getBaseLow()
  {
    return baseLow;
  }
  
  public byte getBaseMid()
  {
    return baseMid;
  }
  
  public byte getBaseHi()
  {
    return baseHi;
  }
  
  public int getType()
  {
    return flags1 & 0x1F;
  }
  
  public int getPrivilegeLevel()
  {
    return (flags1 & 0x60) >> 5;
  }
  
  public boolean isSegmentPhysical()
  {
    return (flags1 & 0x70) != 0;
  }
  
  public int getLimitHi()
  {
    return flags2 & 0xF;
  }
  
  public boolean isDefaultBig()
  {
    return (flags2 & 0x40) != 0;
  }
  
  public boolean isPageGranular()
  {
    return (flags2 & 0x80) != 0;
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.debugger.win32.Win32LDTEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.debugger.win32;

abstract interface Win32LDTEntryConstants
{
  public static final int TYPE_READ_ONLY_DATA = 0;
  public static final int TYPE_READ_WRITE_DATA = 1;
  public static final int TYPE_UNUSED = 2;
  public static final int TYPE_READ_WRITE_EXPAND_DOWN_DATA = 3;
  public static final int TYPE_EXECUTE_ONLY_CODE = 4;
  public static final int TYPE_EXECUTABLE_READABLE_CODE = 5;
  public static final int TYPE_EXECUTE_ONLY_CONFORMING_CODE = 6;
  public static final int TYPE_EXECUTABLE_READABLE_CONFORMING_CODE = 7;
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.debugger.win32.Win32LDTEntryConstants
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.debugger.win32;

import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.OopHandle;

class Win32OopHandle
  extends Win32Address
  implements OopHandle
{
  Win32OopHandle(Win32Debugger debugger, long addr)
  {
    super(debugger, addr);
  }
  
  public boolean equals(Object arg)
  {
    if (arg == null) {
      return false;
    }
    if (!(arg instanceof Win32OopHandle)) {
      return false;
    }
    return addr == addr;
  }
  
  public Address addOffsetTo(long offset)
    throws UnsupportedOperationException
  {
    throw new UnsupportedOperationException("addOffsetTo not applicable to OopHandles (interior object pointers not allowed)");
  }
  
  public Address andWithMask(long mask)
    throws UnsupportedOperationException
  {
    throw new UnsupportedOperationException("andWithMask not applicable to OopHandles (i.e., anything but C addresses)");
  }
  
  public Address orWithMask(long mask)
    throws UnsupportedOperationException
  {
    throw new UnsupportedOperationException("orWithMask not applicable to OopHandles (i.e., anything but C addresses)");
  }
  
  public Address xorWithMask(long mask)
    throws UnsupportedOperationException
  {
    throw new UnsupportedOperationException("xorWithMask not applicable to OopHandles (i.e., anything but C addresses)");
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.debugger.win32.Win32OopHandle
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.debugger.win32;

import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.AddressException;
import sun.jvm.hotspot.debugger.DebuggerException;
import sun.jvm.hotspot.debugger.ThreadContext;
import sun.jvm.hotspot.debugger.ThreadProxy;
import sun.jvm.hotspot.debugger.x86.X86ThreadContext;

class Win32Thread
  implements ThreadProxy
{
  private Win32Debugger debugger;
  private int handle;
  private boolean mustDuplicate;
  private boolean gotID;
  private int id;
  
  Win32Thread(Win32Debugger debugger, Address addr)
  {
    this.debugger = debugger;
    
    handle = ((int)addr.getCIntegerAt(0L, 4L, true));
    
    mustDuplicate = true;
    gotID = false;
  }
  
  Win32Thread(Win32Debugger debugger, long handle)
  {
    this.debugger = debugger;
    this.handle = ((int)handle);
    mustDuplicate = false;
    gotID = false;
  }
  
  public ThreadContext getContext()
    throws IllegalThreadStateException
  {
    if (!debugger.isSuspended()) {
      throw new IllegalThreadStateException("Target process must be suspended");
    }
    long[] data = debugger.getThreadIntegerRegisterSet(handle, mustDuplicate);
    Win32ThreadContext context = new Win32ThreadContext(debugger);
    for (int i = 0; i < data.length; i++) {
      context.setRegister(i, data[i]);
    }
    return context;
  }
  
  public boolean canSetContext()
    throws DebuggerException
  {
    return true;
  }
  
  public void setContext(ThreadContext thrCtx)
    throws IllegalThreadStateException, DebuggerException
  {
    if (!debugger.isSuspended()) {
      throw new IllegalThreadStateException("Target process must be suspended");
    }
    X86ThreadContext context = (X86ThreadContext)thrCtx;
    long[] data = new long[25];
    for (int i = 0; i < data.length; i++) {
      data[i] = context.getRegister(i);
    }
    debugger.setThreadIntegerRegisterSet(handle, mustDuplicate, data);
  }
  
  public boolean equals(Object obj)
  {
    if ((obj == null) || (!(obj instanceof Win32Thread))) {
      return false;
    }
    return ((Win32Thread)obj).getThreadID() == getThreadID();
  }
  
  public int hashCode()
  {
    return getThreadID();
  }
  
  public String toString()
  {
    return Integer.toString(getThreadID());
  }
  
  private int getThreadID()
  {
    if (!gotID) {
      try
      {
        X86ThreadContext context = (X86ThreadContext)getContext();
        
        Win32LDTEntry ldt = debugger.getThreadSelectorEntry(handle, mustDuplicate, (int)context.getRegister(1));
        
        Address teb = debugger.newAddress(ldt.getBase());
        
        id = ((int)teb.getCIntegerAt(36L, 4L, true));
        gotID = true;
      }
      catch (AddressException e)
      {
        throw new DebuggerException(e);
      }
    }
    return id;
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.debugger.win32.Win32Thread
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.debugger.win32;

import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.x86.X86ThreadContext;

class Win32ThreadContext
  extends X86ThreadContext
{
  private Win32Debugger debugger;
  
  public Win32ThreadContext(Win32Debugger debugger)
  {
    this.debugger = debugger;
  }
  
  public void setRegisterAsAddress(int index, Address value)
  {
    setRegister(index, debugger.getAddressValue(value));
  }
  
  public Address getRegisterAsAddress(int index)
  {
    return debugger.newAddress(getRegister(index));
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.debugger.win32.Win32ThreadContext
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.debugger.windbg;

import java.io.IOException;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.DataSource;
import sun.jvm.hotspot.debugger.DebuggerException;
import sun.jvm.hotspot.debugger.UnmappedAddressException;

public class AddressDataSource
  implements DataSource
{
  private Address addr;
  private long offset;
  
  public AddressDataSource(Address addr)
  {
    this.addr = addr;
    offset = 0L;
  }
  
  public byte readByte()
    throws IOException
  {
    try
    {
      byte res = (byte)(int)addr.getCIntegerAt(offset, 1L, false);
      offset += 1L;
      return res;
    }
    catch (UnmappedAddressException e)
    {
      throw ((IOException)new IOException("Unmapped address at 0x" + Long.toHexString(e.getAddress())).initCause(e));
    }
    catch (DebuggerException e)
    {
      throw ((IOException)new IOException().initCause(e));
    }
  }
  
  public short readShort()
    throws IOException
  {
    int b1 = readByte() & 0xFF;
    int b2 = readByte() & 0xFF;
    return (short)(b1 << 8 | b2);
  }
  
  public int readInt()
    throws IOException
  {
    int b1 = readByte() & 0xFF;
    int b2 = readByte() & 0xFF;
    int b3 = readByte() & 0xFF;
    int b4 = readByte() & 0xFF;
    return b1 << 24 | b2 << 16 | b3 << 8 | b4;
  }
  
  public long readLong()
    throws IOException
  {
    long b1 = readByte() & 0xFF;
    long b2 = readByte() & 0xFF;
    long b3 = readByte() & 0xFF;
    long b4 = readByte() & 0xFF;
    long b5 = readByte() & 0xFF;
    long b6 = readByte() & 0xFF;
    long b7 = readByte() & 0xFF;
    long b8 = readByte() & 0xFF;
    return (b1 << 24 | b2 << 16 | b3 << 8 | b4) << 32 | b5 << 24 | b6 << 16 | b7 << 8 | b8;
  }
  
  public int read(byte[]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd