Skip to content

Commit

Permalink
Merge pull request #43686 from NipunaRanasinghe/debugger-restart-master
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 333ec52 + 54af2c2 commit 28e7cd7
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DebugOutputLogger {

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

/**
Expand Down Expand Up @@ -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
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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.
*/
Expand Down
Loading

0 comments on commit 28e7cd7

Please sign in to comment.