Skip to content

Commit 81d7b95

Browse files
committed
[fix] source.path resolution in workspace
1 parent c47dfb8 commit 81d7b95

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/cc65Debug.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,9 @@ export class Cc65DebugSession extends LoggingDebugSession {
625625
) {
626626
console.log("setBreakPointsRequest", args);
627627

628-
const workspacePath = path.resolve(this._session.workspaceFolder?.uri.fsPath || ".");
628+
const workspacePath = normalizePath(
629+
path.resolve(this._session.workspaceFolder?.uri.fsPath || "."),
630+
);
629631
const { source, breakpoints, lines } = args;
630632

631633
if (!source.path) throw new Error("Source path is required");
@@ -634,7 +636,19 @@ export class Cc65DebugSession extends LoggingDebugSession {
634636
const sourceLines = lines || breakpoints?.map(({ line }) => line) || [];
635637

636638
const sourcePath = normalizePath(source.path);
637-
const sourceBase = path.relative(workspacePath, sourcePath);
639+
const sourceBase = sourcePath.startsWith(path.posix.sep)
640+
? normalizePath(path.relative(workspacePath, sourcePath))
641+
: sourcePath;
642+
643+
if (sourceBase.startsWith("..")) {
644+
return this.sendErrorResponse(response, {
645+
id: ErrorCodes.DAP_ENV_INCORRECT,
646+
format: "File '{sourcePath}' does not belong to workspace '{workspacePath}'",
647+
variables: { sourcePath, workspacePath },
648+
showUser: true,
649+
});
650+
}
651+
638652
const dbgFile = this._debugData?.file.find((file) => {
639653
const filePath = normalizePath(file.name);
640654
return filePath.endsWith(`${path.posix.sep}${sourceBase}`);
@@ -649,7 +663,7 @@ export class Cc65DebugSession extends LoggingDebugSession {
649663
source,
650664
line,
651665
reason: "failed",
652-
message: `Source file '${sourceBase}' is missing in debug info file`,
666+
message: `Source file '${source.path}' is missing in debug info file`,
653667
}));
654668
return this.sendResponse(response);
655669
}

0 commit comments

Comments
 (0)