Commit Graph

109 Commits

Author SHA1 Message Date
Omar Sandoval
28e7a79925 setup.py: use setuptools versions of distutils.command.build and distutils.errors
The setuptools guide for porting from distutils [1] recommends this.
However, the setuptools versions aren't available on older versions of
setuptools, so we still need to fall back to distutils.

1: https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-27 16:03:43 -07:00
Omar Sandoval
53fdd6cad7 setup.py: replace distutils.log with logging from standard library
The setuptools guide for porting from distutils [1] recommends this.

1: https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-27 16:02:04 -07:00
Omar Sandoval
2017cd6fe2 setup.py: use copy_file and mkpath from setuptools.Command instead of distutils
distutils is deprecated and was removed in Python 3.12 [1]. setuptools
provides a vendored copy of distutils, but they discourage against using
it [2]. So, let's stop importing distutils, starting with replacing our
calls of distutils.file_util.copy_file() and distutils.dir_util.mkpath()
with their equivalent methods from setuptools.Command.

1: https://peps.python.org/pep-0632/
2: https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-27 15:57:21 -07:00
Omar Sandoval
91644e48d3 Move supported kernel versions from setup.py to vmtest.config
And use the list of flavors from vmtest.config in setup.py instead of
duplicating it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-27 10:17:40 -07:00
Omar Sandoval
4c3c886b5a setup.py: add 6.4 to vmtest kernels
6.4 needed an unusual number of changes:

