Skip to content

Add nightly-only support for Cargo unremap trim-paths files in rust-gdb - #160560

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Urgau:trim-paths-gdb-support
Aug 10, 2026
Merged

Add nightly-only support for Cargo unremap trim-paths files in rust-gdb#160560
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Urgau:trim-paths-gdb-support

Conversation

@Urgau

@Urgau Urgau commented Aug 5, 2026

Copy link
Copy Markdown
Member

View all comments

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:

{"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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 5, 2026
@rustbot

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Mark-Simulacrum

Comment thread src/etc/gdb_trim_paths.py

@weihanglo weihanglo Aug 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we test this? Do you have any manual steps to follow?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I am adding tests in rust-lang/rust exercising the unremap file itself.

@Urgau Urgau Aug 5, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. rust-gdb target/debug/hello-world & run
  2. or rust-gdb & file target/debug/hello-world & run

Tip: show substitute-path shows all the substitutions.

@Urgau
Urgau force-pushed the trim-paths-gdb-support branch 3 times, most recently from cb80619 to 410b8d8 Compare August 5, 2026 12:44
Comment thread src/etc/gdb_trim_paths.py

@Mark-Simulacrum Mark-Simulacrum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only semi-blocking bits are the shellcheck + linking a tracking issue.

View changes since this review

Comment thread src/etc/gdb_trim_paths.py
Comment thread src/etc/gdb_trim_paths.py Outdated
Comment thread src/etc/gdb_trim_paths.py


def _load_trim_paths(filepath):
trim_paths_path = f"{filepath}.trim-paths.jsonl"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/etc/gdb_trim_paths.py Outdated
Comment thread src/etc/gdb_trim_paths.py

# Try loading the header line, which contains the version (v) field
try:
header = json.loads(lines[0])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think header follow what Cargo also does for SBOM, @weihanglo you know more I think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, though I think fi we ever change the format, tools should just give up parsing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

@weihanglo weihanglo Aug 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/etc/gdb_trim_paths.py
Comment thread src/etc/rust-gdb Outdated
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2026
@Urgau
Urgau force-pushed the trim-paths-gdb-support branch from 410b8d8 to 9274382 Compare August 9, 2026 09:52
@rustbot

rustbot commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

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.

@Urgau Urgau added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 9, 2026
@rust-log-analyzer

This comment has been minimized.

@Urgau
Urgau force-pushed the trim-paths-gdb-support branch from 9274382 to 6a01cfa Compare August 9, 2026 10:05
@rust-log-analyzer

This comment has been minimized.

@Urgau
Urgau force-pushed the trim-paths-gdb-support branch from 6a01cfa to 9755a34 Compare August 9, 2026 10:22
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9755a34 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 9, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 9, 2026
…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"}
```
rust-bors Bot pushed a commit that referenced this pull request Aug 10, 2026
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)
rust-bors Bot pushed a commit that referenced this pull request Aug 10, 2026
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)
@rust-bors
rust-bors Bot merged commit 7e7fc6f into rust-lang:main Aug 10, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 10, 2026
rust-timer added a commit that referenced this pull request Aug 10, 2026
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"}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants