Skip to content

Commit

Permalink
Some fixes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Nov 12, 2024
1 parent ce4728e commit 39a12ec
Show file tree
Hide file tree
Showing 12 changed files with 690 additions and 1,047 deletions.
1,253 changes: 281 additions & 972 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.6",
"@types/node": "^16.18.119",
"@types/request": "^2.48.8",
"@types/semver": "^7.3.9",
"@types/sinon": "^10.0.6",
Expand Down Expand Up @@ -98,7 +98,7 @@
"dependencies": {
"@rokucommunity/logger": "^0.3.9",
"@types/request": "^2.48.8",
"brighterscript": "^0.67.8",
"brighterscript": "file:../brighterscript",
"dateformat": "^4.6.3",
"debounce": "^1.2.1",
"eol": "^0.9.1",
Expand All @@ -111,7 +111,7 @@
"postman-request": "^2.88.1-postman.32",
"replace-in-file": "^6.3.2",
"replace-last": "^1.2.6",
"roku-deploy": "^3.12.2",
"roku-deploy": "file:../roku-deploy",
"semver": "^7.5.4",
"serialize-error": "^8.1.0",
"smart-buffer": "^4.2.0",
Expand Down
34 changes: 25 additions & 9 deletions src/adapters/DebugProtocolAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CompileErrorProcessor } from '../CompileErrorProcessor';
import type { RendezvousHistory, RendezvousTracker } from '../RendezvousTracker';
import type { ChanperfData } from '../ChanperfTracker';
import { ChanperfTracker } from '../ChanperfTracker';
import type { SourceLocation } from '../managers/LocationManager';
import { ErrorCode, PROTOCOL_ERROR_CODES, UpdateType } from '../debugProtocol/Constants';
import { defer, util } from '../util';
import { logger } from '../logging';
Expand All @@ -21,7 +20,7 @@ import { VariableType } from '../debugProtocol/events/responses/VariablesRespons
import type { TelnetAdapter } from './TelnetAdapter';
import type { DeviceInfo } from 'roku-deploy';
import type { ThreadsResponse } from '../debugProtocol/events/responses/ThreadsResponse';
import type { DebugProtocol } from 'vscode-debugprotocol';
import type { ExceptionBreakpointFilter } from '../debugProtocol/events/requests/SetExceptionsBreakpointsRequest';

/**
* A class that connects to a Roku device over telnet debugger port and provides a standardized way of interacting with it.
Expand Down Expand Up @@ -186,7 +185,7 @@ export class DebugProtocolAdapter {
return new Promise((resolve) => {
let callCount = -1;

function handler() {
function handler(data: Buffer) {
callCount++;
let myCallCount = callCount;
setTimeout(() => {
Expand All @@ -200,23 +199,38 @@ export class DebugProtocolAdapter {

client.addListener(name, handler);
//call the handler immediately so we have a timeout
handler();
handler(Buffer.from([]));
});
}

public get isAtDebuggerPrompt() {
return this.client?.isStopped ?? false;
}

private firstConnectDeferred = defer<void>();

/**
* Resolves when the first connection to the client is established
*/
public onReady() {
return this.firstConnectDeferred.promise;
}