- 3f3a957562 ("libdrgn: linux_kernel: Fix module detection on kernel
  v6.4")
- da7a11f83e ("drgn.helpers.linux.block: update
  for_each_{disk,partition} for Linux 6.4")
- 7e7c300a139b ("libdrgn: orc_info: handle ORC changes in Linux 6.3 and
  6.4")

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-22 15:27:39 -07:00
Omar Sandoval
5c92485950 setup.py: add 6.3 to vmtest kernels
Commit bf9159cff367 ("drgn.helpers.linux.mm: fix compound_{order,nr} for
Linux 6.3+") is the only change necessary for Linux v6.3.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-01 14:50:25 -07:00
Omar Sandoval
38b090ea9d setup.py: handle git not being installed
My previous change to call git unconditionally caused Packit failures,
presumably because git isn't installed for the build:

Traceback (most recent call last):
  File "/builddir/build/BUILD/drgn-0.0.22+71.g2f97cc0/setup.py", line 411, in <module>
    version=get_version(),
            ^^^^^^^^^^^^^
  File "/builddir/build/BUILD/drgn-0.0.22+71.g2f97cc0/setup.py", line 343, in get_version
    subprocess.call(
  File "/usr/lib64/python3.11/subprocess.py", line 389, in call
    with Popen(*popenargs, **kwargs) as p:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.11/subprocess.py", line 1901, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'git'

We shouldn't bother calling git if .git doesn't exist.

Fixes: 2e9e66cedc ("setup.py: use stricter check for git repository")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-21 18:12:54 -08:00
Omar Sandoval
2e9e66cedc setup.py: use stricter check for git repository
To test builds on other architectures, I'm setting up a Debian chroot
with debootstrap and then building with something like:

  mount --bind . "$chroot/mnt"
  chroot "$chroot" sh -c 'cd /mnt && python3 setup.py build_ext -i'

However, if I do this from a Git worktree, this fails with an error from
the git call to determine the local version:

  fatal: not a git repository: /home/osandov/repos/drgn/.git/worktrees/drgn2

Instead of only checking whether .git exists, use `git --git-dir=.git
rev-parse` to verify that .git is valid. (This will of course rely on
drgn/internal/version.py already having been generated.)

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-21 12:07:37 -08:00
Omar Sandoval
c911ccdd36 tests: build test kernel module with kernel.org compiler
Now we'll always get the same compiler that was used for the actual
kernel build. Also split this into its own runnable module, vmtest.kmod,
for testing and custom scripting.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-18 01:42:38 -08:00
Omar Sandoval
1626cc32f2 vmtest.vm: support other architectures
Add the per-architecture QEMU options to the Architecture class and
allow specifying an architecture in -k.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Omar Sandoval
7b8872424e vmtest.download: support downloading cross compilers from kernel.org
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Omar Sandoval
404fb80ca8 vmtest.download: specify kernel architecture per download
This also prepares us for being able to download other things.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-14 16:58:21 -08:00
Stephen Brennan
c24ba99c8c cli: Separate the main function from the REPL
It's quite useful to run drgn's interactive REPL from a user-provided
script. One reason is saving the drgn core dump and debuginfo setup into
a script to more easily start analysis. Another might be to replace
drgn's debuginfo loading scheme with one customized to a different
environment. Or, a script might want to handle errors by allowing an
interactive user to examine the program themselves.

To serve all of these cases and more, separate out the logic of running
the drgn REPL from the internal logic relating to argument parsing,
choosing the correct target, and loading debuginfo. While this may seem
like a simple case of code.interact, there are several important
internal features drgn provides in its CLI: a custom displayhook, a
custom readline completer, a history file, and of course the logic to
import and include the proper drgn APIs and helpers for a core dump.

This means creating a run_interactive() function and moving the cli
module out of the drgn.internal package.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-02-01 09:30:02 -08:00
Omar Sandoval
e7dfdb9c2a setup.py: add 6.2 to vmtest kernels
Commit c48cddbdb0 ("libdrgn: ppc64: fix stack unwinding since Linux
v5.11 and before v4.20") is the only change necessary for Linux v6.2.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 10:59:09 -08:00
Omar Sandoval
4e220b2a61 setup.py: print pass/fail progress while testing kernels
It's useful to check in on a long run without needing to scroll back and
check whether each kernel version passed or failed.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-04 14:25:55 -08:00
Omar Sandoval
55ddc19be4 tests: print more information about HTTP 403 errors
We're getting a bunch of test failures with "HTTP Error 403: rate limit
exceeded" from the GitHub API. The API apparently includes additional
information in the response, so let's print that so that we can figure
out which limit we're hitting.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-19 16:25:56 -08:00
Omar Sandoval
3c76c12ef1 Stop testing Linux 4.4
I wanted to add tests for the radix tree helpers, but found that they
have never worked for Linux 4.4. Linux 4.4 has been EOL for almost a
year, so rather than going out of our way to support it, let's just stop
testing it. I'm not going to go back and remove existing support for
4.4 (yet), but I'm also not going to make sure future changes support
it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-13 15:44:43 -08:00
Omar Sandoval
375fee8d85 setup.py: add 6.1 to vmtest kernels
No changes are required.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-21 01:17:13 -08:00
Omar Sandoval
87b7292aa5 Relicense drgn from GPLv3+ to LGPLv2.1+
drgn is currently licensed as GPLv3+. Part of the long term vision for
drgn is that other projects can use it as a library providing
programmatic interfaces for debugger functionality. A more permissive
license is better suited to this goal. We decided on LGPLv2.1+ as a good
balance between software freedom and permissiveness.

All contributors not employed by Meta were contacted via email and
consented to the license change. The only exception was the author of
commit c4fbf7e589 ("libdrgn: fix for compilation error"), who did not
respond. That commit reverted a single line of code to one originally
written by me in commit 640b1c011d ("libdrgn: embed DWARF index in
DWARF info cache").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-01 17:05:16 -07:00
Omar Sandoval
6cc41dbcf8 vmtest.vm: support running with root directory different from the host
This will be useful for testing different architectures (e.g., by
creating a rootfs with debootstrap) or different userspace environments.
For example, we can test busybox with something like:

  mkdir busyboxroot busyboxroot/bin busyboxroot/tmp
  cp "$(which busybox)" busyboxroot/bin
  busyboxroot/bin/busybox --install busyboxroot/bin
  python3 -Bm vmtest.vm -k '*' -r busyboxroot

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-10-11 16:13:10 -07:00
Omar Sandoval
9e5fb3ef08 vmtest.vm: don't set PYTHON
This is more appropriately done in the test command in setup.py.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-10-11 16:13:10 -07:00
Omar Sandoval
3b6c02107e vmtest: get SYS_kexec_file_load from util.SYS
This still isn't enough to be fully generic since since some
architectures don't support kexec_file_load, especially on older
kernels, and some architectures can't use the vmlinuz directly (e.g.,
AArch64 may need it to be decompressed). But, this is at least cleaner
than hard-coding the number for x86-64.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-10-11 16:08:20 -07:00
Omar Sandoval
ca373fe38a docs: use "programmable debugger" description consistently
Replace the old "Scriptable debugger library" and
"Debugger-as-a-library" taglines with the one we're using on GitHub,
"Programmable debugger". Make up for it by emphasizing that drgn can
also be used as a library a tiny bit more in the README.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-08-19 01:21:32 -07:00
Omar Sandoval
decedc9734 setup.py: add 6.0 to vmtest kernels
cgroup_bpf_prog_for_each() needed a minor update, but after fixing that,
all of the flavors pass all tests.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-08-15 13:41:47 -07:00
Omar Sandoval
b535b8f82e vmtest: don't use BusyBox
We don't specifically need BusyBox; we just need a reasonable Linux
userspace, which we can assume is already available on the host, whether
it's coreutils+util-linux, BusyBox, or something else.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-08-01 11:23:26 -07:00
Omar Sandoval
1b8d0ae82b vmtest.vm: change to host's working directory by default
The test command does this, and I always end up doing it when I'm doing
manual testing with the vmtest.vm CLI, so let's just do it by default.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-08-01 10:59:05 -07:00
Omar Sandoval
05395422eb setup.py: add 5.19 to vmtest kernels
This needed the previous small update to
tests.linux_kernel.test_debug_info.TestModuleDebugInfo.
tests.linux_kernel.helpers.test_tc.TestTc will also only work with
pyroute2 >= 0.6.10 (see svinota/pyroute2#899). No changes needed to drgn
itself.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-06-09 14:35:01 -07:00
Omar Sandoval
1c8ed7189a setup.py: run local tests even if there are no kernels to test
The previous commit broke this.

Fixes: 8c7eb701bd ("setup.py: group test logs on GitHub Actions")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-18 10:12:51 -07:00
Omar Sandoval
8c7eb701bd setup.py: group test logs on GitHub Actions
The test logs on GitHub Actions are getting pretty big. GitHub Actions
has a workflow command that can be used to group log lines together:
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines.
Use it when running tests to make the logs easier to peruse.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-17 16:10:04 -07:00
Omar Sandoval
c4220f21cd tests: move Linux kernel helper tests under tests/linux_kernel
Splitting the tests between tests/linux_kernel and tests/helpers/linux
means that we have to set up the unit tests twice, including loading
debug info. Python 3.7 and newer have a way to get around this, but
we're still sort of supporting Python 3.6. Move them under one path to
speed up test runs.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-17 14:20:34 -07:00
Omar Sandoval
5ca063b921 setup.py: add option to test all kernel flavors
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-16 16:47:35 -07:00
Omar Sandoval
6a3dcad19b tests: add framework for test kernel module
Now that commit d999703f94 ("vmtest: add kernel module build
dependencies to kernel packages") added the files necessary to build a
test kernel module, add the module (currently a stub) and the
scaffolding necessary to build and load it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-05-16 14:27:35 -07:00
Omar Sandoval
2dada19ab9 setup.py: add 5.18 to vmtest kernels
The tiny flavor was failing due to a bug fixed in Linux kernel commit
c12cd77cb028 ("mm/vmalloc: fix spinning drain_vmap_work after reading
from /proc/vmcore") (in v5.18-rc3). Now that the fix is in, we can add
5.18 with no changes required.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-04-21 16:17:42 -07:00
Omar Sandoval
cb69aec85a tests: add Linux kernel version to VM test result
We currently log "Tests in VM returned $STATUS" when vmtest returns. To
find out what kernel version just returned, you have to scroll up to
find a previous log line that mentions the version. Make things more
convenient by adding the version to that message.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-25 17:47:56 -07:00
Omar Sandoval
322e2b1c69 tests: move non-helper Linux kernel tests
tests/helpers/linux contains test cases for Linux kernel helpers and
test cases for core Linux kernel support. The latter don't make sense
there; move them to tests/linux_kernel instead, along with the
scaffolding.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-04 15:43:33 -08:00
Omar Sandoval
7f232a4815 pre-commit: update Black
Black 22.1.0 has some style changes: string prefixes are normalized and
spaces around the power operator are removed.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-02-12 13:48:49 -08:00
Omar Sandoval
88decf6c0e setup.py: add 5.17 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-02-07 18:26:01 -08:00
Omar Sandoval
41de5d72a2 Require Python to build libdrgn
Currently, Python is only required to build the Python bindings. I
originally wanted to avoid having Python as a build dependency of
libdrgn, which is why gen_arch is an AWK script. However, I want to add
another code generation script which is harder to do in AWK.
Additionally, these days more people are familiar with Python than AWK,
so let's just bite the bullet and require Python to build. No one builds
libdrgn by itself anyways.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-02-04 20:26:35 -08:00
Kevin Svetlitski
ac2cadabcd Add framework for testing in kdump
Now that the vmtest kernel supports kdump, add a script that can be used
to crash and enter the kdump environment on demand. Use that to crash
after running the normal test suite so that we can run tests against
/proc/vmcore. vmcore tests live in their own directory; presently the
only test is a simple sanity check that ensures we can can attach to
/proc/vmcore.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Kevin Svetlitski <svetlitski@fb.com>
2022-01-07 14:03:00 -08:00
Omar Sandoval
c0d8709b45 Update copyright headers to Meta
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-21 15:59:44 -08:00
Omar Sandoval
93dc02a271 setup.py: add 5.16 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-21 14:52:46 -08:00
Omar Sandoval
c64d87e41a setup.py: add 5.15 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-09-13 09:59:22 -07:00
Omar Sandoval
5541fad063 Fix some flake8 errors
Mainly unused imports, unused variables, unnecessary f-strings, and
regex literals missing the r prefix. I'm not adding it to the CI linter
because it's too noisy, though.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-08-11 14:52:44 -07:00
Omar Sandoval
dc0c0e05f8 setup.py: add 5.14 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-07-29 17:52:58 -07:00
Omar Sandoval
e7865e2b09 setup.py: add 5.13 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-10 11:15:46 -07:00
Omar Sandoval
841a3dae88 Move vmtest assets to GitHub releases
As noted by commit 738261290f ("CI: temporarily disable vmtest"),
vmtest was generating too much traffic to the Dropbox shared folder that
hosted vmtest kernels. Instead, we can store kernel packages as GitHub
release assets. Update the code for downloading and uploading vmtest
assets, and also add a scheduled GitHub action to build new kernels
every Monday so I don't have to remember to do it manually.

This also drops vmtest support for 5.6-5.9, which now fail to build with
newer binutils due to the issue fixed in Linux kernel commit
1d489151e9f9 ("objtool: Don't fail on missing symbol table").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 00:28:56 -07:00
Omar Sandoval
a4b9d68a8c Use GPL-3.0-or-later license identifier instead of GPL-3.0+
Apparently the latter is deprecated and the former is preferred.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-03 01:10:35 -07:00
Omar Sandoval
f285764f8a Include full libdrgn distribution in drgn sdist
Building drgn from an sdist currently requires autotools and gawk
because libdrgn in the sdist is more or less a git checkout. It's more
user-friendly to include the autotools output and generated code. Do
this by extending the sdist command to include a full libdrgn
distribution with `make distdir`.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-03-30 23:19:38 -07:00
Omar Sandoval
4c5c5f3842 Remove bundled version of elfutils
We currently bundle a version of elfutils with patches to export
additional stack tracing functionality. This has a few drawbacks:

- Most of drgn's build time is actually building elfutils.
- Distributions don't like packages that bundle verions of other
  packages.
- elfutils, and thus drgn, can't be built with clang.

Now that we've replaced the elfutils DWARF unwinder with our own, we
don't need the patches, so we can drop the bundled elfutils and fix
these issues.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-03-16 00:52:09 -07:00
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