-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeScript proxy to support JrS debugging w/ Chrome DevTools (#4)
Basic debugging features of step over, step in , step out, continue, stop, add/remove breakpoints, provide backtrace at breakpoint, and evaluate watch expressions are all working. A few low-hanging features still missing: - passthrough of output to CDT console - reporting exceptions - verbosity control Other features of CDT will require enhancement to JrS debugger, e.g.: - scope chain - inspectable eval output (e.g. JSON, not just strings) - memory analysis - profiling Significant level of unit testing provided via jest. Thanks to Martijn The <[email protected]> for initial TS code skeleton, some unit tests, 'step out' feature, and tons of review! JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson [email protected]
- Loading branch information
Showing
25 changed files
with
6,562 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
dist | ||
node_modules | ||
src/coverage | ||
yarn-error.log |
This file contains 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 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,6 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
node $DIR/dist/cli/index.js $@ |
This file contains 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 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,104 @@ | ||
// Copyright JS Foundation and other contributors, http://js.foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { getOptionsFromArgs } from '../cli'; | ||
import { | ||
DEFAULT_DEBUGGER_HOST, | ||
DEFAULT_DEBUGGER_PORT, | ||
} from '../../lib/debugger-client'; | ||
import { | ||
DEFAULT_SERVER_HOST, | ||
DEFAULT_SERVER_PORT, | ||
} from '../../lib/cdt-proxy'; | ||
|
||
describe('getOptionsFromArgs', () => { | ||
|
||
function getOptionsFromUserArgs(userArgs: string[]) { | ||
return getOptionsFromArgs(['node', 'jerry-debugger.js'].concat(userArgs)); | ||
} | ||
|
||
it('works without --inspect-brk', () => { | ||
const opt = getOptionsFromUserArgs([]); | ||
expect(opt.proxyAddress.host).toEqual(DEFAULT_SERVER_HOST); | ||
expect(opt.proxyAddress.port).toEqual(DEFAULT_SERVER_PORT); | ||
}); | ||
|
||
it('parses --inspect-brk with port only', () => { | ||
const opt = getOptionsFromUserArgs(['--inspect-brk=1234']); | ||
expect(opt.proxyAddress.host).toEqual(undefined); | ||
expect(opt.proxyAddress.port).toEqual(1234); | ||
}); | ||
|
||
it('parses --inspect-brk with no port', () => { | ||
const opt = getOptionsFromUserArgs(['--inspect-brk=10.10.10.10:']); | ||
expect(opt.proxyAddress.host).toEqual('10.10.10.10'); | ||
expect(opt.proxyAddress.port).toEqual(undefined); | ||
}); | ||
|
||
it('parses --inspect-brk with no host', () => { | ||
const opt = getOptionsFromUserArgs(['--inspect-brk=:1234']); | ||
expect(opt.proxyAddress.host).toEqual(undefined); | ||
expect(opt.proxyAddress.port).toEqual(1234); | ||
}); | ||
|
||
it('parses --inspect-brk with host and port', () => { | ||
const opt = getOptionsFromUserArgs(['--inspect-brk=10.10.10.10:1234']); | ||
expect(opt.proxyAddress.host).toEqual('10.10.10.10'); | ||
expect(opt.proxyAddress.port).toEqual(1234); | ||
}); | ||
|
||
it('works without --jerry-remote', () => { | ||
const opt = getOptionsFromUserArgs([]); | ||
expect(opt.remoteAddress.host).toEqual(DEFAULT_DEBUGGER_HOST); | ||
expect(opt.remoteAddress.port).toEqual(DEFAULT_DEBUGGER_PORT); | ||
}); | ||
|
||
it('parses --jerry-remote with port only', () => { | ||
const opt = getOptionsFromUserArgs(['--jerry-remote=1234']); | ||
expect(opt.remoteAddress.host).toEqual(undefined); | ||
expect(opt.remoteAddress.port).toEqual(1234); | ||
}); | ||
|
||
it('parses --jerry-remote with host and port', () => { | ||
const opt = getOptionsFromUserArgs(['--jerry-remote=10.10.10.10:1234']); | ||
expect(opt.remoteAddress.host).toEqual('10.10.10.10'); | ||
expect(opt.remoteAddress.port).toEqual(1234); | ||
}); | ||
|
||
it('verbose defaults to false', () => { | ||
const opt = getOptionsFromUserArgs([]); | ||
expect(opt.verbose).toEqual(false); | ||
}); | ||
|
||
it('parses verbose flag', () => { | ||
const opt = getOptionsFromUserArgs(['--verbose']); | ||
expect(opt.verbose).toEqual(true); | ||
}); | ||
|
||
it('parses v alias for verbose', () => { | ||
const opt = getOptionsFromUserArgs(['-v']); | ||
expect(opt.verbose).toEqual(true); | ||
}); | ||
|
||
it('jsfile defaults to untitled.js', () => { | ||
const opt = getOptionsFromUserArgs([]); | ||
expect(opt.jsfile).toEqual('untitled.js'); | ||
}); | ||
|
||
it('returns client source as jsfile', () => { | ||
const opt = getOptionsFromUserArgs(['foo/bar.js']); | ||
expect(opt.jsfile).toEqual('foo/bar.js'); | ||
}); | ||
|
||
}); |
This file contains 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,97 @@ | ||
// Copyright JS Foundation and other contributors, http://js.foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { CDTController } from '../lib/cdt-controller'; | ||
import { | ||
ChromeDevToolsProxyServer, | ||
DEFAULT_SERVER_HOST, | ||
DEFAULT_SERVER_PORT, | ||
} from '../lib/cdt-proxy'; | ||
import { | ||
JerryDebuggerClient, | ||
DEFAULT_DEBUGGER_HOST, | ||
DEFAULT_DEBUGGER_PORT, | ||
} from '../lib/debugger-client'; | ||
import { Command } from 'commander'; | ||
import { JerryDebugProtocolHandler } from '../lib/protocol-handler'; | ||
|
||
/** | ||
* Converts string of format [host:][port] to an object with host and port, | ||
* each possibly undefined | ||
*/ | ||
function getHostAndPort(input: string) { | ||
const hostAndPort = input.split(':'); | ||
const portIndex = hostAndPort.length - 1; | ||
const host = hostAndPort[portIndex - 1]; | ||
const port = hostAndPort[portIndex]; | ||
return { | ||
host: host ? host : undefined, | ||
port: port ? Number(port) : undefined, | ||
}; | ||
} | ||
|
||
export function getOptionsFromArgs(argv: Array<string>) { | ||
const program = new Command('jerry-debugger'); | ||
program | ||
.usage('[options] <script.js ...>') | ||
.option( | ||
'-v, --verbose', | ||
'Enable verbose logging', false) | ||
.option( | ||
'--inspect-brk [[host:]port]', | ||
'Activate Chrome DevTools proxy on host:port', | ||
`${DEFAULT_SERVER_HOST}:${DEFAULT_SERVER_PORT}`) | ||
.option( | ||
'--jerry-remote [[host:]port]', | ||
'Connect to JerryScript on host:port', | ||
`${DEFAULT_DEBUGGER_HOST}:${DEFAULT_DEBUGGER_PORT}`) | ||
.parse(argv); | ||
|
||
return { | ||
proxyAddress: getHostAndPort(program.inspectBrk), | ||
remoteAddress: getHostAndPort(program.jerryRemote), | ||
jsfile: program.args[0] || 'untitled.js', | ||
verbose: program.verbose || false, | ||
}; | ||
} | ||
|
||
export function main(proc: NodeJS.Process) { | ||
const options = getOptionsFromArgs(proc.argv); | ||
|
||
const controller = new CDTController(); | ||
const jhandler = new JerryDebugProtocolHandler(controller); | ||
const jclient = new JerryDebuggerClient({ | ||
delegate: jhandler, | ||
...options.remoteAddress, | ||
}); | ||
jhandler.debuggerClient = jclient; | ||
// set this before connecting to the client | ||
controller.protocolHandler = jhandler; | ||
|
||
const debuggerUrl = `ws://${jclient.host}:${jclient.port}`; | ||
jclient.connect().then(() => { | ||
console.log(`Connected to debugger at ${debuggerUrl}`); | ||
const proxy = new ChromeDevToolsProxyServer({ | ||
delegate: controller, | ||
...options.proxyAddress, | ||
jsfile: options.jsfile, | ||
}); | ||
// set this before making further debugger calls | ||
controller.proxyServer = proxy; | ||
console.log(`Proxy listening at ws://${proxy.host}:${proxy.port}`); | ||
}).catch((err) => { | ||
console.log(`Error connecting to debugger at ${debuggerUrl}`); | ||
console.log(err); | ||
}); | ||
} |
This file contains 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,17 @@ | ||
// Copyright JS Foundation and other contributors, http://js.foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { main } from './cli'; | ||
|
||
main(process); |
This file contains 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,17 @@ | ||
// Copyright JS Foundation and other contributors, http://js.foundation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// TODO: re-export more things here from lib/ that we want to expose as 'API' | ||
|
||
export { ChromeDevToolsProxyServer } from './lib/cdt-proxy'; |
Oops, something went wrong.