X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace.hpp;h=dc11bb382243b13c51afe837c7fec40f6664a7de;hb=fe806cb6c3a13071126f4eff4bcb8a28d8b0b777;hp=a59a6eb8901e97195d2f268082101a331396881b;hpb=b4a3d1495a5e92ba23bf463bcea34a6e75b55294;p=apitrace diff --git a/retrace.hpp b/retrace.hpp index a59a6eb..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,6 +80,53 @@ 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); @@ -95,6 +142,11 @@ toPointer(trace::Value &value, bool bind = false); */ extern int verbosity; +/** + * Add profiling data to the dump when retracing. + */ +extern bool profiling; + std::ostream &warning(trace::Call &call);