Skip to content

Commit

Permalink
Elide ALL commands that we are not trying to trace.
Browse files Browse the repository at this point in the history
We were ignoring some of the data, but not all of it. We would
end up adding the commands to the tree, but no observations,
this caused havok with the new memory work, since replaying
those commands would cause OOB memory accesses.
  • Loading branch information
AWoloszyn committed May 25, 2018
1 parent d2417a2 commit dd3cad2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
29 changes: 24 additions & 5 deletions gapii/cc/call_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ CallObserver::CallObserver(SpyBase* spy, CallObserver* parent, uint8_t api)
[](uint8_t* buffer) { return releaseBuffer(buffer); }),
mError(0 /*GL_NO_ERROR*/),
mApi(api),
mShouldTrace(false),
mCurrentThread(core::Thread::current().id()) {

// context_t initialization.
Expand All @@ -69,9 +70,14 @@ CallObserver::CallObserver(SpyBase* spy, CallObserver* parent, uint8_t api)
this->context_t::next_pool_id = &spy->next_pool_id();
this->context_t::globals = nullptr;
this->context_t::arena = reinterpret_cast<arena_t*>(spy->arena());
mShouldTrace = mSpy->should_trace(mApi);

if (parent) {
mEncoderStack.push(mShouldTrace? parent->encoder(): mSpy->nullEncoder());
} else {
mEncoderStack.push(mSpy->getEncoder(mApi));
}

mEncoderStack.push((parent == nullptr) ?
mSpy->getEncoder(mApi) : parent->encoder());
mPendingObservations.setMergeThreshold(MEMORY_MERGE_THRESHOLD);
}

Expand All @@ -83,7 +89,7 @@ core::Arena* CallObserver::arena() const {
}

void CallObserver::read(const void* base, uint64_t size) {
if (!mSpy->should_trace(mApi)) return;
if (!mShouldTrace) return;
if (size > 0) {
uintptr_t start = reinterpret_cast<uintptr_t>(base);
uintptr_t end = start + static_cast<uintptr_t>(size);
Expand All @@ -92,7 +98,7 @@ void CallObserver::read(const void* base, uint64_t size) {
}

void CallObserver::write(const void* base, uint64_t size) {
if (!mSpy->should_trace(mApi)) return;
if (!mShouldTrace) return;
if (size > 0) {
uintptr_t start = reinterpret_cast<uintptr_t>(base);
uintptr_t end = start + static_cast<uintptr_t>(size);
Expand All @@ -101,7 +107,7 @@ void CallObserver::write(const void* base, uint64_t size) {
}

void CallObserver::observePending() {
if (!mSpy->should_trace(mApi)) {
if (!mShouldTrace) {
return;
}
for (auto p : mPendingObservations) {
Expand All @@ -118,18 +124,31 @@ void CallObserver::observePending() {
}

void CallObserver::enter(const ::google::protobuf::Message* cmd) {
if (!mShouldTrace) {
return;
}
mEncoderStack.push(encoder()->group(cmd));
}

void CallObserver::encode(const ::google::protobuf::Message* cmd) {
if (!mShouldTrace) {
return;
}
encoder()->object(cmd);
}

void CallObserver::exit() {
if (!mShouldTrace) {
return;
}
mEncoderStack.pop();
}

void CallObserver::encodeAndDelete(::google::protobuf::Message* cmd) {
if (!mShouldTrace) {
delete cmd;
return;
}
encoder()->object(cmd);
delete cmd;
}
Expand Down
3 changes: 3 additions & 0 deletions gapii/cc/call_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class CallObserver : public context_t {
// The current API that this call-observer is observing.
uint8_t mApi;

// Whether or not we should be tracing with this call observer
bool mShouldTrace;

// The current thread id.
uint64_t mCurrentThread;

Expand Down
4 changes: 4 additions & 0 deletions gapii/cc/spy_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class SpyBase {
return should_trace(api) ? mEncoder : mNullEncoder;
}

std::shared_ptr<gapii::PackEncoder> nullEncoder() {
return mNullEncoder;
}

// Returns true if we should observe application pool.
bool shouldObserveApplicationPool() { return mObserveApplicationPool; }

Expand Down

0 comments on commit dd3cad2

Please sign in to comment.