compiler/rustc_codegen_cranelift/scripts/jit-helpers.py PYTHON 58 lines View on github.com → Search inside
1import gdb234def jitmap_raw():5    pid = gdb.selected_inferior().pid6    jitmap_file = open("/tmp/perf-%d.map" % (pid,), "r")7    jitmap = jitmap_file.read()8    jitmap_file.close()9    return jitmap101112def jit_functions():13    jitmap = jitmap_raw()1415    functions = []16    for line in jitmap.strip().split("\n"):17        [addr, size, name] = line.split(" ")18        functions.append((int(addr, 16), int(size, 16), name))1920    return functions212223class JitDecorator(gdb.FrameDecorator.FrameDecorator):24    def __init__(self, fobj, name):25        super(JitDecorator, self).__init__(fobj)26        self.name = name2728    def function(self):29        return self.name303132class JitFilter:33    """34    A backtrace filter which reads perf map files produced by cranelift-jit.35    """3637    def __init__(self):38        self.name = "JitFilter"39        self.enabled = True40        self.priority = 04142        gdb.current_progspace().frame_filters[self.name] = self4344    # FIXME add an actual unwinder or somehow register JITed .eh_frame with gdb to avoid relying on45    # gdb unwinder heuristics.46    def filter(self, frame_iter):47        for frame in frame_iter:48            frame_addr = frame.inferior_frame().pc()49            for addr, size, name in jit_functions():50                if frame_addr >= addr and frame_addr < addr + size:51                    yield JitDecorator(frame, name)52                    break53            else:54                yield frame555657JitFilter()

Code quality findings 5

Ensure functions have docstrings for documentation
missing-docstring
def jitmap_raw():
Use 'with open()' to ensure Files are properly closed
open-without-with
jitmap_file = open("/tmp/perf-%d.map" % (pid,), "r")
Ensure functions have docstrings for documentation
missing-docstring
def jit_functions():
Ensure functions have docstrings for documentation
missing-docstring
def function(self):
Ensure functions have docstrings for documentation
missing-docstring
def filter(self, frame_iter):

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.