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++] Index from 0 in GDB pretty printers #110881

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Oct 2, 2024

Fixes #62168

@ldionne ldionne requested a review from a team as a code owner October 2, 2024 16:33
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 2, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 2, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

Fixes #62168


Full diff: https://github.com/llvm/llvm-project/pull/110881.diff

2 Files Affected:

  • (modified) libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp (+1-1)
  • (modified) libcxx/utils/gdb/libcxx/printers.py (+3-3)
diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
index 2c8534977febc7..f4b097613baf3c 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -234,7 +234,7 @@ void tuple_test() {
   std::tuple<int, int, int> test0(2, 3, 4);
   ComparePrettyPrintToChars(
       test0,
-      "std::tuple containing = {[1] = 2, [2] = 3, [3] = 4}");
+      "std::tuple containing = {[0] = 2, [1] = 3, [2] = 4}");
 
   std::tuple<> test1;
   ComparePrettyPrintToChars(
diff --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index 49087f94c06265..8e74b93e7b121f 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -173,7 +173,7 @@ def __next__(self):
             field_name = next(self.child_iter)
             child = self.val["__base_"][field_name]["__value_"]
             self.count += 1
-            return ("[%d]" % self.count, child)
+            return ("[%d]" % (self.count - 1), child)
 
         next = __next__  # Needed for GDB built against Python 2.7.
 
@@ -331,7 +331,7 @@ def __next__(self):
             if self.offset >= self.bits_per_word:
                 self.item += 1
                 self.offset = 0
-            return ("[%d]" % self.count, outbit)
+            return ("[%d]" % (self.count - 1), outbit)
 
         next = __next__  # Needed for GDB built against Python 2.7.
 
@@ -352,7 +352,7 @@ def __next__(self):
                 raise StopIteration
             entry = self.item.dereference()
             self.item += 1
-            return ("[%d]" % self.count, entry)
+            return ("[%d]" % (self.count - 1), entry)
 
         next = __next__  # Needed for GDB built against Python 2.7.
 

Copy link

github-actions bot commented Oct 2, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 586736226e3a25b1fd647d3257270c1388f907bf a3626dba6c4d1e3c1fb502c3882d56ff4fc88477 --extensions cpp -- libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
View the diff from clang-format here.
diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
index f4b097613b..9d4b703940 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -232,9 +232,7 @@ void u32string_test() {
 
 void tuple_test() {
   std::tuple<int, int, int> test0(2, 3, 4);
-  ComparePrettyPrintToChars(
-      test0,
-      "std::tuple containing = {[0] = 2, [1] = 3, [2] = 4}");
+  ComparePrettyPrintToChars(test0, "std::tuple containing = {[0] = 2, [1] = 3, [2] = 4}");
 
   std::tuple<> test1;
   ComparePrettyPrintToChars(

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 this pull request may close these issues.

[libc++] Vector index starts at 1 instead of 0 in pretty-printing with libc++ in gdb
2 participants