Open hiratasa opened 1 year ago
I think this would be a libc++ issue but not 100% sure CC @mordante @ldionne
I found that tuple's index also starts at 1, and this is not omitted in GDB in CLI:
#include <iostream>
#include <tuple>
int main() {
std::tuple<int, int, int> t{0, 1, 2};
return 0;
}
(gdb) p t
$1 = std::tuple containing = {[1] = 0, [2] = 1, [3] = 2}
@shafik Thank you for the reply!
I edited the issue for the following information:
When debugging a program using libc++ by gdb with the pretty-printer script provided by https://github.com/llvm/llvm-project/blob/main/libcxx/utils/gdb/libcxx/printers.py, the output of the pretty-printing for the vector's index starts from 1 instead of 0.
GDB does not display the index of a std::vector in normal mode, but it can be shown in MI mode and therefore also appears in some IDEs, such as VSCode. (ADDED: I append steps to reproduce using GDB's MI mode directly)
For the following vector,
GDB in normal mode outputs the following, with the index omitted:
And in VSCode, the view shows the following, with the index starting at 1:
(Note that if I use libstdc++ instead of libc++, the index starts at 0)
It appears that the code in https://github.com/llvm/llvm-project/blob/main/libcxx/utils/gdb/libcxx/printers.py#L375-L381 is responsible for this behavior.
This code returns 1 as index for the first element.
UPDATE: I confirmed that by changing the return statement as follows, the expected behavior can be obtained in GDB's MI mode and in VSCode:
UPDATE END
I'm not sure whether this is intended behavior or a bug, but it would be helpful if this issue could be addressed. Thank you.
ADDED: Following are steps to reproduce using GDB's MI mode directly
int main() { std::vector v{0, 1, 2};
}
Result
The following result is obtained:
The name and exp of the first child is
[1]
.For reference, the following is the result of a similar experiment with libstdc++: