From 79080bdf532d1fb445432b973df99ba9b068de4b Mon Sep 17 00:00:00 2001 From: strange Date: Fri, 12 Feb 2010 00:46:47 -0700 Subject: [PATCH] I just realized something . . . . . . BiTreeNodes don't actually have to store their addresses, do they? I suppose it depends on if I'm going to be doing any lookups from subtree heads, rather than entire tree heads . . . I don't think I am, to be honest. If that's true, then I can get rid of a huge hassle . . . which, I think, is a good idea. Watch me eat those words in, hmm. Three days. --- gui/src/data/NetworkReceiver.cpp | 15 ++++----- gui/src/session/Session.cpp | 1 + gui/src/storage/AllocEvent.cpp | 72 +++++++++++++++++----------------------- gui/src/storage/BiTreeNode.cpp | 2 ++ gui/src/storage/BiTreeNode.h | 10 +++++- gui/src/storage/Snapshot.cpp | 2 +- gui/src/storage/Snapshot.h | 3 ++ monitor/src/event/BlockEvent.cpp | 2 ++ 8 files changed, 56 insertions(+), 51 deletions(-) rewrite gui/src/storage/AllocEvent.cpp (61%) diff --git a/gui/src/data/NetworkReceiver.cpp b/gui/src/data/NetworkReceiver.cpp index 6786790..00bc335 100644 --- a/gui/src/data/NetworkReceiver.cpp +++ b/gui/src/data/NetworkReceiver.cpp @@ -21,15 +21,14 @@ void NetworkReceiver::run() { quint64 NetworkReceiver::pop_quint64() { quint64 ret = 0; - /* Reserve space for one 64-bit integer . . . */ - ret |= quint64(unprocessed.at(7)) >> 56; - ret |= quint64(unprocessed.at(6)) >> 48; - ret |= quint64(unprocessed.at(5)) >> 40; - ret |= quint64(unprocessed.at(4)) >> 32; - ret |= quint64(unprocessed.at(3)) >> 24; - ret |= quint64(unprocessed.at(2)) >> 16; - ret |= quint64(unprocessed.at(1)) >> 8; ret |= unprocessed.at(0); + ret |= quint64(quint8(unprocessed.at(1))) << 8; + ret |= quint64(quint8(unprocessed.at(2))) << 16; + ret |= quint64(quint8(unprocessed.at(3))) << 24; + ret |= quint64(quint8(unprocessed.at(4))) << 32; + ret |= quint64(quint8(unprocessed.at(5))) << 40; + ret |= quint64(quint8(unprocessed.at(6))) << 48; + ret |= quint64(quint8(unprocessed.at(7))) << 56; unprocessed.remove(0, 8); return ret; } diff --git a/gui/src/session/Session.cpp b/gui/src/session/Session.cpp index 99f2f6a..4ca5a88 100644 --- a/gui/src/session/Session.cpp +++ b/gui/src/session/Session.cpp @@ -4,6 +4,7 @@ Session::Session(QWidget *parent, DataSource *data_source) : QWidget(parent), data_source(data_source) { data_receiver = data_source->spawn_receiver(this); + connect(data_receiver, SIGNAL(event_received(Event*)), SLOT(handle_event(Event*))); data_receiver->start(); current_memory = snapshot_list.append_snapshot(); } diff --git a/gui/src/storage/AllocEvent.cpp b/gui/src/storage/AllocEvent.cpp dissimilarity index 61% index f68332d..9145f3a 100644 --- a/gui/src/storage/AllocEvent.cpp +++ b/gui/src/storage/AllocEvent.cpp @@ -1,41 +1,31 @@ -#include "AllocEvent.h" -#include "StorageFactory.h" - -/* NOTE: this should be redefined somewhere, perhaps . . . assumes 64-bit address space . . . */ -const MemoryAddress ADDRESS_MAX = 0xffffffffffffffff; - -void AllocEvent::apply_to(Snapshot *snapshot) { - qDebug("Asked to apply AllocEvent to snapshot #%i . . .", snapshot->get_snapshot_id()); - /* If the snapshot block tree head is NULL, then don't do anything special . . . */ - if(snapshot->get_head_node() == NULL) { - snapshot->set_head_node(StorageFactory::new_node(snapshot->get_snapshot_id(), (ADDRESS_MAX/2)+1)); - /* Now just chain onto the other code . . . */ - } - - BiTreeNode *node = snapshot->get_head_node(); - /* Find the correct node to split . . . */ - while(true) { - if(node->get_left() && get_address() < node->get_address()) - node = node->get_left(); - else if(node->get_right() && get_address() >= node->get_address()) - node = node->get_right(); - else break; - } - - BiTreeNode *n = NULL; - - Block *block = StorageFactory::new_block(address, size); - - /* Now add the new block into the correct spot . . . */ - MemoryAddress diff = 0; - if(node->get_parent()) diff = node->get_parent()->get_address() - node->get_address(); - else diff = node->get_address(); - diff /= 2; - /* First, handle the special cases of a NULL left/right */ - - if(node->get_left() == NULL && address < node->get_address()) { - n = StorageFactory::new_node(snapshot->get_snapshot_id(), address); - node->mark_changed(snapshot->get_snapshot_id()); - } - -} +#include + +#include "AllocEvent.h" +#include "StorageFactory.h" + +/* NOTE: this should be redefined somewhere, perhaps . . . assumes 64-bit address space . . . */ +const MemoryAddress ADDRESS_MAX = 0xffffffffffffffff; + +void AllocEvent::apply_to(Snapshot *snapshot) { + qDebug("Asked to apply AllocEvent to snapshot #%li . . .", (long int)snapshot->get_snapshot_id()); + /* If the snapshot block tree head is NULL, then don't do anything special . . . */ + if(snapshot->get_head_node() == NULL) { + snapshot->set_head_node(StorageFactory::new_node(snapshot->get_snapshot_id(), (ADDRESS_MAX/2)+1)); + /* Now just chain onto the other code . . . */ + } + + BiTreeNode *node = snapshot->get_head_node(); + + quint8 max_depth = snapshot->get_max_tree_depth(); + qDebug("MemoryAddress is %p", address); + for(quint8 depth = 0; depth < max_depth; depth ++) { + bool bit = MemoryAddress(address << depth) & 0x01; + qDebug("%dth bit is %s", depth, bit?"true":"false"); + if(bit) { + if(node->get_right() == NULL) { + node = node->mark_changed(snapshot->get_snapshot_id()); + node->set_right(StorageFactory::new_node(snapshot->get_snapshot_id())); + } + } + } +} diff --git a/gui/src/storage/BiTreeNode.cpp b/gui/src/storage/BiTreeNode.cpp index a4dcbc4..9775727 100644 --- a/gui/src/storage/BiTreeNode.cpp +++ b/gui/src/storage/BiTreeNode.cpp @@ -12,7 +12,9 @@ BiTreeNode *BiTreeNode::mark_changed(SnapshotID by_snapshot) { if(snapshot_id == by_snapshot) return this; BiTreeNode *new_node = new BiTreeNode(by_snapshot, address); new_node->left = left; + if(left) left->parent = new_node; new_node->right = right; + if(right) right->parent = new_node; new_node->end = end; new_node->block_list = block_list; new_node->parent = parent->mark_changed(by_snapshot); diff --git a/gui/src/storage/BiTreeNode.h b/gui/src/storage/BiTreeNode.h index 5e02d29..c4917f1 100644 --- a/gui/src/storage/BiTreeNode.h +++ b/gui/src/storage/BiTreeNode.h @@ -13,7 +13,15 @@ private: MemoryAddress address; SnapshotID snapshot_id; - BiTreeNode *left, *right, *parent; + /** The left node in the tree, e.g. the node that stores the blocks with + lower addresses than @a address */ + BiTreeNode *left; + /** The right node in the tree, e.g. the node that stores the blocks with + higher addresses than @a address */ + BiTreeNode *right; + /** The immediate parent in the tree. In this case, this is hijacked to + reference the most recent version of the parent. */ + BiTreeNode *parent; QList block_list; public: diff --git a/gui/src/storage/Snapshot.cpp b/gui/src/storage/Snapshot.cpp index dde93a4..168d2a5 100644 --- a/gui/src/storage/Snapshot.cpp +++ b/gui/src/storage/Snapshot.cpp @@ -1,6 +1,6 @@ #include "Snapshot.h" -Snapshot::Snapshot(SnapshotID snapshot_id) : snapshot_id(snapshot_id), head_node(NULL) { +Snapshot::Snapshot(SnapshotID snapshot_id) : snapshot_id(snapshot_id), head_node(NULL), max_tree_depth(56) { } diff --git a/gui/src/storage/Snapshot.h b/gui/src/storage/Snapshot.h index 66e8b0f..b3f83a0 100644 --- a/gui/src/storage/Snapshot.h +++ b/gui/src/storage/Snapshot.h @@ -10,6 +10,7 @@ private: SnapshotID snapshot_id; BiTreeNode *head_node; EventList event_list; + quint8 max_tree_depth; public: Snapshot(SnapshotID snapshot_id); virtual ~Snapshot(); @@ -20,6 +21,8 @@ public: void set_head_node(BiTreeNode *new_head) { head_node = new_head; } void add_event(Event *event) { event_list.add_event(event); } + + quint8 get_max_tree_depth() { return max_tree_depth; } }; #endif diff --git a/monitor/src/event/BlockEvent.cpp b/monitor/src/event/BlockEvent.cpp index 0cdb016..9fdd6c6 100644 --- a/monitor/src/event/BlockEvent.cpp +++ b/monitor/src/event/BlockEvent.cpp @@ -20,6 +20,8 @@ Block *BlockEvent::serialize() { switch(get_block_type()) { case ALLOC_EVENT: + std::cout << "first byte of address is " << std::hex << (address & 0xff) << std::endl; + std::cout << "second byte of address is " << std::hex << ((address & 0xff00) >> 8) << std::endl; serialized->push_word(get_size()); break; case REALLOC_EVENT: -- 2.11.4.GIT