summaryrefslogtreecommitdiff
path: root/trace_parser.hpp
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-11-25 16:14:45 +0000
committerJosé Fonseca <jfonseca@vmware.com>2010-11-25 16:14:45 +0000
commit3495713d02b8f9ef28981ac54c22c4c8ee9b2299 (patch)
treea5b6cf7481716429c67e1d0167eb05447a1b84be /trace_parser.hpp
parentf4b071e057378a0e8cd0a785a5a396f3bb44a59a (diff)
Fix multithreaded reentrancy.
Happens on windows when SetPixelFormat is called...
Diffstat (limited to 'trace_parser.hpp')
-rw-r--r--trace_parser.hpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/trace_parser.hpp b/trace_parser.hpp
index 6a2c92f..850dc8d 100644
--- a/trace_parser.hpp
+++ b/trace_parser.hpp
@@ -53,9 +53,15 @@ protected:
typedef std::map<size_t, std::string> namemap;
namemap names;
+ typedef std::map<unsigned, Call *> callmap;
+ callmap calls;
+
+ unsigned next_call_no;
+
public:
Parser() {
file = NULL;
+ next_call_no = 0;
}
~Parser() {
@@ -87,13 +93,52 @@ public:
}
Call *parse_call(void) {
+ do {
+ int c = read_byte();
+ switch(c) {
+ case Trace::EVENT_ENTER:
+ parse_enter();
+ break;
+ case Trace::EVENT_LEAVE:
+ return parse_leave();
+ case Trace::EVENT_MESSAGE:
+ std::cerr << "message: " << read_string() << "\n";
+ break;
+ default:
+ std::cerr << "error: unknown call detail " << c << "\n";
+ assert(0);
+ /* fallthrough */
+ case -1:
+ return NULL;
+ }
+ } while(true);
+ }
+
+ void parse_enter(void) {
Call *call = new Call;
+ call->no = next_call_no++;
call->name = read_name();
+ parse_call_details(call);
+ calls[call->no] = call;
+ }
+
+ Call *parse_leave(void) {
+ unsigned call_no = read_uint();
+ Call *call = calls[call_no];
+ assert(call);
+ if (!call) {
+ return NULL;
+ }
+ parse_call_details(call);
+ return call;
+ }
+
+ void parse_call_details(Call *call) {
do {
int c = read_byte();
switch(c) {
case Trace::CALL_END:
- return call;
+ return;
case Trace::CALL_ARG:
parse_arg(call);
break;
@@ -105,8 +150,7 @@ public:
assert(0);
/* fallthrough */
case -1:
- delete call;
- return NULL;
+ return;
}
} while(true);
}