Skip to content

Commit

Permalink
added a function to add a stack trace. need to figure outhow to get g…
Browse files Browse the repository at this point in the history
…roup id's into the stacktrie
  • Loading branch information
matthew-liu801 committed Jun 28, 2023
1 parent 23abae9 commit d0b4a15
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions fhe-debugger/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,74 @@ use radix_trie::{Trie, SubTrieMut, SubTrie};
/**
* Stores information about stack calls.
*/
struct StackFrame {
pub struct StackFrame {
/**
* The function name.
*/
callee: String,
pub callee: String,

/**
* The file the function is defined in.
*/
callee_file: String,
pub callee_file: String,

/**
* The file the function is called from.
*/
caller_file: String,
pub caller_file: String,

/**
* The line the function is called from.
*/
caller_line: u64,
pub caller_line: u64,
}
/**
* A wrapper struct to efficiently store stack traces for each program node,
*/
struct StackTrie<u64, StackFrame> {
pub struct StackTrie {
/**
* Stores stack frames as nodes.
*/
trie: Trie<u64, StackFrame>,
pub trie: Trie<u64, StackFrame>,
/**
* Allows for indexing into a stack frame given a `group_id` associated with a program node.
*/
group_id: u64
pub group_id: u64
}

impl StackTrie {

fn new() {
Trie::new()
/**
* Creates an empty StackTrie.
*/
fn new() -> Self {
StackTrie {
trie: Trie::new(),
group_id: 0
}
}

/**
* Returns a sequence of StackFrames given a node in the StackTrie.
*/
fn get_stack_trace(&self) -> Vec<StackFrame> {
let ancestors = Vec::<StackFrame>::new();
let ancestor: SubTrie<u64, StackFrame> = self.get_ancestor();
while let Some(ancestor) = ancestor {
ancestors.push(ancestor);
ancestor = ancestor.get_ancestor();
let mut ancestors = Vec::<StackFrame>::new();
let mut ancestor = self.trie.subtrie(&self.group_id);
while let Some(subtrie) = ancestor {
ancestors.push(*subtrie.value().unwrap());
ancestor = self.trie.get_ancestor(&self.group_id);
}
ancestors
}
/**
* Adds a stack trace to the StackTrie.
*/
fn add_stack_trace(&self, trace: Vec::<StackFrame>) -> Self {

let mut current = self.trie.subtrie_mut(self.group_id).unwrap();

for frame in trace.iter() {
// TODO: Insert with a group ID, not 0
current = current.insert(0, frame);
}
ancestors
}
}

0 comments on commit d0b4a15

Please sign in to comment.