Skip to content
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

Add support for remote debugging with experimental debugger #1230

Merged
merged 20 commits into from
Apr 4, 2018

Conversation

DonJayamanne
Copy link

@DonJayamanne DonJayamanne commented Mar 28, 2018

Fixes #1229
Fixes #1265

This pull request:

  • Has a title summarizes what is changing
  • Includes a news entry file (remember to thank yourself!)
  • Has unit tests & code coverage is not adversely affected (within reason)
  • Works on all actively maintained versions of Python (e.g. Python 2.7 & the latest Python 3 release)
  • Works on Windows 10, macOS, and Linux (e.g. considered file system case-sensitivity)

@codecov
Copy link

codecov bot commented Mar 29, 2018

Codecov Report

Merging #1230 into master will increase coverage by 0.13%.
The diff coverage is 78.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1230      +/-   ##
==========================================
+ Coverage   70.94%   71.07%   +0.13%     
==========================================
  Files         266      267       +1     
  Lines       12284    12350      +66     
  Branches     2172     2188      +16     
==========================================
+ Hits         8715     8778      +63     
+ Misses       3445     3432      -13     
- Partials      124      140      +16
Impacted Files Coverage Δ
src/client/debugger/Common/Contracts.ts 100% <ø> (ø) ⬆️
...rc/client/debugger/configProviders/baseProvider.ts 93.97% <100%> (+0.92%) ⬆️
...lient/debugger/configProviders/pythonV2Provider.ts 100% <100%> (ø) ⬆️
.../client/debugger/DebugClients/RemoteDebugClient.ts 35% <33.33%> (+17.35%) ⬆️
...lient/debugger/DebugServers/RemoteDebugServerv2.ts 66.66% <66.66%> (ø)
src/client/debugger/mainV2.ts 76.03% <72.72%> (+4.41%) ⬆️
src/client/debugger/PythonProcess.ts 45.83% <0%> (-2.92%) ⬇️
src/client/linters/lintingEngine.ts 90.35% <0%> (-0.88%) ⬇️
...rc/client/debugger/PythonProcessCallbackHandler.ts 53.61% <0%> (+0.65%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 962c850...9bf271a. Read the comment docs.

@DonJayamanne DonJayamanne changed the title WIP - Add support for remote debugging with experimental debugger Add support for remote debugging with experimental debugger Mar 29, 2018
@DonJayamanne DonJayamanne force-pushed the issueAttachExperimental branch 2 times, most recently from fcf15dd to 673ef14 Compare April 2, 2018 21:46
// tslint:disable:quotemark ordered-imports no-any no-empty curly member-ordering one-line max-func-body-length no-var-self prefer-const cyclomatic-complexity prefer-template

import { DebugSession } from "vscode-debugadapter";
import { IPythonProcess, IDebugServer, AttachRequestArguments } from "../Common/Contracts";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evil double quotes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaah, copy paste.

this.provideDefaults(workspaceFolder, config);
if (config.request === 'attach') {
// tslint:disable-next-line:no-any
this.provideAttachDefaults(workspaceFolder, config as any as PythonAttachDebugConfiguration);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - why is getting casted twice

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config can be of two types. Modified code accordingly to make it clearer (using a union type).

@@ -87,14 +81,24 @@ export class PythonDebugger extends DebugSession {
this.sendResponse(response);
}
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
this.sendResponse(response);
const launcher = CreateAttachDebugClient(args as AttachRequestArguments, this);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args seems to be of that type already

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -211,6 +230,7 @@ class DebugManager implements Disposable {

this.initializeRequestDeferred = createDeferred<DebugProtocol.InitializeRequest>();
this.launchRequestDeferred = createDeferred<DebugProtocol.LaunchRequest>();
this.attachRequestDeferred = createDeferred<DebugProtocol.LaunchRequest>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DebugProtocol.AttachRequest?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

const numberOfSettings = Object.keys(config);
const workspaceFolder = this.getWorkspaceFolder(folder, config);
const workspaceFolder = this.getWorkspaceFolder(folder, config as PythonLaunchDebugConfiguration);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getWorkspaceFolder doesn't seem to be using config (it passes it to getProgram which does not use it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// tslint:disable:no-invalid-template-strings

export type PythonDebugConfiguration = DebugConfiguration & LaunchRequestArguments;
export type PythonLaunchDebugConfiguration = DebugConfiguration & LaunchRequestArguments;
export type PythonAttachDebugConfiguration = DebugConfiguration & AttachRequestArguments;

@injectable()
export abstract class BaseConfigurationProvider implements DebugConfigurationProvider {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth splitting into AttachConfigurationProvider and LaunchConfigurationProvider and have static factory like getConfigurationProvider(mode). Class has bunch of getLaunchX and getAttachX and casts and checks for the debug mode.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there can only be one debug configuration, that handles both launch and attach (& more in the future).
I've cleaned up the code,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be one class that contains a handler specific to the mode. I.e. debug configuration class acts as a proxy and simply forwards calls to 'launch or 'attach handler

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -263,7 +283,7 @@ class DebugManager implements Disposable {
this.terminatedEventSent = true;
}

if (this.killPTVSDProcess && this.ptvsdProcessId) {
if (this.launchOrAttach === 'launch' && this.ptvsdProcessId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In big VS Stop Debugging terminates debuggee even on attach. There is separate Detach command if user wants to keep debuggee running. I guess VSC does it differently.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In VSC, we don't have the ability to kill for attach scenarios, at least not yet (the protocol supports it for VS), the UI doesn't.
I'll create an issue so we add support for this, this way if the UI does add support for this in VSC, it'll work without much changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, we won't need to do anything. There's a ticket item in PTVSD to support this functionality ( required by VS).
in reality PTVSD is the debug adapter, hence it will kill the process if it needs to (the stuff we have here, is a temporary bridge to connect VSC to PTVSD - to perform initial handshake).
I.e. nothing to do here.

if (this.launchOrAttach === 'launch') {
const debugSoketProtocolParser = this.serviceContainer.get<IProtocolParser>(IProtocolParser);
debugSoketProtocolParser.connect(this.ptvsdSocket);
debugSoketProtocolParser.once('event_process', (proc: DebugProtocol.ProcessEvent) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Socket

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -17,6 +17,5 @@
"python.linting.pylamaEnabled": false,
"python.linting.mypyEnabled": false,
"python.formatting.provider": "yapf",
"python.linting.pylintUseMinimalCheckers": false,
"python.pythonPath": "python"
"python.linting.pylintUseMinimalCheckers": false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@DonJayamanne DonJayamanne merged commit 3e40ce2 into microsoft:master Apr 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants