Commit Graph

431 Commits

Author SHA1 Message Date
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
Omar Sandoval
99575cec29 README: reword some more 2018-08-17 10:38:05 -07:00
Omar Sandoval
498819a8d0 README: fix typo, clarify some things 2018-08-17 01:39:44 -07:00
Omar Sandoval
03fd5eeed4 lib: fix mypy error
We're reusing f as a TextIO after it was defined as a BinaryIO.
2018-08-17 00:57:01 -07:00
Omar Sandoval
4f56a22d2e dwarftypeindex: handle zero-length and flexible array ambiguity
The DIE generated by GCC for a zero-length array doesn't have a
DW_AT_upper_bound or DW_AT_count attribute; it looks identical to that
of a flexible array. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86985.

The semantics of zero-length and flexible arrays are slightly different
(see https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html), so there are
a few specific cases where replacing a zero-length array with a flexible
array creates an invalid type. We can tell when the type must have been
a zero-length array; in other cases, we will just assume the type is a
flexible array. This ambiguity will hopefully be fixed in a future
version of GCC.
2018-08-17 00:41:47 -07:00
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