|
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 |
2 | 2 | # - https://github.com/rust-lang/cargo/issues/12137 |
3 | 3 | # - https://github.com/rust-lang/rust/issues/111540 |
4 | 4 |
|
|
9 | 9 | import threading |
10 | 10 |
|
11 | 11 |
|
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) |
25 | 18 |
|
26 | 19 |
|
27 | 20 | def _load_trim_paths(debugger, filepath): |
28 | | - trim_paths_path = f"{filepath}.trim-paths.jsonl" |
| 21 | + trim_paths_path = f"{filepath}.trim-paths.json" |
29 | 22 |
|
30 | 23 | if not os.path.isfile(trim_paths_path): |
31 | 24 | return |
32 | 25 |
|
33 | 26 | try: |
34 | | - # Load all the lines of the trim-paths file |
35 | 27 | 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") |
53 | 31 |
|
54 | 32 | # We only handle version 1 |
55 | 33 | if ver == 1: |
56 | | - _process_v1_trim_paths(debugger, lines, trim_paths_path) |
| 34 | + _process_v1_trim_paths(debugger, doc) |
57 | 35 | else: |
58 | 36 | print( |
59 | 37 | f"(rust-lldb) warning: unsupported trim-paths version {ver}: {trim_paths_path}", |
|
0 commit comments