class Cradare2::Lines::SourceMap

Overview

Bidirectional mapping engine between native assembly instructions and Crystal source code.

Defined in:

cradare2/lines/source_map.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(reader : SourceReader = SourceReader.new) #

[View source]
def self.new(mappings : Array(InstructionMapping), reader : SourceReader = SourceReader.new) #

[View source]

Instance Method Detail

def add(address : UInt64, file : String, line : Int32, column : Int32 = 0, opcode : String = "", size : Int32 = 0, bytes : String | Nil = "", function_name : String | Nil = nil, source_text : String | Nil = nil) : InstructionMapping #

Adds a mapping between an instruction address and a source location.


[View source]
def add(mapping : InstructionMapping) : InstructionMapping #

Adds a pre-constructed instruction mapping.


[View source]
def address_to_instruction : Hash(UInt64, InstructionMapping) #

[View source]
def clear : Nil #

Clears all mappings.


[View source]
def empty? : Bool #

Returns true if no mappings exist.


[View source]
def file_to_lines : Hash(String, Hash(Int32, Array(InstructionMapping))) #

Normalized file => (Line => Array(InstructionMapping))


[View source]
def files : Array(String) #

Returns all unique source file paths recorded in the map.


[View source]
def find_by_address(address : UInt64) : SourceLocation | Nil #

Finds the source location for an instruction address.


[View source]
def find_by_file(file : String) : Hash(Int32, Array(InstructionMapping)) #

Finds all line-to-instruction mappings for a given file.


[View source]
def find_by_line(file : String, line : Int32) : Array(InstructionMapping) #

Finds all instructions generated for a given file and line number.


[View source]
def find_instruction(address : UInt64) : InstructionMapping | Nil #

Finds the mapped instruction for an exact address.


[View source]
def find_instruction_containing(address : UInt64) : InstructionMapping | Nil #

Finds the instruction matching or containing the given address (within instruction size range). Performs an O(log N) binary search over sorted address intervals.


[View source]
def format_interleaved_view(fn_name : String, show_context : Bool = false, context_window : Int32 = 1) : String #

Convenience overload to format interleaved view for a specific function name.


[View source]
def format_interleaved_view(show_context : Bool = false, context_window : Int32 = 1) : String #

Convenience overload to format interleaved view for all mapped instructions.


[View source]
def format_interleaved_view(groups : Array(LineInstructionGroup), show_context : Bool = false, context_window : Int32 = 1) : String #

Generates a formatted interleaved view displaying Crystal source code lines alongside the disassembled instructions that implement each line.


[View source]
def groups_for_function_name(fn_name : String) : Array(LineInstructionGroup) #

Groups instructions for a specific function name.


[View source]
def groups_for_range(start_addr : UInt64, end_addr : UInt64) : Array(LineInstructionGroup) #

Groups instructions within an address range or function into LineInstructionGroups.


[View source]
def lines_for_file(file : String) : Array(Int32) #

Returns all unique line numbers mapped for a given file.


[View source]
def reader : SourceReader #

[View source]
def size : Int32 #

Returns the number of mapped instructions.


[View source]
def sync_to_r2(client : Client, annotate_comments : Bool = true) : Int32 #

Synchronizes all mappings into a running radare2 session. Registers entries into radare2's CL codeline table and optionally sets CC comments.


[View source]