Omar Sandoval
c744b77f23
lib: workaround invalid p_paddr on kernels before v4.11
...
p_paddr in /proc/kcore is always zero before Linux v4.11, so we can't
easily read from the physical address we get from /sys/kernel/vmcoreinfo
(we would need architecture-specific knowledge of the virtual address of
the direct mapping, as well as a way to defeat CONFIG_RANDOMIZE_MEMORY).
Instead, we can get the only two fields we currently use through other
means (OSRELEASE is trivial and KERNELOFFSET can be determined by
comparing /proc/kallsyms to the ELF symbols).
2018-07-27 22:41:40 -07:00
Omar Sandoval
e8bafb750b
type: also dereference C strings in structs and arrays
2018-07-23 20:30:26 -07:00
Omar Sandoval
56166396ab
type: move pretty print dereferencing into Type._pretty()
...
Instead of ProgramObject.__format__().
2018-07-23 20:12:09 -07:00
Omar Sandoval
98a26ad610
corereader: add CoreReader.read_c_string()
...
And replace the Python implementation in ProgramObject.string_(). The
CoreReader implementation is still naive in that it reads byte-by-byte,
but this could always be improved in the future.
2018-07-23 18:19:41 -07:00
Omar Sandoval
da140ed094
type: rename Type.is_pointer() to Type.is_pointer_operand()
2018-07-22 17:43:27 -07:00
Omar Sandoval
b70addd5ae
type: get rid of unused Type._read_pretty()
2018-07-22 00:30:41 -07:00
Omar Sandoval
cab896a65b
type: exclude all-zero arrays and structs from array pretty-printing
2018-07-22 00:26:10 -07:00
Omar Sandoval
e8881f9b4d
cli: use terminal size as precision for ProgramObject in displayhook
2018-07-21 22:56:21 -07:00
Omar Sandoval
d7ff578f0e
program: add ProgramObject.__format__() with precision support
...
This gets passed along as the columns to Type._pretty().
2018-07-21 22:54:32 -07:00
Omar Sandoval
f4bb55e359
type: support putting multiple array elements on the same line
2018-07-21 22:53:05 -07:00
Omar Sandoval
d34df7a280
helpers: add missing imports in kernel block helpers
2018-07-20 21:20:05 -07:00
Omar Sandoval
6f14d82024
memberdesignator: fix error message when missing ']'
2018-07-16 20:30:09 -07:00
Omar Sandoval
f95eb9deab
Add some missing type annotations
2018-07-16 19:53:51 -07:00
Omar Sandoval
0cb3876900
tests: don't shell out to GCC for DwarfTypeIndex tests
...
Instead, make a mock DwarfIndex and CompilationUnit and construct Dies
directly.
2018-07-16 19:45:30 -07:00
Omar Sandoval
959968b4e4
dwarftypeindex: isolate pre-GCC 5.1 enum special case code
...
And change the signed heuristic.
2018-07-16 19:44:09 -07:00
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