Skip to content

Commit afd6204

Browse files
committed
debugger: respect latest trim-paths.json format
Cargo has changed the format from JSONL to plain JSON
1 parent d15086a commit afd6204

2 files changed

Lines changed: 23 additions & 67 deletions

File tree

‎src/etc/gdb_trim_paths.py‎

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# GDB Python script to handle Cargo `<exe>.trim-paths.jsonl` files from the trim-paths feature
1+
# GDB Python script to handle Cargo `<exe>.trim-paths.json` files from the trim-paths feature
22
# - https://github.com/rust-lang/cargo/issues/12137
33
# - https://github.com/rust-lang/rust/issues/111540
44

@@ -9,52 +9,30 @@
99

1010

1111
# https://doc.guix.gnu.org/gdb/16.3/en/html_node/Source-Path.html#index-set-substitute_002dpath
12-
def _process_v1_trim_paths(lines, trim_paths_path):
13-
for idx, line in enumerate(lines[2:], start=3):
14-
try:
15-
entry = json.loads(line)
16-
if "from" in entry and "to" in entry:
17-
cmd = f'set substitute-path "{entry["from"]}" "{entry["to"]}"'
18-
gdb.execute(cmd)
19-
except json.JSONDecodeError:
20-
print(
21-
f"(rust-gdb) warning: invalid JSON on line {idx} of {trim_paths_path}",
22-
file=sys.stderr,
23-
)
12+
def _process_v1_trim_paths(doc):
13+
for entry in doc.get("remaps", []):
14+
if "from" in entry and "to" in entry:
15+
cmd = f'set substitute-path "{entry["from"]}" "{entry["to"]}"'
16+
gdb.execute(cmd)
2417

2518

2619
def _load_trim_paths(filepath):
27-
trim_paths_path = f"{filepath}.trim-paths.jsonl"
20+
trim_paths_path = f"{filepath}.trim-paths.json"
2821

2922
# FIXME: It might be worth looking into the debuginfod fetch content if the local file
3023
# doesn't exists (maybe with `debuginfod-find debuginfo`).
3124
if not os.path.isfile(trim_paths_path):
3225
return
3326

3427
try:
35-
# Load all the lines of the trim-paths file
3628
with open(trim_paths_path, "r", encoding="utf-8") as f:
37-
lines = [line.strip() for line in f]
38-
39-
# Abort if we have less than 3 lines as that means that we cannot have any
40-
# substitutions (header + metadata is already 2 lines)
41-
if not lines or len(lines) < 3:
42-
return
43-
44-
# Try loading the header line, which contains the version (v) field
45-
try:
46-
header = json.loads(lines[0])
47-
ver = header["v"]
48-
except json.JSONDecodeError:
49-
print(
50-
f"(rust-gdb) warning: header line 1 of {trim_paths_path} is not valid JSON",
51-
file=sys.stderr,
52-
)
53-
return
29+
doc = json.load(f)
30+
31+
ver = doc.get("v")
5432

5533
# We only handle version 1
5634
if ver == 1:
57-
_process_v1_trim_paths(lines, trim_paths_path)
35+
_process_v1_trim_paths(doc)
5836
else:
5937
print(
6038
f"(rust-gdb) warning: unsupported trim-paths version {ver}: {trim_paths_path}",

‎src/etc/lldb_trim_paths.py‎

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LLDB Python script to handle Cargo `<exe>.trim-paths.jsonl` files from the trim-paths feature
1+
# LLDB Python script to handle Cargo `<exe>.trim-paths.json` files from the trim-paths feature
22
# - https://github.com/rust-lang/cargo/issues/12137
33
# - https://github.com/rust-lang/rust/issues/111540
44

@@ -9,51 +9,29 @@
99
import threading
1010

1111

12-
def _process_v1_trim_paths(debugger, lines, trim_paths_path):
13-
for idx, line in enumerate(lines[2:], start=3):
14-
try:
15-
entry = json.loads(line)
16-
if "from" in entry and "to" in entry:
17-
# LLDB syntax: settings append target.source-map <from> <to>
18-
cmd = f'settings append target.source-map "{entry["from"]}" "{entry["to"]}"'
19-
debugger.HandleCommand(cmd)
20-
except json.JSONDecodeError:
21-
print(
22-
f"(rust-lldb) warning: invalid JSON on line {idx} of {trim_paths_path}",
23-
file=sys.stderr,
24-
)
12+
def _process_v1_trim_paths(debugger, doc):
13+
for entry in doc.get("remaps", []):
14+
if "from" in entry and "to" in entry:
15+
# LLDB syntax: settings append target.source-map <from> <to>
16+
cmd = f'settings append target.source-map "{entry["from"]}" "{entry["to"]}"'
17+
debugger.HandleCommand(cmd)
2518

2619

2720
def _load_trim_paths(debugger, filepath):
28-
trim_paths_path = f"{filepath}.trim-paths.jsonl"
21+
trim_paths_path = f"{filepath}.trim-paths.json"
2922

3023
if not os.path.isfile(trim_paths_path):
3124
return
3225

3326
try:
34-
# Load all the lines of the trim-paths file
3527
with open(trim_paths_path, "r", encoding="utf-8") as f:
36-
lines = [line.strip() for line in f]
37-
38-
# Abort if we have less than 3 lines as that means that we cannot have any
39-
# substitutions (header + metadata is already 2 lines)
40-
if not lines or len(lines) < 3:
41-
return
42-
43-
# Try loading the header line, which contains the version (v) field
44-
try:
45-
header = json.loads(lines[0])
46-
ver = header.get("v")
47-
except json.JSONDecodeError:
48-
print(
49-
f"(rust-lldb) warning: header line 1 of {trim_paths_path} is not valid JSON",
50-
file=sys.stderr,
51-
)
52-
return
28+
doc = json.load(f)
29+
30+
ver = doc.get("v")
5331

5432
# We only handle version 1
5533
if ver == 1:
56-
_process_v1_trim_paths(debugger, lines, trim_paths_path)
34+
_process_v1_trim_paths(debugger, doc)
5735
else:
5836
print(
5937
f"(rust-lldb) warning: unsupported trim-paths version {ver}: {trim_paths_path}",

0 commit comments

Comments
 (0)