Created
November 22, 2019 16:41
-
-
Save atotic/8b70bec6fe2a8976bd2356c860c0b287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import itertools | |
import gdb | |
from gdb.FrameDecorator import FrameDecorator | |
from gdb.FrameDecorator import SymValueWrapper | |
# | |
# Pretty printing for layoutng | |
# | |
# 1) NGBlockNode -> prints layout_box_->debugName() | |
# | |
# 2) backtrace decorates NGBlockNode lines with NGBlockNode->debugName | |
# | |
# Backtrace decoration | |
# Prints pretty names for NGBlockNode, LayoutNGBlockFlow | |
# | |
class NGFrameDecorator(FrameDecorator): | |
ng_block_re = re.compile('^blink::NGBlockNode') | |
ng_block_painter_re = re.compile('^blink::BlockPainter') | |
std_re = re.compile('^std::__') | |
def __init__(self, fobj): | |
super(NGFrameDecorator, self).__init__(fobj) | |
def function(self): | |
frame = self._base.inferior_frame() | |
name = str(frame.name()) | |
try: | |
if NGFrameDecorator.ng_block_re.match(name): | |
symbol = frame.read_var('this') | |
name = '#? {0} {1}'.format(name, symbol[0]) | |
if NGFrameDecorator.ng_block_painter_re.match(name): | |
symbol = frame.read_var('this') | |
name = '#? {0} {1}'.format(name, symbol[0]) | |
if NGFrameDecorator.ng_block_painter_re.match(name): | |
name = 'std::stuff' | |
except: | |
name = name | |
return name | |
def address(self): | |
return None | |
def frame_args(self): | |
# return FrameDecorator.frame_args(self) | |
return None | |
def filename(self): | |
return "" | |
def frame_locals(self): | |
return None | |
class NGFrameFilter(): | |
def __init__(self): | |
self.name = "NGFilter" | |
self.priority = 100 | |
self.enabled = True | |
# Register this frame filter with the global frame_filters | |
# dictionary. | |
gdb.frame_filters[self.name] = self | |
def filter(self, frame_iter): | |
frame_iter = itertools.imap(NGFrameDecorator, frame_iter) | |
return frame_iter | |
# install frame filter | |
NGFrameFilter() | |
# | |
# Pretty printers | |
# | |
class NGBlockNodePrinter(object): | |
"Print blink::NGBlockNode" | |
class_name_match = re.compile("^blink::NGBlockNode$") | |
@staticmethod | |
def can_print(lookup_tag): | |
return NGBlockNodePrinter.class_name_match.match(lookup_tag) | |
def __init__(self, val): | |
self.val = val | |
def to_string(self): | |
# if layout_box_ call layout_box_->debugName() | |
if not self.val['box_']: | |
return "no box_"; | |
eval_string = "((blink::LayoutBox*)%s)->DebugName()" % self.val['box_'].dereference().address | |
return gdb.parse_and_eval(eval_string); | |
def display_hint(self): | |
return 'string' | |
class LayoutObjectPrinter(object): | |
"Print blink::LayoutObject" | |
def __init__(self, val): | |
self.val = val | |
def to_string(self): | |
# if layout_box_ call layout_box_->debugName() | |
if not self.val['box_']: | |
return "no box_"; | |
eval_string = "((blink::LayoutObject*)%s)->DebugName()" % self.val.address | |
return gdb.parse_and_eval(eval_string); | |
def display_hint(self): | |
return 'string' | |
class BlockPainterPrinter(object): | |
"Print blink::BlockPainter with Node info" | |
def __init__(self, val): | |
self.val = val | |
def to_string(self): | |
if not self.val['layout_block_']: | |
return "no layout_block_"; | |
eval_string = "((blink::LayoutBlock*)%s)->DebugName()" % self.val['layout_block_'].address | |
return gdb.parse_and_eval(eval_string); | |
def display_hint(self): | |
return 'string' | |
class BaseOptionalPrinter(object): | |
"Print base::Optional" | |
class_name_match = re.compile("^base::Optional<") | |
@staticmethod | |
def can_print(lookup_tag): | |
return BaseOptionalPrinter.class_name_match.match(lookup_tag) | |
def __init__(self, val): | |
self.val = val | |
def to_string(self): | |
if self.val['storage_']['is_populated_']: | |
return "Optional< %s >" % self.val['storage_']['value_'] | |
else: | |
return "Optional<>" | |
def ng_pretty_printer_lookup_function(val): | |
lookup_tag = val.type.tag | |
if lookup_tag == None: | |
return None | |
block_node = re.compile("^blink::NGBlockNode$") | |
input_node = re.compile("^blink::NGLayoutInputNode$") | |
block_painter = re.compile("^blink::BlockPainter$") | |
layout_block = re.compile("^blink::LayoutBlock$") | |
layout_image = re.compile("^blink::LayoutImage$") | |
if NGBlockNodePrinter.can_print(lookup_tag): | |
return NGBlockNodePrinter(val) | |
if input_node.match(lookup_tag): | |
return NGBlockNodePrinter(val) | |
if block_painter.match(lookup_tag): | |
return BlockPainterPrinter(val) | |
if BaseOptionalPrinter.can_print(lookup_tag): | |
return BaseOptionalPrinter(val) | |
if layout_block.match(lookup_tag) or layout_image.match(lookup_tag): | |
return LayoutObjectPrinter(val) | |
return None | |
# install pretty printers | |
gdb.pretty_printers.append(ng_pretty_printer_lookup_function) | |
print("ng_gdb loaded") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment