fix(Debugger) list,map,对象类型的变量展示值

This commit is contained in:
youys 2023-08-24 10:09:58 +08:00
parent 7b0d778e82
commit dcdab43146
3 changed files with 42 additions and 7 deletions

13
pom.xml
View File

@ -82,6 +82,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- <release>17</release>-->
<compilerArgs>
<arg>--add-exports</arg>
<arg>jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -10,6 +10,7 @@ import com.sun.jdi.event.BreakpointEvent;
import com.sun.jdi.event.Event;
import com.sun.jdi.event.StepEvent;
import com.sun.jdi.request.StepRequest;
import com.sun.tools.jdi.ClassObjectReferenceImpl;
import java.io.IOException;
import java.io.OutputStream;
@ -36,8 +37,10 @@ public class Debugger {
private String outputFilePath = "";
private StepRequest stepRequest;
private Boolean isRunning;
private String mainClass;
public Debugger(String mainClass, String classPath) {
this.mainClass = mainClass;
debugSession = getDebugSession(mainClass, classPath);
this.isRunning = Boolean.valueOf(true);
@ -140,8 +143,8 @@ public class Debugger {
this.breakpoints.remove(str);
}
public Map<String,List<Integer>> getBreakpoints() {
Map<String,List<Integer>> listMap = new HashMap<>();
public Map<String, List<Integer>> getBreakpoints() {
Map<String, List<Integer>> listMap = new HashMap<>();
Set<String> set = this.breakpoints.keySet();
Iterator<String> iterator = set.iterator();
while (iterator.hasNext()) {
@ -153,7 +156,7 @@ public class Debugger {
if (listMap.containsKey(className)) {
List<Integer> lineNoList = listMap.get(className);
lineNoList.add(lineNo);
}else{
} else {
List<Integer> lineNoList = new ArrayList<>();
lineNoList.add(lineNo);
listMap.put(className, lineNoList);
@ -226,6 +229,22 @@ public class Debugger {
VirtualMachine virtualMachine = debugSession.getVM();
List<ReferenceType> list = virtualMachine.classesByName(SERIALIZER_CLASS);
if (list.size() == 0) {
ClassLoaderReference reference = virtualMachine.classesByName(mainClass).get(0).classLoader();
Method method = virtualMachine.classesByName("jdk.internal.loader.ClassLoaders$AppClassLoader").get(0).methodsByName("loadClass").get(1);
List<Value> arguments = new ArrayList<>();
arguments.add(virtualMachine.mirrorOf(SERIALIZER_CLASS));
ThreadReference threadReference = getThreadFromLastEvent();
Value value = reference.invokeMethod(threadReference, method, arguments, 1);
ReferenceType referenceType = ((ClassObjectReferenceImpl) value).referenceType();
ClassType classType = (ClassType) referenceType;
method = referenceType.methodsByName("forName").get(0);
classType.invokeMethod(threadReference, method, arguments, 1);
}
list = virtualMachine.classesByName(SERIALIZER_CLASS);
ClassType classType = (ClassType) list.get(0);
List<Method> list1 = classType.methodsByName(paramString);
@ -246,6 +265,7 @@ public class Debugger {
List<Value> list = Arrays.asList(new Value[]{paramValue});
return callSerializerMethod(SERIALIZE_DYNAMIC_RESOLVE, list);
} catch (Exception exception) {
exception.printStackTrace();
return null;
}
}
@ -255,6 +275,7 @@ public class Debugger {
List<Value> list = Arrays.asList(new Value[]{paramValue});
return callSerializerMethod(OBJECT_TO_CLASS, list);
} catch (Exception exception) {
exception.printStackTrace();
try {
return paramValue.toString();
@ -363,7 +384,7 @@ public class Debugger {
ThreadReference threadReference = getThreadFromLastEvent();
if (threadReference.frameCount() > 0) {
return "PAUSED";
}else{
} else {
return "RUNNING";
}
} catch (Exception exception) {

View File

@ -32,6 +32,7 @@ public class DebuggerController {
private static final Gson gson = new Gson();
private String outputPath;
private static final String workspace = "/data/workspace";
private final Logger logger = LoggerFactory.getLogger(DebuggerController.class);
@ -256,12 +257,12 @@ public class DebuggerController {
* @param originalEvaluateFile 原始评测文件
*/
private void compileCode(String originalEvaluateFile) {
String compilePath = "/data/workspace" + File.separator + originalEvaluateFile.substring(0, originalEvaluateFile.lastIndexOf("/") + 1);
String compileCommand = StringUtils.join("javac -g -cp ", compilePath, " ", compilePath+"*.java");
String compilePath = workspace + File.separator + originalEvaluateFile.substring(0, originalEvaluateFile.lastIndexOf("/") + 1);
String compileCommand = StringUtils.join("javac -g -cp ", compilePath,":", workspace,"/precompiled.jar:", workspace,"/minimal-json.jar ", " ", compilePath+"*.java");
ShellResult shellResult = ShellUtil.executeAndGetExitStatus(compileCommand);
logger.info("编译代码command:{}, status:{}, out:{}", compileCommand, shellResult.getExitStatus(), shellResult.getOut());
if(shellResult.getExitStatus() != 0){
throw new RuntimeException(shellResult.getOut().replaceAll("/data/workspace/", ""));
throw new RuntimeException(shellResult.getOut().replaceAll(workspace + "/", ""));
}
}
}