Commit Graph

728 Commits

Author SHA1 Message Date
Omar Sandoval
016189f477 Update elfutils with improved stack frame interface
Rebase on master, add the improved
dwfl_frame_module/dwfl_frame_dwarf_frame patch, and add the
dwfl_frame_register patch.

Based on:

889edd912 PR25365: debuginfod-client: restrict cleanup to client-pattern files

With the following patches:

configure: Add --disable-programs
configure: Add --disable-shared
libdwfl: add interface for attaching to/detaching from threads
libdwfl: add interface for getting Dwfl_Module and Dwarf_Frame for Dwfl_Frame
libdwfl: export __libdwfl_frame_reg_get as dwfl_frame_register
libdwfl: add interface for evaluating DWARF expressions in a frame
2020-02-20 13:49:10 -08:00
Omar Sandoval
a5cd92f24e libdrgn: make vmcoreinfo accessible before loading debug info
UTS_RELEASE is currently only accessible once debug info is loaded with
prog.load_debug_info(main=True). This makes it difficult to get the
release, find the appropriate vmlinux, then load the found vmlinux. We
can add vmcoreinfo_object_find as part of set_core_dump(), which makes
it possible to do the following:

  prog = drgn.Program()
  prog.set_core_dump(core_dump_path)
  release = prog['UTS_RELEASE'].string_()
  vmlinux_path = find_vmlinux(release)
  prog.load_debug_info([vmlinux_path])

The only downside is that this ends up using the default definition of
char rather than what we would get from the debug info, but that
shouldn't be a big problem.
2020-02-19 12:11:45 -08:00
Omar Sandoval
cc18d9e502 libdrgn: add UTS_RELEASE to vmcoreinfo_object_find
The osrelease is accessible via init_uts_ns.name.release, but we can
also get it straight out of vmcoreinfo, which will be useful for the
next change. UTS_RELEASE is the name of the macro defined in the kernel.
2020-02-19 12:11:20 -08:00
Omar Sandoval
da26e814c2 docs: add missing mentions of class types
Commit 0df2152307 ("Add basic class type support") missed updating the
API reference.
2020-02-12 15:40:19 -08:00
Omar Sandoval
26ef465007 libdrgn/python: add proper type for members and parameters
This continues the conversion from the last commit. Members and
parameters are basically the same, so we can do them together. Unlike
enumerators, these don't make sense to unpack or access as sequences.
2020-02-12 15:40:19 -08:00
Omar Sandoval
7c70a1a384 libdrgn/python: add proper type for enumerators
Currently, type members, enumerators, and parameters are all represented
by tuples in the Python bindings. This is awkward to document and
implement. Instead, let's replace these tuples with proper types,
starting with the easiest one, TypeEnumerator. This one still makes
sense to treat as a sequence so that it can be unpacked as (name,
value).
2020-02-12 15:37:41 -08:00
Omar Sandoval
bda1426ae9 python: use tuple instead of list for __all__
It makes more sense semantically for __all__ to be immutable (except for
drgn.helpers.linux.__all__, which is built dynamically). While we're
here, sort the names, too.
2020-02-12 14:19:07 -08:00
Jay Kamat
23c7d34099 helpers: Add get_config helper for getting kconfig map 2020-02-12 14:06:49 -08:00
Jay Kamat
31d544949f libdrgn: Add find_symbol_by_name to look up ELF symbols 2020-02-12 14:06:49 -08:00
Jay Kamat
054cb54a01 libdrgn: Rename find_symbol to find_symbol_by_address 2020-02-12 14:06:49 -08:00
Omar Sandoval
9de2cc8410 libdrgn/python: make Object.__index__() TypeError message clearer
Currently, we print:

>>> prog.symbol(prog['init_task'])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: cannot convert 'struct task_struct' to index

It's not obvious what it means to convert to an index. Instead, let's
use the error message raised by operator.index():

TypeError: 'struct task_struct' object cannot be interpreted as an integer
2020-02-11 09:19:53 -08:00
Omar Sandoval
4adc691622 helpers: add helpers for finding user_structs 2020-02-10 18:11:25 -08:00
Omar Sandoval
71ce81ecbf travis.yml: add 5.6 to vmtest kernels and remove 5.3
v5.6-rc1 was released today, and 5.3 was recently EOL'd. (It might be
worthwhile to continue testing EOL kernels, but for now I don't want
Travis runs to take forever).
2020-02-10 12:43:25 -08:00
Omar Sandoval
b5232d944d tests: fix skipping Linux kernel tests if missing debug info
I forgot to name the caught exception.
2020-02-07 14:45:34 -08:00
Omar Sandoval
401a310fed python: add missed return type annotation for execscript() 2020-02-07 14:31:32 -08:00
Omar Sandoval
43277f59f2 docs: fix OutOfBoundsError exception directive
Commit ad82e9623a ("Introduce OutOfBoundsError") missed a space in the
documentation for OutOfBoundsError. Fix it.
2020-02-07 14:29:14 -08:00
Omar Sandoval
6d03d87978 docs: document that sizeof() argument is positional-only 2020-02-07 14:28:14 -08:00
Jay Kamat
ccc17cb846 .editorconfig: Add editorconfig for configuring style 2020-02-07 14:26:27 -08:00
Serapheim Dimitropoulos
80fef04c70 Add address attribute to FaultError exception 2020-02-04 14:59:31 -08:00
Serapheim Dimitropoulos
ad82e9623a Introduce OutOfBoundsError
Decouple some of the responsibilities of FaultError to
OutOfBoundsError so consumers can differentiate between
invalid memory accesses and running out of bounds in
drgn Objects which may be based on valid memory address.
2020-02-04 14:59:31 -08:00
Omar Sandoval
653e923657 drgn 0.0.2 2020-01-31 13:25:33 -08:00
Andrey Ignatov
98d2aba95c examples/tcp_sock: Fix missed import
In the previous commit used import was removed by mistake. Restore them.

Fixes: 7dd1853 ("examples: Switch tcp_sock to cgroup helpers")
2020-01-29 01:05:37 -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
Andrey Ignatov
421bda23f9 examples: Print bpf programs and maps
Add example to print basic info about bpf programs and maps (id, type,
name).

Example output:

  # python36 -m drgn examples/linux/bpf.py
  Usage: examples/linux/bpf.py { prog | map }
  # python36 -m drgn examples/linux/bpf.py p | head
       9: BPF_PROG_TYPE_CGROUP_SKB              name
      10: BPF_PROG_TYPE_CGROUP_SKB              name
   23368: BPF_PROG_TYPE_CGROUP_SOCK_ADDR        name tw_ipt_bind
   23369: BPF_PROG_TYPE_CGROUP_SOCK_ADDR        name tw_ipt_connect
   23370: BPF_PROG_TYPE_SOCK_OPS                name tw_ipt_listen
   23371: BPF_PROG_TYPE_CGROUP_SOCK_ADDR        name tw_ipt_sendmsg
   59538: BPF_PROG_TYPE_CGROUP_SYSCTL           name tw_sysctl
   97104: BPF_PROG_TYPE_SCHED_CLS               name fbflow_egress
   97105: BPF_PROG_TYPE_SCHED_CLS               name fbflow_ingress
   97106: BPF_PROG_TYPE_KPROBE                  name fbflow_tcp_conn
  # python36 -m drgn examples/linux/bpf.py m | head
       8: BPF_MAP_TYPE_LPM_TRIE                 name
       9: BPF_MAP_TYPE_LPM_TRIE                 name
      12: BPF_MAP_TYPE_PERCPU_ARRAY             name fbflow_pkt_info
   16305: BPF_MAP_TYPE_ARRAY                    name tw_ipt_cfg
   16306: BPF_MAP_TYPE_ARRAY                    name tw_tcp_ports_ma
   16307: BPF_MAP_TYPE_LRU_HASH                 name tw_ipt_lo_sk
   42606: BPF_MAP_TYPE_HASH                     name tw_sysctl_ro
   55338: BPF_MAP_TYPE_HASH                     name hash_min
   55341: BPF_MAP_TYPE_HASH                     name hash_8k_1
   55342: BPF_MAP_TYPE_HASH                     name hash_8k_8

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-24 10:53:47 -08:00
Andrey Ignatov
c8ef841768 helpers: Add bpf helpers
Add helpers to iterate over bpf programs and maps.

