From c51a2988ad04de53eca997bbdeae5991e1535cb4 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 15 Sep 2026 13:19:13 -0400 Subject: [PATCH 1/2] Update cargo submodule --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 7941be6fb416b..495c385d0875c 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 7941be6fb416b4cd9666aef7b858dfea25587a8c +Subproject commit 495c385d0875c4ba51eb72ea0448a2d4c018b8d4 From 5b770b87155a17deb0d44deebfa98428adbec6a9 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 15 Sep 2026 13:34:25 -0400 Subject: [PATCH 2/2] debugger: respect latest trim-paths.json format Cargo has changed the format from JSONL to plain JSON --- src/etc/gdb_trim_paths.py | 44 +++++++++--------------------------- src/etc/lldb_trim_paths.py | 46 ++++++++++---------------------------- 2 files changed, 23 insertions(+), 67 deletions(-) diff --git a/src/etc/gdb_trim_paths.py b/src/etc/gdb_trim_paths.py index 695ef1b19a709..8d16c1e93982a 100644 --- a/src/etc/gdb_trim_paths.py +++ b/src/etc/gdb_trim_paths.py @@ -1,4 +1,4 @@ -# GDB Python script to handle Cargo `.trim-paths.jsonl` files from the trim-paths feature +# GDB Python script to handle Cargo `.trim-paths.json` files from the trim-paths feature # - https://github.com/rust-lang/cargo/issues/12137 # - https://github.com/rust-lang/rust/issues/111540 @@ -9,22 +9,15 @@ # https://doc.guix.gnu.org/gdb/16.3/en/html_node/Source-Path.html#index-set-substitute_002dpath -def _process_v1_trim_paths(lines, trim_paths_path): - for idx, line in enumerate(lines[2:], start=3): - try: - entry = json.loads(line) - if "from" in entry and "to" in entry: - cmd = f'set substitute-path "{entry["from"]}" "{entry["to"]}"' - gdb.execute(cmd) - except json.JSONDecodeError: - print( - f"(rust-gdb) warning: invalid JSON on line {idx} of {trim_paths_path}", - file=sys.stderr, - ) +def _process_v1_trim_paths(doc): + for entry in doc.get("remaps", []): + if "from" in entry and "to" in entry: + cmd = f'set substitute-path "{entry["from"]}" "{entry["to"]}"' + gdb.execute(cmd) def _load_trim_paths(filepath): - trim_paths_path = f"{filepath}.trim-paths.jsonl" + trim_paths_path = f"{filepath}.trim-paths.json" # FIXME: It might be worth looking into the debuginfod fetch content if the local file # doesn't exists (maybe with `debuginfod-find debuginfo`). @@ -32,29 +25,14 @@ def _load_trim_paths(filepath): return try: - # Load all the lines of the trim-paths file with open(trim_paths_path, "r", encoding="utf-8") as f: - lines = [line.strip() for line in f] - - # Abort if we have less than 3 lines as that means that we cannot have any - # substitutions (header + metadata is already 2 lines) - if not lines or len(lines) < 3: - return - - # Try loading the header line, which contains the version (v) field - try: - header = json.loads(lines[0]) - ver = header["v"] - except json.JSONDecodeError: - print( - f"(rust-gdb) warning: header line 1 of {trim_paths_path} is not valid JSON", - file=sys.stderr, - ) - return + doc = json.load(f) + + ver = doc.get("v") # We only handle version 1 if ver == 1: - _process_v1_trim_paths(lines, trim_paths_path) + _process_v1_trim_paths(doc) else: print( f"(rust-gdb) warning: unsupported trim-paths version {ver}: {trim_paths_path}", diff --git a/src/etc/lldb_trim_paths.py b/src/etc/lldb_trim_paths.py index 0084c15ab7dde..4f99aa25edc03 100644 --- a/src/etc/lldb_trim_paths.py +++ b/src/etc/lldb_trim_paths.py @@ -1,4 +1,4 @@ -# LLDB Python script to handle Cargo `.trim-paths.jsonl` files from the trim-paths feature +# LLDB Python script to handle Cargo `.trim-paths.json` files from the trim-paths feature # - https://github.com/rust-lang/cargo/issues/12137 # - https://github.com/rust-lang/rust/issues/111540 @@ -9,51 +9,29 @@ import threading -def _process_v1_trim_paths(debugger, lines, trim_paths_path): - for idx, line in enumerate(lines[2:], start=3): - try: - entry = json.loads(line) - if "from" in entry and "to" in entry: - # LLDB syntax: settings append target.source-map - cmd = f'settings append target.source-map "{entry["from"]}" "{entry["to"]}"' - debugger.HandleCommand(cmd) - except json.JSONDecodeError: - print( - f"(rust-lldb) warning: invalid JSON on line {idx} of {trim_paths_path}", - file=sys.stderr, - ) +def _process_v1_trim_paths(debugger, doc): + for entry in doc.get("remaps", []): + if "from" in entry and "to" in entry: + # LLDB syntax: settings append target.source-map + cmd = f'settings append target.source-map "{entry["from"]}" "{entry["to"]}"' + debugger.HandleCommand(cmd) def _load_trim_paths(debugger, filepath): - trim_paths_path = f"{filepath}.trim-paths.jsonl" + trim_paths_path = f"{filepath}.trim-paths.json" if not os.path.isfile(trim_paths_path): return try: - # Load all the lines of the trim-paths file with open(trim_paths_path, "r", encoding="utf-8") as f: - lines = [line.strip() for line in f] - - # Abort if we have less than 3 lines as that means that we cannot have any - # substitutions (header + metadata is already 2 lines) - if not lines or len(lines) < 3: - return - - # Try loading the header line, which contains the version (v) field - try: - header = json.loads(lines[0]) - ver = header.get("v") - except json.JSONDecodeError: - print( - f"(rust-lldb) warning: header line 1 of {trim_paths_path} is not valid JSON", - file=sys.stderr, - ) - return + doc = json.load(f) + + ver = doc.get("v") # We only handle version 1 if ver == 1: - _process_v1_trim_paths(debugger, lines, trim_paths_path) + _process_v1_trim_paths(debugger, doc) else: print( f"(rust-lldb) warning: unsupported trim-paths version {ver}: {trim_paths_path}",