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);