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>
impl<'db> DebugInfo<'db>
Sourcepub fn new<P: AsRef<Path>>(
db: &'db DebugDatabaseImpl,
binary_path: P,
) -> Result<Self>
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 databasebinary_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();
Sourcepub fn address_to_line(&self, address: u64) -> Option<ResolvedLocation>
pub fn address_to_line(&self, address: u64) -> 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 Some(location) = debug_info.address_to_line(0x12345) {
println!("Address 0x12345 is at {}:{}", location.file, location.line);
}
Sourcepub fn find_function_by_name(
&self,
function: &str,
) -> Result<Option<ResolvedFunction>>
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);
}
pub fn find_symbol_by_name(&self, symbol: &str) -> Result<Option<Symbol>>
Sourcepub fn resolve_address_to_location(
&self,
address: u64,
) -> Result<Option<ResolvedLocation>>
pub fn resolve_address_to_location( &self, address: u64, ) -> Result<Option<ResolvedLocation>>
Sourcepub fn resolve_position(
&self,
file: &str,
line: u64,
column: Option<u64>,
) -> Result<Option<ResolvedAddress>>
pub fn resolve_position( &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 pathline
- The line number in the source filecolumn
- Optional column number
§Returns
The memory address if the position can be resolved
§Examples
if let Some(addr) = debug_info.resolve_position("src/main.rs", 42, None).unwrap() {
println!("Line 42 of src/main.rs is at address {:#x}", addr.address);
}
Sourcepub fn get_variable_at_pc(
&self,
address: u64,
name: &str,
data_resolver: &dyn DataResolver,
) -> Result<Option<VariableInfo>>
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 inspectname
- The name of the variable to finddata_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);
}
Sourcepub fn get_all_variables_at_pc(
&self,
address: u64,
data_resolver: &dyn DataResolver,
) -> Result<(Vec<VariableInfo>, Vec<VariableInfo>, Vec<VariableInfo>)>
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 inspectdata_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());
Sourcepub fn read_variable(
&self,
var_info: &VariableInfo,
data_resolver: &dyn DataResolver,
) -> Result<Value>
pub fn read_variable( &self, var_info: &VariableInfo, data_resolver: &dyn DataResolver, ) -> Result<Value>
Reads and formats a variable’s value from its metadata.
This method takes variable metadata (from get_variable_at_pc
or get_all_variables_at_pc
)
and reads the actual value from memory, formatting it for display.
§Arguments
var_info
- Variable metadata containing address and type informationdata_resolver
- Interface for reading memory and register values
§Returns
The formatted variable value
§Examples
if let Some(var_info) = debug_info.get_variable_at_pc(0x12345, "foo", &resolver).unwrap() {
let value = debug_info.read_variable(&var_info, &resolver).unwrap();
println!("Variable value: {:?}", value);
}
Sourcepub fn resolve_variables_at_address(
&self,
address: u64,
data_resolver: &dyn DataResolver,
) -> Result<(Vec<Variable>, Vec<Variable>, Vec<Variable>)>
pub fn resolve_variables_at_address( &self, address: u64, data_resolver: &dyn DataResolver, ) -> Result<(Vec<Variable>, Vec<Variable>, Vec<Variable>)>
Resolves variables visible at a given memory address (legacy method).
This method combines get_all_variables_at_pc
and read_variable
for convenience.
For better performance or more control, prefer using the separate methods.
§Arguments
address
- The memory address to inspectdata_resolver
- Interface for reading memory and register values
§Returns
A tuple of (parameters, locals, globals)
§Examples
let (params, locals, globals) = debug_info
.resolve_variables_at_address(0x12345, &resolver)
.unwrap();
println!("Found {} parameters, {} locals, {} globals",
params.len(), locals.len(), globals.len());
Sourcepub fn resolve_type(&self, type_name: &str) -> Result<Option<DieTypeDefinition>>
pub fn resolve_type(&self, type_name: &str) -> Result<Option<DieTypeDefinition>>
Resolve a type by name in the debug information
§Arguments
type_name
- The name of the type to resolve (e.g., “String”, “Vec”, “TestPerson”)
§Returns
The resolved type definition if found, or None
if the type cannot be found
§Examples
if let Some(typedef) = debug_info.resolve_type("String").unwrap() {
println!("Found String type: {}", typedef.display_name());
}
Sourcepub fn read_pointer(
&self,
typed_pointer: &TypedPointer,
data_resolver: &dyn DataResolver,
) -> Result<Value>
pub fn read_pointer( &self, typed_pointer: &TypedPointer, data_resolver: &dyn DataResolver, ) -> Result<Value>
Sourcepub fn get_field(
&self,
base_address: u64,
base_type: &DieTypeDefinition,
field_name: &str,
) -> Result<TypedPointer>
pub fn get_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 valuebase_type
- Type definition of the base valuefield_name
- Name of the field to access
§Returns
Variable information for the field if found
§Examples
if let Ok(field_info) = debug_info.get_field(var_info.address.unwrap(), &var_info.type_def, "name") {
println!("Field 'name' at address {:?}", field_info.address);
}
Sourcepub fn get_index_by_int(
&self,
type_pointer: &TypedPointer,
index: u64,
data_resolver: &dyn DataResolver,
) -> Result<TypedPointer>
pub fn get_index_by_int( &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/vectorbase_type
- Type definition of the base valueindex
- Integer index to accessdata_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.get_index_by_int(&var_pointer, 0, &resolver) {
println!("Element 0 at address {:?}", element_info.address);
}
Sourcepub fn get_index_by_value(
&self,
base_address: u64,
base_type: &DieTypeDefinition,
key: &Value,
data_resolver: &dyn DataResolver,
) -> Result<TypedPointer>
pub fn get_index_by_value( &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 mapbase_type
- Type definition of the base mapkey
- Key value to look updata_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.get_index_by_value(var_info.address.unwrap(), &var_info.type_def, &key, &resolver) {
println!("Map value at address {:?}", value_info.address);
}
pub fn discover_all_methods( &self, ) -> Result<BTreeMap<String, Vec<DiscoveredMethod>>>
pub fn discover_all_methods_debug( &self, ) -> Result<BTreeMap<String, SymbolAnalysisResult>>
pub fn discover_methods_for_pointer( &self, typed_pointer: &TypedPointer, ) -> Result<Vec<DiscoveredMethod>>
pub fn discover_methods_for_type( &self, type_def: &DieTypeDefinition, ) -> Result<Vec<DiscoveredMethod>>
Sourcepub fn discover_functions(
&self,
pattern: &str,
) -> Result<Vec<DiscoveredFunction>>
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);
}
Sourcepub fn discover_all_functions(
&self,
) -> Result<BTreeMap<String, DiscoveredFunction>>
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);
}
Sourcepub fn create_typed_value(
&self,
source_value: &str,
target_type: &DieTypeDefinition,
data_resolver: &dyn DataResolver,
) -> Result<u64>
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 DWARFdata_resolver
- DataResolver for memory allocation and writing
§Returns
The address where the typed value was created in target memory
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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