-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Fix mi-mode in GDB pretty printers #120951
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
Conversation
|
@llvm/pr-subscribers-libcxx Author: Sv. Lockal (AngryLoki) ChangesGDB/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 #62340 This is the final result from vscode perspective:
Full diff: https://github.com/llvm/llvm-project/pull/120951.diff 1 Files Affected:
diff --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index 8e74b93e7b121f..77736f4722d067 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -446,10 +446,13 @@ def _list_it(self):
num_emitted = 0
current_addr = self.start_ptr
start_index = self.first_block_start_index
+ i = 0
while num_emitted < self.size:
end_index = min(start_index + self.size - num_emitted, self.block_size)
for _, elem in self._bucket_it(current_addr, start_index, end_index):
- yield "", elem
+ key_name = "[%d]" % i
+ i += 1
+ yield key_name, elem
num_emitted += end_index - start_index
current_addr = gdb.Value(addr_as_long(current_addr) + _pointer_size).cast(
self.node_type
@@ -494,8 +497,8 @@ def to_string(self):
def _list_iter(self):
current_node = self.first_node
- for _ in range(self.size):
- yield "", current_node.cast(self.nodetype).dereference()["__value_"]
+ for i in range(self.size):
+ yield "[%d]" % i, current_node.cast(self.nodetype).dereference()["__value_"]
current_node = current_node.dereference()["__next_"]
def __iter__(self):
@@ -512,15 +515,14 @@ class StdQueueOrStackPrinter(object):
"""Print a std::queue or std::stack."""
def __init__(self, val):
- self.val = val
- self.underlying = val["c"]
+ self.typename = _remove_generics(_prettify_typename(val.type))
+ self.visualizer = gdb.default_visualizer(val['c'])
def to_string(self):
- typename = _remove_generics(_prettify_typename(self.val.type))
- return "%s wrapping" % typename
+ return "%s wrapping: %s" % (self.typename, self.visualizer.to_string())
def children(self):
- return iter([("", self.underlying)])
+ return self.visualizer.children()
def display_hint(self):
return "array"
@@ -530,19 +532,18 @@ class StdPriorityQueuePrinter(object):
"""Print a std::priority_queue."""
def __init__(self, val):
- self.val = val
- self.underlying = val["c"]
+ self.typename = _remove_generics(_prettify_typename(val.type))
+ self.visualizer = gdb.default_visualizer(val['c'])
def to_string(self):
# TODO(tamur): It would be nice to print the top element. The technical
# difficulty is that, the implementation refers to the underlying
# container, which is a generic class. libstdcxx pretty printers do not
# print the top element.
- typename = _remove_generics(_prettify_typename(self.val.type))
- return "%s wrapping" % typename
+ return "%s wrapping: %s" % (self.typename, self.visualizer.to_string())
def children(self):
- return iter([("", self.underlying)])
+ return self.visualizer.children()
def display_hint(self):
return "array"
@@ -622,13 +623,16 @@ def _traverse(self):
"""Traverses the binary search tree in order."""
current = self.util.root
skip_left_child = False
+ i = 0
while True:
if not skip_left_child and self.util.left_child(current):
current = self.util.left_child(current)
continue
skip_left_child = False
for key_value in self._get_key_value(current):
- yield "", key_value
+ key_name = "[%d]" % i
+ i += 1
+ yield key_name, key_value
right_child = self.util.right_child(current)
if right_child:
current = right_child
@@ -784,10 +788,13 @@ def __init__(self, val):
def _list_it(self, sentinel_ptr):
next_ptr = sentinel_ptr["__next_"]
+ i = 0
while str(next_ptr.cast(_void_pointer_type)) != "0x0":
next_val = next_ptr.cast(self.cast_type).dereference()
for key_value in self._get_key_value(next_val):
- yield "", key_value
+ key_name = "[%d]" % i
+ i += 1
+ yield key_name, key_value
next_ptr = next_val["__next_"]
def to_string(self):
@@ -851,8 +858,8 @@ def children(self):
return self if self.addr else iter(())
def __iter__(self):
- for key_value in self._get_key_value():
- yield "", key_value
+ for i, key_value in enumerate(self._get_key_value()):
+ yield "[%d]" % i, key_value
class StdUnorderedSetIteratorPrinter(AbstractHashMapIteratorPrinter):
|
|
✅ With the latest revision this PR passed the Python code formatter. |
39792aa to
125138b
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
125138b to
d58559e
Compare
GDB/MI requires unique names for each child, otherwise fails with "Duplicate variable object name". Also wrapped containers printers were flattened for cleaner visualization in IDEs and CLI. Fixes llvm#62340
d58559e to
60a8424
Compare
GDB/MI requires unique names for each child, otherwise fails with "Duplicate variable object name".
Also wrapped containers printers were flattened for cleaner visualization in IDEs and CLI.
Fixes #62340
This is the final result from vscode perspective: