Exemplo n.º 1
0
/* Implementation of gdb.read_memory (address, length).
   Returns a Python buffer object with LENGTH bytes of the inferior's
   memory at ADDRESS.  Both arguments are integers.  */
static PyObject *
infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
{
    int error = 0;
    CORE_ADDR addr, length;
    void *buffer = NULL;
    membuf_object *membuf_obj;
    PyObject *addr_obj, *length_obj;
    struct cleanup *cleanups;
    volatile struct gdb_exception except;
    static char *keywords[] = { "address", "length", NULL };

    if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
                                       &addr_obj, &length_obj))
        return NULL;

    cleanups = make_cleanup (null_cleanup, NULL);

    TRY_CATCH (except, RETURN_MASK_ALL)
    {
        if (!get_addr_from_python (addr_obj, &addr)
                || !get_addr_from_python (length_obj, &length))
        {
            error = 1;
            break;
        }

        buffer = xmalloc (length);
        make_cleanup (xfree, buffer);

        read_memory (addr, buffer, length);
    }
    if (except.reason < 0)
    {
        do_cleanups (cleanups);
        GDB_PY_HANDLE_EXCEPTION (except);
    }

    if (error)
    {
        do_cleanups (cleanups);
        return NULL;
    }

    membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
    if (membuf_obj == NULL)
    {
        PyErr_SetString (PyExc_MemoryError,
                         _("Could not allocate memory buffer object."));
        do_cleanups (cleanups);
        return NULL;
    }

    discard_cleanups (cleanups);

    membuf_obj->buffer = buffer;
    membuf_obj->addr = addr;
    membuf_obj->length = length;

    return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
                                         Py_END_OF_BUFFER);
}
Exemplo n.º 2
0
static PyObject *
image_surface_get_data (PycairoImageSurface *o)
{
    return PyBuffer_FromReadWriteObject((PyObject *)o, 0, Py_END_OF_BUFFER);
}