Skip to content

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

Open
Urgau wants to merge 1 commit into
rust-lang:mainfrom
Urgau:trim-paths-gdb-support
Open

Add nightly-only support for Cargo unremap trim-paths files in rust-gdb#160560
Urgau wants to merge 1 commit into
rust-lang:mainfrom
Urgau:trim-paths-gdb-support

Conversation

@Urgau

@Urgau Urgau commented Aug 5, 2026

Copy link
Copy Markdown
Member

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 2 times, most recently from 813cc60 to cb80619 Compare August 5, 2026 12:22
@Urgau
Urgau force-pushed the trim-paths-gdb-support branch from cb80619 to 410b8d8 Compare August 5, 2026 12:44
Comment thread src/etc/gdb_trim_paths.py

# We only handle version 1
if ver == 1:
_process_v1_trim_paths(lines, trim_paths_path)

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

Should we print a warning for unrecognized version?

View changes since the review

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 don't know, I added one at first, but I don't want users to have one (or more) warnings about unsupported versions, which can happen when Cargo update the version, in particular since this logic is been handled automatically.

There isn't a way to suppress the warning at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants