Commit Graph

281 Commits

Author SHA1 Message Date
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
Omar Sandoval
263f8c2c4d dwarf: update DWARF constants
Update generate_dwarf_constants.py to parse dwarf.h, and update it with
the dwarf.h on my system.
2018-06-27 22:31:01 -07:00
Omar Sandoval
2a76972e68 Get symbol address from DWARF/ELF info instead of /proc/kallsyms
This has a few benefits:

1. We no longer have to parse /proc/kallsyms, which actually takes just
   as long as parsing all of the DWARF files
2. We can support vmcores
3. We can find the address of a specific variable even if it has the
   same name as other variables in the same object file
2018-06-27 21:45:36 -07:00
Omar Sandoval
266b35a7ae dwarfindex/elf: save file path in ElfFile 2018-06-27 19:51:06 -07:00
Omar Sandoval
0adac0747c Bring back ElfFile
Instead of constructing DwarfFile with a dict of sections, pass in an
ElfFile.
2018-06-25 23:43:14 -07:00
Omar Sandoval
68ebade7fa dwarfindex: fix number of symbols calculation 2018-06-25 21:47:53 -07:00
Omar Sandoval
d88ad8bd1d cli: read OS release from vmcoreinfo instead of uname
This is preparation for a couple of big future changes:

1. Using the ELF symbol table instead of /proc/kallsyms
2. Supporting vmcore crash dumps
2018-06-25 20:52:52 -07:00
Omar Sandoval
8340afb03b corereader: add context manager methods 2018-06-25 19:59:22 -07:00
Omar Sandoval
15c3db0936 corereader: support reading from physical addresses
/proc/kcore and vmcores include the physical memory address in the
program headers. Reading from physical memory can be useful, so support
it in CoreReader.
2018-06-25 00:41:29 -07:00
Omar Sandoval
26d3880708 dwarfindex: move indexing to a method instead of __init__()
We want to allow indexing files on the fly instead of all up front, so
move the indexing to a new DwarfIndex.add() method.
2018-06-25 00:25:49 -07:00
Omar Sandoval
6841eaace4 dwarfindex: replace cu->file and die_hash_entry->cu pointers with indices
We need this in order to be able to reallocate the files and cus arrays.
It also shrinks the size of struct die_hash_entry back to what it was
before file_name_hash was added.
2018-06-24 19:57:56 -07:00
Omar Sandoval
e2caf2bb0d dwarfindex: don't index any declarations and handle specifications
For variables which are predeclared, GCC generates a DW_TAG_variable DIE
with DW_AT_name and DW_AT_declaration as well as a DW_TAG_variable DIE
without DW_AT_name but with DW_AT_specification pointing to the
declaration DIE. We should index the latter, not the former. This has a
couple of benefits: we can skip indexing variable declaration DIEs,
which contribute a lot of duplicate hash table insertions; and, we can
always get the address of a variable from DW_AT_location of the indexed
DIE instead of having to parse the symbol table.
2018-06-23 00:23:30 -07:00
Omar Sandoval
a856eb4af9 cli: handle specification variable DIEs 2018-06-23 00:20:52 -07:00
Omar Sandoval
a05913298b dwarfindex: split read_die() out of index_cu() 2018-06-22 23:57:41 -07:00