Omar Sandoval
e3fa0bca93
dwarf: pass a thunk to Die instead of offset, length
...
This is mostly to make it more testable.
2018-07-16 19:43:33 -07:00
Omar Sandoval
a69a743f55
tests: fix const_anonymous_color_type
...
It has negative enumerators, so it obviously must be signed.
2018-07-16 19:42:52 -07:00
Omar Sandoval
f9976855ee
Add Python coverage output to .gitignore
2018-07-16 19:42:32 -07:00
Omar Sandoval
b490f1c7bc
program: micro-optimize ProgramObject.container_of_()
2018-07-15 23:55:43 -07:00
Omar Sandoval
7de73c2a21
program: micro-optimize ProgramObject.__init__()
...
Save some "is None"s, use a local for real_type.
2018-07-15 23:47:15 -07:00
Omar Sandoval
4fa82d0bac
type: optimize _convert() methods
...
Avoid calling isinstance(); instead, catch errors. Also use & instead of
% for truncating ints and give PointerType its own implementation.
2018-07-15 23:22:46 -07:00
Omar Sandoval
45da5e8d35
tests: split DwarfTypeIndex tests out of TypeIndex tests
2018-07-15 18:07:36 -07:00
Omar Sandoval
a4ecbff27f
Fix some minor code style spacing issues
2018-07-15 16:48:11 -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
f22ff38b28
elf: fix off-by-one in note parsing
...
I copied and pasted from the name parsing but forgot to get rid of the -
1.
2018-07-12 17:13:12 -07:00
Omar Sandoval
9273de829b
type: handle anonymous types thoroughly
...
There were a couple more corner cases missing: arrays of anonymous types
and bit fields of anonymous enums.
2018-07-11 23:56:32 -07:00
Omar Sandoval
6e05f9d0b2
type: add Type.is_anonymous()
...
And use it for CompoundType.__str__() and TypedefType.__str__().
2018-07-11 22:36:37 -07:00
Omar Sandoval
51aa35bc05
type: also format typedefs of anonymous enums
2018-07-11 22:34:01 -07:00
Omar Sandoval
e18670ff3d
type: support enum bit fields
2018-07-11 22:18:50 -07:00
Omar Sandoval
6fa2d68c0c
type: add Type.unqualified()
2018-07-11 21:51:48 -07:00
Omar Sandoval
9b5b721838
type: format typedefs of anonymous types better
...
Currently, printing, e.g.,
typedef struct {
int counter;
} atomic_t
results in
typedef struct atomic_t
Which isn't very useful. Instead, print the former.
2018-07-11 21:40:01 -07:00
Omar Sandoval
c58c7d30ac
dwarfindex: support cyclic garbage collection
...
I forgot to add tp_traverse and tp_clear.
2018-07-11 20:18:37 -07:00
Omar Sandoval
7a45446729
Move CLI setup code into library
...
This way, it can be used outside of drgn.
2018-07-11 20:08:06 -07:00
Omar Sandoval
6a6d37c5e1
Make Program and CoreReader context managers
...
This is preparation for the next change, so that a Program can clean up
after itself. The Program will close the CoreReader, and the CoreReader
will close the underlying file.
2018-07-11 19:16:34 -07:00
Omar Sandoval
d46be4cb77
corereader: fix "could not find memory segment containing 0x(nil)" message
...
PyUnicode_FromFormat()'s %p does this for some reason (and also doesn't
support %llx). We can explicitly format into a buffer, instead.
2018-07-10 20:02:43 -07:00
Omar Sandoval
7613fe0e36
program: fix type isinstance() checks to use is_foo()
...
These take enums and typedefs into account.
2018-07-10 19:36:33 -07:00
Omar Sandoval
1c80eb468b
Support running userspace programs
...
We can get the same information that a core dump's NT_FILE gives us
through /proc/$PID/maps, and we can treat /proc/$PID/mem as a core file
with a single giant segment.
2018-07-09 23:08:56 -07:00
Omar Sandoval
c2d51fe295
Support userspace program core dumps
...
We only need to add a little bit of infrastructure to map variable
addresses for ASLR/shared libraries, which we find using the NT_FILE
note.
2018-07-09 22:34:03 -07:00
Omar Sandoval
631f50a2f6
variableindex: factor DwarfVariableIndex out of KernelVariableIndex
...
The DWARF functionality can be shared with userspace programs.
2018-07-09 22:03:49 -07:00
Omar Sandoval
0190467ee6
dwarfindex: allow files without debugging information
...
For userspace programs, most system libraries will not have debugging
information. This shouldn't be fatal. Instead, the caller can check
which files were in fact indexed.
2018-07-09 21:15:42 -07:00
Omar Sandoval
000a03619d
dwarfindex: add DwarfIndex.files property
2018-07-09 21:11:52 -07:00
Omar Sandoval
ca55a6f44f
dwarfindex: fix resize_array() with n = 0
...
realloc() can succeed and return NULL if size is 0, so check errno
instead.
2018-07-09 20:40:53 -07:00
Omar Sandoval
43cb15d4e6
dwarfindex: allow passing paths to DwarfIndex.__init__()
...
I didn't end up needing DwarfIndex.add(), so it's more convenient to
pass the paths to __init__(). The add() functionality might be useful in
the future, and it's pretty simple, so we might as well leave it in.
2018-07-09 20:24:46 -07:00
Omar Sandoval
800ee3ec36
corereader: take fd and list of segments instead of path
...
Now, we can get rid of the ELF parsing implementation in CoreReader.
Instead, we parse in ElfFile and pass the parsed information to
CoreReader.
2018-07-09 19:12:33 -07:00
Omar Sandoval
d376b3c557
elf: pass a BinaryIO instead of a memoryview
2018-07-09 17:34:52 -07:00
Omar Sandoval
7ae295dda5
Add MemoryViewIO
...
This will be used so that ElfFile can take a BufferedIOReader instead of
a memoryview.
2018-07-09 17:03:15 -07:00
Omar Sandoval
e489c243b3
cli: support kernel vmcores
...
Finally, all the infrastructure is in place for reading core dumps
instead of just the running kernel, so we can hook it up.
2018-07-07 10:57:24 -07:00
Omar Sandoval
7ef3a71741
corereader: support parsing ELF notes
...
This will be used for reading the vmcoreinfo note.
2018-07-07 10:35:04 -07:00
Omar Sandoval
306862167d
corereader: handle segments with p_filesz < p_memsz
...
The extra is defined to be zero-filled.
2018-07-06 19:28:20 -07:00
Omar Sandoval
a22f4b7d4f
corereader: save segments as Elf64_Phdr
...
This is preparation for the following two changes.
2018-07-06 18:01:57 -07:00
Omar Sandoval
3ff1cc185a
variableindex: distinguish vmlinux vs modules with ELF e_type
...
For /boot/vmlinux-$(uname -r) or if passed a vmlinux image with -e, the
basename of vmlinux is not always exactly "vmlinux". Don't rely on the
filename.
2018-07-03 00:27:56 -07:00
Omar Sandoval
abb2c2f71f
dwarfindex: remove unused include
...
The include of <sys/random.h> was a leftover from when we were actually
using a SipHash key.
2018-07-03 00:19:52 -07:00
Omar Sandoval
e5048e24e9
Add README and examples
2018-07-02 23:59:39 -07:00
Omar Sandoval
dd149c6d4f
helpers: remove leading slash from dentry_path()
...
The path returned is relative to the root of the filesystem, not an
absolute path, so remove the misleading leading slash.
2018-07-02 23:51:00 -07:00
Omar Sandoval
2b22fe0a29
helpers: simplify PID enum handling
2018-07-02 23:48:49 -07:00
Omar Sandoval
b20d544242
helpers: add list_for_each{,_entry}_reverse()
2018-07-02 23:48:32 -07:00
Omar Sandoval
06064fa988
elf: fix style error
2018-06-30 22:10:21 -07:00
Omar Sandoval
50f52ec295
program: make ProgramObject() arguments mandatory keywords
...
It's too hard to remember whether value or address comes first, so make
sure we're always explicit which one.
2018-06-28 23:40:47 -07:00
Omar Sandoval
0d4c4d159b
variableindex: include enumerators in variable search
2018-06-28 23:07:13 -07:00
Omar Sandoval
9d24bc9c5c
dwarfindex: make DwarfIndex.find() tag optional
2018-06-28 21:53:00 -07:00
Omar Sandoval
d9e6fa94b5
dwarfindex: index enumerator names
...
The enumerator DIE itself doesn't let us get at the type, though, so
hack it to point at the enumeration_type DIE.
2018-06-28 21:47:27 -07:00
Omar Sandoval
cea27cc0a0
variableindex: support disambiguating variables by filename
2018-06-28 21:16:06 -07:00
Omar Sandoval
aeb767d43e
Replace lookup_variable callback with new VariableIndex class
...
Similar to how we replaced the lookup_type callback with TypeIndex.
2018-06-28 21:05:21 -07:00
Omar Sandoval
02c75770ea
typeindex: support disambiguating types by filename
2018-06-28 19:34:10 -07:00