1 |
769 |
jeremybenn |
/* MethodCommandSet.java -- class to implement the Method Command Set
|
2 |
|
|
Copyright (C) 2005, 2006, 2007 Free Software Foundation
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package gnu.classpath.jdwp.processor;
|
40 |
|
|
|
41 |
|
|
import gnu.classpath.jdwp.JdwpConstants;
|
42 |
|
|
import gnu.classpath.jdwp.VMMethod;
|
43 |
|
|
import gnu.classpath.jdwp.VMVirtualMachine;
|
44 |
|
|
import gnu.classpath.jdwp.exception.JdwpException;
|
45 |
|
|
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
46 |
|
|
import gnu.classpath.jdwp.exception.NotImplementedException;
|
47 |
|
|
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
48 |
|
|
import gnu.classpath.jdwp.util.LineTable;
|
49 |
|
|
import gnu.classpath.jdwp.util.VariableTable;
|
50 |
|
|
|
51 |
|
|
import java.io.DataOutputStream;
|
52 |
|
|
import java.io.IOException;
|
53 |
|
|
import java.nio.ByteBuffer;
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* A class representing the Method Command Set.
|
57 |
|
|
*
|
58 |
|
|
* @author Aaron Luchko <aluchko@redhat.com>
|
59 |
|
|
*/
|
60 |
|
|
public class MethodCommandSet
|
61 |
|
|
extends CommandSet
|
62 |
|
|
{
|
63 |
|
|
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
64 |
|
|
throws JdwpException
|
65 |
|
|
{
|
66 |
|
|
try
|
67 |
|
|
{
|
68 |
|
|
switch (command)
|
69 |
|
|
{
|
70 |
|
|
case JdwpConstants.CommandSet.Method.LINE_TABLE:
|
71 |
|
|
executeLineTable(bb, os);
|
72 |
|
|
break;
|
73 |
|
|
case JdwpConstants.CommandSet.Method.VARIABLE_TABLE:
|
74 |
|
|
executeVariableTable(bb, os);
|
75 |
|
|
break;
|
76 |
|
|
case JdwpConstants.CommandSet.Method.BYTE_CODES:
|
77 |
|
|
executeByteCodes(bb, os);
|
78 |
|
|
break;
|
79 |
|
|
case JdwpConstants.CommandSet.Method.IS_OBSOLETE:
|
80 |
|
|
executeIsObsolete(bb, os);
|
81 |
|
|
break;
|
82 |
|
|
case JdwpConstants.CommandSet.Method.VARIABLE_TABLE_WITH_GENERIC:
|
83 |
|
|
executeVariableTableWithGeneric(bb, os);
|
84 |
|
|
break;
|
85 |
|
|
default:
|
86 |
|
|
throw new NotImplementedException(
|
87 |
|
|
"Command " + command + " not found in Method Command Set.");
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
catch (IOException ex)
|
91 |
|
|
{
|
92 |
|
|
// The DataOutputStream we're using isn't talking to a socket at all
|
93 |
|
|
// So if we throw an IOException we're in serious trouble
|
94 |
|
|
throw new JdwpInternalErrorException(ex);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
return false;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
private void executeLineTable(ByteBuffer bb, DataOutputStream os)
|
101 |
|
|
throws JdwpException, IOException
|
102 |
|
|
{
|
103 |
|
|
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
104 |
|
|
Class clazz = refId.getType();
|
105 |
|
|
|
106 |
|
|
VMMethod method = VMMethod.readId(clazz, bb);
|
107 |
|
|
LineTable lt = method.getLineTable();
|
108 |
|
|
lt.write(os);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
private void executeVariableTable(ByteBuffer bb, DataOutputStream os)
|
112 |
|
|
throws JdwpException, IOException
|
113 |
|
|
{
|
114 |
|
|
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
115 |
|
|
Class clazz = refId.getType();
|
116 |
|
|
|
117 |
|
|
VMMethod method = VMMethod.readId(clazz, bb);
|
118 |
|
|
VariableTable vt = method.getVariableTable();
|
119 |
|
|
vt.write(os);
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
private void executeByteCodes(ByteBuffer bb, DataOutputStream os)
|
123 |
|
|
throws JdwpException, IOException
|
124 |
|
|
{
|
125 |
|
|
if (!VMVirtualMachine.canGetBytecodes)
|
126 |
|
|
{
|
127 |
|
|
String msg = "getting bytecodes is unsupported";
|
128 |
|
|
throw new NotImplementedException(msg);
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
ReferenceTypeId id = idMan.readReferenceTypeId(bb);
|
132 |
|
|
Class klass = id.getType();
|
133 |
|
|
VMMethod method = VMMethod.readId(klass, bb);
|
134 |
|
|
byte[] bytecode = VMVirtualMachine.getBytecodes(method);
|
135 |
|
|
os.writeInt(bytecode.length);
|
136 |
|
|
os.write(bytecode);
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
private void executeIsObsolete(ByteBuffer bb, DataOutputStream os)
|
140 |
|
|
throws IOException
|
141 |
|
|
{
|
142 |
|
|
// The debugger is really asking if this method has been redefined using
|
143 |
|
|
// VirtualMachineCommandSet.RedefineClasses. Since we don't implement that
|
144 |
|
|
// command the answer to this will always be false.
|
145 |
|
|
os.writeBoolean(false);
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
private void executeVariableTableWithGeneric(ByteBuffer bb,
|
149 |
|
|
DataOutputStream os)
|
150 |
|
|
throws JdwpException
|
151 |
|
|
{
|
152 |
|
|
// We don't have generics yet
|
153 |
|
|
throw new NotImplementedException(
|
154 |
|
|
"Command VariableTableWithGeneric not implemented.");
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
}
|