/* Returns false if the record is not valid.  */
static bool get_trace_record(unsigned int idx, TraceRecord **recordptr)
/* Returns false if the record is not valid.  */
static bool get_trace_record(unsigned int idx, TraceRecord **recordptr)
{
    uint64_t event_flag = 0;
    TraceRecord record;
    read_from_buffer(idx, &record, sizeof(event_flag));
    if (!(record.event & TRACE_RECORD_VALID)) {
        return false;
    }
    smp_rmb();
    read_from_buffer(idx, &record, sizeof(TraceRecord));
    *recordptr = malloc(record.length);
    read_from_buffer(idx, *recordptr, record.length);
    smp_rmb();
    (*recordptr)->event &= ~TRACE_RECORD_VALID;
    clear_buffer_range(idx, record.length);
    return true;
}