Commit Graph

359 Commits

Author SHA1 Message Date
Omar Sandoval
3bc5b3b4fc helpers: rename mounts() to for_each_mount() 2018-05-29 21:08:30 -07:00
Omar Sandoval
e2ef1b9b27 helpers: support PID hash from before Linux v4.15 2018-05-29 21:05:54 -07:00
Omar Sandoval
fea85e8d72 helpers: add kernel PID helpers
I considered calling this module sched instead of pid but it's really
about PIDs, not tasks.
2018-05-29 00:25:45 -07:00
Omar Sandoval
d4b73c03ac helpers: add kernel VFS helpers 2018-05-28 23:51:37 -07:00
Omar Sandoval
ea121af2ad Add Linux kernel helpers
Beyond providing the raw interface for accessing objects, drgn should
provide helpers for inspecting programs. This introduces the first set
of helpers for the Linux kernel. In the future, it would be cool to have
helpers for common libraries like libstd++.
2018-05-28 00:08:03 -07:00
Omar Sandoval
32974c3c98 Fix some minor style problems 2018-05-27 22:44:05 -07:00
Omar Sandoval
a7448f4ce6 program: fix mypy errors about builtins._ 2018-05-26 23:43:55 -07:00
Omar Sandoval
5701689436 program: add ProgramObject.read_once() 2018-05-26 23:01:09 -07:00
Omar Sandoval
cc5fb61295 program: add Program.null()
Shorthand for Program.object(type, value=0).
2018-05-26 22:49:32 -07:00
Omar Sandoval
52052959ae program: only convert errors from CompoundType.member() to AttributeError
Errors reading memory, for example, should stay as ValueError. Maybe
these should have more specific exception types in the future.
2018-05-26 22:44:25 -07:00
Omar Sandoval
906f16832f program: make ProgramObject() address optional
This way, rvalues can be more conveniently created with
prog.object(type, value=x).
2018-05-26 17:48:52 -07:00
Omar Sandoval
2ee6662639 program: handle pointers to typedefs of struct/union types
ProgramObject.__dir__(), member_(), and container_of_() all check that
the relevant type is a struct or union, but they all need to allow
typedefs of structs or unions, as well.
2018-05-25 22:32:03 -07:00
Omar Sandoval
9c94b82c6c program: make CompoundType.member() public
ProgramObject.member_() calls typeof() and offsetof(), which we can get
at the same time. While we're here, catch AttributeError instead of
doing the isinstance() check, which is slightly more efficient.
2018-05-25 22:17:54 -07:00
Omar Sandoval
6b178c5108 program: only check struct or union in ProgramObject.member_()
We're currently also doing this check in __getattr__(), which is
unnecessary overhead in the common case. We can just check the exception
in the error case.
2018-05-25 21:56:24 -07:00
Omar Sandoval
95c0682718 corereader: implement type reads in C
Now that read_memory() was converted to C, IntType.read() and friends
are a bottleneck. Convert them to C methods of CoreReader.
2018-05-25 00:41:12 -07:00
Omar Sandoval
95bde56cb7 Implement core dump reading in C
read_memory() is one of the hottest functions in profiles of tight loops
over lists of items, and it can be done much more efficiently in C.
2018-05-24 17:55:47 -07:00
Omar Sandoval
2fa4150581 type: add Type.is_pointer() and call isinstance() less 2018-05-19 00:09:15 -07:00
Omar Sandoval
15849f5795 type: make operand_type() a method of Type
This gets rid of the huge isinstance() chain in
TypeIndex.operand_type().
2018-05-18 23:51:20 -07:00
Omar Sandoval
2c0b63eda3 type: cache CompoundType._member()
Parsing the member designator and walking the members is relatively
expensive and can be in the hot path when iterating over lots of
objects.
2018-05-18 23:18:40 -07:00
Omar Sandoval
0089014fed cli: add Type to displayhook 2018-05-14 20:43:16 -07:00
Omar Sandoval
e7a2ba32e8 program: show dereferenced value for ProgramObject.str()
I always forget to dereference pointers, which gets annoying.
2018-05-14 20:36:19 -07:00
Omar Sandoval
54f5124be8 type: format char arrays as strings
For, e.g., comm in struct task_struct, a string is much nicer to look
at.
2018-05-14 20:35:21 -07:00
Omar Sandoval
7088aac53f cli: add display hook that calls str() for ProgramObjects
Having to do print(...) all of the time at the CLI is tiresome.
2018-05-14 20:33:12 -07:00
Omar Sandoval
de5bb2c887 program: fix typo in docstring 2018-05-14 00:16:45 -07:00
Omar Sandoval
6d980a95a7 Add better rlcompleter
The standard library rlcompleter doesn't support expressions involving
an item lookup (e.g., x[0] or x['foo']). This is a pain for the drgn
CLI, because it's common to use prog['variable'] and want to
autocomplete it. Instead of using the standard library rlcompleter,
implement our own, cleaned up version of it with the ability to handle
expressions containing [key]. rlcompleter already allows for arbitrary
__getattr__() calls, and __getitem__() isn't any different.
2018-05-13 23:51:42 -07:00
Omar Sandoval
467fc66ef3 type: fix member designator exceptions 2018-05-13 01:13:38 -07:00
Omar Sandoval
e327aef860 program: fix ProgramObject.__round__() with ndigits is not None
In this case, we must return a ProgramObject.
2018-05-13 00:47:44 -07:00
Omar Sandoval
1916528f5d type: make offsetof() and typeof() accept arbitrary member designators
Instead of only accepting an identifier.
2018-05-13 00:42:50 -07:00
Omar Sandoval
8f46673649 Add member designator parser
A member designator is the second argument to the C offsetof() macro.
2018-05-13 00:41:20 -07:00
Omar Sandoval
b43e2094ff typename: split lexer out into a separate module
It will be used for parsing member designators next.
2018-05-13 00:40:28 -07:00
Omar Sandoval
3d5af98a90 type/typename: fix anonymous and incomplete type annotations 2018-05-12 15:43:58 -07:00
Omar Sandoval
90ca412a33 typeindex: fix mypy errors in drgn.program 2018-05-12 15:34:00 -07:00
Omar Sandoval
10cf1097b5 program: fix mypy errors regarding array rvalues
We don't support array rvalues, so just add some asserts.
2018-05-12 12:02:50 -07:00
Omar Sandoval
6e208005a2 typeindex: fix some more mypy errors 2018-05-12 11:51:20 -07:00
Omar Sandoval
f299bea98a type/typeindex: implement saner typing for EnumType
This is a big change that makes EnumType have a compatible integer type
member instead of copying the fields, which ends up touching a lot of
stuff but also fixing a bunch of static typing errors.
2018-05-11 23:57:52 -07:00
Omar Sandoval
333b782172 dwarf: fix some type errors
Not real bugs.
2018-05-11 22:33:09 -07:00
Omar Sandoval
80df521452 type: handle some type errors caused by optional members
I don't know why mypy suddenly started warning about these where it
didn't before, but they're real bugs.
2018-05-09 02:11:39 -07:00
Omar Sandoval
07bcded124 typename: fix some harmless type errors
These aren't actual bugs, but silence mypy anyways.
2018-05-09 01:55:42 -07:00
Omar Sandoval
0a089e6ac9 cli: add history and tab completion
rlcompleter won't complete getitem or any function calls, so that can be
improved upon, but this is already much better than nothing.
2018-05-09 01:52:21 -07:00
Omar Sandoval
35271231fe program: swap ProgramObject arguments
type, address, value makes more sense and looks more like C.
2018-05-07 22:48:00 -07:00
Omar Sandoval
15ea6e8d97 program: implement ProgramObject binary operators 2018-05-07 18:48:10 -07:00
Omar Sandoval
9560b913f3 typeindex: change Type.unqualified() to TypeIndex.operand_type()
Converting an lvalue to an operand has to do a little bit more than
remove qualifiers:

