Skip to content

Commit bbdaa7d

Browse files
committed
Add relative path support to SSH source file mapping.
The SSH source file mapping now utilizes the CWD of the remote machine to determine the path kind that is being used when the supplied path mapping is a relative path. This assumes that the CWD is an absolute path (which it should be) and is used as a backup when the path in the map cannot be determined to be an absolute path. Fixes WebFreak001#381.
1 parent f37ffb2 commit bbdaa7d

File tree

4 files changed

+217
-25
lines changed

4 files changed

+217
-25
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# [Unreleased]
22
## Fixed
3+
* Fixes #381 - POSIX relative paths in SSH `sourceFileMap` were not properly formatted (@brownts)
34
* Fixes #348 - Not waiting for `autorun` commands to complete before continuing execution (@brownts).
45
* Fixes #382 - Breakpoints not always cleared over SSH - PR #383 (@abussy-aldebaran)
56
* Fixes #346 - Case-sensitivity not respected in SSH path mapping - PR #352 (@brownts)

Diff for: src/mibase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ export class MI2DebugSession extends DebugSession {
734734
if (configMap === undefined) {
735735
this.sourceFileMap = new SourceFileMap({[fallbackGDB]: fallbackIDE});
736736
} else {
737-
this.sourceFileMap = new SourceFileMap(configMap);
737+
this.sourceFileMap = new SourceFileMap(configMap, fallbackGDB);
738738
}
739739
}
740740

Diff for: src/source_file_map.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ interface Mapping {
88
export class SourceFileMap {
99
private sortedMappings: { [key in keyof Mapping]: Mapping[] } = {remote: [], local: []};
1010
private nativePath: PathKind;
11+
private remoteCwd: string|undefined;
1112

12-
constructor (map: { [index: string]: string }) {
13+
constructor (map: { [index: string]: string }, remoteCwd?: string) {
1314
const mappings: Mapping[] = [];
15+
this.remoteCwd = remoteCwd;
1416
this.nativePath = this.getNativePath();
1517
for (let [remotePrefix, localPrefix] of Object.entries(map)) {
1618
// Normalize local path, adding trailing separator if missing.
1719
localPrefix = this.nativePath.normalizeDir(localPrefix);
1820

1921
// Try to detect remote path.
20-
const debuggerPath: PathKind = SourceFileMap.toPathKind(remotePrefix);
22+
const debuggerPath: PathKind = this.toPathKind(remotePrefix);
2123
// Normalize remote path, adding trailing separator if missing.
2224
remotePrefix = debuggerPath.normalizeDir(remotePrefix);
2325

@@ -42,10 +44,17 @@ export class SourceFileMap {
4244
return PathPosix.getInstance();
4345
}
4446

45-
private static toPathKind(unknownPath: string): PathKind {
47+
private toPathKind(unknownPath: string): PathKind {
4648
const pathPosix: PathKind = PathPosix.getInstance();
4749
const pathWin32: PathKind = PathWin32.getInstance();
48-
return pathPosix.isAbsolute(unknownPath) ? pathPosix : pathWin32;
50+
51+
if (pathPosix.isAbsolute(unknownPath) ||
52+
(this.remoteCwd && pathPosix.isAbsolute(this.remoteCwd)))
53+
{
54+
return pathPosix;
55+
} else {
56+
return pathWin32;
57+
}
4958
}
5059

5160
private pathMatch(key: keyof Mapping, caseSensitive: boolean, path: string): Mapping | undefined {
@@ -66,7 +75,7 @@ export class SourceFileMap {
6675

6776
public toLocalPath(remotePath: string): string {
6877
// Try to detect remote path.
69-
const debuggerPath: PathKind = SourceFileMap.toPathKind(remotePath);
78+
const debuggerPath: PathKind = this.toPathKind(remotePath);
7079
const normalizedRemotePath: string = debuggerPath.normalize(remotePath);
7180
const mapping: Mapping | undefined =
7281
this.pathMatch("remote", debuggerPath.caseSensitive, normalizedRemotePath);
@@ -88,7 +97,7 @@ export class SourceFileMap {
8897
if (mapping) {
8998
const pathSuffix = normalizedLocalPath.substring(mapping.local.length);
9099
// Try to detect remote path.
91-
const debuggerPath = SourceFileMap.toPathKind(mapping.remote);
100+
const debuggerPath = this.toPathKind(mapping.remote);
92101
return debuggerPath.join(mapping.remote, pathSuffix);
93102
}
94103

0 commit comments

Comments
 (0)