28 #ifdef HAVE_LIBUNWIND_H 29 #include <libunwind.h> 61 index = (crc_value & (
SDL_arraysize(s_tracked_allocations) - 1));
69 for (entry = s_tracked_allocations[index]; entry; entry = entry->
next) {
70 if (mem == entry->
mem) {
94 #ifdef HAVE_LIBUNWIND_H 100 unw_getcontext(&context);
101 unw_init_local(&cursor, &context);
104 while (unw_step(&cursor) > 0) {
108 unw_get_reg(&cursor, UNW_REG_IP, &pc);
109 entry->
stack[stack_index] = pc;
111 if (unw_get_proc_name(&cursor, sym,
sizeof(sym), &offset) == 0) {
112 snprintf(entry->
stack_names[stack_index],
sizeof(entry->
stack_names[stack_index]),
"%s+0x%llx", sym, offset);
123 entry->
next = s_tracked_allocations[
index];
124 s_tracked_allocations[
index] = entry;
133 for (entry = s_tracked_allocations[index]; entry; entry = entry->
next) {
134 if (mem == entry->
mem) {
138 s_tracked_allocations[
index] = entry->
next;
175 if (mem && mem != ptr) {
225 size_t message_size = 0;
226 char line[128], *tmp;
236 message_size += (SDL_strlen(line) + 1); \ 237 tmp = (char *)SDL_realloc_orig(message, message_size); \ 242 SDL_strlcat(message, line, message_size) 244 SDL_strlcpy(line,
"Memory allocations:\n",
sizeof(line));
246 SDL_strlcpy(line,
"Expect 2 allocations from within SDL_GetErrBuf()\n",
sizeof(line));
252 for (entry = s_tracked_allocations[index]; entry; entry = entry->
next) {
253 SDL_snprintf(line,
sizeof(line),
"Allocation %d: %d bytes\n", count, (
int)entry->
size);
257 if (!entry->
stack[stack_index]) {
263 total_allocated += entry->
size;
267 SDL_snprintf(line,
sizeof(line),
"Total: %.2f Kb in %d allocations\n", (
float)total_allocated / 1024, count);
void SDLTest_LogAllocations()
Print a log of any outstanding allocations.
static int s_previous_allocations
static SDL_calloc_func SDL_calloc_orig
GLuint GLsizei const GLchar * message
static void SDLTest_TrackedFree(void *ptr)
GLuint GLuint GLsizei count
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
static void SDL_TrackAllocation(void *mem, size_t size)
static unsigned int get_allocation_bucket(void *mem)
static screen_context_t context
int SDLTest_TrackAllocations()
Start tracking SDL memory allocations.
void *(* SDL_calloc_func)(size_t nmemb, size_t size)
static void * SDLTest_TrackedMalloc(size_t size)
void(* SDL_free_func)(void *mem)
#define SDL_SetMemoryFunctions
static void * SDLTest_TrackedCalloc(size_t nmemb, size_t size)
static SDL_realloc_func SDL_realloc_orig
static SDL_tracked_allocation * s_tracked_allocations[256]
void *(* SDL_malloc_func)(size_t size)
static void SDL_UntrackAllocation(void *mem)
void *(* SDL_realloc_func)(void *mem, size_t size)
static SDL_bool SDL_IsAllocationTracked(void *mem)
#define SDL_GetMemoryFunctions
static SDL_free_func SDL_free_orig
#define SDL_assert(condition)
int SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext)
Initialize the CRC context.
#define SDL_arraysize(array)
static SDL_malloc_func SDL_malloc_orig
struct SDL_tracked_allocation * next
int SDLTest_Crc32Calc(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
calculate a crc32 from a data block
#define SDL_GetNumAllocations
char stack_names[10][256]
static void * SDLTest_TrackedRealloc(void *ptr, size_t size)
static SDLTest_Crc32Context s_crc32_context