-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paths to source files for inlined items from extern crates not absolute in debuginfo #34179
Comments
Some relevant links from our discussion:
So I think if we persisted the absolute path in the |
@luser I would just store both the short path and the absolute one. |
The origin for this file name is actually on the bots which are producing the relevant nightlies. That is, the crux is an invocation on the nightly bots that looks like: rustc ../src/libcore/lib.rs --out-dir path/to/out/dir I think that means that we basically plumb through the relative path all the way down to the monomorphizations themselves, so any monomorphization of @luser if we were to store an absolute path it'd look something like:
Would that be ok? I guess gecko would automatically map these paths? It may not be an adequate long-term solution, however, to store absolute paths in the metadata (unless there's a separate space we can store them) because we'll want to support installing the standard library source code and having debuginfo hooked up to what's installed locally. I'm not actually sure how that would work as I doubt it would involve rewriting the metadata. (cc @brson on this point) |
@alexcrichton Having the absolute paths like that would be something we could work with, certainly. It's comparable to what we get for e.g. C functions inlined from libc. For example, on Windows we get paths like Having the debuginfo hooked up to the matching source sounds pretty great long-term, whatever form that'd take. Presumably that'd somehow involve also persisting information about the source the crate was built from, which is the direction I was going at the end of my initial comment. I'd love to be able to map source paths from lib{std,core} to links to the proper source revision on github without having to maintain a separate mapping of hardcoded paths from your builders. :) |
Ok cool, I do think it'd be super slick if we had enough info hook the standard library and all dependencies up as well! For now though the standard library source links could be reconstructed at least through:
So in that sense I think as long as you can identify and parse what source paths are standard library sources it should be pretty good to go, right? Unfortunately that identification will vary across platforms but I wonder if we could somehow annotate the source in the DWARF info as specifically coming from the standard library or something like that (as that would even work for debuggers perhaps!). @michaelwoerister is our local debuginfo guru, so I'll see what he has to say as well! |
I'm not a super DWARF expert (and things are different on Windows), but I'm not aware of any way to annotate the original source location beyond pathnames. This is what I meant by "we'd be inventing things there". DWARF is extremely flexible, however, so we could certainly invent attributes and use them. (We'd have to plumb this through LLVM, I suppose.) I'm not sure what we'd do on Windows. PDB files do allow arbitrary data streams, and Microsoft has long supported something in this space with their "source server indexing". You can put a specially-formatted stream into a PDB file that maps source filenames to a way to retrieve them from VCS. We use this in Firefox to map source files to URLs to hg.mozilla.org, so when you debug a Firefox Nighly/Release on Windows the debugger can fetch the matching source automatically: https://developer.mozilla.org/en-US/docs/Mozilla/Using_the_Mozilla_source_server |
The bug on "get the rustc commit hash" is https://bugzilla.mozilla.org/show_bug.cgi?id=1275424. |
Something like this information is usually found in the
The path given in As an intermediate fix, it should not be much of a problem to always store absolute paths for functions inlined from external crates. |
I've got a WIP patch. |
Resummarizing, given the comments here I think this is only an issue for inlined items or monomorphisms? (Most Rust code will likely have a lot of monomorphisms from libstd, though.) |
Yes, I think that's true. From the compiler's point of view, both cases are handled the same.
Yes, it's definitely not a niche problem. I'm wondering though if this could not be solved by setting up GDB's source path in just the right way (e.g. adding |
I encountered this problem in the context of linking Rust code into Gecko. We parse the debug symbols from the binaries we generate to convert them to a format we use for processing crash reports. Since the filenames for these DIEs are relative, we handle them as relative to the comp_dir of the CU they're linked into, so we get bogus paths. So FWIW, the closest analogue here in C is probably just inlined functions, and if I compile this tiny example: The DWARF for the inlined function looks like:
|
And if your tool would use a similar strategy as GDB if it encountered a relative path? That is, if |
Well, that requires making the tool reading the DWARF smarter than it currently is. Right now it just takes the decl_file, joins it to the comp_dir, and hands that back. Also we're not likely to actually have the libstd sources installed when processing the debug info. We do post-processing with a Python script, and my thought was to have a mapping of known Rust source dirs (which isn't great, but is workable). |
Thinking more about the absolute paths approach, I'm a little concerned that we might break people's GDB setups. Right now they can get GDB to find the sources for libstd if they are using the |
Oh, nevermind my last comment: there is |
@michaelwoerister Could |
@eddyb Yes, that's what I was thinking of. |
Add an abs_path member to FileMap, use it when writing debug info. Fixes #34179. When items are inlined from extern crates, the filename in the debug info is taken from the FileMap that's serialized in the rlib metadata. Currently this is just FileMap.name, which is whatever path is passed to rustc. Since libcore and libstd are built by invoking rustc with relative paths, they wind up with relative paths in the rlib, and when linked into a binary the debug info uses relative paths for the names, but since the compilation directory for the final binary, tools trying to read source filenames will wind up with bad paths. We noticed this in Firefox with source filenames from libcore/libstd having bad paths. This change stores an absolute path in FileMap.abs_path, and uses that if available for writing debug info. This is not going to magically make debuggers able to find the source, but it will at least provide sensible paths.
@eddyb and I have been poking at this on IRC for a little bit. For code that's linked in from an extern crate, the source file paths that wind up in the debug info have relative paths, like:
For the debug symbols that we generate from Firefox binaries, we wind up interpreting these relative to the compilation dir of the rust crate we're compiling that imports them, so the paths wind up completely wrong, like
/build/debug-mozilla-central/media/libstagefright/../src/libcore/option.rs
(actual output from my local Firefox build).If there were absolute paths, they'd be persisted all the way through, and then we could do something useful with them.
Longer-term it'd be great if we also persisted info about what source repository and revision they were built from, or something like that, but we'd be inventing things there, since there's no analogue in existing DWARF produced by C compilers, AFAIK.
/cc @rillian
The text was updated successfully, but these errors were encountered: