static void get_stack_for_address_enumerator(mach_stack_logging_record_t stack_record, void *task_ptr) { uint32_t num_frames = 0; kern_return_t err = __mach_stack_logging_frames_for_uniqued_stack (*(task_t *)task_ptr, stack_record.stack_identifier, g_stack_frames, MAX_FRAMES, &num_frames); g_malloc_stack_history.resize(g_malloc_stack_history.size() + 1); g_malloc_stack_history.back().address = (void *)stack_record.address; g_malloc_stack_history.back().type_flags = stack_record.type_flags; g_malloc_stack_history.back().argument = stack_record.argument; if (num_frames > 0) g_malloc_stack_history.back().frames.assign(g_stack_frames, g_stack_frames + num_frames); g_malloc_stack_history.back().frames.push_back(0); // Terminate the frames with zero }
bool MachTask::EnumerateMallocFrames (MachMallocEventId event_id, mach_vm_address_t *function_addresses_buffer, uint32_t buffer_size, uint32_t *count) { if (!function_addresses_buffer || !count) return false; if (buffer_size == 0) return false; __mach_stack_logging_frames_for_uniqued_stack(m_task, event_id, &function_addresses_buffer[0], buffer_size, count); *count -= 1; if (function_addresses_buffer[*count-1] < PageSize()) *count -= 1; return (*count > 0); }
static void get_stack_for_address_enumerator(mach_stack_logging_record_t stack_record, void *task_ptr) { malloc_stack_entry *stack_entry = g_malloc_stack_history.next(); if (stack_entry) { stack_entry->address = (void *)stack_record.address; stack_entry->type_flags = stack_record.type_flags; stack_entry->argument = stack_record.argument; stack_entry->num_frames = 0; stack_entry->frames[0] = 0; kern_return_t err = __mach_stack_logging_frames_for_uniqued_stack (*(task_t *)task_ptr, stack_record.stack_identifier, stack_entry->frames, MAX_FRAMES, &stack_entry->num_frames); // Terminate the frames with zero if there is room if (stack_entry->num_frames < MAX_FRAMES) stack_entry->frames[stack_entry->num_frames] = 0; } }