Skip to content

Commit 97b44d7

Browse files
authored
Reverse sort sourceMap (#1428)
Do reverse sort of the `sourceMap`. In my `launch.json` configuration I have the following `sourceFileMap`: ``` "sourceFileMap": { "/usr/src/debug/my-project/git-r0/build/src/../../git": "${workspaceFolder}", "/usr/src/debug": { "editorPath": "${config:YOCTO_ARCH}", "useForBreakpoints": false } }, ``` The YOCTO_ARCH set in `settings.json` to: ``` "terminal.integrated.env.linux": { "YOCTO_ARCH": "/home/mouse/linux-bsp/linux-devel-build/build/work/cortexa7t2hf-neon-vfpv4_linux-linux-gnueabi" }, ``` This PR addresses an issue encountered while debugging a binary that's running on a remote system and built using Yocto. Currently, when debugging, the source files are being referenced from the Yocto build tree instead of the local workspace. This issue prevents setting breakpoints effectively in the local workspace source files. To resolve this, the change involves modifying the way source mappings are processed. Specifically, it proposes sorting the mappings in reverse order, starting with the longer, more specific paths and moving towards the more general ones. By doing this, the debugger will first consider the project-specific paths defined in `sourceFileMap`. If it doesn't find a match there, it will then fall back to the more general paths. This reverse sorting ensures that the local workspace sources are prioritized over the Yocto build tree sources, allowing for effective breakpoint setting and debugging in the local workspace.
1 parent 9f35772 commit 97b44d7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/MICore/LaunchOptions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public static ReadOnlyCollection<SourceMapEntry> CreateCollection(Xml.LaunchOpti
370370

371371
public static ReadOnlyCollection<SourceMapEntry> CreateCollection(Dictionary<string, object> source)
372372
{
373-
IList<SourceMapEntry> sourceMaps = new List<SourceMapEntry>(source.Keys.Count);
373+
var sourceMaps = new List<SourceMapEntry>(source.Keys.Count);
374374

375375
foreach (var item in source)
376376
{
@@ -416,6 +416,11 @@ public static ReadOnlyCollection<SourceMapEntry> CreateCollection(Dictionary<str
416416
throw new InvalidLaunchOptionsException(String.Format(CultureInfo.CurrentCulture, MICoreResources.Error_SourceFileMapInvalidEditorPath));
417417
}
418418
}
419+
420+
// Ensure the map is sorted such that more specific directories are in front of less specific by sorting the map
421+
// in descending order of the compile time path
422+
sourceMaps.Sort((x, y) => string.CompareOrdinal(y.CompileTimePath, x.CompileTimePath));
423+
419424
return new ReadOnlyCollection<SourceMapEntry>(sourceMaps);
420425
}
421426
}

0 commit comments

Comments
 (0)