Commit Graph

363 Commits

Author SHA1 Message Date
Omar Sandoval
6f16ab09d6 libdrgn: only apply ELF relocations to relocatable files
Relocations are only supposed to be applied to ET_REL files, not ET_EXEC
files like vmlinux. This hasn't been an issue with the kernel builds
that I've tested on because the relocations match the contents of the
section. However, on Fedora, the relocation sections don't match,
probably because they post-process the binary in some way. This leads to
completely bogus debug information being parsed by drgn_dwarf_index. Fix
it by only relocating ET_REL files.
2019-05-06 11:09:46 -07:00
Omar Sandoval
4bb36fc150 libdrgn: check for Python development headers at configure time 2019-05-03 14:10:48 -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
ce74f3fee1 docs: document Python 3 development header dependency 2019-05-03 10:23:02 -07:00
Omar Sandoval
3e1f31ed37 docs: document GNU Make dependency
I assumed installing autotools would pull this in, by at least on a
fresh Fedora install, it doesn't.
2019-05-03 09:56:36 -07:00
Omar Sandoval
8c229b794b helpers: handle inodes with no aliases in inode_path() 2019-05-02 08:12:58 -07:00
Omar Sandoval
7282c40a75 libdrgn: fix crash in drgn_object_slice()
We need to set the value after we've reinitialized the object, otherwise
drgn_object_deinit() may try to free a buffer that we've already
overwritten. This also adds a test which triggers the crash.
2019-04-24 17:57:36 -07:00
Omar Sandoval
0cc16bcdbb Add pronunciation to README 2019-04-17 01:18:44 -07:00
Omar Sandoval
fbbc7c55a2 Add logo and favicon 2019-04-17 01:16:31 -07:00
Omar Sandoval
452901923b docs: document creating incomplete type with struct_type()
This got lost in the conversion to Sphinx.
2019-04-12 16:46:07 -07:00
Omar Sandoval
97f5cf70c6 libdrgn: fix C array and function casting
Casting an array or function should first convert the array or function
into a pointer.
2019-04-12 16:40:12 -07:00
Omar Sandoval
1db8d11f84 libdrgn: allow void pointer arithmetic
This is a GCC extension, but it's used pretty often in practice.
2019-04-12 16:06:24 -07:00
Omar Sandoval
7719d76820 libdrgn: allow comparison of function pointers and incomplete arrays 2019-04-12 15:49:15 -07:00
Omar Sandoval
309dc82789 libdrgn: allow comparing any pointer types in C
There's a bug that we don't allow comparisons between void * and other
pointer types, so let's fix it by allowing all pointer comparisons
regardless of the referenced type. Although this isn't valid by the C
standard, GCC and Clang both allow it by default (with a warning).
2019-04-12 15:44:08 -07:00
Omar Sandoval
73090f6128 libdrgn: fix error message for cast to incomplete type
The errant type is the one we're trying to cast to, not the object's
type. This fixes an abort in drgn_error_incomplete_type().
2019-04-12 13:24:51 -07:00
Omar Sandoval
43614cce81 helpers: add a few more struct list_head helpers 2019-04-11 23:42:58 -07:00
Omar Sandoval
1b4aee1a55 libdrgn/python: add Program.pointer_type() 2019-04-11 23:35:10 -07:00
Omar Sandoval
435640faf6 Fix some linter errors 2019-04-11 15:51:20 -07:00
Omar Sandoval
b86fdf6e5c helpers: automatically import linux submodules
This way, we don't need to remember to add the imports explicitly.
2019-04-11 15:48:14 -07:00
Omar Sandoval
772254af3f examples: fix fs_inodes.py
Commit 48c5f37d01 ("Make read_once() a method again, as
Object.read_()") mistakenly changed fs_inodes.py to a benchmark I was
running. Additionally, commit 393a1f3149 ("Document with Sphinx")
changed the for_each_mount() helper to only yield the struct mount *.
2019-04-11 15:11:36 -07:00
Omar Sandoval
fc3db80957 Configure Travis CI 2019-04-11 14:17:44 -07:00
Omar Sandoval
393a1f3149 Document with Sphinx
drgn has pretty thorough in-program documentation, but it doesn't have a
nice overview or introduction to the basic concepts. This commit adds
that using Sphinx. In order to avoid documenting everything in two
places, the libdrgn bindings have their docstrings generated from the
API documentation. The alternative would be to use Sphinx's autodoc
extension, but that's not as flexible and would also require building
the extension to build the docs. The documentation for the helpers is
generated using autodoc and a small custom extension.
2019-04-11 12:48:15 -07:00
Omar Sandoval
9be2627418 helpers: make for_each_{disk,partition,mount}() generate NamedTuples 2019-04-05 11:59:03 -07:00
Omar Sandoval
321e2c210e libdrgn/python: format pointers in hex for Object.__repr__() 2019-04-05 10:36:54 -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
908e289eb8 cli: make -p 0 debug the debugger itself
This isn't super useful for end users, but it's been useful for me.
2019-04-02 14:18:07 -07:00
Omar Sandoval
0b72e180fa libdrgn: match partial paths for type/object lookups
The declaration file name of a DIE depends on the compilation directory,
which may not always be what the user expects. Instead, make the search
match as long as the full declaration file name ends with the given file
name. This is more convenient and more intuitive.
2019-04-02 14:12:11 -07:00
Omar Sandoval
19c8fd75e6 libdrgn: don't use zero length arrays for struct drgn_type
Running tests with Clang's AddressSanitizer fails with "runtime error:
index 1 out of bounds for type 'struct drgn_type_member [0]'". Zero
length arrays are a GCC extension and aren't buying us much anyways, so
just add a helper function that gets the array payload using pointer
arithmetic.
2019-04-02 14:12:11 -07:00
Omar Sandoval
a5fb8ed4c3 Add libelf/libdw wrappers to _drgn
If libelf or libdw are statically linked or not in the usual search
path, ctypes won't be able to find them. Add the required functions to
the wrappers in the libdrgn bindings so that we can easily find them.
2019-04-02 14:12:11 -07:00
Omar Sandoval
2dd14ad522 libdrgn: work around "undefined reference to '__muloti4'" when using Clang
Older versions of Clang generate a call to __muloti4() for
__builtin_mul_overflow() with mixed signed and unsigned types. However,
Clang doesn't link to compiler-rt by default. Work around it by making
all of our calls to __builtin_mul_overflow() use unsigned types only.

1: https://bugs.llvm.org/show_bug.cgi?id=16404
2019-04-02 14:12:11 -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
661af811bd Rename kernel helpers to linux 2019-03-29 01:59:53 -07:00
Omar Sandoval
48c5f37d01 Make read_once() a method again, as Object.read_()
After using it a few times, this operation is more fundamental than the
read_once() function lets on: it converts an lvalue to an rvalue. Make
it a method again, but rename it to read_().
2019-03-27 11:53:21 -07:00
Omar Sandoval
2addd9414c Fix a read_once() typo 2019-02-22 11:16:12 -08:00
Omar Sandoval
8edcb3052b Make read_once() a function instead of a method 2019-02-22 10:48:24 -08:00
Omar Sandoval
9a4262b609 Make cast() a function instead of a method 2019-02-22 10:34:53 -08:00
Omar Sandoval
3b998be960 Make container_of() a function instead of a method
The Object class is a little too bloated in terms of functionality, so
let's start streamlining it.
2019-02-22 10:34:46 -08:00
Omar Sandoval
29cfa7d03d program: get rid of Program.object() and null()
It's silly to have these trival factory methods. Instead, directly
construct with Object() and add a new NULL() function. We also
automatically import these in interactive mode.
2019-01-31 00:54:42 -08:00
Omar Sandoval
e912edc7d6 Move Program and Object to top-level drgn module 2019-01-29 21:04:40 -08:00
Omar Sandoval
2d340e30bb Rename ProgramObject to Object 2019-01-29 20:48:37 -08:00
Omar Sandoval
89eb868e95 helpers: make find_task() work on recent kernels
Linux kernel commit 2c4704756cab ("pids: Move the pgrp and session pid
pointers from task_struct to signal_struct") in v4.19 changed the method
of mapping a struct pid back to a struct task_struct. The radix tree
data structure was also replaced by a new XArray data structure in
v4.20. Handle both of those changes.
2019-01-29 16:01:45 -08:00
Omar Sandoval
6533fc0cdc cli: automatically import kernel helpers in interactive mode
It's annoying to always have to do the import manually.
2019-01-29 15:20:50 -08:00
Omar Sandoval
032a2a6dfa variableindex: raise KeyError instead of ValueError
This fixes the _vmemmap() and _page_offset() kernel mm helpers.
2019-01-09 00:06:20 -08:00
Omar Sandoval
8a02017ded README: fix license formatting 2018-08-23 01:07:33 -07:00
Omar Sandoval
99d4d1d212 lib: check for vmecoreinfo note in /proc/kcore
My patch adding the vmcoreinfo note to /proc/kcore was recently merged,
so we can use it now.
2018-08-23 00:50:27 -07:00
Omar Sandoval
0e9ca182bc program: fix ProgramObject.__index__() for enum objects
EnumType is in fact an integer, so enum objects should be allowed as an
index.
2018-08-22 01:04:06 -07:00
Omar Sandoval
5fa8217302 program, type: clean up type names and exceptions
Add a name attribute to all Type subclasses, which we can use in
exceptions everywhere.
2018-08-22 00:59:18 -07:00
Omar Sandoval
e5e0c62b9c type: rename {Struct,Union,Enum}Type.name to tag 2018-08-22 00:49:56 -07:00
Omar Sandoval
4458fb36e4 typename: rename {Struct,Union,Enum}Type.name to tag 2018-08-22 00:41:00 -07:00