[llvm-branch-commits] [libcxx] cde8663 - Various minor fixes for python 3
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jun 8 16:11:39 PDT 2021
Author: Sterling Augustine
Date: 2021-06-08T16:11:06-07:00
New Revision: cde86632a772b523ba3db7039f75d979f557b57c
URL: https://github.com/llvm/llvm-project/commit/cde86632a772b523ba3db7039f75d979f557b57c
DIFF: https://github.com/llvm/llvm-project/commit/cde86632a772b523ba3db7039f75d979f557b57c.diff
LOG: Various minor fixes for python 3
Switch StdTuple printer from python 2-style "next" to python 3.
Nested iteration changed enough to make the original bitset iteration
code a bit trickier than it needs to be, so unnest.
The end node of a map iterator is sometimes hard to detect in isolation,
don't fail in that case.
Differential Revision: https://reviews.llvm.org/D96167
(cherry picked from commit a34b8b879e345397880c1f9f8de4c294dd0b370c)
Added:
Modified:
libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
libcxx/utils/gdb/libcxx/printers.py
Removed:
################################################################################
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 cf560ce310972..d8a02a3845638 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -489,8 +489,9 @@ void map_iterator_test() {
auto not_found = one_two_three.find(7);
MarkAsLive(not_found);
- CompareExpressionPrettyPrintToRegex("not_found",
- R"(std::__map_iterator = {\[0x[a-f0-9]+\] = end\(\)})");
+ // Because the end_node is not easily detected, just be sure it doesn't crash.
+ CompareExpressionPrettyPrintToRegex(
+ "not_found", R"(std::__map_iterator ( = {\[0x[a-f0-9]+\] = .*}|<error reading variable:.*>))");
}
void unordered_set_test() {
diff --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index 0ee446f46c51f..9b413a86b1597 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -13,6 +13,7 @@
from __future__ import print_function
+import math
import re
import gdb
@@ -141,7 +142,7 @@ def __iter__(self):
def __next__(self):
# child_iter raises StopIteration when appropriate.
- field_name = self.child_iter.next()
+ field_name = next(self.child_iter)
child = self.val["__base_"][field_name]["__value_"]
self.count += 1
return ("[%d]" % self.count, child)
@@ -425,6 +426,7 @@ def __init__(self, val):
self.val = val
self.n_words = int(self.val["__n_words"])
self.bits_per_word = int(self.val["__bits_per_word"])
+ self.bit_count = self.val.type.template_argument(0)
if self.n_words == 1:
self.values = [int(self.val["__first_"])]
else:
@@ -435,21 +437,12 @@ def to_string(self):
typename = _prettify_typename(self.val.type)
return "%s" % typename
- def _byte_it(self, value):
- index = -1
- while value:
- index += 1
- will_yield = value % 2
- value /= 2
- if will_yield:
- yield index
-
def _list_it(self):
- for word_index in range(self.n_words):
- current = self.values[word_index]
- if current:
- for n in self._byte_it(current):
- yield ("[%d]" % (word_index * self.bits_per_word + n), 1)
+ for bit in range(self.bit_count):
+ word = math.floor(bit / self.bits_per_word)
+ word_bit = bit % self.bits_per_word
+ if self.values[word] & (1 << word_bit):
+ yield ("[%d]" % bit, 1)
def __iter__(self):
return self._list_it()
More information about the llvm-branch-commits
mailing list