<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143710>143710</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLDB] Language categories can't be disabled until a value was formatted
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Nerixyz
</td>
</tr>
</table>
<pre>
(I feel like I mentioned this somewhere, but I can't find where)
Currently, all language categories are always [enabled by default](https://github.com/llvm/llvm-project/blob/775ad3e49c83407b79dd5ad533204884cb8b23ce/lldb/source/DataFormatters/LanguageCategory.cpp#L30) and the language categories are created on demand (in [`FormatManager::GetCategoryForLanguage`](https://github.com/llvm/llvm-project/blob/775ad3e49c83407b79dd5ad533204884cb8b23ce/lldb/source/DataFormatters/FormatManager.cpp#L601)). This makes it impossible to disable a language category upfront (e.g. in a `.lldbinit`). The following demonstrates this with the C++ language:
**test.cpp**:
```cpp
namespace std {
template <typename T> struct optional {
T foo;
};
}
int main() {
std::optional<int> test{42};
return 0; // break here
}
```
```console
> clang -g test.cpp
> lldb.exe ./a.exe -o "type category disable cplusplus" -o "b test.cpp:9" -o r -o "p test" -o "type category disable cplusplus" -o "p test"
(lldb) target create "a.exe"
Current executable set to 'F:\Dev\cpp-test\testing\a.exe' (x86_64).
(lldb) type category disable cplusplus
(lldb) b test.cpp:9
Breakpoint 1: where = a.exe`main + 18 at test.cpp:9, address = 0x0000000140007262
(lldb) r
Process 23684 launched: 'F:\Dev\cpp-test\testing\a.exe' (x86_64)
Process 23684 stopped
* thread #1, stop reason = breakpoint 1.1
frame #0: 0x00007ff6b12d7262 a.exe`main at test.cpp:9
6
7 int main() {
8 std::optional<int> test{42};
-> 9 return 0;
10 }
(lldb) p test
(std::optional<int>) Has Value=false {}
(lldb) type category disable cplusplus
(lldb) p test
(std::optional<int>) (foo = 42)
```
**Expected**: Both `p test` should print the same (`(std::optional<int>) (foo = 42)`).
**Current**: The first time, the libstdc++ formatter is used to format the value even though we disabled the category.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVkuP4zYS_jX0pdAGRerlgw9-jHcH6F3sYbDXgJJKNjM0KZBUdzu_PihK6ocng6SRSwwbsshiPb76qlgqBH22iFtW7FlxXKkxXpzf_he9frn9tmpcd9syUX-FHtGA0d8RvsIVbdTOYgfxogMEd8XnC3pk4gDNGOErtMoyUUXote1g3tswvmN8dxi9RxvNjaSVMWCUPY_qjNCqiGfnNQZQHkGZZ3ULwIo9WtUY7KC5QYe9Gk1kxZGJ-hLjEJjcMXFi4nTW8TI269ZdmTgZ87Q8HgbvfsU2MnFqjGuYOFVVoTqJ-aatZc6rptp0XaG6QkrB87rO26ZuhGwxKejoRHCjT-9HFdXJ-auKEX1g4vQ4e3-YnL-t22FgQj5KzsQGlCWM8Kcxth5VxA6chQ6vJM1ErS0FzUo-GfqPsuqMnuKUu39hXCydnF-Ms5L_cxD54PUCR8kzYoDYrOEbceaqvmMAHUFfBxeCbgxCdNDpQKkG9QNiNxiH3jsbCSFcn9egLShgJV-TR9rqSChMBhB6Z4x71vZMuDobolcRw8TXZx0vKSsHJvZM7F9tEXCJo0zQN2KIk_9pYdos-fSldb6z6ophUC1CiB2was_4LuJ1MCoiMHmItwFJBr4x-QVC9GMbwQ1UPcrM8gDfoHeOSXph1fHtT_JF2whXpS0TNTFqORNiNzFi0cbkQdtIZshvVu1z8aoMwGMcvQXO5B4mckDjUX2HVJuv5pboPkTqbHAmCckv0BJY8HCGV3SmdUrCGl8Q1kycVPr34IAJQRC8JXFJcDuYMdCPCQGzZPOmU-42tPHgwM-bwxTWtPjX1N4dTHmtJ_puICp_xjgXIMklnyexuUUBvmA7xqQ4YCR-MlGdCPbicMQnVhzaYXhI6osDPbQ9s-Iwa6qIqS91-UuZEy3vzP-J-x-E74Dhuz2lbnBEjYzJ3dRhgckjTLZLTowB4nZWg4p3wB5AdZ3HENIR_sKnT5Zzz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