Skip to content

Commit d2c6972

Browse files
committed
refactor(debugger): variable module refactoring
1 parent 008dc16 commit d2c6972

File tree

38 files changed

+5281
-5319
lines changed

38 files changed

+5281
-5319
lines changed

src/debugger/debugee/dwarf/eval.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::debugger::error::Error::{
1111
};
1212
use crate::debugger::register::{DwarfRegisterMap, RegisterMap};
1313
use crate::debugger::{debugee, ExplorationContext};
14+
use crate::version::Version;
1415
use bytes::{BufMut, Bytes, BytesMut};
1516
use gimli::{
1617
DebugAddr, Encoding, EndianSlice, EvaluationResult, Expression, Location, Piece, Register,
@@ -24,8 +25,20 @@ use std::collections::hash_map::Entry;
2425
use std::collections::HashMap;
2526
use std::mem;
2627

28+
pub struct EvaluationContext<'a> {
29+
pub evaluator: &'a ExpressionEvaluator<'a>,
30+
pub expl_ctx: &'a ExplorationContext,
31+
}
32+
33+
impl<'a> EvaluationContext<'a> {
34+
pub fn rustc_version(&self) -> Option<Version> {
35+
self.evaluator.unit().rustc_version()
36+
}
37+
}
38+
2739
/// Resolve requirements that the `ExpressionEvaluator` may need. Relevant for the current breakpoint.
2840
/// Some options are lazy to avoid overhead on recalculation.
41+
#[derive(Clone)]
2942
struct RequirementsResolver<'a> {
3043
debugee: &'a Debugee,
3144
cfa: RefCell<HashMap<Pid, RelocatedAddress>>,
@@ -164,6 +177,7 @@ impl ExternalRequirementsResolver {
164177
}
165178
}
166179

180+
#[derive(Clone)]
167181
pub struct ExpressionEvaluator<'a> {
168182
encoding: Encoding,
169183
unit: &'a Unit,

src/debugger/debugee/dwarf/mod.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ pub use self::unwind::DwarfUnwinder;
1111

1212
use crate::debugger::address::{GlobalAddress, RelocatedAddress};
1313
use crate::debugger::debugee::dwarf::eval::AddressKind;
14+
use crate::debugger::debugee::dwarf::eval::EvaluationContext;
1415
use crate::debugger::debugee::dwarf::location::Location as DwarfLocation;
1516
use crate::debugger::debugee::dwarf::r#type::ComplexType;
16-
use crate::debugger::debugee::dwarf::r#type::EvaluationContext;
1717
use crate::debugger::debugee::dwarf::symbol::SymbolTab;
1818
use crate::debugger::debugee::dwarf::unit::{
1919
DieRef, DieVariant, DwarfUnitParser, Entry, FunctionDie, Node, ParameterDie,
@@ -26,7 +26,7 @@ use crate::debugger::error::Error::{
2626
DebugIDFormat, FBANotAnExpression, FunctionNotFound, NoFBA, NoFunctionRanges, UnitNotFound,
2727
};
2828
use crate::debugger::register::{DwarfRegisterMap, RegisterMap};
29-
use crate::debugger::variable::select::ObjectBinaryRepr;
29+
use crate::debugger::variable::ObjectBinaryRepr;
3030
use crate::debugger::ExplorationContext;
3131
use crate::{muted_error, resolve_unit_call, version_switch, weak_error};
3232
use fallible_iterator::FallibleIterator;
@@ -512,7 +512,7 @@ impl DebugInformation {
512512
&self,
513513
location: Location,
514514
name: &str,
515-
) -> Result<Vec<ContextualDieRef<'_, VariableDie>>, Error> {
515+
) -> Result<Vec<ContextualDieRef<'_, '_, VariableDie>>, Error> {
516516
let units = self.get_units()?;
517517

518518
let mut found = vec![];
@@ -944,11 +944,11 @@ impl NamespaceHierarchy {
944944
}
945945
}
946946

947-
pub struct ContextualDieRef<'a, T> {
948-
pub debug_info: &'a DebugInformation,
947+
pub struct ContextualDieRef<'node, 'dbg: 'node, T> {
948+
pub debug_info: &'dbg DebugInformation,
949949
pub unit_idx: usize,
950-
pub node: &'a Node,
951-
pub die: &'a T,
950+
pub node: &'node Node,
951+
pub die: &'node T,
952952
}
953953

954954
#[macro_export]
@@ -958,26 +958,26 @@ macro_rules! ctx_resolve_unit_call {
958958
}};
959959
}
960960

961-
impl<'a, T> Clone for ContextualDieRef<'a, T> {
961+
impl<'node, 'dbg, T> Clone for ContextualDieRef<'node, 'dbg, T> {
962962
fn clone(&self) -> Self {
963963
*self
964964
}
965965
}
966966

967-
impl<'a, T> Copy for ContextualDieRef<'a, T> {}
967+
impl<'node, 'dbg, T> Copy for ContextualDieRef<'node, 'dbg, T> {}
968968

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

975-
pub fn unit(&self) -> &'a Unit {
975+
pub fn unit(&self) -> &'dbg Unit {
976976
self.debug_info.unit_ensure(self.unit_idx)
977977
}
978978
}
979979

980-
impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
980+
impl<'ctx> ContextualDieRef<'ctx, 'ctx, FunctionDie> {
981981
pub fn full_name(&self) -> Option<String> {
982982
self.die
983983
.base_attributes
@@ -1007,7 +1007,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
10071007
pub fn local_variables<'this>(
10081008
&'this self,
10091009
pc: GlobalAddress,
1010-
) -> Vec<ContextualDieRef<'ctx, VariableDie>> {
1010+
) -> Vec<ContextualDieRef<'ctx, 'ctx, VariableDie>> {
10111011
let mut result = vec![];
10121012
let mut queue = VecDeque::from(self.node.children.clone());
10131013
while let Some(idx) = queue.pop_front() {
@@ -1033,7 +1033,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
10331033
&'this self,
10341034
pc: GlobalAddress,
10351035
needle: &str,
1036-
) -> Option<ContextualDieRef<'ctx, VariableDie>> {
1036+
) -> Option<ContextualDieRef<'ctx, 'ctx, VariableDie>> {
10371037
let mut queue = VecDeque::from(self.node.children.clone());
10381038
while let Some(idx) = queue.pop_front() {
10391039
let entry = ctx_resolve_unit_call!(self, entry, idx);
@@ -1054,7 +1054,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
10541054
None
10551055
}
10561056

1057-
pub fn parameters(&self) -> Vec<ContextualDieRef<'_, ParameterDie>> {
1057+
pub fn parameters(&self) -> Vec<ContextualDieRef<'ctx, 'ctx, ParameterDie>> {
10581058
let mut result = vec![];
10591059
for &idx in &self.node.children {
10601060
let entry = ctx_resolve_unit_call!(self, entry, idx);
@@ -1139,7 +1139,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
11391139
}
11401140
}
11411141

1142-
impl<'ctx> ContextualDieRef<'ctx, VariableDie> {
1142+
impl<'ctx> ContextualDieRef<'ctx, 'ctx, VariableDie> {
11431143
pub fn ranges(&self) -> Option<&[Range]> {
11441144
if let Some(lb_idx) = self.die.lexical_block_idx {
11451145
let entry = ctx_resolve_unit_call!(self, entry, lb_idx);
@@ -1160,7 +1160,7 @@ impl<'ctx> ContextualDieRef<'ctx, VariableDie> {
11601160
.unwrap_or(true)
11611161
}
11621162

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

11661166
while let Some(p) = mb_parent {
@@ -1181,7 +1181,7 @@ impl<'ctx> ContextualDieRef<'ctx, VariableDie> {
11811181
}
11821182
}
11831183

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

1208-
impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, D> {
1208+
impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, 'ctx, D> {
12091209
pub fn r#type(&self) -> Option<ComplexType> {
12101210
let parser = r#type::TypeParser::new();
12111211
Some(parser.parse(*self, self.die.type_ref()?))
@@ -1227,7 +1227,7 @@ impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, D> {
12271227
evaluator: &evaluator,
12281228
expl_ctx: ctx,
12291229
},
1230-
r#type.root,
1230+
r#type.root(),
12311231
)? as usize;
12321232
let (address, raw_data) =
12331233
weak_error!(eval_result.into_raw_bytes(type_size, AddressKind::MemoryAddress))?;

0 commit comments

Comments
 (0)