apple / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. This fork is used to manage Apple’s stable releases of Clang as well as support the Swift project.
https://llvm.org
Other
1.1k stars 320 forks source link

Produce a summary for non-decodable strings. #8811

Closed adrian-prantl closed 1 month ago

adrian-prantl commented 1 month ago

Currently when LLDB encounters an uninitialized string the summary formatter will fail and the user sees something like:

(String) s = {
  _guts = {
    _object = (_countAndFlagsBits = 18374403900871474942, _object = 0xfefefefefefefefe)
  }
}

with this patch this becomes

(String) s = <could not decode string: unexpected discriminator>
adrian-prantl commented 1 month ago

@swift-ci test

kastiglione commented 1 month ago

Proposed test case:

var coin: String
if Bool.random() {
    coin = "heads"
} else {
    coin = "tails"
}

When I print the string before it's assigned, the output is:

(lldb) p coin
(String) coin = {
  _guts = {
    _object = (_countAndFlagsBits = 0, _object = 0x0000000000000000)
  }
}

Does this patch address this case? If so what is the error message displayed? I wonder if the error should state "unassigned"/"uninitialized" or something else?

adrian-prantl commented 1 month ago

Does this patch address this case? If so what is the error message displayed? I wonder if the error should state "unassigned"/"uninitialized" or something else?

The summary (one one machine I tried this on) is

<cannot decode string: memory read failed for 0x18>

but keep in mind that the exact error is going to be random, because we're reading from uninitialized memory.

adrian-prantl commented 1 month ago

The reason I don't want to say "unassigned" or "uninitialized" is because the summary formatter really doesn't know that. I have encountered this most often in situations where a field's offset was miscomputed (probably biased because I've been debugging these scenarios a lot) and in such a case, "uninitialized" is just wrong.

adrian-prantl commented 1 month ago

However, I could add a special case for an all-zero string?

adrian-prantl commented 1 month ago

Done. Your example has a good chance of printing as <uninitialized> now, depending on whether or not the compiler zeros out the memory first.

adrian-prantl commented 1 month ago

@swift-ci test

adrian-prantl commented 1 month ago

I agree about eventually adding error handling to the summaries. If these actually were errors, then an IDE could e.g., mark them up graphically different.

adrian-prantl commented 1 month ago

@swift-ci test windows