Add nightly-only support for Cargo unremap trim-paths files in rust-gdb - #160560
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
How should we test this? Do you have any manual steps to follow?
There was a problem hiding this comment.
Side note: I am adding tests in rust-lang/rust exercising the unremap file itself.
There was a problem hiding this comment.
I tested it by manually modifying the rust-gdb script to point to my local gdb_trim_paths.py ("$GDB_PYTHON_MODULE_DIRECTORY/gdb_trim_paths.py" to "$YOUR_RUST_LOCAL_CHECKOUT/src/etc/gdb_trim_paths.py"), as otherwise you need to do x.py dist which annoying.
Then I created a dummy hello-world Cargo project, cargo build-it and manually added the hello-world.trim-paths.jsonl file (since the Cargo bump PR is not yet merged).
After that you can just execute rust-gdb as always:
rust-gdb target/debug/hello-world&run- or
rust-gdb&file target/debug/hello-world&run
Tip: show substitute-path shows all the substitutions.
cb80619 to
410b8d8
Compare
|
|
||
|
|
||
| def _load_trim_paths(filepath): | ||
| trim_paths_path = f"{filepath}.trim-paths.jsonl" |
There was a problem hiding this comment.
Not blocking (consider it just a thought out of curiosity) -- should this be looking up in some gdb facility for finding these? E.g., so that you can fetch this from debuginfod servers or look next to the debuginfo on disk rather than the actual binary?
There was a problem hiding this comment.
That's a interesting idea.
I haven't looked it up much, but it seems like debuginfod works with some kind of "BuildID" to retrieve the debuginfo files. gdb automatically reads the "BuildID" and fetches from debuginfod.
What I haven't figure-out is how to access the fetched content, there doesn't seems to be an easy way for that. We could invoke debuginfod-find debuginfo to "force" the fetch and look inside the fetched content, but that seems a bit hacky.
Leaving a comment inside the script to look at it.
|
|
||
| # Try loading the header line, which contains the version (v) field | ||
| try: | ||
| header = json.loads(lines[0]) |
There was a problem hiding this comment.
Not blocking, but it seems a little odd to me to include a version like this as a JSON blob. Maybe we should have magic starting bytes instead? E.g., specifically rust-trim-paths-v1\n?
There was a problem hiding this comment.
I think header follow what Cargo also does for SBOM, @weihanglo you know more I think?
There was a problem hiding this comment.
I guess my feeling is that if we're going to have a versioned header, I'd much rather treat it as a magic byte sequence than a JSON blob. That seems more reliable against future iteration (e.g., allows us to move away from JSON for it).
There was a problem hiding this comment.
Good point, though I think fi we ever change the format, tools should just give up parsing
There was a problem hiding this comment.
Sure, but it's generally noisy and more expensive to attempt to parse JSON than to look for a fixed string. Here it's not terrible, we have Python anyway, but if we were doing this in (say) C then that becomes much more gnarly. Of course, if the actual format is JSON then that's no big deal :)
There was a problem hiding this comment.
Yeah. I meant we can always change the format in a new toolchain version. People anyway need to align with the parsing logic, so it doesn't matter if this version it is JSON and next becomes ad-hoc binary format.
410b8d8 to
9274382
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
9274382 to
6a01cfa
Compare
This comment has been minimized.
This comment has been minimized.
6a01cfa to
9755a34
Compare
|
@bors r+ rollup |
…rk-Simulacrum Add nightly-only support for Cargo unremap trim-paths files in `rust-gdb` This PR adds support in `rust-gdb` for the un-remapping file produced by Cargo with `-Ztrim-paths` (rust-lang/cargo#17303). This support is nightly-only, and only activated when `RUST_GDB_TRIM_PATHS=unstable` is set. An example of the unremap file: ```json {"v":1} {"rust_version":"1.96.0-nightly","workspace_root":"/home/me/app"} {"from":"/cargo/build-dir","to":"/home/me/app/target"} {"from":"/cargo/registry/6f17d22d3f0a95d1","to":"/home/me/.cargo/registry/src/index.crates.io-6f17d22d3f0a95d1"} {"from":"/rustc/abc123","to":"/home/me/.rustup/toolchains/nightly/lib/rustlib/src/rust"} ```
Rollup of 7 pull requests Successful merges: - #160533 (dirfd dir operations (3/4)) - #160675 (bootstrap: Remove `PATH_REMAP` from command-line selector handling ) - #160807 (Update rustc crate rkyv to 0.8.18) - #160560 (Add nightly-only support for Cargo unremap trim-paths files in `rust-gdb`) - #160804 (Change .expect message on net/parser to follow precondition style) - #160805 (`extern "custom"`: add tests) - #160816 (Mark const ptr methods and free functions as inline(always) to match *mut)
Rollup of 11 pull requests Successful merges: - #160675 (bootstrap: Remove `PATH_REMAP` from command-line selector handling ) - #160807 (Update rustc crate rkyv to 0.8.18) - #159690 (Clarify `--remap-path-scope` impact on `rustc` metadata) - #160560 (Add nightly-only support for Cargo unremap trim-paths files in `rust-gdb`) - #160608 (normalization rework: clean up projection_ty_core) - #160785 (Get rid of LLM disclosure checkboxes) - #160804 (Change .expect message on net/parser to follow precondition style) - #160805 (`extern "custom"`: add tests) - #160816 (Mark const ptr methods and free functions as inline(always) to match *mut) - #160820 (Stabilize fs_set_times) - #160826 (Rename parse_delimited_token_tree in cfg_select)
Rollup merge of #160560 - Urgau:trim-paths-gdb-support, r=Mark-Simulacrum Add nightly-only support for Cargo unremap trim-paths files in `rust-gdb` This PR adds support in `rust-gdb` for the un-remapping file produced by Cargo with `-Ztrim-paths` (rust-lang/cargo#17303). This support is nightly-only, and only activated when `RUST_GDB_TRIM_PATHS=unstable` is set. An example of the unremap file: ```json {"v":1} {"rust_version":"1.96.0-nightly","workspace_root":"/home/me/app"} {"from":"/cargo/build-dir","to":"/home/me/app/target"} {"from":"/cargo/registry/6f17d22d3f0a95d1","to":"/home/me/.cargo/registry/src/index.crates.io-6f17d22d3f0a95d1"} {"from":"/rustc/abc123","to":"/home/me/.rustup/toolchains/nightly/lib/rustlib/src/rust"} ```
View all comments
This PR adds support in
rust-gdbfor the un-remapping file produced by Cargo with-Ztrim-paths(rust-lang/cargo#17303). This support is nightly-only, and only activated whenRUST_GDB_TRIM_PATHS=unstableis set.An example of the unremap file:
{"v":1} {"rust_version":"1.96.0-nightly","workspace_root":"/home/me/app"} {"from":"/cargo/build-dir","to":"/home/me/app/target"} {"from":"/cargo/registry/6f17d22d3f0a95d1","to":"/home/me/.cargo/registry/src/index.crates.io-6f17d22d3f0a95d1"} {"from":"/rustc/abc123","to":"/home/me/.rustup/toolchains/nightly/lib/rustlib/src/rust"}Disclaimer: I used Gemini to figure out how to interact with GDB, GDB doc is not very discoverable, everything can be sourced to the docs (links in the source code).
cc @weihanglo