Struct DebugInfo

Source
pub struct DebugInfo<'db> { /* private fields */ }
Expand description

Main interface for accessing debug information from binary files.

DebugInfo provides methods to resolve addresses to source locations, look up function information, and inspect variables at runtime.

The struct holds a reference to the debug database and manages the binary file and associated debug files.

Implementations§

Source§

impl<'db> DebugInfo<'db>

Source

pub fn new<P: AsRef<Path>>( db: &'db DebugDatabaseImpl, binary_path: P, ) -> Result<Self>

Creates a new DebugInfo instance for analyzing a binary file.

§Arguments
  • db - Reference to the debug database
  • binary_path - Path to the binary file to analyze
§Returns

A DebugInfo instance or an error if the binary cannot be loaded

§Examples
use rudy_db::{DebugDb, DebugInfo};

let db = DebugDb::new();
let debug_info = DebugInfo::new(&db, "/path/to/binary").unwrap();
Source

pub fn address_to_location( &self, address: u64, ) -> Result<Option<ResolvedLocation>>

Resolves a memory address to its source location.

§Arguments
  • address - The memory address to resolve
§Returns

The source location if found, or None if the address cannot be resolved

§Examples
if let Ok(Some(location)) = debug_info.address_to_location(0x12345) {
    println!("Address 0x12345 is at {}:{}", location.file, location.line);
}
Source

pub fn find_function_by_name( &self, function: &str, ) -> Result<Option<ResolvedFunction>>

Resolves a function name to its debug information.

The function name can include module paths using :: separators.

§Arguments
  • function - The function name to resolve (e.g., “main” or “module::function”)
§Returns

The resolved function information if found, or None if not found

§Examples
if let Some(func) = debug_info.find_function_by_name("main").unwrap() {
    println!("Function 'main' is at address {:#x}", func.address);
}
Source

pub fn find_symbol_by_name(&self, symbol: &str) -> Result<Option<Symbol>>

Source

pub fn find_address_from_source_location( &self, file: &str, line: u64, column: Option<u64>, ) -> Result<Option<ResolvedAddress>>

Resolves a source file position to a memory address.

§Arguments
  • file - The source file path
  • line - The line number in the source file
  • column - Optional column number
§Returns

The memory address if the position can be resolved

§Examples
if let Some(addr) = debug_info.find_address_from_source_location("src/main.rs", 42, None).unwrap() {
    println!("Line 42 of src/main.rs is at address {:#x}", addr.address);
}
Source

pub fn get_variable_at_pc( &self, address: u64, name: &str, data_resolver: &dyn DataResolver, ) -> Result<Option<VariableInfo>>

Gets metadata for a specific variable at a memory address without reading its value.

This method is useful for expression evaluation where you need type information and memory addresses without immediately reading the value.

§Arguments
  • address - The memory address to inspect
  • name - The name of the variable to find
  • data_resolver - Interface for reading memory and register values
§Returns

Variable metadata if found, or None if the variable is not found

§Examples
if let Some(var_info) = debug_info.get_variable_at_pc(0x12345, "foo", &resolver).unwrap() {
    println!("Variable '{}' at address {:?}", var_info.name, var_info.address);
}
Source

pub fn get_all_variables_at_pc( &self, address: u64, data_resolver: &dyn DataResolver, ) -> Result<(Vec<VariableInfo>, Vec<VariableInfo>, Vec<VariableInfo>)>

Gets metadata for all variables at a memory address without reading their values.

This method returns three categories of variables:

  • Function parameters
  • Local variables
  • Global variables
§Arguments
  • address - The memory address to inspect
  • data_resolver - Interface for reading memory and register values
§Returns

A tuple of (parameters, locals, globals)

§Examples
let (params, locals, globals) = debug_info
    .get_all_variables_at_pc(0x12345, &resolver)
    .unwrap();
println!("Found {} parameters, {} locals, {} globals",
         params.len(), locals.len(), globals.len());
Source

pub fn lookup_type_by_name( &self, type_name: &str, ) -> Result<Option<DieTypeDefinition>>

Resolve a type by name in the debug information

Note: The type name must be fully qualified, e.g., “alloc::string::String”, and must include any generic parameters if applicable (e.g., “alloc::vec::Vec”).

Where possible it’s better to find a variable at an address, and then get the type of the variable.

§Arguments
  • type_name - The name of the type to resolve
§Returns

The resolved type definition if found, or None if the type cannot be found

§Examples
if let Some(typedef) = debug_info.lookup_type_by_name("alloc::string::String").unwrap() {
    println!("Found String type: {}", typedef.display_name());
}
Source

pub fn read_pointer( &self, typed_pointer: &TypedPointer, data_resolver: &dyn DataResolver, ) -> Result<Value>

Read a value from memory using type information

§Arguments
  • address - The memory address to read from
  • typed_pointer - TODO
  • data_resolver - Interface for reading memory and register values
§Returns

The interpreted value from memory

Source

pub fn get_struct_field( &self, base_address: u64, base_type: &DieTypeDefinition, field_name: &str, ) -> Result<TypedPointer>

Access a field of a struct/union/enum value

§Arguments
  • base_address - Memory address of the base value
  • base_type - Type definition of the base value
  • field_name - Name of the field to access
§Returns

Variable information for the field if found

§Examples
if let Ok(field_info) = debug_info.get_struct_field(var_info.address.unwrap(), &var_info.type_def, "name") {
    println!("Field 'name' at address {:?}", field_info.address);
}
Source

pub fn index_array_or_slice( &self, type_pointer: &TypedPointer, index: u64, data_resolver: &dyn DataResolver, ) -> Result<TypedPointer>

Index into an array/slice/vector by integer index

§Arguments
  • base_address - Memory address of the base array/slice/vector
  • base_type - Type definition of the base value
  • index - Integer index to access
  • data_resolver - Interface for reading memory and register values
§Returns

Variable information for the element at the given index

§Examples
if let Ok(element_info) = debug_info.index_array_or_slice(&var_pointer, 0, &resolver) {
    println!("Element 0 at address {:?}", element_info.address);
}
Source

pub fn index_map( &self, base_address: u64, base_type: &DieTypeDefinition, key: &Value, data_resolver: &dyn DataResolver, ) -> Result<TypedPointer>

Index into a map/dictionary by value key

§Arguments
  • base_address - Memory address of the base map
  • base_type - Type definition of the base map
  • key - Key value to look up
  • data_resolver - Interface for reading memory and register values
§Returns

Variable information for the value at the given key

§Examples
if let Ok(value_info) = debug_info.index_map(var_info.address.unwrap(), &var_info.type_def, &key, &resolver) {
    println!("Map value at address {:?}", value_info.address);
}
Source

pub fn discover_all_methods( &self, ) -> Result<BTreeMap<String, Vec<DiscoveredMethod>>>

Source

pub fn discover_all_methods_debug( &self, ) -> Result<BTreeMap<String, SymbolAnalysisResult>>

Source

pub fn discover_methods_for_pointer( &self, typed_pointer: &TypedPointer, ) -> Result<Vec<DiscoveredMethod>>

Source

pub fn discover_methods_for_type( &self, type_def: &DieTypeDefinition, ) -> Result<Vec<DiscoveredMethod>>

Source

pub fn discover_functions( &self, pattern: &str, ) -> Result<Vec<DiscoveredFunction>>

Discover functions in the binary that match a given pattern

This method searches through all function symbols in the binary and returns functions that match the provided pattern. It supports:

  • Exact matches (e.g., “main”)
  • Fuzzy matches (e.g., “calc” matching “calculate_sum”)
  • Fully qualified names (e.g., “test_mod1::my_fn”)
§Arguments
  • pattern - The pattern to match against function names
§Returns

A vector of discovered functions sorted by match quality (exact matches first)

§Examples
// Find all functions containing "main"
let functions = debug_info.discover_functions("main").unwrap();
for func in functions {
    println!("Found function: {} at address {:#x}", func.name, func.address);
}
Source

pub fn discover_all_functions( &self, ) -> Result<BTreeMap<String, DiscoveredFunction>>

Discover all functions in the binary

Returns a map of function name to discovered function information. This includes both functions with debug information and those without.

§Returns

A map of function name to discovered function information

§Examples
let all_functions = debug_info.discover_all_functions().unwrap();
println!("Found {} functions in binary", all_functions.len());
for (name, func) in all_functions {
    println!("Function: {} -> {}", name, func.signature);
}
Source

pub fn create_typed_value( &self, source_value: &str, target_type: &DieTypeDefinition, data_resolver: &dyn DataResolver, ) -> Result<u64>

Create a typed value in the target process based on the target type.

This method uses DWARF type information to determine the correct conversion strategy for creating values that match function parameter types.

§Arguments
  • source_value - The source value to convert (e.g., string literal, number)
  • target_type - The target type definition from DWARF
  • data_resolver - DataResolver for memory allocation and writing
§Returns

The address where the typed value was created in target memory

Trait Implementations§

Source§

impl<'db> Clone for DebugInfo<'db>

Source§

fn clone(&self) -> DebugInfo<'db>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'db> Debug for DebugInfo<'db>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'db> Freeze for DebugInfo<'db>

§

impl<'db> RefUnwindSafe for DebugInfo<'db>

§

impl<'db> !Send for DebugInfo<'db>

§

impl<'db> !Sync for DebugInfo<'db>

§

impl<'db> Unpin for DebugInfo<'db>

§

impl<'db> UnwindSafe for DebugInfo<'db>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more