Skip to content

Commit

Permalink
refactor(debugger): variable module refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
godzie44 committed Jul 3, 2024
1 parent 0386e5a commit ecc1dd1
Show file tree
Hide file tree
Showing 38 changed files with 5,138 additions and 5,262 deletions.
14 changes: 14 additions & 0 deletions src/debugger/debugee/dwarf/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::debugger::error::Error::{
};
use crate::debugger::register::{DwarfRegisterMap, RegisterMap};
use crate::debugger::{debugee, ExplorationContext};
use crate::version::Version;
use bytes::{BufMut, Bytes, BytesMut};
use gimli::{
DebugAddr, Encoding, EndianSlice, EvaluationResult, Expression, Location, Piece, Register,
Expand All @@ -24,8 +25,20 @@ use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::mem;

pub struct EvaluationContext<'a> {
pub evaluator: &'a ExpressionEvaluator<'a>,
pub expl_ctx: &'a ExplorationContext,
}

impl<'a> EvaluationContext<'a> {
pub fn rustc_version(&self) -> Option<Version> {
self.evaluator.unit().rustc_version()
}
}

/// Resolve requirements that the `ExpressionEvaluator` may need. Relevant for the current breakpoint.
/// Some options are lazy to avoid overhead on recalculation.
#[derive(Clone)]
struct RequirementsResolver<'a> {
debugee: &'a Debugee,
cfa: RefCell<HashMap<Pid, RelocatedAddress>>,
Expand Down Expand Up @@ -164,6 +177,7 @@ impl ExternalRequirementsResolver {
}
}

#[derive(Clone)]
pub struct ExpressionEvaluator<'a> {
encoding: Encoding,
unit: &'a Unit,
Expand Down
40 changes: 20 additions & 20 deletions src/debugger/debugee/dwarf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub use self::unwind::DwarfUnwinder;

use crate::debugger::address::{GlobalAddress, RelocatedAddress};
use crate::debugger::debugee::dwarf::eval::AddressKind;
use crate::debugger::debugee::dwarf::eval::EvaluationContext;
use crate::debugger::debugee::dwarf::location::Location as DwarfLocation;
use crate::debugger::debugee::dwarf::r#type::ComplexType;
use crate::debugger::debugee::dwarf::r#type::EvaluationContext;
use crate::debugger::debugee::dwarf::symbol::SymbolTab;
use crate::debugger::debugee::dwarf::unit::{
DieRef, DieVariant, DwarfUnitParser, Entry, FunctionDie, Node, ParameterDie,
Expand All @@ -26,7 +26,7 @@ use crate::debugger::error::Error::{
DebugIDFormat, FBANotAnExpression, FunctionNotFound, NoFBA, NoFunctionRanges, UnitNotFound,
};
use crate::debugger::register::{DwarfRegisterMap, RegisterMap};
use crate::debugger::variable::select::ObjectBinaryRepr;
use crate::debugger::variable::ObjectBinaryRepr;
use crate::debugger::ExplorationContext;
use crate::{muted_error, resolve_unit_call, weak_error};
use fallible_iterator::FallibleIterator;
Expand Down Expand Up @@ -512,7 +512,7 @@ impl DebugInformation {
&self,
location: Location,
name: &str,
) -> Result<Vec<ContextualDieRef<'_, VariableDie>>, Error> {
) -> Result<Vec<ContextualDieRef<'_, '_, VariableDie>>, Error> {
let units = self.get_units()?;

let mut found = vec![];
Expand Down Expand Up @@ -934,11 +934,11 @@ impl NamespaceHierarchy {
}
}

pub struct ContextualDieRef<'a, T> {
pub debug_info: &'a DebugInformation,
pub struct ContextualDieRef<'node, 'dbg: 'node, T> {
pub debug_info: &'dbg DebugInformation,
pub unit_idx: usize,
pub node: &'a Node,
pub die: &'a T,
pub node: &'node Node,
pub die: &'node T,
}

#[macro_export]
Expand All @@ -948,26 +948,26 @@ macro_rules! ctx_resolve_unit_call {
}};
}

