X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace.hpp;h=1b5fdd23cdff7ba01ee17d3164d8697e332f2229;hb=12a22803faa06a0db229b6dfb6130a0e8156ba31;hp=33671411deb2a8b7841a078adfefc71d60fe273f;hpb=8e3c2c0d01c7ec5479845fedc053da00fa88e76a;p=apitrace diff --git a/retrace.hpp b/retrace.hpp index 3367141..1b5fdd2 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 @@ -84,6 +84,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); @@ -99,6 +146,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);