Skip to content

Support file hashes in .debug_line #972

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

Merged
merged 8 commits into from
Apr 21, 2020
Merged

Conversation

l4l
Copy link
Contributor

@l4l l4l commented Apr 18, 2020

resolves #936

});

line_program.file_has_timestamp = true;
line_program.file_has_md5 = md5.is_some();
Copy link
Member

Choose a reason for hiding this comment

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

It may be possible for files coming from different crates (due to for example macros) to have different hash algorithms. Does always setting this to true work? Or will gdb or lldb think an MD5 of 0 means that the file should actually hash to 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems that true here means zeroed md5 considered as a hash.

What exactly do you mean for "files coming from different crates"? I think SourceFile should have some info about its crate, so even same files from different crates are added separately here, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

I think if one crate uses no hash and it is imported in another crate using md5 as hash, that the files from the imported crate will still get no hash, while the files of the other crate will get an md5 hash.

Copy link
Member

Choose a reason for hiding this comment

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

If you pass None for file_info to add_file, gimli will write a FileInfo with md5 set to 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are these cases, when that hash is not available? I'm not sure that can even possible

Copy link
Member

Choose a reason for hiding this comment

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

You can switch to an SHA-1 hash using -Zsrc-hash-algorithm=sha1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quiet weird scenario, if I understood correctly. So the complete case is:

  • compile crate Y with defaults;
  • compile crate X (whose depends on Y) with sha1 src-hash;

Now if include both crates there will be 2 X-es, but only one with a debug file hashes, right?

Copy link
Member

Choose a reason for hiding this comment

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

I was referring to:

// foo/lib.rs (compile with defaults)
pub fn foo_fn<T>() {}

// bar/lib.rs (compile with sha1 src-hash)
pub fn call_foo_fn() {
    foo_fn::<()>();
}

In crate bar, the debuginfo for foo_fn::<()> will refer to foo/lib.rs with md5 hash, while the debuginfo of call_foo_fn will refer to bar/lib.rs with sha1 hash.

Copy link
Contributor

@philipc philipc Apr 19, 2020

Choose a reason for hiding this comment

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

If you pass None for file_info to add_file, gimli will write a FileInfo with md5 set to 0.

That seems like a bug in gimli. LLVM only emits the MD5 field if all files have MD5 info. DWARF does not support only having MD5 fields for some of the files.

@bjorn3
Copy link
Member

bjorn3 commented Apr 21, 2020

Thanks for the PR! Unfortunately I just noticed that my gdb and lldb don't yet support DWARF version 5. I have switched this PR to version 4 for now, which means that no md5 hash is currently emitted. Once my gdb and lldb support it, I will switch back to DWARF version 5. I will merge this PR anyway, as it does almost all of the work necessary to support md5 checksums.

@bjorn3 bjorn3 merged commit 5a6d9e1 into rust-lang:master Apr 21, 2020
@l4l l4l deleted the debug-file-hash branch April 21, 2020 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add file hash to .debug_line
3 participants