Commit Graph

49 Commits

Author SHA1 Message Date
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
Omar Sandoval
96c35e0f68 dwarfindex: use OpenMP to parallelize CU indexing
A couple of tricky things to handle:

- The DIE hash needs to be thread-safe. This implements a lock-free
  algorithm.
- We need to make sure exceptions are only raised with the GIL held.
  This adds some hacky macro magic to avoid adding a bunch of
  easy-to-forget boilerplate everywhere.
- We need to make sure the main thread reraises any exceptions thrown by
  the worker threads.
2018-04-02 00:33:23 -07:00
Omar Sandoval
b45e930336 dwarf: rewrite drgn.dwarf in pure Python
Now that DwarfIndex is in C, the rest can be simpler Python rather than
Cython.
2018-03-26 01:51:20 -07:00
Omar Sandoval
acbf14d10c dwarf: rewrite DwarfIndex in pure C
Most of drgn.dwarf is not performance-sensitive, and the part that is
(DwarfIndex) can use some extra tuning which is easier to do in C rather
than Cython.
2018-03-25 02:10:15 -07:00
Omar Sandoval
c81b7729c3 Compile Cython with language level 3 2018-03-13 00:20:24 -07:00
Omar Sandoval
a7309d2a15 elf: support debug sections with relocations 2018-03-09 17:41:54 -08:00
Omar Sandoval
16c5cff47c Prototype of "crash" utility 2018-02-19 00:46:39 -08:00
Omar Sandoval
97e604c05c Rewrite in Cython
The lldwarf/drgn.dwarf split wasn't working out too well, and moving all
of drgn.dwarf into lldwarf (by rewriting it into C) would be way too
much work. Instead, use Cython, which results in a parser which is just
as fast but with much cleaner code overall. It also turns out lldwarf
wasn't doing GC right, so the switch also fixed that.
2017-08-28 21:16:43 -07:00
Omar Sandoval
682fd172a4 cli/probe: start implementing variable fetching
Resolving parameters, variables with function scope, and global
variables should work. This is just the variable resolution, no fetching
yet, but a bunch of refactors snuck in here so committing it all now.
2017-08-27 23:56:14 -07:00
Omar Sandoval
72b9af2b82 Add address range table parsing 2017-08-25 23:24:38 -07:00
Omar Sandoval
1fc2b6e89b Initial commit
I wrote all of this code a few months back and am just now getting
around to committing it. The low-level DWARF parsing library is pretty
solid, although it only implements a subset of DWARF so far. The CLI and
higher-level interface are experimental.
2017-08-24 22:46:16 -07:00