Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] Pretty printing not working for some containers in GDB's MI mode and IDEs #62340

Open
hiratasa opened this issue Apr 25, 2023 · 0 comments · May be fixed by #120951
Open

[libc++] Pretty printing not working for some containers in GDB's MI mode and IDEs #62340

hiratasa opened this issue Apr 25, 2023 · 0 comments · May be fixed by #120951
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@hiratasa
Copy link

hiratasa commented Apr 25, 2023

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 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:
#include <list>

int main() {
    std::list<int> l {0, 1, 2};

    return 0;
}
  1. Run the following commands in the terminal (the second and subsequent lines are input to GDB):
$ gdb -interpreter=mi ./a.out
-enable-pretty-printing
b a.cpp:6
r
-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:
image

Thank you.

@EugeneZelenko EugeneZelenko added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Apr 25, 2023
@AngryLoki AngryLoki linked a pull request Dec 23, 2024 that will close this issue
AngryLoki added a commit to AngryLoki/llvm-project that referenced this issue Dec 23, 2024
GDB/MI requires unique names for each child, otherwise fails with "Duplicate variable object name".
Additionally wrapped containers printers were flattened for cleaner visualization in IDEs and CLI.

Fixes llvm#62340
AngryLoki added a commit to AngryLoki/llvm-project that referenced this issue Dec 23, 2024
GDB/MI requires unique names for each child, otherwise fails with "Duplicate variable object name".
Additionally wrapped containers printers were flattened for cleaner visualization in IDEs and CLI.

Fixes llvm#62340
AngryLoki added a commit to AngryLoki/llvm-project that referenced this issue Dec 23, 2024
GDB/MI requires unique names for each child, otherwise fails with "Duplicate variable object name".
Additionally wrapped containers printers were flattened for cleaner visualization in IDEs and CLI.

Fixes llvm#62340
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants