cppgc: Add pretty-printers for (cppgc|blink)::Members

No need to use 'cpcp' or 'cpm' now, simple 'print' shall work:
Instead of:
  {
    <cppgc::internal::MemberBase> = {raw_ = {value_ = 2300193596}},
    <cppgc::internal::DisabledCheckingPolicy> = {<No data fields>},
    <No data fields>
  }
the output becomes:
  cppgc::Member<GCed> pointing to 0xbbbbbbbb12345678

Bug: chromium:1373391
Change-Id: I72645d372ee830e20ec02b991ddff94851c4a49f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3948607
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83654}
This commit is contained in:
Anton Bikineev 2022-10-12 15:20:18 +02:00 committed by V8 LUCI CQ
parent 51aef72aeb
commit 83fdcb45cc

View File

@ -279,3 +279,44 @@ document cpm
Prints member, compressed or not.
Usage: cpm member
end
# Pretty printer for cppgc::Member.
python
import re
class CppGCMemberPrinter(object):
"""Print cppgc Member types."""
def __init__(self, val, category, pointee_type):
self.val = val
self.category = category
self.pointee_type = pointee_type
def to_string(self):
pointer = gdb.parse_and_eval(
"_cppgc_internal_Print_Member((cppgc::internal::MemberBase*){})".format(
self.val.address))
return "{}Member<{}> pointing to {}".format(
'' if self.category is None else self.category, self.pointee_type,
pointer)
def display_hint(self):
return "{}Member<{}>".format('' if self.category is None else self.category,
self.pointee_type)
def cppgc_pretty_printers(val):
typename = val.type.name or val.type.tag or str(val.type)
regex = re.compile("^(cppgc|blink)::(Weak|Untraced)?Member<(.*)>$")
match = regex.match(typename)
if match is None:
return None
return CppGCMemberPrinter(
val, category=match.group(2), pointee_type=match.group(3))
gdb.pretty_printers.append(cppgc_pretty_printers)
end