Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ keywords = ["debugging", "development-tools"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
base64 = "0.22.1"
num-traits = "0.2"
num-derive = "0.4"
serde = { version = "1.0", features = ["derive"] }
Expand Down
13 changes: 13 additions & 0 deletions src/base64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use base64::Engine;
use serde::{Deserialize, Serialize};
use serde::{Deserializer, Serializer};

pub fn serialize<S: Serializer>(v: &Vec<u8>, s: S) -> Result<S::Ok, S::Error> {
let base64 = base64::engine::general_purpose::STANDARD.encode(v);
String::serialize(&base64, s)
}

pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<u8>, D::Error> {
let base64 = String::deserialize(d)?;
base64::engine::general_purpose::STANDARD.decode(base64.as_bytes()).map_err(serde::de::Error::custom)
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! The format is documented in `docs/` and the README.
mod tracer;
mod types;
mod base64;
pub use crate::tracer::{Tracer, NONE_TYPE_ID, NONE_VALUE};
pub use crate::types::*;

Expand Down
20 changes: 8 additions & 12 deletions src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,33 +248,29 @@ impl Tracer {

pub fn bind_variable(&mut self, variable_name: &str, place: Place) {
let variable_id = self.ensure_variable_id(variable_name);
self.events.push(TraceLowLevelEvent::BindVariable(crate::BindVariableRecord {
variable_id,
place,
}));
self.events
.push(TraceLowLevelEvent::BindVariable(crate::BindVariableRecord { variable_id, place }));
}

pub fn drop_variables(&mut self, variable_names: &[String]) {
let variable_ids : Vec<VariableId> = variable_names
let variable_ids: Vec<VariableId> = variable_names
.to_vec()
.iter()
.map(| variable_name | self.ensure_variable_id(variable_name))
.map(|variable_name| self.ensure_variable_id(variable_name))
.collect();
self.events.push(TraceLowLevelEvent::DropVariables(
variable_ids
))
self.events.push(TraceLowLevelEvent::DropVariables(variable_ids))
}

pub fn simple_rvalue(&mut self, variable_name: &str) -> RValue {
let variable_id = self.ensure_variable_id(variable_name);
RValue::Simple(variable_id)
}

pub fn compound_rvalue(&mut self, variable_dependencies: &[String]) -> RValue {
let variable_ids : Vec<VariableId> = variable_dependencies
let variable_ids: Vec<VariableId> = variable_dependencies
.to_vec()
.iter()
.map(| variable_dependency | self.ensure_variable_id(variable_dependency))
.map(|variable_dependency| self.ensure_variable_id(variable_dependency))
.collect();
RValue::Compound(variable_ids)
}
Expand Down
7 changes: 7 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::PathBuf;
use num_derive::FromPrimitive;
use serde::{Deserialize, Serialize};
use serde_repr::*;
use crate::base64;

// currently, we do assume that we record the whole program
// so, we try to include minimal amount of data,
Expand Down Expand Up @@ -386,6 +387,12 @@ pub enum ValueRecord {
Cell {
place: Place,
},
BigInt {
#[serde(with = "base64")]
b: Vec<u8>, // Base64 encoded bytes of a big-endian unsigned integer
negative: bool,
type_id: TypeId,
},
}

/// Categories of types recorded in the trace.
Expand Down