Skip to content
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

Incorrect debug information leading to bad visualzization for &str and slice arguments in MSVC debuggers. #81894

Closed
nanguye2496 opened this issue Feb 8, 2021 · 2 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nanguye2496
Copy link

nanguye2496 commented Feb 8, 2021

(Fix for this problem: #81898)

When lowering MIR to LLVM IR, the compiler decomposes every function argument of type &str or slice into two components: a pointer to the memory address referenced to by the &str or slice and an integer represent the length of the str or slice. Then, the original argument is constructed in the body of the function from the data pointer and the integer arguments. Since the original argument is declared in the body of the function that owns it, it should be marked as a LocalVariable instead of an ArgumentVariable. This confusion makes MSVC debuggers unable to visualize &str and slice arguments correctly. Because these debuggers implicit treat arguments whose sizes are greater than that of a pointer as pass by reference, the values of &str or slice arguments are treated as their reference, leading to incorrect visualization for &str and slice arguments.

I tried this code:

#[inline(never)]
pub fn nam_foo_function(first_var: &str) -> usize {
    first_var.len()
}

fn main() {
    s = "hello";
    nam_foo_function(&s[1..3]);
}

When stepping through the code in VS Code C++ debugger, I expected to see this happen:
image

Instead, this happened:
image

Meta

This error is found on rust 1.51.0-dev, 1.50, and 1.49.

@nanguye2496 nanguye2496 added the C-bug Category: This is a bug. label Feb 8, 2021
@jonas-schievink jonas-schievink added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 8, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 17, 2021
…_slice_visualization, r=varkor

Fix debug information for function arguments of type &str or slice.

Issue details:
When lowering MIR to LLVM IR, the compiler decomposes every &str and slice argument into a data pointer and a usize. Then, the original argument is reconstructed from the pointer and the usize arguments in the body of the function that owns it. Since the original argument is declared in the body of a function, it should be marked as a LocalVariable instead of an ArgumentVairable. This confusion causes MSVC debuggers unable to visualize &str and slice arguments correctly. (See rust-lang#81894 for more details).

Fix details:
Making sure that the debug variable for every &str and slice argument is marked as LocalVariable instead of ArgumentVariable in computing_per_local_var_debug_info. This change has been verified on VS Code debugger, VS debugger, WinDbg and LLDB.
@rylev
Copy link
Member

rylev commented Feb 26, 2021

@nanguye2496 Can this be closed now that #81898 has been merged?

@nanguye2496
Copy link
Author

Fix #81898 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants