2020-02-21 23:08:37 +00:00
|
|
|
// Copyright 2018-2020 - Omar Sandoval
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
|
|
|
|
|
|
|
#include "drgnpy.h"
|
2020-05-08 00:01:26 +01:00
|
|
|
#include "../internal.h"
|
2019-10-04 00:21:48 +01:00
|
|
|
#ifdef WITH_KDUMPFILE
|
|
|
|
#include <libkdumpfile/kdumpfile.h>
|
|
|
|
#endif
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
2019-05-10 07:53:16 +01:00
|
|
|
PyObject *MissingDebugInfoError;
|
2020-02-03 18:07:07 +00:00
|
|
|
PyObject *OutOfBoundsError;
|
2019-05-10 07:53:16 +01:00
|
|
|
|
|
|
|
static PyObject *filename_matches(PyObject *self, PyObject *args,
|
|
|
|
PyObject *kwds)
|
|
|
|
{
|
|
|
|
static char *keywords[] = {"haystack", "needle", NULL};
|
|
|
|
struct path_arg haystack_arg = {.allow_none = true};
|
|
|
|
struct path_arg needle_arg = {.allow_none = true};
|
|
|
|
struct path_iterator haystack = {
|
|
|
|
.components = (struct path_iterator_component [1]){},
|
|
|
|
.num_components = 0,
|
|
|
|
};
|
|
|
|
struct path_iterator needle = {
|
|
|
|
.components = (struct path_iterator_component [1]){},
|
|
|
|
.num_components = 0,
|
|
|
|
};
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&:filename_matches",
|
|
|
|
keywords, path_converter,
|
|
|
|
&haystack_arg, path_converter,
|
|
|
|
&needle_arg))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (haystack_arg.path) {
|
|
|
|
haystack.components[0].path = haystack_arg.path;
|
|
|
|
haystack.components[0].len = haystack_arg.length;
|
|
|
|
haystack.num_components = 1;
|
|
|
|
}
|
|
|
|
if (needle_arg.path) {
|
|
|
|
needle.components[0].path = needle_arg.path;
|
|
|
|
needle.components[0].len = needle_arg.length;
|
|
|
|
needle.num_components = 1;
|
|
|
|
}
|
|
|
|
ret = path_ends_with(&haystack, &needle);
|
|
|
|
path_cleanup(&haystack_arg);
|
|
|
|
path_cleanup(&needle_arg);
|
|
|
|
if (ret)
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
else
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
}
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
2019-10-18 19:47:32 +01:00
|
|
|
static PyObject *sizeof_(PyObject *self, PyObject *arg)
|
|
|
|
{
|
|
|
|
struct drgn_error *err;
|
|
|
|
uint64_t size;
|
|
|
|
|
|
|
|
if (PyObject_TypeCheck(arg, &DrgnType_type)) {
|
|
|
|
err = drgn_type_sizeof(((DrgnType *)arg)->type, &size);
|
|
|
|
} else if (PyObject_TypeCheck(arg, &DrgnObject_type)) {
|
|
|
|
err = drgn_object_sizeof(&((DrgnObject *)arg)->obj, &size);
|
|
|
|
} else {
|
|
|
|
return PyErr_Format(PyExc_TypeError,
|
|
|
|
"expected Type or Object, not %s",
|
|
|
|
Py_TYPE(arg)->tp_name);
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
return set_drgn_error(err);
|
|
|
|
return PyLong_FromUnsignedLongLong(size);
|
|
|
|
}
|
|
|
|
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
static PyMethodDef drgn_methods[] = {
|
2019-05-10 07:53:16 +01:00
|
|
|
{"filename_matches", (PyCFunction)filename_matches,
|
|
|
|
METH_VARARGS | METH_KEYWORDS, drgn_filename_matches_DOC},
|
2019-04-04 09:27:23 +01:00
|
|
|
{"NULL", (PyCFunction)DrgnObject_NULL, METH_VARARGS | METH_KEYWORDS,
|
|
|
|
drgn_NULL_DOC},
|
2019-10-18 19:47:32 +01:00
|
|
|
{"sizeof", (PyCFunction)sizeof_, METH_O, drgn_sizeof_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"cast", (PyCFunction)cast, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_cast_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"reinterpret", (PyCFunction)reinterpret, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_reinterpret_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"container_of", (PyCFunction)DrgnObject_container_of,
|
2019-04-04 09:27:23 +01:00
|
|
|
METH_VARARGS | METH_KEYWORDS, drgn_container_of_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"program_from_core_dump", (PyCFunction)program_from_core_dump,
|
2019-04-04 09:27:23 +01:00
|
|
|
METH_VARARGS | METH_KEYWORDS, drgn_program_from_core_dump_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"program_from_kernel", (PyCFunction)program_from_kernel,
|
2019-05-10 07:53:16 +01:00
|
|
|
METH_NOARGS, drgn_program_from_kernel_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"program_from_pid", (PyCFunction)program_from_pid,
|
2019-04-04 09:27:23 +01:00
|
|
|
METH_VARARGS | METH_KEYWORDS, drgn_program_from_pid_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"void_type", (PyCFunction)void_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_void_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"int_type", (PyCFunction)int_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_int_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"bool_type", (PyCFunction)bool_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_bool_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"float_type", (PyCFunction)float_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_float_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"complex_type", (PyCFunction)complex_type,
|
2019-04-04 09:27:23 +01:00
|
|
|
METH_VARARGS | METH_KEYWORDS, drgn_complex_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"struct_type", (PyCFunction)struct_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_struct_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"union_type", (PyCFunction)union_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_union_type_DOC},
|
2019-11-15 01:12:47 +00:00
|
|
|
{"class_type", (PyCFunction)class_type, METH_VARARGS | METH_KEYWORDS,
|
|
|
|
drgn_class_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"enum_type", (PyCFunction)enum_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_enum_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"typedef_type", (PyCFunction)typedef_type,
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_typedef_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"pointer_type", (PyCFunction)pointer_type,
|
2019-04-04 09:27:23 +01:00
|
|
|
METH_VARARGS | METH_KEYWORDS, drgn_pointer_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"array_type", (PyCFunction)array_type, METH_VARARGS | METH_KEYWORDS,
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn_array_type_DOC},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{"function_type", (PyCFunction)function_type,
|
2019-04-04 09:27:23 +01:00
|
|
|
METH_VARARGS | METH_KEYWORDS, drgn_function_type_DOC},
|
2020-05-06 02:21:36 +01:00
|
|
|
{"_linux_helper_read_vm", (PyCFunction)drgnpy_linux_helper_read_vm,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
2019-10-25 23:23:02 +01:00
|
|
|
{"_linux_helper_radix_tree_lookup",
|
|
|
|
(PyCFunction)drgnpy_linux_helper_radix_tree_lookup,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
|
|
|
{"_linux_helper_idr_find", (PyCFunction)drgnpy_linux_helper_idr_find,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
|
|
|
{"_linux_helper_find_pid", (PyCFunction)drgnpy_linux_helper_find_pid,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
|
|
|
{"_linux_helper_pid_task", (PyCFunction)drgnpy_linux_helper_pid_task,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
|
|
|
{"_linux_helper_find_task", (PyCFunction)drgnpy_linux_helper_find_task,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
2019-10-28 09:38:51 +00:00
|
|
|
{"_linux_helper_task_state_to_char",
|
|
|
|
(PyCFunction)drgnpy_linux_helper_task_state_to_char,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
2020-04-09 22:29:47 +01:00
|
|
|
{"_linux_helper_pgtable_l5_enabled",
|
|
|
|
(PyCFunction)drgnpy_linux_helper_pgtable_l5_enabled,
|
|
|
|
METH_VARARGS | METH_KEYWORDS},
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct PyModuleDef drgnmodule = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"_drgn",
|
2020-02-25 19:43:01 +00:00
|
|
|
drgn_DOC,
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
-1,
|
|
|
|
drgn_methods,
|
|
|
|
};
|
|
|
|
|
|
|
|
DRGNPY_PUBLIC PyMODINIT_FUNC PyInit__drgn(void)
|
|
|
|
{
|
|
|
|
PyObject *m;
|
2019-07-29 08:57:28 +01:00
|
|
|
PyObject *host_platform_obj;
|
2019-10-04 00:21:48 +01:00
|
|
|
PyObject *with_libkdumpfile;
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
|
|
|
m = PyModule_Create(&drgnmodule);
|
|
|
|
if (!m)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (add_module_constants(m) == -1)
|
|
|
|
goto err;
|
|
|
|
|
2020-02-03 18:27:49 +00:00
|
|
|
FaultError_type.tp_base = (PyTypeObject *)PyExc_Exception;
|
|
|
|
if (PyType_Ready(&FaultError_type) < 0)
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
goto err;
|
2020-02-03 18:27:49 +00:00
|
|
|
Py_INCREF(&FaultError_type);
|
|
|
|
PyModule_AddObject(m, "FaultError", (PyObject *)&FaultError_type);
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
2019-05-10 07:53:16 +01:00
|
|
|
MissingDebugInfoError = PyErr_NewExceptionWithDoc("_drgn.MissingDebugInfoError",
|
|
|
|
drgn_MissingDebugInfoError_DOC,
|
|
|
|
NULL, NULL);
|
|
|
|
if (!MissingDebugInfoError)
|
2019-04-26 19:56:47 +01:00
|
|
|
goto err;
|
2019-05-10 07:53:16 +01:00
|
|
|
PyModule_AddObject(m, "MissingDebugInfoError", MissingDebugInfoError);
|
2019-04-26 19:56:47 +01:00
|
|
|
|
2020-02-03 18:07:07 +00:00
|
|
|
OutOfBoundsError = PyErr_NewExceptionWithDoc("_drgn.OutOfBoundsError",
|
|
|
|
drgn_OutOfBoundsError_DOC,
|
|
|
|
NULL, NULL);
|
|
|
|
if (!OutOfBoundsError)
|
|
|
|
goto err;
|
|
|
|
PyModule_AddObject(m, "OutOfBoundsError", OutOfBoundsError);
|
|
|
|
|
2020-02-21 23:08:37 +00:00
|
|
|
if (PyType_Ready(&Language_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&Language_type);
|
|
|
|
PyModule_AddObject(m, "Language", (PyObject *)&Language_type);
|
|
|
|
if (add_languages() == -1)
|
|
|
|
goto err;
|
|
|
|
|
2019-10-18 10:03:32 +01:00
|
|
|
if (PyStructSequence_InitType2(&Register_type, &Register_desc) == -1)
|
|
|
|
goto err;
|
|
|
|
PyModule_AddObject(m, "Register", (PyObject *)&Register_type);
|
|
|
|
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
if (PyType_Ready(&DrgnObject_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&DrgnObject_type);
|
|
|
|
PyModule_AddObject(m, "Object", (PyObject *)&DrgnObject_type);
|
|
|
|
|
|
|
|
if (PyType_Ready(&ObjectIterator_type) < 0)
|
|
|
|
goto err;
|
|
|
|
|
2019-07-29 08:57:28 +01:00
|
|
|
if (PyType_Ready(&Platform_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&Platform_type);
|
|
|
|
PyModule_AddObject(m, "Platform", (PyObject *)&Platform_type);
|
|
|
|
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
if (PyType_Ready(&Program_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&Program_type);
|
|
|
|
PyModule_AddObject(m, "Program", (PyObject *)&Program_type);
|
|
|
|
|
2019-07-29 22:41:33 +01:00
|
|
|
if (PyType_Ready(&StackFrame_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&StackFrame_type);
|
|
|
|
PyModule_AddObject(m, "StackFrame", (PyObject *)&StackFrame_type);
|
|
|
|
|
|
|
|
if (PyType_Ready(&StackTrace_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&StackTrace_type);
|
|
|
|
PyModule_AddObject(m, "StackTrace", (PyObject *)&StackTrace_type);
|
|
|
|
|
2019-07-25 08:47:13 +01:00
|
|
|
if (PyType_Ready(&Symbol_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&Symbol_type);
|
|
|
|
PyModule_AddObject(m, "Symbol", (PyObject *)&Symbol_type);
|
|
|
|
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
if (PyType_Ready(&DrgnType_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&DrgnType_type);
|
|
|
|
PyModule_AddObject(m, "Type", (PyObject *)&DrgnType_type);
|
|
|
|
|
2020-02-11 19:33:22 +00:00
|
|
|
if (PyType_Ready(&TypeEnumerator_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&TypeEnumerator_type);
|
|
|
|
PyModule_AddObject(m, "TypeEnumerator",
|
|
|
|
(PyObject *)&TypeEnumerator_type);
|
|
|
|
|
2020-02-12 20:04:36 +00:00
|
|
|
if (PyType_Ready(&TypeMember_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&TypeMember_type);
|
|
|
|
PyModule_AddObject(m, "TypeMember", (PyObject *)&TypeMember_type);
|
|
|
|
|
|
|
|
if (PyType_Ready(&TypeParameter_type) < 0)
|
|
|
|
goto err;
|
|
|
|
Py_INCREF(&TypeParameter_type);
|
|
|
|
PyModule_AddObject(m, "TypeParameter", (PyObject *)&TypeParameter_type);
|
|
|
|
|
2019-07-29 08:57:28 +01:00
|
|
|
host_platform_obj = Platform_wrap(&drgn_host_platform);
|
|
|
|
if (!host_platform_obj)
|
|
|
|
goto err;
|
|
|
|
PyModule_AddObject(m, "host_platform", host_platform_obj);
|
|
|
|
|
2019-10-04 00:21:48 +01:00
|
|
|
#ifdef WITH_LIBKDUMPFILE
|
|
|
|
with_libkdumpfile = Py_True;
|
|
|
|
#else
|
|
|
|
with_libkdumpfile = Py_False;
|
|
|
|
#endif
|
|
|
|
Py_INCREF(with_libkdumpfile);
|
|
|
|
PyModule_AddObject(m, "_with_libkdumpfile", with_libkdumpfile);
|
|
|
|
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
return m;
|
|
|
|
|
|
|
|
err:
|
|
|
|
Py_DECREF(m);
|
|
|
|
return NULL;
|
|
|
|
}
|