#include <stdlib.h>
#include <string.h>
-#include <map>
+#include <vector>
#include <zlib.h>
Write(str, len);
}
-typedef std::map<const char *, size_t> namemap;
-static namemap names;
-
-static inline void
-WriteName(const char *name) {
- namemap::iterator it = names.find(name);
- if (it == names.end()) {
- size_t name_id = names.size();
- WriteUInt(name_id);
- WriteString(name);
- names[name] = name_id;
- } else {
- WriteUInt(it->second);
- }
-}
-
void Open(void) {
if (!g_gzFile) {
_Open("trace");
static unsigned call_no = 0;
-static std::map<Id, bool> functions;
-static std::map<Id, bool> bitmasks;
+inline bool lookup(std::vector<bool> &map, size_t index) {
+ if (index >= map.size()) {
+ map.resize(index + 1);
+ return false;
+ } else {
+ return map[index];
+ }
+}
+
+static std::vector<bool> functions;
+static std::vector<bool> structs;
+static std::vector<bool> enums;
+static std::vector<bool> bitmasks;
unsigned BeginEnter(const FunctionSig &function) {
Open();
WriteByte(Trace::EVENT_ENTER);
WriteUInt(function.id);
- if (!functions[function.id]) {
+ if (!lookup(functions, function.id)) {
WriteString(function.name);
WriteUInt(function.num_args);
for (unsigned i = 0; i < function.num_args; ++i) {
WriteUInt(length);
}
-void BeginStruct(size_t length) {
+void BeginStruct(const StructSig *sig) {
WriteByte(Trace::TYPE_STRUCT);
- WriteUInt(length);
-}
-
-void BeginMember(const char *name) {
- WriteName(name);
-}
-
-void BeginBitmask(void) {
- WriteByte(Trace::TYPE_BITMASK);
-}
-
-void EndBitmask(void) {
- WriteByte(Trace::TYPE_NULL);
+ WriteUInt(sig->id);
+ if (!lookup(structs, sig->id)) {
+ WriteString(sig->name);
+ WriteUInt(sig->num_members);
+ for (unsigned i = 0; i < sig->num_members; ++i) {
+ WriteString(sig->members[i]);
+ }
+ structs[sig->id] = true;
+ }
}
void LiteralBool(bool value) {
}
}
-void LiteralNamedConstant(const char *name, long long value) {
- WriteByte(Trace::TYPE_CONST);
- WriteName(name);
- LiteralSInt(value);
+void LiteralEnum(const EnumSig *sig) {
+ WriteByte(Trace::TYPE_ENUM);
+ WriteUInt(sig->id);
+ if (!lookup(enums, sig->id)) {
+ WriteString(sig->name);
+ LiteralSInt(sig->value);
+ enums[sig->id] = true;
+ }
}
void LiteralBitmask(const BitmaskSig &bitmask, unsigned long long value) {
WriteByte(Trace::TYPE_BITMASK);
WriteUInt(bitmask.id);
- if (!bitmasks[bitmask.id]) {
+ if (!lookup(bitmasks, bitmask.id)) {
WriteUInt(bitmask.count);
for (unsigned i = 0; i < bitmask.count; ++i) {
WriteString(bitmask.values[i].name);
}
} /* namespace Trace */
+
+
+#ifdef WIN32
+
+#if 0
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
+ switch(fdwReason) {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ return TRUE;
+ case DLL_THREAD_DETACH:
+ return TRUE;
+ case DLL_PROCESS_DETACH:
+ Trace::Close();
+ return TRUE;
+ }
+ (void)hinstDLL;
+ (void)lpvReserved;
+ return TRUE;
+}
+#endif
+
+#else
+
+static void _uninit(void) __attribute__((destructor));
+static void _uninit(void) {
+ Trace::Close();
+}
+
+#endif