rust-lang / rust-lang/rust

rust-lldb: Incorrectly display Option::None as Option::Some

Open
#152,743 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-debuggers-lldb C-bug S-needs-repro
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I am developing a kernel, and when I tried debugging with rust-lldb, I found this:

pm1b = Some({gas:{address_space:SystemMemory, bit_width:'\x99', bit_offset:'\0', access_size:'\0', address:234201088}, handler:(), mapping:Some({physical_start:18446603338569718192, virtual_start:{pointer:"APIC\x99"}, region_length:18446603338569718160, mapped_length:18446603336455397376, handler:()})}) {
    0 = {
      gas = {
        address_space = SystemMemory
        bit_width = '\x99'
        bit_offset = '\0'
        access_size = '\0'
        address = 234201088
      }
      handler =
      mapping = Some({physical_start:18446603338569718192, virtual_start:{pointer:"APIC\x99"}, region_length:18446603338569718160, mapped_length:18446603336455397376, handler:()}) {
        0 = {
          physical_start = 18446603338569718192
          virtual_start = {
            pointer = 0xffff80000df5a000 "APIC\x99"
          }
          region_length = 18446603338569718160
          mapped_length = 18446603336455397376
          handler =
        }
      }
    }
  }

While I unwrapped pm1b with the following code:

let pm1 = &registers.pm1_control_registers;
log::debug!("pm1: {:?}", pm1.pm1b.is_some());
loop {
    let pm1b = pm1.pm1b.as_ref();
    pm1b.unwrap().write((slp_typa | (1 << 13)) as u64).unwrap();
}

And there's the output.

[DEBUG] pm1: false, kernel_hal/src/platform/bare/acpi/power.rs:20
[ERROR] Panic: panicked at kernel_hal/src/platform/bare/acpi/power.rs:23:14:
called `Option::unwrap()` on a `None` value

What made me sure that this is a bug of rust-lldb is the length of the region, which is too large to be valid.
And I am using 1.95.0-nightly (ce69df6f7 2026-02-12) toolchain, while the version of lldb is 21.1.8 from nixpkgs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with rust-lldb 21.1.8 and the nightly toolchain, using the Option value and code in kernel_hal/src/platform/bare/acpi/power.rs around lines 20 and 23. Compare the debugger's displayed value with the logged is_some() result and unwrap panic; done means the cause is identified and the debugger no longer presents None as Some.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.