/**
* Connect to the telnet session. This should be called before the channel is launched.
*/
public async connect() {
public async connect(): Promise<void> {
//Start processing telnet output to look for compile errors or the debugger prompt
await this.processTelnetOutput();

this.on('waiting-for-debugger', () => {
void this.createDebugProtocolClient();
this.on('waiting-for-debugger', async () => { // eslint-disable-line @typescript-eslint/no-misused-promises
await this.createDebugProtocolClient();

//if this is the first time we are connecting, resolve the promise.
//(future events fire for "reconnect" situations, we don't need to resolve again for those)
if (!this.firstConnectDeferred.isCompleted) {
this.firstConnectDeferred.resolve();
}
});
}

Expand Down Expand Up @@ -830,9 +844,11 @@ export class DebugProtocolAdapter {
this.chanperfTracker.clearHistory();
}

public async setExceptionsBreakpointsRequest(filters: string[]) {
public async setExceptionBreakpoints(filters: ExceptionBreakpointFilter[]) {
//tell the client to set the exception breakpointsA
return this.client?.setExceptionBreakpoints(filters);
const response = await this.client?.setExceptionBreakpoints(filters);
console.log(response);
return response;
}

private syncBreakpointsPromise = Promise.resolve();
Expand Down
11 changes: 9 additions & 2 deletions src/adapters/TelnetAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { AdapterOptions, RokuAdapterEvaluateResponse } from '../interfaces'
import { HighLevelType } from '../interfaces';
import { TelnetRequestPipeline } from './TelnetRequestPipeline';
import type { DebugProtocolAdapter } from './DebugProtocolAdapter';
import type { DebugProtocol } from 'vscode-debugprotocol';
import type { ExceptionBreakpointFilter } from '../debugProtocol/events/requests/SetExceptionsBreakpointsRequest';

/**
* A class that connects to a Roku device over telnet debugger port and provides a standardized way of interacting with it.
Expand Down Expand Up @@ -227,6 +227,12 @@ export class TelnetAdapter {
}
}

private firstConnectDeferred = defer<void>();

public onReady() {
return this.firstConnectDeferred.promise;
}

/**
* Connect to the telnet session. This should be called before the channel is launched.
*/
Expand Down Expand Up @@ -357,6 +363,7 @@ export class TelnetAdapter {
} catch (e) {
deferred.reject(e);
}
this.firstConnectDeferred.resolve();
return deferred.promise;
}

Expand Down Expand Up @@ -1077,7 +1084,7 @@ export class TelnetAdapter {
this.chanperfTracker.clearHistory();
}

public async setExceptionsBreakpointsRequest(filters: string[]) {
public async setExceptionBreakpoints(filters: ExceptionBreakpointFilter[]) {
//we can't send dynamic breakpoints to the server...so just do nothing
}

Expand Down
38 changes: 30 additions & 8 deletions src/debugProtocol/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export enum ErrorCode {
UNDEFINED_COMMAND = 2,
CANT_CONTINUE = 3,
NOT_STOPPED = 4,
INVALID_ARGS = 5
INVALID_ARGS = 5,
THREAD_DETACHED = 6,
EXECUTION_TIMEOUT = 7
}

export enum ErrorFlags {
Expand Down Expand Up @@ -205,7 +207,18 @@ export enum UpdateType {
* Breakpoints were successfully verified
* @since protocol 3.2
*/
BreakpointVerified = 'BreakpointVerified'
BreakpointVerified = 'BreakpointVerified',
/**
* An unrecoverable error has occurred on the protocol stream. As a result, the debug target is terminated.
* @since Roku OS 12.0
*/
ProtocolError = 'ProtocolError',
/**
* ExceptionBreakpointError updates will be sent for compile and runtime errors for exception breakpoint conditions.
* These updates will be sent every time the condition fails to compile/run while throwing an exception.
* @since protocol 3.3 (OS 14.1.4 or greater)
*/
ExceptionBreakpointError = 'ExceptionBreakpointError'
}
/**
* The integer values for `UPDATE_TYPE`. Only used for serializing/deserializing over the debug protocol. Use `UpdateType` in your code.
Expand All @@ -217,10 +230,19 @@ export enum UpdateTypeCode {
ThreadAttached = 3,
BreakpointError = 4,
CompileError = 5,
// /**
// * Breakpoints were successfully verified
// * @since protocol 3.2
// */
BreakpointVerified = 6
/**
* Breakpoints were successfully verified
* @since protocol 3.2
*/
BreakpointVerified = 6,
/**
* An unrecoverable error has occurred on the protocol stream. As a result, the debug target is terminated.
*/
ProtocolError = 7,
/**
* ExceptionBreakpointError updates will be sent for compile and runtime errors for exception breakpoint conditions.
* These updates will be sent every time the condition fails to compile/run while throwing an exception.
* @since protocol 3.2
*/
ExceptionBreakpointError = 8
}

31 changes: 16 additions & 15 deletions src/debugProtocol/client/DebugProtocolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ListBreakpointsRequest } from '../events/requests/ListBreakpointsReques
import { VariablesRequest } from '../events/requests/VariablesRequest';
import { StackTraceRequest } from '../events/requests/StackTraceRequest';
import { ThreadsRequest } from '../events/requests/ThreadsRequest';
import type { ExceptionBreakpointFilter } from '../events/requests/SetExceptionsBreakpointsRequest';
import { SetExceptionsBreakpointsRequest } from '../events/requests/SetExceptionsBreakpointsRequest';
import { ExecuteRequest } from '../events/requests/ExecuteRequest';
import { AddBreakpointsRequest } from '../events/requests/AddBreakpointsRequest';
Expand All @@ -45,6 +46,7 @@ import PluginInterface from '../PluginInterface';
import type { VerifiedBreakpoint } from '../events/updates/BreakpointVerifiedUpdate';
import { BreakpointVerifiedUpdate } from '../events/updates/BreakpointVerifiedUpdate';
import type { AddConditionalBreakpointsResponse } from '../events/responses/AddConditionalBreakpointsResponse';
import { ExceptionBreakpointErrorUpdate } from '../events/updates/ExceptionBreakpointErrorUpdate';

export class DebugProtocolClient {

Expand Down Expand Up @@ -290,15 +292,16 @@ export class DebugProtocolClient {
/**
* Send the initial handshake request, and wait for the handshake response
*/
public async sendHandshake() {
return this.processHandshakeRequest(
public async sendHandshake(): Promise<HandshakeV3Response | HandshakeResponse> {
const response = await this.processHandshakeRequest(
HandshakeRequest.fromJson({
magic: DebugProtocolClient.DEBUGGER_MAGIC
})
);
return response;
}

private async processHandshakeRequest(request: HandshakeRequest) {
private async processHandshakeRequest(request: HandshakeRequest): Promise<HandshakeV3Response | HandshakeResponse> {
//send the magic, which triggers the debug session
this.logger.log('Sending magic to server');

Expand Down Expand Up @@ -436,19 +439,12 @@ export class DebugProtocolClient {
}
}

public async setExceptionBreakpoints(filters: string[]): Promise<SetExceptionsBreakpointsResponse> {
const json = {
requestId: this.requestIdSequence++,
breakpoints: filters.map(x => {
let breakpoint = {
filter: x === 'caught' ? 1 : x === 'uncaught' ? 2 : 0,
conditionExpression: ''
}
return breakpoint;
})
};
public async setExceptionBreakpoints(filters: ExceptionBreakpointFilter[]): Promise<SetExceptionsBreakpointsResponse> {
return this.processRequest<SetExceptionsBreakpointsResponse>(
SetExceptionsBreakpointsRequest.fromJson(json)
SetExceptionsBreakpointsRequest.fromJson({
requestId: this.requestIdSequence++,
breakpoints: filters
})
);
}

Expand Down Expand Up @@ -990,6 +986,11 @@ export class DebugProtocolClient {
this.emit('breakpoints-verified', response.data);
}
return response;
case UpdateType.ExceptionBreakpointError:
//we do nothing with exception breakpoint errors at this time.
const update = ExceptionBreakpointErrorUpdate.fromBuffer(buffer);
this.logger.error('Exception breakpoint error occurred', update);
return update;
default:
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { Command } from '../../Constants';
import { SetExceptionsBreakpointsRequest } from './SetExceptionsBreakpointsRequest';

describe('SetExceptionsBreakpointsRequest', () => {
describe.only('SetExceptionsBreakpointsRequest', () => {
it('serializes and deserializes properly with zero breakpoints', () => {
const command = SetExceptionsBreakpointsRequest.fromJson({
requestId: 3,
Expand Down Expand Up @@ -33,11 +33,11 @@ describe('SetExceptionsBreakpointsRequest', () => {
const command = SetExceptionsBreakpointsRequest.fromJson({
requestId: 3,
breakpoints: [{
filter: 0,
filter: 'caught',
conditionExpression: 'some conditions'
},
{
filter: 0,
filter: 'uncaught',
conditionExpression: ''
}]
});
Expand All @@ -48,11 +48,11 @@ describe('SetExceptionsBreakpointsRequest', () => {
command: Command.SetExceptionsBreakpoints,

breakpoints: [{
filter: 0,
filter: 'caught',
conditionExpression: 'some conditions'
},
{
filter: 0,
filter: 'uncaught',
conditionExpression: ''
}]
});
Expand All @@ -65,11 +65,11 @@ describe('SetExceptionsBreakpointsRequest', () => {
command: Command.SetExceptionsBreakpoints, // 4 bytes
// num_breakpoints // 4 bytes
breakpoints: [{
filter: 0,
filter: 'caught',
conditionExpression: 'some conditions'
},
{
filter: 0,
filter: 'uncaught',
conditionExpression: ''
}]
});
Expand Down
Loading

0 comments on commit 39a12ec

Please sign in to comment.