Skip to main content

Utilities for dealing with live register analysis in GTIRB functions

Project description

gtirb-live-register-analysis

Overview

The gtirb-live-register-analysis package provides a Python API for live register analysis of GTIRB functions. A simple interface is also provided for working with gtirb-rewriting patches.

Supported ABIs

ISA File Format
X64 (x86-64) ELF

Getting Started

Generic Usage

from gtirb_live_register_analysis import LiveRegisterManager

reg_manager = LiveRegisterManager(module)

# Analyze function of interest
reg_manager.analyze(function)

# The sets of live and free registers can then be retrieved
live_regs = reg_manager.live_registers(function, block, instruction_idx)
free_regs = reg_manager.free_registers(function, block, instruction_idx)

Use with gtirb-rewriting patches

Wrap the decorator function around a patch function to assign free registers to be used as scratch registers. When there are not enough free registers, the library falls back to gtirb-rewriting, which generates code to spill/restore the excess registers to stack.

@reg_manager.allocate_registers(function, block, instruction_idx)
@patch_constraints(x86_syntax=X86Syntax.INTEL, scratch_registers=6)
def my_patch(self, ctx: InsertionContext):
    reg1, reg2, reg3, reg4, reg5, reg6 = ctx.scratch_registers
    return f"""
        xor {reg1}, {reg1}
        xor {reg2}, {reg2}
        xor {reg3}, {reg3}
        xor {reg4}, {reg4}
        xor {reg5}, {reg5}
        xor {reg6}, {reg6}
    """

rewriting_ctx.insert_at(block, offset, Patch.from_function(my_patch))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gtirb-live-register-analysis-0.0.2.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file gtirb-live-register-analysis-0.0.2.tar.gz.

File metadata

File hashes

Hashes for gtirb-live-register-analysis-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9131c4b4fe328955b63ac9971c5765e0599a2ca7bc2302f365e2c77e4c632882
MD5 0bbe0ab5ce84b2f58c7e6399294fb378
BLAKE2b-256 9b75715e8ff9ab5dd2650213ecc4f0dd52f2a08d207be77a0d5ee9d52aedc4bf

See more details on using hashes here.

File details

Details for the file gtirb_live_register_analysis-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gtirb_live_register_analysis-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f5a06db7067ac9fab5568f3b0ded3922a82ff0727bbf56af709388740dab0c50
MD5 90ba1f73c3852d1cce644e1f26627a64
BLAKE2b-256 6f598b9cda280dff391dfce37cda155d4514e67f5876f0e6183d52a35a03d059

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page