1 /**************************************************************************
3 * Copyright 2011 Jose Fonseca
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
27 #include "trace_writer.hpp"
33 class ModelWriter : public Visitor
39 ModelWriter(Writer &_writer) :
47 void visit(Bool *node) {
48 writer.writeBool(node->value);
51 void visit(SInt *node) {
52 writer.writeSInt(node->value);
55 void visit(UInt *node) {
56 writer.writeUInt(node->value);
59 void visit(Float *node) {
60 writer.writeFloat(node->value);
63 void visit(Double *node) {
64 writer.writeDouble(node->value);
67 void visit(String *node) {
68 writer.writeString(node->value);
71 void visit(Enum *node) {
72 writer.writeEnum(node->sig, node->value);
75 void visit(Bitmask *node) {
76 writer.writeBitmask(node->sig, node->value);
79 void visit(Struct *node) {
80 writer.beginStruct(node->sig);
81 for (unsigned i = 0; i < node->sig->num_members; ++i) {
82 _visit(node->members[i]);
87 void visit(Array *node) {
88 writer.beginArray(node->values.size());
89 for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
95 void visit(Blob *node) {
96 writer.writeBlob(node->buf, node->size);
99 void visit(Pointer *node) {
100 writer.writePointer(node->value);
103 void visit(Repr *node) {
105 _visit(node->humanValue);
106 _visit(node->machineValue);
110 void visit(StackFrame* frame) {
111 writer.beginStackFrame();
112 if (frame->module != NULL) {
113 writer.beginStackFrameModule();
114 _visit(frame->module);
115 writer.endStackFrameModule();
117 if (frame->function != NULL) {
118 writer.beginStackFrameFunction();
119 _visit(frame->function);
120 writer.endStackFrameFunction();
122 if (frame->filename != NULL) {
123 writer.beginStackFrameFilename();
124 _visit(frame->filename);
125 writer.endStackFrameFilename();
127 if (frame->linenumber != NULL) {
128 writer.beginStackFrameLinenumber();
129 _visit(frame->linenumber);
130 writer.endStackFrameLinenumber();
132 if (frame->offset != NULL) {
133 writer.beginStackFrameOffset();
134 _visit(frame->offset);
135 writer.endStackFrameOffset();
137 writer.endStackFrame();
140 void visit(Backtrace * backtrace) {
141 writer.beginBacktrace();
142 for (int i =0; i < backtrace->frames.size(); i++) {
143 visit(backtrace->frames[i]);
145 writer.endBacktrace();
148 void visit(Call *call) {
149 unsigned call_no = writer.beginEnter(call->sig, call->thread_id);
150 if (call->backtrace != NULL) {
151 visit(call->backtrace);
153 for (unsigned i = 0; i < call->args.size(); ++i) {
154 if (call->args[i].value) {
156 _visit(call->args[i].value);
161 writer.beginLeave(call_no);
163 writer.beginReturn();
172 void Writer::writeCall(Call *call) {
173 ModelWriter visitor(*this);
178 } /* namespace trace */