impl<'a, T> Clone for ContextualDieRef<'a, T> {
impl<'node, 'dbg, T> Clone for ContextualDieRef<'node, 'dbg, T> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, T> Copy for ContextualDieRef<'a, T> {}
impl<'node, 'dbg, T> Copy for ContextualDieRef<'node, 'dbg, T> {}

impl<'a, T> ContextualDieRef<'a, T> {
impl<'node, 'dbg, T> ContextualDieRef<'node, 'dbg, T> {
pub fn namespaces(&self) -> NamespaceHierarchy {
let entries = ctx_resolve_unit_call!(self, entries,);
NamespaceHierarchy::for_node(self.node, entries)
}

pub fn unit(&self) -> &'a Unit {
pub fn unit(&self) -> &'dbg Unit {
self.debug_info.unit_ensure(self.unit_idx)
}
}

impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
impl<'ctx> ContextualDieRef<'ctx, 'ctx, FunctionDie> {
pub fn full_name(&self) -> Option<String> {
self.die
.base_attributes
Expand Down Expand Up @@ -997,7 +997,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
pub fn local_variables<'this>(
&'this self,
pc: GlobalAddress,
) -> Vec<ContextualDieRef<'ctx, VariableDie>> {
) -> Vec<ContextualDieRef<'ctx, 'ctx, VariableDie>> {
let mut result = vec![];
let mut queue = VecDeque::from(self.node.children.clone());
while let Some(idx) = queue.pop_front() {
Expand All @@ -1023,7 +1023,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
&'this self,
pc: GlobalAddress,
needle: &str,
) -> Option<ContextualDieRef<'ctx, VariableDie>> {
) -> Option<ContextualDieRef<'ctx, 'ctx, VariableDie>> {
let mut queue = VecDeque::from(self.node.children.clone());
while let Some(idx) = queue.pop_front() {
let entry = ctx_resolve_unit_call!(self, entry, idx);
Expand All @@ -1044,7 +1044,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
None
}

pub fn parameters(&self) -> Vec<ContextualDieRef<'_, ParameterDie>> {
pub fn parameters(&self) -> Vec<ContextualDieRef<'ctx, 'ctx, ParameterDie>> {
let mut result = vec![];
for &idx in &self.node.children {
let entry = ctx_resolve_unit_call!(self, entry, idx);
Expand Down Expand Up @@ -1129,7 +1129,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
}
}

impl<'ctx> ContextualDieRef<'ctx, VariableDie> {
impl<'ctx> ContextualDieRef<'ctx, 'ctx, VariableDie> {
pub fn ranges(&self) -> Option<&[Range]> {
if let Some(lb_idx) = self.die.lexical_block_idx {
let entry = ctx_resolve_unit_call!(self, entry, lb_idx);
Expand All @@ -1150,7 +1150,7 @@ impl<'ctx> ContextualDieRef<'ctx, VariableDie> {
.unwrap_or(true)
}

pub fn assume_parent_function(&self) -> Option<ContextualDieRef<'_, FunctionDie>> {
pub fn assume_parent_function(&self) -> Option<ContextualDieRef<'_, '_, FunctionDie>> {
let mut mb_parent = self.node.parent;

while let Some(p) = mb_parent {
Expand All @@ -1171,7 +1171,7 @@ impl<'ctx> ContextualDieRef<'ctx, VariableDie> {
}
}

impl<'ctx> ContextualDieRef<'ctx, ParameterDie> {
impl<'ctx> ContextualDieRef<'ctx, 'ctx, ParameterDie> {
/// Return max range (with max `end` address) of an underlying function.
/// If it's possible, `end` address in range equals to function epilog begin.
pub fn max_range(&self) -> Option<Range> {
Expand All @@ -1195,7 +1195,7 @@ impl<'ctx> ContextualDieRef<'ctx, ParameterDie> {
}
}

impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, D> {
impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, 'ctx, D> {
pub fn r#type(&self) -> Option<ComplexType> {
let parser = r#type::TypeParser::new();
Some(parser.parse(*self, self.die.type_ref()?))
Expand All @@ -1217,7 +1217,7 @@ impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, D> {
evaluator: &evaluator,
expl_ctx: ctx,
},
r#type.root,
r#type.root(),
)? as usize;
let (address, raw_data) =
weak_error!(eval_result.into_raw_bytes(type_size, AddressKind::MemoryAddress))?;
Expand Down
Loading

0 comments on commit ecc1dd1

Please sign in to comment.