Skip to content

Commit a0f0e16

Browse files
committed
refactor(debugger): variable module refactoring
1 parent dd8af00 commit a0f0e16

File tree

38 files changed

+5147
-5265
lines changed

38 files changed

+5147
-5265
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, 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![];
@@ -934,11 +934,11 @@ impl NamespaceHierarchy {
934934
}
935935
}
936936

937-
pub struct ContextualDieRef<'a, T> {
938-
pub debug_info: &'a DebugInformation,
937+
pub struct ContextualDieRef<'node, 'dbg: 'node, T> {
938+
pub debug_info: &'dbg DebugInformation,
939939
pub unit_idx: usize,
940-
pub node: &'a Node,
941-
pub die: &'a T,
940+
pub node: &'node Node,
941+
pub die: &'node T,
942942
}
943943

944944
#[macro_export]
@@ -948,26 +948,26 @@ macro_rules! ctx_resolve_unit_call {
948948
}};
949949
}
950950

951-
impl<'a, T> Clone for ContextualDieRef<'a, T> {
951+
impl<'node, 'dbg, T> Clone for ContextualDieRef<'node, 'dbg, T> {
952952
fn clone(&self) -> Self {
953953
*self
954954
}
955955
}
956956

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

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

965-
pub fn unit(&self) -> &'a Unit {
965+
pub fn unit(&self) -> &'dbg Unit {
966966
self.debug_info.unit_ensure(self.unit_idx)
967967
}
968968
}
969969

970-
impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
970+
impl<'ctx> ContextualDieRef<'ctx, 'ctx, FunctionDie> {
971971
pub fn full_name(&self) -> Option<String> {
972972
self.die
973973
.base_attributes
@@ -997,7 +997,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
997997
pub fn local_variables<'this>(
998998
&'this self,
999999
pc: GlobalAddress,
1000-
) -> Vec<ContextualDieRef<'ctx, VariableDie>> {
1000+
) -> Vec<ContextualDieRef<'ctx, 'ctx, VariableDie>> {
10011001
let mut result = vec![];
10021002
let mut queue = VecDeque::from(self.node.children.clone());
10031003
while let Some(idx) = queue.pop_front() {
@@ -1023,7 +1023,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
10231023
&'this self,
10241024
pc: GlobalAddress,
10251025
needle: &str,
1026-
) -> Option<ContextualDieRef<'ctx, VariableDie>> {
1026+
) -> Option<ContextualDieRef<'ctx, 'ctx, VariableDie>> {
10271027
let mut queue = VecDeque::from(self.node.children.clone());
10281028
while let Some(idx) = queue.pop_front() {
10291029
let entry = ctx_resolve_unit_call!(self, entry, idx);
@@ -1044,7 +1044,7 @@ impl<'ctx> ContextualDieRef<'ctx, FunctionDie> {
10441044
None
10451045
}
10461046

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

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

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

11561156
while let Some(p) = mb_parent {
@@ -1171,7 +1171,7 @@ impl<'ctx> ContextualDieRef<'ctx, VariableDie> {
11711171
}
11721172
}
11731173

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

1198-
impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, D> {
1198+
impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, 'ctx, D> {
11991199
pub fn r#type(&self) -> Option<ComplexType> {
12001200
let parser = r#type::TypeParser::new();
12011201
Some(parser.parse(*self, self.die.type_ref()?))
@@ -1217,7 +1217,7 @@ impl<'ctx, D: AsAllocatedData> ContextualDieRef<'ctx, D> {
12171217
evaluator: &evaluator,
12181218
expl_ctx: ctx,
12191219
},
1220-
r#type.root,
1220+
r#type.root(),
12211221
)? as usize;
12221222
let (address, raw_data) =
12231223
weak_error!(eval_result.into_raw_bytes(type_size, AddressKind::MemoryAddress))?;

0 commit comments

Comments
 (0)