Repository navigation
Support exceptionInfo request to show exception info #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...ft.java.debug.core/src/main/java/com/microsoft/java/debug/core/JdiExceptionReference.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2019 Microsoft Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: | ||
| * Microsoft Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| package com.microsoft.java.debug.core; | ||
|
|
||
| import com.sun.jdi.ObjectReference; | ||
|
|
||
| public class JdiExceptionReference { | ||
| public ObjectReference exception; | ||
| public boolean isUncaught; | ||
|
|
||
| public JdiExceptionReference(ObjectReference exception, boolean isUncaught) { | ||
| this.exception = exception; | ||
| this.isUncaught = isUncaught; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ExceptionManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2019 Microsoft Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: | ||
| * Microsoft Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| package com.microsoft.java.debug.core.adapter; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import com.microsoft.java.debug.core.JdiExceptionReference; | ||
|
|
||
| public class ExceptionManager implements IExceptionManager { | ||
| private Map<Long, JdiExceptionReference> exceptions = Collections.synchronizedMap(new HashMap<>()); | ||
|
|
||
| @Override | ||
| public JdiExceptionReference getException(long threadId) { | ||
| return exceptions.get(threadId); | ||
| } | ||
|
|
||
| @Override | ||
| public JdiExceptionReference removeException(long threadId) { | ||
| return exceptions.remove(threadId); | ||
| } | ||
|
|
||
| @Override | ||
| public JdiExceptionReference setException(long threadId, JdiExceptionReference exception) { | ||
| return exceptions.put(threadId, exception); | ||
| } | ||
|
|
||
| @Override | ||
| public void removeAllExceptions() { | ||
| exceptions.clear(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ava.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/IExceptionManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2019 Microsoft Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: | ||
| * Microsoft Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| package com.microsoft.java.debug.core.adapter; | ||
|
|
||
| import com.microsoft.java.debug.core.JdiExceptionReference; | ||
|
|
||
| public interface IExceptionManager { | ||
| /** | ||
| * Returns the Exception associated with the thread. | ||
| */ | ||
| JdiExceptionReference getException(long threadId); | ||
|
|
||
| /** | ||
| * Removes the Exception associated with the thread. Returns the previous Exception mapping to the thread, | ||
| * null if no mapping exists. | ||
| */ | ||
| JdiExceptionReference removeException(long threadId); | ||
|
|
||
| /** | ||
| * Associates an Exception with the thread. Returns the previous Exception mapping to the thread, | ||
| * null if no mapping exists before. | ||
| */ | ||
| JdiExceptionReference setException(long threadId, JdiExceptionReference exception); | ||
|
|
||
| /** | ||
| * Clear all Exceptions. | ||
| */ | ||
| void removeAllExceptions(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
.../main/java/com/microsoft/java/debug/core/adapter/handler/ExceptionInfoRequestHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2019 Microsoft Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: | ||
| * Microsoft Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| package com.microsoft.java.debug.core.adapter.handler; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import com.microsoft.java.debug.core.Configuration; | ||
| import com.microsoft.java.debug.core.DebugUtility; | ||
| import com.microsoft.java.debug.core.JdiExceptionReference; | ||
| import com.microsoft.java.debug.core.adapter.AdapterUtils; | ||
| import com.microsoft.java.debug.core.adapter.ErrorCode; | ||
| import com.microsoft.java.debug.core.adapter.IDebugAdapterContext; | ||
| import com.microsoft.java.debug.core.adapter.IDebugRequestHandler; | ||
| import com.microsoft.java.debug.core.protocol.Messages.Response; | ||
| import com.microsoft.java.debug.core.protocol.Requests.Arguments; | ||
| import com.microsoft.java.debug.core.protocol.Requests.Command; | ||
| import com.microsoft.java.debug.core.protocol.Requests.ExceptionInfoArguments; | ||
| import com.microsoft.java.debug.core.protocol.Responses; | ||
| import com.microsoft.java.debug.core.protocol.Types.ExceptionBreakMode; | ||
| import com.sun.jdi.ClassNotLoadedException; | ||
| import com.sun.jdi.IncompatibleThreadStateException; | ||
| import com.sun.jdi.InvalidTypeException; | ||
| import com.sun.jdi.InvocationException; | ||
| import com.sun.jdi.Method; | ||
| import com.sun.jdi.ObjectReference; | ||
| import com.sun.jdi.ThreadReference; | ||
| import com.sun.jdi.Value; | ||
|
|
||
| public class ExceptionInfoRequestHandler implements IDebugRequestHandler { | ||
| protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); | ||
|
|
||
| @Override | ||
| public List<Command> getTargetCommands() { | ||
| return Arrays.asList(Command.EXCEPTIONINFO); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, | ||
| IDebugAdapterContext context) { | ||
| ExceptionInfoArguments exceptionInfoArgs = (ExceptionInfoArguments) arguments; | ||
| ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), exceptionInfoArgs.threadId); | ||
| if (thread == null) { | ||
| throw AdapterUtils.createCompletionException("Thread " + exceptionInfoArgs.threadId + " doesn't exist.", ErrorCode.EXCEPTION_INFO_FAILURE); | ||
| } | ||
|
|
||
| JdiExceptionReference jdiException = context.getExceptionManager().getException(exceptionInfoArgs.threadId); | ||
| if (jdiException == null) { | ||
| throw AdapterUtils.createCompletionException("No exception exists in thread " + exceptionInfoArgs.threadId, ErrorCode.EXCEPTION_INFO_FAILURE); | ||
| } | ||
|
|
||
| Method toStringMethod = null; | ||
| for (Method method : jdiException.exception.referenceType().allMethods()) { | ||
| if (Objects.equals("toString", method.name()) && Objects.equals("()Ljava/lang/String;", method.signature())) { | ||
| toStringMethod = method; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| String typeName = jdiException.exception.type().name(); | ||
| String exceptionToString = typeName; | ||
| if (toStringMethod != null) { | ||
| try { | ||
| Value returnValue = jdiException.exception.invokeMethod(thread, toStringMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); | ||
| exceptionToString = returnValue.toString(); | ||
| } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | ||
| | InvocationException e) { | ||
| logger.log(Level.SEVERE, String.format("Failed to get the return value of the method Exception.toString(): %s", e.toString(), e)); | ||
| } | ||
| } | ||
|
|
||
| response.body = new Responses.ExceptionInfoResponse(typeName, exceptionToString, | ||
| jdiException.isUncaught ? ExceptionBreakMode.USERUNHANDLED : ExceptionBreakMode.ALWAYS); | ||
| return CompletableFuture.completedFuture(response); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.