X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=retrace.hpp;h=dc11bb382243b13c51afe837c7fec40f6664a7de;hb=e40a6ab0e01933c31a4e4701ea300736d7e3e32b;hp=300f00757aed19648a930a7cc8e9e98db3cd70ec;hpb=f5cda41c985730fc27361f3bb36cc2c5ede77e1c;p=apitrace diff --git a/retrace.hpp b/retrace.hpp index 300f007..dc11bb3 100644 --- a/retrace.hpp +++ b/retrace.hpp @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2011 Jose Fonseca + * Copyright 2011-2012 Jose Fonseca * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -80,20 +80,82 @@ public: }; +/** + * Similar to alloca(), but implemented with malloc. + */ +class ScopedAllocator +{ +private: + void *next; + +public: + ScopedAllocator() : + next(NULL) { + } + + inline void * + alloc(size_t size) { + if (!size) { + return NULL; + } + + void * * buf = static_cast(malloc(sizeof(void *) + size)); + if (!buf) { + return NULL; + } + + *buf = next; + next = buf; + + return &buf[1]; + } + + template< class T > + inline T * + alloc(size_t n = 1) { + return static_cast(alloc(sizeof(T) * n)); + } + + inline + ~ScopedAllocator() { + while (next) { + void *temp = *static_cast(next); + free(next); + next = temp; + } + } +}; + + +void +addRegion(unsigned long long address, void *buffer, unsigned long long size); + +void +delRegionByPointer(void *ptr); + +void * +toPointer(trace::Value &value, bool bind = false); + + /** * Output verbosity when retracing files. */ extern int verbosity; +/** + * Add profiling data to the dump when retracing. + */ +extern bool profiling; + -std::ostream &warning(Trace::Call &call); +std::ostream &warning(trace::Call &call); -void ignore(Trace::Call &call); -void unsupported(Trace::Call &call); +void ignore(trace::Call &call); +void unsupported(trace::Call &call); -typedef void (*Callback)(Trace::Call &call); +typedef void (*Callback)(trace::Call &call); struct Entry { const char *name; @@ -108,6 +170,9 @@ struct stringComparer { }; +extern const Entry stdc_callbacks[]; + + class Retracer { typedef std::map Map; @@ -116,14 +181,16 @@ class Retracer std::vector callbacks; public: - Retracer() {} + Retracer() { + addCallbacks(stdc_callbacks); + } virtual ~Retracer() {} void addCallback(const Entry *entry); void addCallbacks(const Entry *entries); - void retrace(Trace::Call &call); + void retrace(trace::Call &call); };