Skip to content

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

Closed
@nanguye2496

Description

@nanguye2496

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions