Example #1
0
static void
event_thread_init(void *drcontext)
{
    byte *data;

    data = drx_buf_get_buffer_ptr(drcontext, buf);
    memset(data, 0, DRX_BUF_FAST_CIRCULAR_BUFSZ);
}
Example #2
0
static void
verify_buffers_empty(drx_buf_t *client)
{
    void *drcontext = dr_get_current_drcontext();
    byte *buf_base, *buf_ceil;

    buf_base = drx_buf_get_buffer_base(drcontext, client);
    buf_ceil = drx_buf_get_buffer_ptr(drcontext, client);
    CHECK(buf_base == buf_ceil, "buffer not empty");
}
Example #3
0
static void
verify_buffers_dirty(drx_buf_t *client, int32_t test)
{
    void *drcontext = dr_get_current_drcontext();
    byte *buf_base, *buf_ceil;

    buf_base = drx_buf_get_buffer_base(drcontext, client);
    buf_ceil = drx_buf_get_buffer_ptr(drcontext, client);
    CHECK(buf_base + sizeof(int32_t) == buf_ceil, "buffer not dirty");
    CHECK(*(int32_t *)buf_base == test, "buffer has wrong value");
}
Example #4
0
/* Called when the trace buffer has filled up, and needs to be flushed to disk. */
static void
trace_fault(void *drcontext, void *buf_base, size_t size)
{
    per_thread_t *data = drmgr_get_tls_field(drcontext, tls_idx);
    mem_ref_t *trace_base = (mem_ref_t *)(char *)buf_base;
    mem_ref_t *trace_ptr = (mem_ref_t *)((char *)buf_base + size);
    byte *write_base = drx_buf_get_buffer_base(drcontext, write_buffer);
    byte *write_ptr = drx_buf_get_buffer_ptr(drcontext, write_buffer);
    int largest_size = 0;
    mem_ref_t *mem_ref;
    char *hex_buf;

    /* find the largest necessary buffer so we only perform a single allocation */
    for (mem_ref = trace_base; mem_ref < trace_ptr; mem_ref++) {
        if (mem_ref->size > largest_size)
            largest_size = mem_ref->size;
    }
    hex_buf = dr_thread_alloc(drcontext, 2 * largest_size + 1);
    /* write the memrefs to disk */
    for (mem_ref = trace_base; mem_ref < trace_ptr; mem_ref++) {
        /* Each memref in the trace buffer has an "associated" write in the write buffer.
         * We pull mem_ref->size bytes from the write buffer, and assert we haven't yet
         * gone too far.
         */
        /* We use libc's fprintf as it is buffered and much faster than dr_fprintf for
         * repeated printing that dominates performance, as the printing does here. Note
         * that a binary dump is *much* faster than fprintf still.
         */
        fprintf(data->logf, "" PFX ": %s %2d %s\n", (ptr_uint_t)mem_ref->addr,
                decode_opcode_name(mem_ref->type), mem_ref->size,
                write_hexdump(hex_buf, write_base, mem_ref));
        write_base += mem_ref->size;
        DR_ASSERT(write_base <= write_ptr);
    }
    dr_thread_free(drcontext, hex_buf, 2 * largest_size + 1);
    /* reset the write buffer (note: the trace buffer gets reset automatically) */
    drx_buf_set_buffer_ptr(drcontext, write_buffer,
                           drx_buf_get_buffer_base(drcontext, write_buffer));
}