Skip to content

Commit

Permalink
Merge pull request #43684 from NipunaRanasinghe/2201.11.0-stage
Browse files Browse the repository at this point in the history
[Debugger] Add support for restart requests
  • Loading branch information
NipunaRanasinghe authored Dec 5, 2024
2 parents 0d1e483 + 55cee50 commit 9b642cc
Showing 10 changed files with 241 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -31,13 +31,13 @@
</And>
<And>
<Bug pattern="DE_MIGHT_IGNORE"/>
<Method name="terminateDebugServer"/>
<Method name="terminateDebuggee"/>
</And>
<And>
<Bug pattern="BC_UNCONFIRMED_CAST"/>
<Or>
<Method name="attach"/>
<Method name="launch"/>
<Method name="launchDebuggeeProgram"/>
</Or>
</And>
</Or>
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ public class DebugExecutionManager {
private static final String SOCKET_CONNECTOR_NAME = "com.sun.jdi.SocketAttach";
private static final String CONNECTOR_ARGS_HOST = "hostname";
private static final String CONNECTOR_ARGS_PORT = "port";
private static final String VALUE_UNKNOWN = "unknown";
private static final Logger LOGGER = LoggerFactory.getLogger(DebugExecutionManager.class);

DebugExecutionManager(JBallerinaDebugServer server) {
@@ -61,6 +62,12 @@ public Optional<Integer> getPort() {
return Optional.ofNullable(port);
}

public String getRemoteVMAddress() {
String host = getHost().orElse(VALUE_UNKNOWN);
String port = getPort().map(String::valueOf).orElse(VALUE_UNKNOWN);
return String.format("%s:%s", host, port);
}

/**
* Attaches to an existing JVM using an SocketAttachingConnector and returns the attached VM instance.
*/
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ public class DebugOutputLogger {

public DebugOutputLogger(IDebugProtocolClient client) {
this.client = client;
this.isCompilationDone = false;
}

/**
@@ -129,4 +130,8 @@ private static boolean isInternalLog(String output) {
|| output.startsWith("JAVACMD")
|| output.startsWith("Stream closed");
}

public void reset() {
isCompilationDone = false;
}
}
Original file line number Diff line number Diff line change
@@ -52,32 +52,24 @@ public DebugProjectCache() {
public Project getProject(Path filePath) {
Map.Entry<ProjectKind, Path> projectKindAndRoot = computeProjectKindAndRoot(filePath);
Path projectRoot = projectKindAndRoot.getValue();
if (!loadedProjects.containsKey(projectRoot)) {
addProject(loadProject(filePath.toAbsolutePath().toString()));
}
return loadedProjects.get(projectRoot);

return loadedProjects.computeIfAbsent(projectRoot, key -> loadProject(projectKindAndRoot));
}

/**
* Adds the given project instance into the cache.
*
* @param project project instance.
* Clears the project cache.
*/
public void addProject(Project project) {
Path projectSourceRoot = project.sourceRoot().toAbsolutePath();
loadedProjects.put(projectSourceRoot, project);
public void clear() {
loadedProjects.clear();
}

/**
* Loads the target ballerina source project instance using the Project API, from the file path of the open/active
* editor instance in the client(plugin) side.
*
* @param filePath file path of the open/active editor instance in the plugin side.
*/
private static Project loadProject(String filePath) {
Map.Entry<ProjectKind, Path> projectKindAndProjectRootPair = computeProjectKindAndRoot(Path.of(filePath));
ProjectKind projectKind = projectKindAndProjectRootPair.getKey();
Path projectRoot = projectKindAndProjectRootPair.getValue();
private static Project loadProject(Map.Entry<ProjectKind, Path> projectKindAndRoot) {
ProjectKind projectKind = projectKindAndRoot.getKey();
Path projectRoot = projectKindAndRoot.getValue();
BuildOptions options = BuildOptions.builder().setOffline(true).build();
if (projectKind == ProjectKind.BUILD_PROJECT) {
return BuildProject.load(projectRoot, options);
Original file line number Diff line number Diff line change
@@ -144,17 +144,12 @@ public Project getSourceProject() {
public void setSourceProject(Project sourceProject) {
this.sourceProject = sourceProject;
this.setSourceProjectRoot(sourceProject.sourceRoot().toAbsolutePath().toString());
updateProjectCache(sourceProject);
}

public DebugProjectCache getProjectCache() {
return projectCache;
}

public void updateProjectCache(Project project) {
this.projectCache.addProject(project);
}

public String getSourceProjectRoot() {
return sourceProjectRoot;
}
@@ -171,6 +166,19 @@ public boolean getSupportsRunInTerminalRequest() {
return supportsRunInTerminalRequest;
}

public void reset() {
this.projectCache.clear();
this.debugMode = null;
this.debuggeeVM = null;
this.prevLocation = null;
this.sourceProject = null;
this.launchedProcess = null;
this.sourceProjectRoot = null;
this.terminateRequestReceived = false;
this.supportsRunInTerminalRequest = false;
this.prevInstruction = DebugInstruction.CONTINUE;
}

/**
* Currently supported debug configuration modes.
*/
Loading

0 comments on commit 9b642cc

Please # to comment.