Commit Graph

1487 Commits

Author SHA1 Message Date
Imran Khan
4f2c8f0735 tests: idr: add test cases for idr.
So far idr support was available for only radix-tree based idrs.
Thus radix-tree tests were implicity covering idr test as well.
Now as we are supporting non radix-tree based idrs as well, so
add explicit test cases for idr testing.
The test are applicable for both new (i.e radix-tree based) and
old implementation of idrs.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
2023-01-23 17:32:17 -08:00
Imran Khan
4d7c709621 helpers: idr: Enable idr helpers to work with older kernel.
Prior to kernel v4.11, idr was not using radix tree as its backend.
So current idr helper(s) only work for kernel v4.11+.
Enable idr helpers(s) to work with non-radix tree based idr, so that
the helpers can be used with older kernels as well.

Thanks to Omar for optimizing the idr_for_each helper.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
2023-01-23 17:32:17 -08:00
Omar Sandoval
48dd87da98 vmtest.download: check actual download length against Content-Length
The CI keeps has been sporadically hitting errors like:

  downloading kernel release 6.0.19-vmtest17.1default to build/vmtest/x86_64/kernel-6.0.19-vmtest17.1default from https://api.github.com/repos/osandov/drgn/releases/assets/91622017
  /*stdin*\ : Read error (39) : premature end
  tar: Unexpected EOF in archive
  tar: Unexpected EOF in archive
  tar: Error is not recoverable: exiting now

The only way I can see this happening is if the download is being
truncated, so add a check (inspired by urllib.request.urlretrieve()).

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-23 15:43:54 -08:00
Timothée Cocault
9730deeb85 Fix example for add_memory_segment
The parameters of the read_file function in the example are swapped.
This matches the parameters order used by py_memory_read_fn.

Fixes: c0bc72b0ea ("libdrgn: use splay tree for memory reader")
Signed-off-by: Timothée Cocault <timothee.cocault@gmail.com>
2023-01-23 13:04:46 -08:00
Kevin Svetlitski
7e6efe6649 Add support for looking up types in namespaces
Looking up objects in namespaces is already well-supported by `drgn`.
These changes bring the same to functionality type lookup, so that
`prog.type('struct A::B::C::MyType')` works in an analogous fashion to
`prog['A::B::C::MyVar']`.

Signed-off-by: Kevin Svetlitski <svetlitski@meta.com>
2023-01-19 10:19:36 -08:00
Kevin Svetlitski
e5754e47ba Mark immutable attributes as Final in type stubs
Object attributes which are not changed after the object's creation
have been marked with the `Final` type attribute. The primary utility
of this change is that some Python type checkers, [such as
Pyre](https://pyre-check.org/docs/errors/#optional-attributes), rely on
the presence of the `Final` attribute to determine whether `Optional`
values have been validated as being present before their contents are
accessed.

Signed-off-by: Kevin Svetlitski <svetlitski@meta.com>
2023-01-18 16:01:52 -08:00
Stephen Brennan
15f151c1e4 Document the linux kernel object finder
drgn is able to lookup some special metadata for the Linux kernel,
sometimes even without debuginfo. For users who may expect that
Program.object() will only return objects corresponding to variables,
these metadata are unexpected and can be quite useful. Regardless,
they're currently undocumented. Add documentation under Advanced Usage
for these, and reference it in the Program.object() docstring.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-01-17 16:10:49 -08:00
Omar Sandoval
7a3ddf20d3 vmtest: kbuild: fix typo in comment
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-13 14:17:11 -08:00
Omar Sandoval
d829775287 vmtest: kbuild: enable Unix sockets
Lots of core tools expect Unix sockets to work. Stephen Brennan recently
hit issue where installing Ksplice on Ubuntu replaced modprobe with a
version that uses Unix sockets, which caused the kernel to call modprobe
to load the Unix socket module, recursively until the kernel's modprobe
limit of 50 was hit.

Enable Unix sockets to avoid other surprises like this. (We'll probably
eventually have drgn helpers for Unix sockets, too.)

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-13 14:12:09 -08:00
Omar Sandoval
f3cf8fb36d Revert "packit: temporarily work around examples directory"
This reverts commit 845ac5fceb. The Fedora
RPM spec has been updated.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-13 10:38:54 -08:00
Omar Sandoval
9cce4c33b2 drgndoc: support formating unary operators
This is necessary for type annotations like `def foo(fd: int = -1)` in
future changes.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-13 10:38:44 -08:00
Kevin Svetlitski
c32f0811cb Fix memory leak in c_format_compound_object
Found via CodeChecker static analysis.

Signed-off-by: Kevin Svetlitski <svetlitski@meta.com>
2023-01-11 11:59:43 -08:00
Stephen Brennan
33c3e36fd2 helpers/linux/fs: for_each_file: handle NULL files
It's allowable for task->files to be NULL. Handle this case gracefully
by returning without yielding any files.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Reported-by: Wengang Wang <wen.gang.wang@oracle.com>
2023-01-09 16:15:53 -08:00
Omar Sandoval
1c6ea8e00d docs: add release highlights for 0.0.22
I've been posting these internally at Meta for previous releases, but I
think others would find them useful, too. In the future, I'll write them
up before cutting the release.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-06 15:21:43 -08:00
Omar Sandoval
2181826570 drgn 0.0.22
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 20:38:32 -08:00
Omar Sandoval
5dd03eead9 Build manylinux2014 wheels instead of manylinux2010
manylinux2010 has been EOL since August 2022; see pypa/manylinux#1281.
In particular, the manylinux2010 image wasn't updated with Python 3.11.
Update scripts/build_dist.sh to use manylinux2014 and drop some CentOS 6
workarounds from scripts/build_manylinux_in_docker.sh.

If someone really wants manylinux2010, we can probably build both, but
none of the popular packages I checked (NumPy, SciPy, cryptography,
charset-normalizer) do this.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 20:10:36 -08:00
Omar Sandoval
69d3ce5ced Update libkdumpfile in manylinux wheels to 0.5.0
And make sure that it's built with zstd support.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 20:08:55 -08:00
Omar Sandoval
134393f5f0 Update elfutils in manylinux wheels to 0.188
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 19:44:24 -08:00
Omar Sandoval
a7224dbc77 Fix more MANIFEST.in issues
We need to include contrib. Also improve the tools and LICENSES
patterns.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 19:13:19 +00: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
9dbf5d03fa CI: update GitHub action versions to silence Node.js warnings
Runs have been getting warnings like the following:

  Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: actions/checkout@v2, actions/setup-python@v2

The guilty actions all have new versions that use Node.js 16.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 10:41:30 -08:00
Omar Sandoval
4731de6acc libdrgn: x86_64: unwind with frame pointer more permissively
get_registers_from_frame_pointer() has a sanity check that the unwound
frame pointer must be greater than the current frame pointer. This is
generally true if the entire program is using frame pointers, but not
necessarily otherwise. In particular, if the program is a Linux kernel
configured with ORC, most of the time, rbp is a general purpose
register; it is only used as a frame pointer in special cases without
unwinder information like BPF programs. Those cases are exactly when we
want the frame pointer unwinder, but depending on what the caller was
using rbp for, the frame pointer unwinder might bail prematurely.

Let's remove the sanity check. In the worst case, this could lead us off
into the weeds chasing pointers, but the iteration limit in
drgn_get_stack_trace() prevents that from being dangerous.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-04 16:45:28 -08:00
Omar Sandoval
3ec91c723a tests: kmod: stop using crash_setup_regs()
ppc64's crash_setup_regs() calls ppc_save_regs(), which isn't exported.
So, we need to provide our own implementation. At this point, we might
as well just copy the implementations of crash_setup_regs() for x86-64
and AArch64 and stop trying to use crash_setup_regs().

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-04 16:35:51 -08:00
Omar Sandoval
975255f209 tests: handle cases without slab support in print_annotated_stack() test
When the architecture is missing virtual address translation or the
kernel is configured with SLOB, print_annotated_stack() will not
identify slab objects.

Fixes: 05041423c7 ("drgn.helpers.common.stack: add print_annotated_stack helper function")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-04 15:10:16 -08:00
Omar Sandoval
f0c573dbd9 drgn.helpers.common.memory: handle architectures without virtual address translation in identify_address()
identify_address() is supposed to be best-effort, but if it is called on
an architecture without virtual address translation support, it will
raise a NotImplementedError. Let's catch and ignore it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-04 15:09:56 -08:00
Omar Sandoval
a6b6afaba2 libdrgn: return DRGN_ERROR_NOT_IMPLEMENTED_ERROR if virtual address translation is not implemented
This will allow us to distinguish it from other errors.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-04 15:09:56 -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
c48cddbdb0 libdrgn: ppc64: fix stack unwinding since Linux v5.11 and before v4.20
linux_kernel_get_initial_registers_ppc64() depends on the size of struct
pt_regs, but this has changed multiple times, in:

- Linux kernel commit 4c2de74cc869 ("powerpc/64: Interrupts save PPR on stack rather than
  thread_struct") (in v4.20)
- Linux kernel commit 66f93c5a02d5 ("powerpc/64: Fix kernel stack
  16-byte alignment") (in v4.20)
- Linux kernel commit 8e560921b58c ("powerpc/book3s64/pkeys:
  Store/restore userspace AMR/IAMR correctly on entry and exit from
  kernel") (in v5.11)

It also depends on the overhead stored before struct pt_regs on the
stack, which changed in Linux kernel commit cd52414d5a6c ("powerpc/64:
ELFv2 use minimal stack frames in int and switch frame sizes") (in
v6.2).

We can handle all of these cases by reading the previous r1 from memory
instead of computing it from a hard-coded size and finding the struct
pt_regs based on that r1 and the actual size of struct pt_regs.

Reported in #232.

Reported-by: Sourabh Jain <jainsourabh679@gmail.com>
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-04 13:42:28 -08:00
Omar Sandoval
58e7d751e7 vmtest: add content write permissions to vmtest build job
I changed the default workflow permissions to be restrictive, but I
forgot that the vmtest build needs to upload assets. Add write
permissions for the contents scope, which seems to cover asset uploads.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-29 00:17:46 -08:00
Omar Sandoval
c9e970c935 vmtest: set raise_for_status=True for GitHub API requests
The vmtest build is silently failing to upload kernel builds. We're not
checking for HTTP errors, so let's see if that provides some
information.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-28 23:24:52 -08:00
Omar Sandoval
9ced57a6e1 CI: set GITHUB_TOKEN environment variable
This should fix the "HTTP Error 403: rate limit exceeded" errors we've
been seeing. (I don't know if GitHub Actions used to do this
automatically or they started being stricter about rate limits.)

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-20 21:45:44 -08:00
Omar Sandoval
05d9cb58eb Fix MANIFEST.in warning for LICENSES directory
We're getting this warning from setuptools:

  warning: manifest_maker: MANIFEST.in, line 6: 'recursive-include' expects <dir> <pattern1> <pattern2> ...

Fix it by adding '*'.

Fixes: b156d987d7 ("Move license to LICENSES")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-19 16:31:20 -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
e860a6e077 tests: use #ifdef __s390x__ instead of #if
The Linux kernel apparently enables -Wundef, so although #if is correct,
it results in a warning. Use #ifdef instead.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-19 16:25:05 -08:00
Sven Schnelle
44648ae139 tests: add drgn_test_get_pt_regs() for s390
s390 doesn't implement crash_setup_regs(). Add an alternative
implementation instead.

Suggested-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
2022-12-19 13:48:44 -08:00
Sven Schnelle
1bbeff92bf libdrgn: add s390x unwinding support
Co-authored-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
2022-12-19 13:48:44 -08:00
Omar Sandoval
9ee1ccff98 libdrgn: add stub s390 and s390x architectures with relocation implementation
The only relocation type I saw in Debian's kernel module debug info was
R_390_32. R_390_8, R_390_16, R_390_64, R_390_PC16, R_390_PC32, and
R_390_PC64 are trivial to support, as well. The Linux kernel supports
many more, but hopefully they won't show up for debug info.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-19 13:48:44 -08:00
Omar Sandoval
6ad80feb83 cli: make missing debug info warning more prominent
I've had lots of reports that turned out to be due to missing debug info
(e.g., #161, #175, #231, and more offline). A big part of the problem is
probably that the warning gets lost among the startup information. Let's
move the warning to be the last thing we print and also color it.

After the debug info discovery rework, we can print more specific
advice, but this is better than nothing.

Closes #41.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-19 12:20:45 -08:00
Omar Sandoval
aa5f121ac9 libdrgn: document implementation-defined behavior in add_to_possibly_null_pointer()
Konrad Borowski pointed out that add_to_possibly_null_pointer() relies
on GCC-specific behavior:
https://fosstodon.org/@xfix/109542070338182493. CONTRIBUTING.rst
mentions that we assume that casting between pointers and integers does
not change the bit representation, but we might as well document it
here, too.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-19 12:07:40 -08:00
Omar Sandoval
7b64aee4dd tests: add a real test case for unwinding from struct pt_regs
The current test case only checks that getting a stack trace succeeds.
By having the test kernel module create a struct pt_regs, we can
actually test that we get a reasonable stack trace.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-15 17:44:22 -08:00
Omar Sandoval
868ae51329 drgn.helpers.linux.mm: expand on for_each_page() FaultError note
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-15 09:32:45 -08:00
Omar Sandoval
0d9252ea0c drgn.helpers.linux.mm: document catching FaultError for for_each_page()
for_each_page() can return offline pages that don't actually exist.
Fixing this is difficult (see #228), but working around it by catching
FaultError is easy. Document the recommended usage.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-15 01:37:12 -08:00
Omar Sandoval
c6a24eea6b vmtest: kbuild: prepare for SLOB deprecation in Linux 6.2
CONFIG_SLOB was renamed to CONFIG_SLOB_DEPRECATED during the Linux 6.2
merge window. Let's prepare for that now before rc1 is released.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-14 21:32:40 -08:00
Kevin Svetlitski
454e6e8197 Add test cases for parsing C++ identifiers with template parameters
Signed-off-by: Kevin Svetlitski <svetlitski@meta.com>
2022-12-14 20:55:03 -08:00
Kevin Svetlitski
4213bea149 libdrgn: add limited support for looking up types with template arguments
Currently, looking up a type with template arguments results in an
"invalid character" syntax error on the "<" character. The DWARF index
includes template arguments in indexed names, so we need to do lookups
including the template arguments. Full support for this would require
parsing the template argument list syntax and normalizing it or looking
it up as an AST in some way. For now, it's at least an improvement to
pass the user's string verbatim. To do so, kludge it by adding a token
containing everything from "<" to the matching ">" to the C++ lexer and
appending that to the identifier.

Co-authored-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Kevin Svetlitski <svetlitski@meta.com>
2022-12-14 20:55:03 -08:00
Davide Cavalca
d1bfe17097 packit: add SRPM build deps
Signed-off-by: Davide Cavalca <dcavalca@meta.com>
2022-12-14 09:54:15 -08:00
Davide Cavalca
170eaf8bf4 packit: update to use the new syntax
Signed-off-by: Davide Cavalca <dcavalca@meta.com>
2022-12-14 09:54:15 -08:00
Omar Sandoval
8867b6ee7e drgn.helpers.linux.xarray: fix a couple more documentation typos
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-13 23:26:50 -08:00
Omar Sandoval
cd769c06f0 drgn.helpers.linux.xarray: fix typo in module docstring
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-13 18:25:49 -08:00
Omar Sandoval
7ce84a3f1f drgn.helpers.linux: add proper XArray helpers
Commit 89eb868e95 ("helpers: make find_task() work on recent kernels")
made radix_tree_lookup() and radix_tree_for_each() work for basic
XArrays. However, it doesn't handle a couple of more advanced features:
multi-index entries (which old radix trees actually also supported) and
zero entries. It has also been really confusing to explain to people
unfamiliar with the radix tree -> XArray transition that they should use
helpers named radix_tree for a structure named xarray.

So, let's finally add xa_load(), xa_for_each(), and some additional
auxiliary helpers. The non-recursive xa_for_each() implementation is
based on Kevin Svetlitski's C implementation from commit 2b47583c73
("Rewrite linux helper iterators in C"). radix_tree_lookup() and
radix_tree_for_each() share the implementation with xa_load() and
xa_for_each(), respectively, so they are mostly interchangeable.

Fixes: #61

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-12-13 17:46:37 -08:00