forked from fmoessbauer/drace
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stack trace handling was implemented with boost graph library
- Loading branch information
1 parent
37e570e
commit 10206f0
Showing
3 changed files
with
46 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,88 @@ | ||
#ifndef _STACKTRAC_H_ | ||
#define _STACKTRAC_H_ | ||
|
||
#include "xvector.h" | ||
#include <unordered_map> | ||
#include <ipc/DrLock.h> | ||
|
||
#include <boost/graph/adjacency_list.hpp> | ||
|
||
class StackTrace { | ||
typedef boost::property<boost::vertex_name_t, size_t> VertexProperty; | ||
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProperty> stack_tree; | ||
|
||
|
||
xvector<size_t> global_stack; | ||
//holds var_address, pc, stack_length | ||
std::unordered_map<size_t, | ||
std::pair<size_t, size_t>> read_write; | ||
std::unordered_map<size_t, std::pair<size_t, | ||
stack_tree::vertex_descriptor>> read_write; | ||
|
||
stack_tree local_stack; | ||
stack_tree::vertex_descriptor ce; | ||
|
||
std::list<size_t> make_trace(std::pair<size_t, stack_tree::vertex_descriptor> data) | ||
{ | ||
std::list<size_t> this_stack; | ||
|
||
xvector<size_t> make_trace(std::pair<size_t, size_t> data) { | ||
xvector<size_t> this_stack; | ||
this_stack.push_back(data.first); | ||
return this_stack; | ||
stack_tree::vertex_descriptor act_item = data.second; | ||
|
||
/* size_t len = data.second; | ||
const auto begin = global_stack.begin(); | ||
const auto end = begin + len; | ||
xvector<size_t> this_stack(global_stack); | ||
unsigned int flag = 1; // contains_zero(*this_stack); | ||
unsigned int last_pos = 1; | ||
do{ | ||
flag = 1; | ||
for (auto it = this_stack.begin() ; it != this_stack.end(); it++) { | ||
if (*it == 0 && this_stack.size() > 2) { | ||
auto e_it = this_stack.begin(); | ||
this_stack.erase(e_it + (last_pos - 1), e_it + (last_pos +1)); | ||
//last_pos -= 2; | ||
flag = 0; | ||
break; | ||
} | ||
last_pos++; | ||
} | ||
} while (flag == 0 && this_stack.size() > 0); | ||
this_stack.push_front(data.first); | ||
auto map = boost::get(boost::vertex_name_t(), local_stack); | ||
this_stack.push_front(map[act_item]); | ||
|
||
this_stack.push_back(data.first); | ||
return this_stack;*/ | ||
|
||
while (boost::out_degree(act_item, local_stack) != 0) { | ||
auto edge = boost::out_edges(act_item, local_stack); | ||
act_item = (boost::target(*(edge.first), local_stack)); | ||
if (map[act_item] != 0) { | ||
this_stack.push_front(map[act_item]); | ||
} | ||
} | ||
|
||
return this_stack; | ||
} | ||
|
||
|
||
public: | ||
StackTrace():ce(boost::add_vertex(0, local_stack)){} | ||
|
||
|
||
void pop_stack_element() { | ||
global_stack.push_back(0); | ||
|
||
auto edge = boost::out_edges(ce, local_stack); | ||
ce = (boost::target(*(edge.first), local_stack)); | ||
} | ||
|
||
void push_stack_element(size_t element) { | ||
global_stack.push_back(element); | ||
auto temp = boost::add_vertex(VertexProperty(element), local_stack); | ||
boost::add_edge(temp, ce, local_stack); | ||
ce = temp; | ||
} | ||
|
||
///when a var is written or read, it copies the stack and adds the pc of the | ||
///r/w operation to be able to return the stack trace if a race was detected | ||
void set_read_write(size_t addr, size_t pc) { | ||
size_t len = global_stack.size(); | ||
|
||
if (read_write.find(addr) == read_write.end()) { | ||
read_write.insert({ addr, {pc, len} }); | ||
read_write.insert({ addr, {pc, ce} }); | ||
} | ||
else { | ||
read_write.find(addr)->second = { pc, len }; | ||
read_write.find(addr)->second = { pc, ce }; | ||
} | ||
|
||
} | ||
|
||
///returns a stack trace of a clock for handing it over to drace | ||
xvector<size_t> return_stack_trace(size_t address) { | ||
std::list<size_t> return_stack_trace(size_t address) { | ||
|
||
auto it = read_write.find(address); | ||
if (it != read_write.end()) { | ||
auto data = it->second; | ||
xvector<size_t> t = make_trace(data); | ||
std::list<size_t> t = make_trace(data); | ||
return t; | ||
} | ||
else { | ||
//A read/write operation was not tracked correctly -> return empty stack trace | ||
return xvector<size_t>(0); | ||
return std::list<size_t>(0); | ||
} | ||
|
||
} | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters