Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 8309839

Browse files
fix: breakpoints work on windows (#815)
On Windows, on Node 11+, the URL provided to the inspector API must start with file:/// instead of file:// and all backslashes must be converted to forward slashes. Otherwise, on Node 10 on windows, the URL must not start with file:// and must contain backslashes. Fixes: #795
1 parent d5a17b2 commit 8309839

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

.kokoro/test.bat

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agent/state/inspector-state.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ const GETTER_MESSAGE_INDEX = 2;
3333
const ARG_LOCAL_LIMIT_MESSAGE_INDEX = 3;
3434

3535
const FILE_PROTOCOL = 'file://';
36+
// on windows on Node 11+ the file protocol needs to have three slashes
37+
const WINDOWS_FILE_PROTOCOL = 'file:///';
38+
39+
// Used to match paths like file:///C:/... on windows
40+
// but do not match paths like file:///home/... on linux
41+
const WINDOWS_URL_REGEX = RegExp(`^${WINDOWS_FILE_PROTOCOL}[a-zA-Z]+:`);
3642

3743
const STABLE_OBJECT_ID_PROPERTY = '[[StableObjectId]]';
3844
const NO_STABLE_OBJECT_ID = -1;
@@ -316,7 +322,13 @@ class StateResolver {
316322
const scriptUrl = this.scriptmapper[scriptId].url;
317323
// In Node 11+, non-internal files are formatted as URLs, so get just the
318324
// path.
319-
return StateResolver.stripFileProtocol_(scriptUrl);
325+
const strippedUrl = StateResolver.stripFileProtocol_(scriptUrl);
326+
if (process.platform === 'win32') {
327+
// on windows the script url provided to v8 uses forward slashes
328+
// convert them back to backslashes
329+
return strippedUrl.replace(/\//g, '\\');
330+
}
331+
return strippedUrl;
320332
}
321333

322334
resolveRelativePath_(frame: inspector.Debugger.CallFrame): string {
@@ -325,9 +337,16 @@ class StateResolver {
325337
}
326338

327339
static stripFileProtocol_(path: string) {
328-
return path.toLowerCase().startsWith(FILE_PROTOCOL)
329-
? path.substr(FILE_PROTOCOL.length)
330-
: path;
340+
const lowerPath = path.toLowerCase();
341+
if (WINDOWS_URL_REGEX.test(lowerPath)) {
342+
return path.substr(WINDOWS_FILE_PROTOCOL.length);
343+
}
344+
345+
if (lowerPath.startsWith(FILE_PROTOCOL)) {
346+
return path.substr(FILE_PROTOCOL.length);
347+
}
348+
349+
return path;
331350
}
332351

333352
stripCurrentWorkingDirectory_(path: string): string {

src/agent/v8/inspector-debugapi.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,15 @@ export class InspectorDebugApi implements debugapi.DebugApi {
489489
let v8BreakpointId; // v8/inspector breakpoint id
490490
if (!this.locationMapper[locationStr]) {
491491
// The first time when a breakpoint was set to this location.
492-
const url = this.inspectorOptions.useWellFormattedUrl
492+
const rawUrl = this.inspectorOptions.useWellFormattedUrl
493493
? `file://${matchingScript}`
494494
: matchingScript;
495+
// on windows on Node 11+, the url must start with file:///
496+
// (notice 3 slashes) and have all backslashes converted into forward slashes
497+
const url =
498+
process.platform === 'win32' && utils.satisfies(process.version, '>=11')
499+
? rawUrl.replace(/^file:\/\//, 'file:///').replace(/\\/g, '/')
500+
: rawUrl;
495501
const res = this.v8Inspector.setBreakpointByUrl({
496502
lineNumber: line - 1,
497503
url,

synth.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
logging.basicConfig(level=logging.DEBUG)
2121
common_templates = gcp.CommonTemplates()
2222
templates = common_templates.node_library()
23-
# stop excluding '.kokoro/test.bat' as soon as we figure out why Node 10 tests
24-
# have issues on Windows (see #686).
25-
s.copy(templates, excludes=[
26-
'.kokoro/test.bat'
27-
])
23+
s.copy(templates)
2824

2925
subprocess.run(['npm', 'install'])
3026
subprocess.run(['npm', 'run', 'fix'])

0 commit comments

Comments
 (0)