Skip to content

Commit

Permalink
refactor: rename variable::select::Expression to variable::select::DQE
Browse files Browse the repository at this point in the history
  • Loading branch information
godzie44 committed Apr 16, 2024
1 parent 265e74d commit a78ee29
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 216 deletions.
12 changes: 6 additions & 6 deletions src/debugger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::debugger::error::Error::{
use crate::debugger::process::{Child, Installed};
use crate::debugger::register::{DwarfRegisterMap, Register, RegisterMap};
use crate::debugger::step::StepResult;
use crate::debugger::variable::select::{Expression, VariableSelector};
use crate::debugger::variable::select::{VariableSelector, DQE};
use crate::debugger::variable::VariableIR;
use crate::debugger::Error::Syscall;
use crate::oracle::Oracle;
Expand Down Expand Up @@ -782,7 +782,7 @@ impl Debugger {

let evaluator = variable::select::SelectExpressionEvaluator::new(
self,
Expression::Variable(VariableSelector::Any),
DQE::Variable(VariableSelector::Any),
);
evaluator.evaluate()
}
Expand All @@ -793,7 +793,7 @@ impl Debugger {
/// # Arguments
///
/// * `select_expr`: data query expression
pub fn read_variable(&self, select_expr: Expression) -> Result<Vec<VariableIR>, Error> {
pub fn read_variable(&self, select_expr: DQE) -> Result<Vec<VariableIR>, Error> {
disable_when_not_stared!(self);
let evaluator = variable::select::SelectExpressionEvaluator::new(self, select_expr);
evaluator.evaluate()
Expand All @@ -805,7 +805,7 @@ impl Debugger {
/// # Arguments
///
/// * `select_expr`: data query expression
pub fn read_variable_names(&self, select_expr: Expression) -> Result<Vec<String>, Error> {
pub fn read_variable_names(&self, select_expr: DQE) -> Result<Vec<String>, Error> {
disable_when_not_stared!(self);
let evaluator = variable::select::SelectExpressionEvaluator::new(self, select_expr);
evaluator.evaluate_names()
Expand All @@ -817,7 +817,7 @@ impl Debugger {
/// # Arguments
///
/// * `select_expr`: data query expression
pub fn read_argument(&self, select_expr: Expression) -> Result<Vec<VariableIR>, Error> {
pub fn read_argument(&self, select_expr: DQE) -> Result<Vec<VariableIR>, Error> {
disable_when_not_stared!(self);
let evaluator = variable::select::SelectExpressionEvaluator::new(self, select_expr);
evaluator.evaluate_on_arguments()
Expand All @@ -829,7 +829,7 @@ impl Debugger {
/// # Arguments
///
/// * `select_expr`: data query expression
pub fn read_argument_names(&self, select_expr: Expression) -> Result<Vec<String>, Error> {
pub fn read_argument_names(&self, select_expr: DQE) -> Result<Vec<String>, Error> {
disable_when_not_stared!(self);
let evaluator = variable::select::SelectExpressionEvaluator::new(self, select_expr);
evaluator.evaluate_on_arguments_names()
Expand Down
78 changes: 33 additions & 45 deletions src/debugger/variable/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,22 @@ impl Literal {
}
}

/// Data query expression.
/// List of operations for select variables and their properties.
/// Expression can be parsed from an input string like `*(*variable1.field2)[1]` (see debugger::command module)
///
/// Supported operations are: dereference, get element by index, get field by name, make slice from pointer.
/// Supported operations are: dereference, get an element by index, get field by name, make slice from a pointer.
#[derive(Debug, PartialEq, Clone)]
pub enum Expression {
pub enum DQE {
Variable(VariableSelector),
PtrCast(usize, String),
Field(Box<Expression>, String),
Index(Box<Expression>, Literal),
Slice(Box<Expression>, Option<usize>, Option<usize>),
Parentheses(Box<Expression>),
Deref(Box<Expression>),
Field(Box<DQE>, String),
Index(Box<DQE>, Literal),
Slice(Box<DQE>, Option<usize>, Option<usize>),
Deref(Box<DQE>),
}

impl Expression {
impl DQE {
/// Return boxed expression.
pub fn boxed(self) -> Box<Self> {
Box::new(self)
Expand All @@ -132,7 +132,7 @@ impl Expression {
/// Evaluate `Expression` at current breakpoint (for current debugee location).
pub struct SelectExpressionEvaluator<'a> {
debugger: &'a Debugger,
expression: Expression,
expression: DQE,
}

macro_rules! type_from_cache {
Expand All @@ -151,7 +151,7 @@ macro_rules! type_from_cache {
}

impl<'a> SelectExpressionEvaluator<'a> {
pub fn new(debugger: &'a Debugger, expression: Expression) -> Self {
pub fn new(debugger: &'a Debugger, expression: DQE) -> Self {
Self {
debugger,
expression,
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<'a> SelectExpressionEvaluator<'a> {
/// This method will panic if select expression contain any operators excluding a variable selector.
pub fn evaluate_names(&self) -> Result<Vec<String>, Error> {
match &self.expression {
Expression::Variable(selector) => {
DQE::Variable(selector) => {
let vars = self.extract_variable_by_selector(selector)?;
Ok(vars
.into_iter()
Expand All @@ -246,11 +246,11 @@ impl<'a> SelectExpressionEvaluator<'a> {
}
}

fn evaluate_inner(&self, expression: &Expression) -> Result<Vec<VariableIR>, Error> {
fn evaluate_inner(&self, expression: &DQE) -> Result<Vec<VariableIR>, Error> {
// evaluate variable one by one in `evaluate_single_variable` method
// here just filter variables
match expression {
Expression::Variable(selector) => {
DQE::Variable(selector) => {
let vars = self.extract_variable_by_selector(selector)?;
let mut type_cache = self.debugger.type_cache.borrow_mut();

Expand All @@ -262,14 +262,11 @@ impl<'a> SelectExpressionEvaluator<'a> {
})
.collect())
}
Expression::PtrCast(_, target_type_name) => {
self.evaluate_from_ptr_cast(target_type_name)
}
Expression::Field(expr, _)
| Expression::Index(expr, _)
| Expression::Slice(expr, _, _)
| Expression::Parentheses(expr)
| Expression::Deref(expr) => self.evaluate_inner(expr),
DQE::PtrCast(_, target_type_name) => self.evaluate_from_ptr_cast(target_type_name),
DQE::Field(expr, _)
| DQE::Index(expr, _)
| DQE::Slice(expr, _, _)
| DQE::Deref(expr) => self.evaluate_inner(expr),
}
}

Expand All @@ -296,7 +293,7 @@ impl<'a> SelectExpressionEvaluator<'a> {
/// Same as [`SelectExpressionEvaluator::evaluate_names`] but for function arguments.
pub fn evaluate_on_arguments_names(&self) -> Result<Vec<String>, Error> {
match &self.expression {
Expression::Variable(selector) => {
DQE::Variable(selector) => {
let expl_ctx_loc = self.debugger.exploration_ctx().location();
let current_function = self
.debugger
Expand Down Expand Up @@ -328,12 +325,9 @@ impl<'a> SelectExpressionEvaluator<'a> {
self.evaluate_on_arguments_inner(&self.expression)
}

fn evaluate_on_arguments_inner(
&self,
expression: &Expression,
) -> Result<Vec<VariableIR>, Error> {
fn evaluate_on_arguments_inner(&self, expression: &DQE) -> Result<Vec<VariableIR>, Error> {
match expression {
Expression::Variable(selector) => {
DQE::Variable(selector) => {
let expl_ctx_loc = self.debugger.exploration_ctx().location();
let debugee = &self.debugger.debugee;
let current_function = debugee
Expand All @@ -360,20 +354,17 @@ impl<'a> SelectExpressionEvaluator<'a> {
})
.collect())
}
Expression::PtrCast(_, target_type_name) => {
self.evaluate_from_ptr_cast(target_type_name)
}
Expression::Field(expr, _)
| Expression::Index(expr, _)
| Expression::Slice(expr, _, _)
| Expression::Parentheses(expr)
| Expression::Deref(expr) => self.evaluate_on_arguments_inner(expr),
DQE::PtrCast(_, target_type_name) => self.evaluate_from_ptr_cast(target_type_name),
DQE::Field(expr, _)
| DQE::Index(expr, _)
| DQE::Slice(expr, _, _)
| DQE::Deref(expr) => self.evaluate_on_arguments_inner(expr),
}
}

fn evaluate_single_variable(
&self,
expression: &Expression,
expression: &DQE,
variable_die: &ContextualDieRef<impl AsAllocatedData>,
r#type: &ComplexType,
) -> Option<VariableIR> {
Expand All @@ -386,7 +377,7 @@ impl<'a> SelectExpressionEvaluator<'a> {
};

match expression {
Expression::Variable(_) => Some(parser.parse(
DQE::Variable(_) => Some(parser.parse(
evaluation_context,
VariableIdentity::from_variable_die(variable_die),
variable_die.read_value(
Expand All @@ -395,30 +386,27 @@ impl<'a> SelectExpressionEvaluator<'a> {
r#type,
),
)),
Expression::PtrCast(addr, ..) => {
DQE::PtrCast(addr, ..) => {
let value = Bytes::copy_from_slice(&(*addr).to_le_bytes());
Some(parser.parse(
evaluation_context,
VariableIdentity::new(NamespaceHierarchy::default(), None),
Some(value),
))
}
Expression::Field(expr, field) => {
DQE::Field(expr, field) => {
let var = self.evaluate_single_variable(expr, variable_die, r#type)?;
var.field(field)
}
Expression::Index(expr, idx) => {
DQE::Index(expr, idx) => {
let var = self.evaluate_single_variable(expr, variable_die, r#type)?;
var.index(idx)
}
Expression::Slice(expr, left, right) => {
DQE::Slice(expr, left, right) => {
let var = self.evaluate_single_variable(expr, variable_die, r#type)?;
var.slice(evaluation_context, &parser, *left, *right)
}
Expression::Parentheses(expr) => {
self.evaluate_single_variable(expr, variable_die, r#type)
}
Expression::Deref(expr) => {
DQE::Deref(expr) => {
let var = self.evaluate_single_variable(expr, variable_die, r#type)?;
var.deref(evaluation_context, &parser)
}
Expand Down
24 changes: 12 additions & 12 deletions src/oracle/builtin/tokio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::debugger::unwind::{Backtrace, FrameSpan};
use crate::debugger::variable::select::{Expression, VariableSelector};
use crate::debugger::variable::select::{VariableSelector, DQE};
use crate::debugger::variable::{ScalarVariable, StructVariable, SupportedScalar, VariableIR};
use crate::debugger::CreateTransparentBreakpointRequest;
use crate::debugger::{Debugger, Error};
Expand Down Expand Up @@ -306,8 +306,8 @@ impl TokioOracle {
.filter(|(_, task)| task.dropped_at.is_none())
.for_each(|(_, task)| {
if let Some(ptr) = task.ptr {
let var = dbg.read_variable(Expression::Deref(
Expression::PtrCast(
let var = dbg.read_variable(DQE::Deref(
DQE::PtrCast(
ptr as usize,
"*const tokio::runtime::task::core::Header".to_string(),
)
Expand Down Expand Up @@ -339,9 +339,9 @@ impl TokioOracle {

/// Read `self` function argument, interpret it as a task and return (task_id, task pointer) pair.
fn get_header_from_self(dbg: &mut Debugger) -> Result<Option<(u64, *const ())>, Error> {
let header_pointer_expr = Expression::Field(
Expression::Field(
Expression::Variable(VariableSelector::Name {
let header_pointer_expr = DQE::Field(
DQE::Field(
DQE::Variable(VariableSelector::Name {
var_name: "self".to_string(),
only_local: true,
})
Expand All @@ -357,10 +357,10 @@ impl TokioOracle {
return Ok(None);
};

let id_offset_args = dbg.read_argument(Expression::Field(
Expression::Deref(
Expression::Field(
Expression::Deref(header_pointer_expr.boxed()).boxed(),
let id_offset_args = dbg.read_argument(DQE::Field(
DQE::Deref(
DQE::Field(
DQE::Deref(header_pointer_expr.boxed()).boxed(),
"vtable".to_string(),
)
.boxed(),
Expand Down Expand Up @@ -408,8 +408,8 @@ impl TokioOracle {
}

fn on_new(&self, debugger: &mut Debugger) -> Result<(), Error> {
let id_args = debugger.read_argument(Expression::Field(
Box::new(Expression::Variable(VariableSelector::Name {
let id_args = debugger.read_argument(DQE::Field(
Box::new(DQE::Variable(VariableSelector::Name {
var_name: "id".to_string(),
only_local: true,
})),
Expand Down
4 changes: 2 additions & 2 deletions src/ui/command/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::debugger::variable::select::Expression;
use crate::debugger::variable::select::DQE;
use crate::debugger::variable::VariableIR;
use crate::debugger::Debugger;
use crate::ui::command;
Expand All @@ -12,7 +12,7 @@ impl<'a> Handler<'a> {
Self { dbg: debugger }
}

pub fn handle(&self, select_expression: Expression) -> command::CommandResult<Vec<VariableIR>> {
pub fn handle(&self, select_expression: DQE) -> command::CommandResult<Vec<VariableIR>> {
Ok(self.dbg.read_argument(select_expression)?)
}
}
6 changes: 3 additions & 3 deletions src/ui/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod symbol;
pub mod thread;
pub mod variables;

use crate::debugger::variable::select::Expression;
use crate::debugger::variable::select::DQE;
use crate::debugger::Error;

#[derive(thiserror::Error, Debug)]
Expand All @@ -42,8 +42,8 @@ pub type CommandResult<T> = Result<T, CommandError>;
/// External commands that can be processed by the debugger.
#[derive(Debug, Clone)]
pub enum Command {
PrintVariables(Expression),
PrintArguments(Expression),
PrintVariables(DQE),
PrintArguments(DQE),
PrintBacktrace(backtrace::Command),
Continue,
Frame(frame::Command),
Expand Down
Loading

0 comments on commit a78ee29

Please sign in to comment.