<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62340>62340</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] Pretty printing not working for some containers in GDB's MI mode and IDEs
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hiratasa
</td>
</tr>
</table>
<pre>
I'm reporting an issue with `printers.py` at https://github.com/llvm/llvm-project/blob/main/libcxx/utils/gdb/libcxx/printers.py.
When using GDB's [MI mode](https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html) and enabling pretty-printing, container contents aren't displayed for the following container types when they contain two or more elements:
- `std::list`
- `std::deque`
- `std::set`
- `std::unordered_set`
- `std::map`
- `std::unordered_map`
This issue affects IDEs such as VSCode's C++ extension that use GDB's MI mode. The issue doesn't occur when using GDB in normal mode.
The issue seems to be caused by duplicate keys in `printers.py`. For example, for `std::deque`, the key is always an empty string in the following line:
https://github.com/llvm/llvm-project/blob/main/libcxx/utils/gdb/libcxx/printers.py#L479
(Note that in `printers.py` for **libstdc++**, sequential numbers with square brackets `[0]`, `[1]`, `[2]`, etc. are used as keys.)
According to GDB's documentation (https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing-API.html), duplicate children keys aren't explicitly forbidden, but in MI mode, they don't seem to work as expected.
Here are the steps to reproduce:
1. Build the following code with libc++ with debug info:
```c++
#include <list>
int main() {
std::list<int> l {0, 1, 2};
return 0;
}
```
2. Run the following commands in the terminal (the second and subsequent lines are input to GDB):
```
$ gdb -interpreter=mi ./a.out
-enable-pretty-printing
-break-insert a.cpp:6
-exec-run
-var-create l * l
-var-list-children l
```
The expected result should be a list of children. However, the following error is returned instead:
```
^error,msg="Duplicate variable object name"
```
Additionally, here is a screenshot of the issue in VSCode. The contents of the std::list is not visible:

Thank you.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.ll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