The map iteration code was used in debugging real-world problem that
turned out to be a kernel bug in memlock accounting in perf. Saving it
as helpers to use in future investigations.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-24 10:53:47 -08:00
Omar Sandoval
d4cc7945af Support building with alternative OpenMP runtime libraries
At Facebook, we link OpenMP code with libomp instead of libgomp. We have
an internal patch to drgn to do this, as it can't be done by setting
CFLAGS/LDFLAGS. Let's add a way to specify the OpenMP library at
configure time so that we can drop the internal patch.
2020-01-24 10:22:38 -08:00
Omar Sandoval
507d50c240 setup.py: support passing additional arguments to configure 2020-01-23 17:54:46 -08:00
Omar Sandoval
f4822be904 Document PyPI package and installation with pip 2020-01-23 15:15:33 -08:00
Omar Sandoval
18dfec083e docs: update local installation directions
Now that the CLI references the distribution, one needs to create the
distribution metadata to run locally.
2020-01-23 14:04:46 -08:00
Omar Sandoval
ea190db3f9 Don't define __version__ in drgn/__init__.py
This breaks autodoc on Read the Docs because it builds the documentation
without creating the distribution. I have something in the works to stop
using autodoc, but for now, we can just get the version in the CLI code.
2020-01-23 14:04:37 -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
ce06683861 vmtest/run: always get list of source files from SOURCES.txt
The next change will make non-git builds depend on a fully-formed source
distribution. So, let's copy in everything from SOURCES.txt, which
should include the egg metadata and anything else setuptools decides is
important.
2020-01-23 10:02:29 -08:00
Omar Sandoval
b2c1a613ec docs: add requirements.txt
Read the Docs is failing to build the documentation because it doesn't
know it needs to install sphinx-autodoc-typehints.
2020-01-14 16:27:10 -08:00
Omar Sandoval
6ee17e8f19 tests: add tests for cgroup helpers 2020-01-14 16:03:20 -08:00
Omar Sandoval
016f2f43c6 tests: add tests for kernfs helpers 2020-01-14 16:03:20 -08:00
Andrey Ignatov
10fa4686c1 examples: Print attached cgroup-bpf programs
Support additional argument `bpf` in `cgroup.py` that, if specified,
prints only cgroups with attached BPF programs in a way similar to
`bpftool cgroup tree`. W/o the `bpf` argument the tool works as before.

For example:

  # python36 -m drgn examples/linux/cgroup.py /sys/fs/cgroup/workload.slice/ bpf
  /workload.slice
      98761    BPF_CGROUP_SOCK_OPS            2               ned_cgrp_dctcp
  /workload.slice/workload-tw.slice/nc_0.58_dev082.prn2_598fe2e810bc4_2.task
      93488    BPF_CGROUP_INET_INGRESS        0               tw_ingress
      93487    BPF_CGROUP_INET_EGRESS         0               tw_egress
      93482    BPF_CGROUP_SOCK_OPS            2               tw_ipt_listen
      93480    BPF_CGROUP_INET6_BIND          0               tw_ipt_bind
      93481    BPF_CGROUP_INET6_CONNECT       0               tw_ipt_connect
      93483    BPF_CGROUP_UDP6_SENDMSG        0               tw_ipt_sendmsg

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
760d42b4ba helpers: Add cgroup-bpf helpers
Add a new module `bpf` and a bunch of cgroup-bpf helpers. More bpf
helpers can be added in the future (e.g. iterate over all programs,
maps, etc).

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
36cedcdc6f examples: Add example to traverse cgroup v2 hierarchy
Add simple example to traverse cgroup v2 hierarchy.

It can be run w/o arguments and in this case root cgroup will be used:

  # python36 -m drgn examples/linux/cgroup.py | wc -l
  1081
  # python36 -m drgn examples/linux/cgroup.py | shuf -n 3
  /system.slice/nfs-idmapd.service
  /user.slice/user-0.slice/user@0.service/dev-hugepages.mount
  /system.slice/crond.service

Or a path in cgroup v2 filesystem can be specified to limit the
traversal by this path:

  # python36 -m drgn examples/linux/cgroup.py /sys/fs/cgroup/www.slice
  /www.slice
  /www.slice/hack.service
  /www.slice/flow.service

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
820d25ae29 helpers: Add cgroup v2 helpers to traverse hierarchy
Add helpers to iterate over all children and all descendants (pre-order
walk only) of a cgroup given its css.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
7dd18535e1 examples: Switch tcp_sock to cgroup helpers
Use cgroup helpers instead of working with socket cgroup manually.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
9c72e68385 helpers: Add cgroup v2 helpers
Add helpers to get cgroup name, path, parent and cgroup by socket.
Only cgroup v2 is supported.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
26389b61fc helpers: Add kernfs helpers
Add helpers to get kernfs node name and path.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Omar Sandoval
7356816f61 helpers: get rid of get_tcp_states()
After thinking about this some more, I decided that although it makes
sense for scripts to convert a type to an IntEnum class, I'd prefer that
the helpers take and return drgn Objects rather than these classes.
2020-01-14 14:25:32 -08:00
Omar Sandoval
b30fb57e2f helpers: add enum_type_to_class()
We have a few use cases for converting a drgn.Type to a Python
enum.IntEnum (if I recall correctly, the original Python version of drgn
even did this automatically for enumerated types). Add an
enum_type_to_class() helper which does this conversion.
2020-01-14 12:13:02 -08:00
Omar Sandoval
842c98b055 Add .git-blame-ignore-revs
To make the previous reformatting commit less annoying, add a file
containing the commits to ignore in git blame. To use it, run `git blame
--ignore-revs-file .git-blame-ignore-revs` or `git config
blame.ignoreRevsFile .git-blame-ignore-revs`.
2020-01-14 12:03:26 -08:00