1 /**************************************************************************
3 * Copyright 2011-2012 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 **************************************************************************/
37 #include "trace_model.hpp"
38 #include "trace_parser.hpp"
49 extern trace::Parser parser;
53 * Similar to alloca(), but implemented with malloc.
67 /* Always return valid address, even when size is zero */
68 size = std::max(size, sizeof(uintptr_t));
70 uintptr_t * buf = static_cast<uintptr_t *>(malloc(sizeof(uintptr_t) + size));
76 next = reinterpret_cast<uintptr_t>(buf);
77 assert((next & 1) == 0);
79 return static_cast<void *>(&buf[1]);
85 return static_cast<T *>(alloc(sizeof(T) * n));
89 * Allocate an array with the same dimensions as the specified value.
93 alloc(const trace::Value *value) {
94 const trace::Array *array = dynamic_cast<const trace::Array *>(value);
96 return alloc<T>(array->size());
98 const trace::Null *null = dynamic_cast<const trace::Null *>(value);
107 * Prevent this pointer from being automatically freed.
113 reinterpret_cast<uintptr_t *>(ptr)[-1] |= 1;
120 uintptr_t temp = *reinterpret_cast<uintptr_t *>(next);
122 bool bind = temp & 1;
126 free(reinterpret_cast<void *>(next));
136 * Output verbosity when retracing files.
138 extern int verbosity;
146 * Add profiling data to the dump when retracing.
148 extern bool profiling;
153 extern bool dumpingState;
156 extern bool doubleBuffer;
157 extern bool coreProfile;
160 std::ostream &warning(trace::Call &call);
163 void ignore(trace::Call &call);
164 void unsupported(trace::Call &call);
167 typedef void (*Callback)(trace::Call &call);
175 struct stringComparer {
176 bool operator() (const char *a, const char *b) const {
177 return strcmp(a, b) < 0;
182 extern const Entry stdc_callbacks[];
187 typedef std::map<const char *, Callback, stringComparer> Map;
190 std::vector<Callback> callbacks;
194 addCallbacks(stdc_callbacks);
197 virtual ~Retracer() {}
199 void addCallback(const Entry *entry);
200 void addCallbacks(const Entry *entries);
202 void retrace(trace::Call &call);
210 addCallbacks(retrace::Retracer &retracer);
213 frameComplete(trace::Call &call);
219 dumpState(std::ostream &os);
222 flushRendering(void);
231 } /* namespace retrace */
233 #endif /* _RETRACE_HPP_ */