Commit Graph

60 Commits

Author SHA1 Message Date
Omar Sandoval
56c4003db7 setup.py: add 5.12 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-03-09 13:51:52 -08:00
Omar Sandoval
9e3b3a36cf setup.py: fix black error
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-01-22 11:45:11 -08:00
Omar Sandoval
2977bee278 Fix reexport of drgn.__version__
mypy 0.800 is stricter about reexports: "from foo import X as Y" is only
considered a reexport if X and Y are the same name (see
python/mypy#9515). mypy 0.800 fails with:

  drgn/internal/cli.py:46: error: Module has no attribute "__version__"

Rename drgn.internal.version.version to __version__ so that
drgn/__init__.py can reexport it with import __version__ as __version__.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-01-22 11:23:06 -08:00
Omar Sandoval
09a9220c60 setup.py: add 5.11 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-01-21 16:59:57 -08:00
Omar Sandoval
2933a41ce1 setup.py: add 5.10 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-11-11 11:29:11 -08:00
Omar Sandoval
388b6a1090 Generate version.py instead of using pkg_resources
We get the version of drgn with pkg_resources.get_distribution() in two
places: setup.py (when using an sdist) and the CLI. The former causes
problems because in some cases, pip doesn't find the drgn distribution
that's currently being built. The latter adds significant latency to
startup. On my laptop, just importing pkg_resources takes 130 ms. We can
solve both of these problems by generating a file containing the version
instead.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-10-20 02:40:16 -07:00
Omar Sandoval
4431b4f918 vmtest: enable kernel modules
We currently build with CONFIG_MODULES=n for simplicity. However, this
means that we don't test kernel module support at all. Let's enable
module support. This requires changing how we distribute kernels. Now,
the /lib/modules/$(uname -r) directory (including the vmlinux and
vmlinuz) is bundled up as a tarball. We extract it, then mount it with
VirtFS, and do some extra setup for device nodes. (We lose the ability
to run kernel builds directly, but I've never actually used that
functionality.)

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-10-18 01:13:01 -07:00
Omar Sandoval
198e7d6999 setup.py: drop 5.5 from vmtest kernels
Linux 5.5 built by GCC 10 doesn't boot due to new optimizations breaking
how the kernel sets up the stack canary
(https://lkml.org/lkml/2020/3/14/186 has the details). 5.5 has been EOL
since April, so the fix was never backported. We could backport it
ourselves for vmtest builds or build with GCC 9, but it's not worth the
extra effort to test an EOL kernel. Let's just drop it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-10-15 12:50:53 -07:00
Omar Sandoval
de98b40495 vmtest: use pathlib
pathlib is a bit nicer than os.path for most cases, so try it out
starting with vmtest.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-10-14 11:37:31 -07:00
Omar Sandoval
d4b1711128 setup.py: add 5.9 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-27 16:29:03 -07:00
Omar Sandoval
36068a0ea8 Fix trailing commas for Black v20.8b1
Black was recently changed to treat a trailing comma as an indicator to
put each item/argument on its own line. We have a bunch of places where
something previously had to be split into multiple lines, then was
edited to fit on one line, but Black kept the trailing comma. Now this
update wants to unnecessarily split it back up. For now, let's get rid
of these commas. Hopefully in the future Black has a way to opt out of
this.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-27 11:31:29 -07:00
Omar Sandoval
4e770fb18a Format imports with isort
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 16:55:07 -07:00
Omar Sandoval
209eaee485 setup.py: import setuptools before distutils
setuptools recently started warning if distutils is imported before it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-07-18 01:41:12 -07:00
Omar Sandoval
27744108e1 setup.py: add 5.8 to vmtest kernels 2020-07-08 18:39:37 -07:00
Omar Sandoval
8b264f8823 Update copyright headers to Facebook and add missing headers
drgn was originally my side project, but for awhile now it's also been
my work project. Update the copyright headers to reflect this, and add a
copyright header to various files that were missing it.
2020-05-15 15:13:02 -07:00
Omar Sandoval
62ddc96350 setup.py: add 5.7 to vmtest kernels
5.7 is up to rc4 (oops). Better late than never.
2020-05-08 18:13:12 -07:00
Omar Sandoval
e03563221d vmtest: use BusyBox shell script as init
Currently, vmtest runs a custom program as init in the guest that
communicates with the host via virtio-serial. This is a lot of C code
that turns out can be replaced with a shell script. In order to keep the
dependencies minimal, we use BusyBox.
2020-04-17 15:11:54 -07:00
Omar Sandoval
1376674068 setup.py: log test returncode from VM
I'm seeing some spurious failures on Travis where the tests pass in the
VM but setup.py reports that they failed. Log the returncode that
setup.py sees to narrow down the issue.
2020-04-13 17:21:02 -07:00
Omar Sandoval
cf8d969048 Run black on some stray changes
A few recent changes weren't formatted with black.
2020-04-10 15:18:10 -07:00
Omar Sandoval
dabfe19719 Rewrite virtual machine testing setup
The current implementation of vmtest has a few issues:

1. Building drgn for each kernel version on Travis is slow, mostly
   because they don't all run in parallel.
2. For local, incremental testing, recreating the filesystem image and
   rebuilding drgn is slow, and syncing the code to the filesystem image
   is brittle.
3. The filesystem image is the only communication channel, and reading
   the exit status from the filesystem image is awkward and fragile.
4. Creating and accessing the filesystem image requires root.

This reworks vmtest to use the build on the host via VirtFS with a
simple agent on the guest that can execute arbitrary commands and return
the exit status. This has a few more moving parts but is faster and
saner overall.
2020-04-02 17:35:24 -07:00
Omar Sandoval
b369ca0dd1 Split some utility functions out of setup.py
These will be shared with vmtest.
2020-03-30 10:51:04 -07:00
Omar Sandoval
80c9fb35ff Add type hint stubs and generate documentation from them
I've been wanting to add type hints for the _drgn C extension for
awhile. The main blocker was that there is a large overlap between the
documentation (in docs/api_reference.rst) and the stub file, and I
really didn't want to duplicate the information. Therefore, it was a
requirement that the the documentation could be generated from the stub
file, or vice versa. Unfortunately, none of the existing tools that I
could find supported this very well. So, I bit the bullet and wrote my
own Sphinx extension that uses the stub file as the source of truth (and
subsumes my old autopackage extension and gen_docstrings script).

The stub file is probably incomplete/inaccurate in places, but this
should be a good starting point to improve on.

Closes #22.
2020-02-25 13:39:06 -08:00
Omar Sandoval
1b7e683930 setup.py: use contextlib.suppress(FileNotFoundError) for SOURCES.txt 2020-02-21 11:09:04 -08:00
Omar Sandoval
927b7897bc setup.py: rerun autoreconf if Makefile.am or configure.ac changes 2020-01-27 12:20:45 -08:00
Omar Sandoval
ebe379c42c setup.py: exclude dirty version identifier for Read the Docs
Read the Docs modifies docs/conf.py, so documentation builds are
displaying a dirty version. Don't do the dirty check if we're building
on Read the Docs (see [1]).

1: https://docs.readthedocs.io/en/stable/faq.html#how-do-i-change-behavior-for-read-the-docs
2020-01-26 00:46:56 -08:00
Omar Sandoval
fe53a33179 setup.py: make git versions sort properly
According to PEP 440, developmental releases sort before their
corresponding final release. We want them to sort after the release, as
they are a previous release plus some number of commits. Move the commit
count to the local version, as well.
2020-01-25 09:15:44 -08:00
Omar Sandoval
d8773b888c setup.py: exclude subpackages of tests, too 2020-01-24 17:21:17 -08:00
Omar Sandoval
87dd27ee12 setup.py: build in parallel by default
This is especially helpful for pip which doesn't have an easy way to
pass build parameters (and most people wouldn't bother, anyways).
2020-01-24 16:47:56 -08:00
Omar Sandoval
0cd7f2eef9 setup.py: rename custom command classes
The "my_" prefix shows up as the command name in --help, which is a bit
confusing. Do what setuptools does and import the original command under
another name so the custom class can have the original name.
2020-01-24 15:25:41 -08:00
Omar Sandoval
507d50c240 setup.py: support passing additional arguments to configure 2020-01-23 17:54:46 -08:00
Omar Sandoval
0088618578 Include git revision in version
When investigating a reported bug, it's important to know which exact
version of drgn is being used. Let's include the git revision in the
version printed by the CLI in PEP440 format. This commit will also serve
as the 0.0.1 release.
2020-01-23 12:29:43 -08:00
Omar Sandoval
660276a0b8 Format Python code with Black
I'm not a fan of 100% of the Black coding style, but I've spent too much
time manually formatting Python code, so let's just pull the trigger.
2020-01-14 11:51:58 -08:00
Omar Sandoval
09a64f5cba Define version in libdrgn/configure.ac
Currently the drgn version number is defined in drgn.h.in, and configure
and setup.py both parse it out of there. However, now that we're
generating drgn.h anyways, it's easier to make configure.ac the source
of truth.
2020-01-11 10:05:57 -08:00
Omar Sandoval
5cf37b96ef Add more setup.py metadata 2020-01-10 17:15:35 -08:00
Omar Sandoval
5fbe1b1ba9 setup.py: fix sdist if files are removed
setuptools has a long-standing bug that if files are removed from the
list of sources but were included in a previous run of egg_info, they
remain in the generated list of sources (pypa/setuptools#436). This
affects egg_info and sdist. Let's work around this by removing the old
SOURCES.txt if we can recreate it from git.
2019-11-18 17:29:46 -08:00
Omar Sandoval
d60c6a1d68 libdrgn: add register information to platform
In order to retrieve registers from stack traces, we need to know what
registers are defined for a platform. This adds a small DSL for defining
registers for an architecture. The DSL is parsed by an awk script that
generates the necessary tables, lookup functions, and enum definitions.
2019-10-18 14:33:02 -07:00
Omar Sandoval
4f2fa5d86f setup.py: only copy extension if newer than destination
I was always doing the copy based on a comment in the equivalent
setuptools code [1]:

    # Always copy, even if source is older than destination, to ensure
    # that the right extensions for the current Python/platform are
    # used.

On closer inspection, this isn't relevant as of PEP 3149 [2], since
extensions are tagged with the ABI version. Let's avoid the unnecessary
copies.

While we're here, let's restore self.inplace just to be safe.

1: e00f4a87ad
2: https://www.python.org/dev/peps/pep-3149/
2019-09-19 11:08:04 -07:00
Omar Sandoval
6a13d74c0c libdrgn: build with bundled elfutils
Now that we have the bundled version of elfutils, build it from libdrgn
and link to it. We can also get rid of the elfutils version checks from
the libdrgn code.
2019-09-19 11:07:12 -07:00
Omar Sandoval
f11a8766bf setup.py: get list of source files from git
Currently, we have a special Makefile target to output the files for a
libdrgn source tarball, and we use that for setuptools. However, the
next change is going to import elfutils, and it'd be a pain to add the
same thing for the elfutils sources. Instead, let's just use git
ls-files for everything. The only difference is that source
distributions won't have the autoconf/automake output.
2019-09-03 17:19:02 -07:00
Omar Sandoval
d02862ab41 setup.py: improve autotools glue
autoreconf may successfully run autoconf but not automake, so we should
check that Makefile.in exists, not configure. Additionally, there also
seem to be some cases where configure fails but Makefile is still
generated. Make sure we delete the potentially-broken output if
autoreconf/configure failed.
2019-05-03 10:23:02 -07:00
Omar Sandoval
435640faf6 Fix some linter errors 2019-04-11 15:51:20 -07:00
Omar Sandoval
687ea74ff2 Build Python bindings with automake
I went back and forth on using setuptools or autotools for the Python
extension, but I eventually settled on using only setuptools after
fighting to get the two to integrate well. However, setuptools is kind
of crappy; for one, it rebuilds every source file when rebuilding the
extension, which is really annoying for development. automake is a
better designed build system overall, so let's use that for the
extension. We override the build_ext command to build using autotools
and copy things where setuptools expects them.
2019-04-03 17:00:53 -07:00
Omar Sandoval
75c3679147 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-04-02 14:12:07 -07:00
Omar Sandoval
d7f0a77856 Parse version from __init__.py
We can't import it from drgn in a fresh checkout because the extensions
won't be present.
2019-03-29 08:51:53 -07:00
Omar Sandoval
878e4017c8 type: add new CompoundType.members()
CompoundType.members() currently returns a list of member names;
sometimes, we actually want the type and offset. So, rename members() to
member_names(), and make members() return the type and offset, using a
newly added version of functools.partial() that caches the return value.
2018-07-15 08:08:42 -07:00
Omar Sandoval
6abb2f2402 Separate internal API from public API
While we're here, clean up some rough edges of the API and document a
lot more.
2018-07-14 10:20:17 -07:00
Omar Sandoval
95bde56cb7 Implement core dump reading in C
read_memory() is one of the hottest functions in profiles of tight loops
over lists of items, and it can be done much more efficiently in C.
2018-05-24 17:55:47 -07:00
Omar Sandoval
0713c57217 Add version information 2018-04-15 15:30:54 -07:00
Omar Sandoval
a4768ba2a4 License under GPL-3.0 or later 2018-04-15 15:03:33 -07:00
Omar Sandoval
76cba644a8 Reorganize packaging 2018-04-07 10:42:48 -07:00