- Convert array types to pointer types
- Convert function types to pointer types
2018-05-06 21:29:59 -07:00
Omar Sandoval
987f9be6db type: add Type.is_arithmetic() and Type.is_integer()
This will be used for ProgramObject operators as a shortcut for
isinstance(type.real_type(), (ArithmeticType, BitFieldType).
2018-05-06 00:28:07 -07:00
Omar Sandoval
da83e0adb3 program: add ProgramObject tests 2018-05-03 23:26:43 -07:00
Omar Sandoval
bad1ab23b0 typeindex: add TypeIndex.array()
Similar to TypeIndex.pointer(), just constructs an array type.
2018-05-03 23:21:53 -07:00
Omar Sandoval
b921d884df program: add ProgramObject.address_of_()
Basically the "&" operator in C.
2018-05-03 23:21:23 -07:00
Omar Sandoval
38262f8d53 typeindex: add TypeIndex.pointer() 2018-05-03 22:34:35 -07:00
Omar Sandoval
18e5e8f9bf typeindex: move easy types into base TypeIndex class
Some types don't actually have to go through find_dwarf_type(), so they
can be handled in the common code. This allows us to add a MockTypeIndex
to the tests.
2018-05-03 20:38:00 -07:00
Omar Sandoval
9f325f5fdc typeindex: fix some type errors in literal_type() 2018-05-02 23:38:55 -07:00
Omar Sandoval
3cc11f3f5e typeindex: rename usual_arithmetic_conversions() to common_real_type()
It doesn't actually do the conversion, it just finds the common type.
While we're here, don't make the types unqualied; the caller should do
that.
2018-05-02 23:36:39 -07:00