From 97b44d777a6417cd4d7b49f3c4aa1585ee916976 Mon Sep 17 00:00:00 2001 From: Anton Burticica Date: Mon, 4 Dec 2023 19:56:27 +0200 Subject: [PATCH] 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. --- src/MICore/LaunchOptions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/MICore/LaunchOptions.cs b/src/MICore/LaunchOptions.cs index 7c102711f..95f1ee049 100644 --- a/src/MICore/LaunchOptions.cs +++ b/src/MICore/LaunchOptions.cs @@ -370,7 +370,7 @@ public static ReadOnlyCollection CreateCollection(Xml.LaunchOpti public static ReadOnlyCollection CreateCollection(Dictionary source) { - IList sourceMaps = new List(source.Keys.Count); + var sourceMaps = new List(source.Keys.Count); foreach (var item in source) { @@ -416,6 +416,11 @@ public static ReadOnlyCollection CreateCollection(Dictionary string.CompareOrdinal(y.CompileTimePath, x.CompileTimePath)); + return new ReadOnlyCollection(sourceMaps); } }