Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public void terminate() {

@Override
public IBreakpoint createBreakpoint(String className, int lineNumber) {
return new Breakpoint(vm, this.eventHub(), className, lineNumber);
return new Breakpoint(vm, this.getEventHub(), className, lineNumber);
}

@Override
public IBreakpoint createBreakpoint(String className, int lineNumber, int hitCount) {
return new Breakpoint(vm, this.eventHub(), className, lineNumber, hitCount);
return new Breakpoint(vm, this.getEventHub(), className, lineNumber, hitCount);
}

@Override
Expand All @@ -102,12 +102,17 @@ public Process process() {
}

@Override
public List<ThreadReference> allThreads() {
public List<ThreadReference> getAllThreads() {
return vm.allThreads();
}

@Override
public IEventHub eventHub() {
public IEventHub getEventHub() {
return eventHub;
}

@Override
public VirtualMachine getVM() {
return vm;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static ThreadReference getThread(IDebugSession debugSession, long threadI
public static List<ThreadReference> getAllThreadsSafely(IDebugSession debugSession) {
if (debugSession != null) {
try {
return debugSession.allThreads();
return debugSession.getAllThreads();
} catch (VMDisconnectedException ex) {
// do nothing.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;

import com.sun.jdi.ThreadReference;
import com.sun.jdi.VirtualMachine;

public interface IDebugSession {
void start();
Expand All @@ -37,8 +38,9 @@ public interface IDebugSession {

Process process();

List<ThreadReference> allThreads();
List<ThreadReference> getAllThreads();

IEventHub eventHub();
}
IEventHub getEventHub();

VirtualMachine getVM();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@

package com.microsoft.java.debug.core.adapter;

import java.util.HashMap;
import java.util.Map;

import com.microsoft.java.debug.core.IDebugSession;

public interface IProvider {
/**
* Initialize this provider.
* @param options the options
*/
default void initialize(Map<String, Object> options) {

}

/**
* Get the default options for this provider.
*
* @return The default options.
* @param debugSession
* The associated debug session
* @param options
* the options
*/
default Map<String, Object> getDefaultOptions() {
return new HashMap<>();
default void initialize(IDebugSession debugSession, Map<String, Object> options) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
Expand Down Expand Up @@ -50,25 +51,25 @@ public void handle(Command command, Arguments arguments, Response response, IDeb
context.setDebuggeeEncoding(StandardCharsets.UTF_8); // Use UTF-8 as debuggee's default encoding format.

IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class);
ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class);
Map<String, Object> options = sourceProvider.getDefaultOptions();
options.put(Constants.DEBUGGEE_ENCODING, context.getDebuggeeEncoding());
if (attachArguments.projectName != null) {
options.put(Constants.PROJECTNAME, attachArguments.projectName);
}
sourceProvider.initialize(options);

try {
logger.info(String.format("Trying to attach to remote debuggee VM %s:%d .",
attachArguments.hostName, attachArguments.port));
IDebugSession debugSession = DebugUtility.attach(vmProvider.getVirtualMachineManager(),
attachArguments.hostName, attachArguments.port, attachArguments.timeout);
logger.info(String.format("Trying to attach to remote debuggee VM %s:%d .", attachArguments.hostName, attachArguments.port));
IDebugSession debugSession = DebugUtility.attach(vmProvider.getVirtualMachineManager(), attachArguments.hostName, attachArguments.port,
attachArguments.timeout);
context.setDebugSession(debugSession);
logger.info("Attaching to debuggee VM succeeded.");
} catch (IOException | IllegalConnectorArgumentsException e) {
AdapterUtils.setErrorResponse(response, ErrorCode.ATTACH_FAILURE,
String.format("Failed to attach to remote debuggee VM. Reason: %s", e.toString()));
}

Map<String, Object> options = new HashMap<>();
options.put(Constants.DEBUGGEE_ENCODING, context.getDebuggeeEncoding());
if (attachArguments.projectName != null) {
options.put(Constants.PROJECTNAME, attachArguments.projectName);
}
ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class);
sourceProvider.initialize(context.getDebugSession(), options);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void handle(Command command, Arguments arguments, Response response, IDeb
IDebugSession debugSession = context.getDebugSession();
if (debugSession != null) {
// This is a global event handler to handle the JDI Event from Virtual Machine.
debugSession.eventHub().events().subscribe(debugEvent -> {
debugSession.getEventHub().events().subscribe(debugEvent -> {
handleDebugEvent(debugEvent, debugSession, context);
});
// configuration is done, and start debug session.
Expand All @@ -72,7 +72,7 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
context.sendEventAsync(new Events.TerminatedEvent());
// Terminate eventHub thread.
try {
debugSession.eventHub().close();
debugSession.getEventHub().close();
} catch (Exception e) {
// do nothing.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ public void handle(Command command, Arguments arguments, Response response, IDeb


IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class);
ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class);
Map<String, Object> options = sourceProvider.getDefaultOptions();
options.put(Constants.DEBUGGEE_ENCODING, context.getDebuggeeEncoding());
if (launchArguments.projectName != null) {
options.put(Constants.PROJECTNAME, launchArguments.projectName);
}
sourceProvider.initialize(options);


// Append environment to native environment.
String[] envVars = null;
Expand Down Expand Up @@ -142,5 +136,13 @@ public void handle(Command command, Arguments arguments, Response response, IDeb
AdapterUtils.setErrorResponse(response, ErrorCode.LAUNCH_FAILURE,
String.format("Failed to launch debuggee VM. Reason: %s", e.toString()));
}

ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class);
Map<String, Object> options = new HashMap<>();
options.put(Constants.DEBUGGEE_ENCODING, context.getDebuggeeEncoding());
if (launchArguments.projectName != null) {
options.put(Constants.PROJECTNAME, launchArguments.projectName);
}
sourceProvider.initialize(context.getDebugSession(), options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void handle(Command command, Arguments arguments, Response response, IDeb
private void threads(Requests.ThreadsArguments arguments, Response response, IDebugAdapterContext context) {
ArrayList<Types.Thread> threads = new ArrayList<>();
try {
for (ThreadReference thread : context.getDebugSession().allThreads()) {
for (ThreadReference thread : context.getDebugSession().getAllThreads()) {
if (thread.isCollected()) {
continue;
}
Expand All @@ -94,23 +94,23 @@ private void threads(Requests.ThreadsArguments arguments, Response response, IDe
private void stepIn(Requests.StepInArguments arguments, Response response, IDebugAdapterContext context) {
ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId);
if (thread != null) {
DebugUtility.stepInto(thread, context.getDebugSession().eventHub());
DebugUtility.stepInto(thread, context.getDebugSession().getEventHub());
checkThreadRunningAndRecycleIds(thread, context);
}
}

private void stepOut(Requests.StepOutArguments arguments, Response response, IDebugAdapterContext context) {
ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId);
if (thread != null) {
DebugUtility.stepOut(thread, context.getDebugSession().eventHub());
DebugUtility.stepOut(thread, context.getDebugSession().getEventHub());
checkThreadRunningAndRecycleIds(thread, context);
}
}

private void next(Requests.NextArguments arguments, Response response, IDebugAdapterContext context) {
ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId);
if (thread != null) {
DebugUtility.stepOver(thread, context.getDebugSession().eventHub());
DebugUtility.stepOver(thread, context.getDebugSession().getEventHub());
checkThreadRunningAndRecycleIds(thread, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected BreakpointEvent waitForBreakPointEvent(String breakpointAtClass, int l
System.out.println("Breakpoint is accepted.");
});
debugSession.start();
debugSession.eventHub().breakpointEvents().subscribe(breakpoint -> {
debugSession.getEventHub().breakpointEvents().subscribe(breakpoint -> {
System.out.println("Breakpoint is hit.");
breakpoint.shouldResume = false;
staticBreakpointEvent = (BreakpointEvent) breakpoint.event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public static IDebugSession getDebugSession(String projectName, String mainClass
try {
final IDebugSession debugSession = DebugUtility.launch(Bootstrap.virtualMachineManager(), mainClass, "", "",
new File(projectRoot, "bin").getAbsolutePath(), null, null);
debugSession.eventHub().events().subscribe(debugEvent -> {
debugSession.getEventHub().events().subscribe(debugEvent -> {
if (debugEvent.event instanceof VMDisconnectEvent) {
try {
debugSession.eventHub().close();
debugSession.getEventHub().close();
} catch (Exception e) {
// do nothing.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import com.microsoft.java.debug.core.Configuration;
import com.microsoft.java.debug.core.DebugException;
import com.microsoft.java.debug.core.IDebugSession;
import com.microsoft.java.debug.core.adapter.AdapterUtils;
import com.microsoft.java.debug.core.adapter.Constants;
import com.microsoft.java.debug.core.adapter.ISourceLookUpProvider;
Expand All @@ -64,14 +65,14 @@ public class JdtSourceLookUpProvider implements ISourceLookUpProvider {
private static final String JDT_SCHEME = "jdt";
private static final String PATH_SEPARATOR = "/";

private HashMap<String, Object> context = new HashMap<String, Object>();
private HashMap<String, Object> options = new HashMap<String, Object>();

@Override
public void initialize(Map<String, Object> props) {
public void initialize(IDebugSession debugSession, Map<String, Object> props) {
if (props == null) {
throw new IllegalArgumentException("argument is null");
}
context.putAll(props);
options.putAll(props);
}

@Override
Expand Down Expand Up @@ -110,7 +111,7 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
String filePath = AdapterUtils.toPath(uri);
// For file uri, read the file contents directly and pass them to the ast parser.
if (filePath != null && Files.isRegularFile(Paths.get(filePath))) {
Charset cs = (Charset) this.context.get(Constants.DEBUGGEE_ENCODING);
Charset cs = (Charset) this.options.get(Constants.DEBUGGEE_ENCODING);
if (cs == null) {
cs = Charset.defaultCharset();
}
Expand All @@ -130,11 +131,11 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
* See the java doc for { @link ASTParser#setSource(char[]) },
* the user need specify the compiler options explicitly.
*/
Map<String, String> options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
parser.setCompilerOptions(options);
Map<String, String> javaOptions = JavaCore.getOptions();
javaOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
javaOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
javaOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
parser.setCompilerOptions(javaOptions);
astUnit = (CompilationUnit) parser.createAST(null);
} else {
// For non-file uri (e.g. jdt://contents/rt.jar/java.io/PrintStream.class),
Expand Down Expand Up @@ -223,7 +224,7 @@ private IJavaProject getJavaProjectFromName(String projectName) throws CoreExcep
}

private String searchDeclarationFileByFqn(String fullyQualifiedName) {
String projectName = (String) context.get(Constants.PROJECTNAME);
String projectName = (String) options.get(Constants.PROJECTNAME);
try {
IJavaSearchScope searchScope = projectName != null
? createSearchScope(getJavaProjectFromName(projectName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

package com.microsoft.java.debug.plugin.internal;

import java.util.Map;

import com.microsoft.java.debug.core.adapter.IVirtualMachineManagerProvider;
import com.sun.jdi.VirtualMachineManager;

Expand All @@ -26,8 +24,4 @@ public synchronized VirtualMachineManager getVirtualMachineManager() {
}
return vmManager;
}

@Override
public void initialize(Map<String, Object> props) {
}
}