| Issue |
238047
|
| Summary |
[lldb] Formatter bytecode: @get_value crashes when parameter has no value of its own (like a struct)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
weinig
|
LLDB crashes when `@get_value` is called on an object that has no value of its own (like a struct).
Consider the following program:
```c++
struct S { int a; };
void stop(void) {}
int main(void) { struct S s = { 1 }; stop(); return s.a; }
// A summary for S, from get-value.asm:
// @get_value call return
// Expected: an empty summary, since a struct has no value.
//
// Generated with llvm-project's assembler:
// python3 lldb/examples/python/formatter_bytecode.py -a -n S -f c -o formatter.inc get-value.asm
__attribute__((used, section("__DATA_CONST,__lldbformatters")))
unsigned char S_formatter[] =
"\x02" // version
"\x09" // remaining record size
"\x01" "S" // type name
"\x00" // flags
"\x00" // sig_summary
"\x04" // program size
"\x23\x20" // @get_value
"\x60" // call
"\x13"; // return
```
(also attached as [main.c](https://github.com/user-attachments/files/34283041/main.c))
If you compile that, `xcrun clang -g main.c -o get-value`, and then run lldb (I was using main@807f9b705b7b4afaa9bac4a4e0fdfcf9addb0d22), `path/to/lldb -b -o 'b stop' -o run -o up -o 'frame variable s' ./get-value` you will see lldb crash:
```
(lldb) frame variable s
LLDB diagnostics will be written to /var/folders/.../diagnostics-1983a3
Please include the directory content when filing a bug report
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash report from ~/Library/Logs/DiagnosticReports/.
Stack dump:
...
8 liblldb.24.0.0git.dylib 0x000000010c7ee9bc lldb_private::FormatterBytecode::Interpret(...) + 27780
10 liblldb.24.0.0git.dylib 0x000000010c80223c lldb_private::BytecodeSummaryFormat::FormatObject(...) + 356
11 liblldb.24.0.0git.dylib 0x000000010c9ce824 lldb_private::ValueObject::GetSummaryAsCString(...) + 440
```
The expected result is:
```
(S) s = {
a = 1
}
```
I had to zip it, but the crashlog is also attached as [lldb-2026-11-02-092427.isp.zip](https://github.com/user-attachments/files/34283372/lldb-2026-11-02-092427.isp.zip). It points to the culprit:
```
0 liblldb.24.0.0git.dylib 0x109e155d8 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:sqn220106]<0>(char const*) + 184
1 liblldb.24.0.0git.dylib 0x10cace9bc lldb_private::FormatterBytecode::Interpret(std::__1::vector<llvm::StringRef, std::__1::allocator<llvm::StringRef>>&, lldb_private::FormatterBytecode::DataStack&, lldb_private::FormatterBytecode::Signatures, unsigned int) + 27780
2 liblldb.24.0.0git.dylib 0x10cae223c lldb_private::BytecodeSummaryFormat::FormatObject(lldb_private::ValueObject*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, lldb_private::TypeSummaryOptions const&) + 356
3 liblldb.24.0.0git.dylib 0x10ccae824 lldb_private::ValueObject::GetSummaryAsCString(lldb_private::TypeSummaryImpl*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, lldb_private::TypeSummaryOptions const&) + 440
4 liblldb.24.0.0git.dylib 0x10ccae658 lldb_private::ValueObject::GetSummaryAsCString(lldb_private::TypeSummaryImpl*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, lldb::LanguageType) + 76
```
Passing nullptr to std::string.
So the fix is probably to do what is done for sel_summary (but without the double calling of the function, which seems like a mistake in sel_summary), something like:
```diff
case sel_get_value: {
TYPE_CHECK(Object);
POP_VALOBJ(valobj);
+ const char *value = valobj->GetValueAsCString();
+ data.Push(value ? std::string(value) : std::string());
- data.Push(std::string(valobj->GetValueAsCString()));
break;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs