Commit Graph

205 Commits

Author SHA1 Message Date
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
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
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
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
90ca412a33 typeindex: fix mypy errors in drgn.program 2018-05-12 15:34:00 -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
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
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
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
Omar Sandoval
928048be97 tests: use mocked TypeIndex for type conversion tests
Instead of a real DwarfTypeIndex.
2018-05-02 23:19:05 -07:00
Omar Sandoval
4891a6341f typeindex: add method for getting type of literal
This will be used for ProgramObject operators where one operand is not a
ProgramObject.
2018-05-02 22:56:16 -07:00
Omar Sandoval
b060c9dcf7 typeindex: make sure we can find base types
The compiler might call a base type by any variation of its name (e.g.,
long or long int). Make sure we find it no matter what it chose.
2018-05-02 22:41:26 -07:00
Omar Sandoval
812951c340 type: add Type.convert()
For converting a value to a valid value of that type (i.e., casting).
2018-05-01 20:49:49 -07:00
Omar Sandoval
68462da720 typeindex: add usual arithmetic conversions
The rules are really subtle and not completely specified, so hopefully
this covers all of the corner cases... This will be used for
ProgramObject operators.
2018-05-01 00:17:20 -07:00
Omar Sandoval
78a745588a type: add TypedefType.real_type()
Instead of open-coding it in ProgramObject.
2018-04-30 22:23:55 -07:00
Omar Sandoval
c49426359b type: add Type.unqualified()
Used to get the same type with no qualifiers.
2018-04-30 22:16:44 -07:00
Omar Sandoval
26d8e0f7e9 type: add compatible integer type to EnumType 2018-04-30 19:33:40 -07:00
Omar Sandoval
cef86a18c0 Move from_dwarf_type{,_name}() logic to a class 2018-04-30 18:11:28 -07:00
Omar Sandoval
80d3058b17 type: canonicalize basic type names
Instead of using whatever the compiler emits, make sure we are
consistent with naming.
2018-04-30 00:01:18 -07:00
Omar Sandoval
e1673f9f29 typename: use a better canonical formatting for integer types
I.e., omit "int" for "short", "long", and "long long".
2018-04-29 23:56:31 -07:00
Omar Sandoval
e38ddba9c6 type: fix pretty-print of array of structs
We need to handle indentation like we do with nested structs.
2018-04-28 22:42:01 -07:00
Omar Sandoval
1d2b90e62b Document drgn.program and drgn.type more 2018-04-12 00:51:32 -07:00
Omar Sandoval
4c9a454cd2 type{,name}: get rid of __eq__()
We should only have these for testing.
2018-04-09 22:49:39 -07:00
Omar Sandoval
f347a51399 type{,name}: make qualifiers a frozenset 2018-04-09 21:57:52 -07:00
Omar Sandoval
366a706a96 type: replace Type.format() with Type.pretty(Type.read())
Most of the implementations of format() call read(). Make pretty() do
just the formatting part of format() and take the already read value.
2018-04-09 21:02:03 -07:00
Omar Sandoval
b848134c49 Add (partial) support for function types
The only part not implemented is function type name parsing.
2018-04-08 23:04:08 -07:00
Omar Sandoval
d41137d6e2 type: format empty struct without newline
This shows up in, e.g., Linux's struct lock_class_key if compiled
without lockdep.
2018-04-07 15:36:46 -07:00
Omar Sandoval
422c39823f type: allow reading incomplete array types
Just return a zero-length array.
2018-04-06 00:27:17 -07:00
Omar Sandoval
2bd81fd5fc coredump: push ELF/DWARF-specific logic out of Coredump
Instead, take callbacks for looking up variables and reading memory.
While we're at it, get rid of TypeFactory and instead implement its
methods as functions taking a DwarfIndex.
2018-04-05 00:52:00 -07:00
Omar Sandoval
b45e930336 dwarf: rewrite drgn.dwarf in pure Python
Now that DwarfIndex is in C, the rest can be simpler Python rather than
Cython.
2018-03-26 01:51:20 -07:00
Omar Sandoval
acbf14d10c dwarf: rewrite DwarfIndex in pure C
Most of drgn.dwarf is not performance-sensitive, and the part that is
(DwarfIndex) can use some extra tuning which is easier to do in C rather
than Cython.
2018-03-25 02:10:15 -07:00
Omar Sandoval
7ebda948c6 dwarf: fix undefined signed integer overflow in LEB128
And add back the old lldwarf LEB128 tests.
2018-03-13 01:38:52 -07:00
Omar Sandoval
a7309d2a15 elf: support debug sections with relocations 2018-03-09 17:41:54 -08:00
Omar Sandoval
dac4f9156a elf: clean up ElfFile API
Use functions instead of properties to make it clear that they're not
free, and make it possible to construct a DwarfFile directly from an
ElfFile.
2018-03-08 23:31:02 -08:00
Omar Sandoval
aa4d5852b3 type: fix handling of arrays with zero-length elements
Encountered in s_writers_key in struct file_system_type.
2018-03-07 21:20:38 -08:00
Omar Sandoval
7d21255007 type: add format() to type classes
For formatting read values nicely in C syntax.
2018-03-07 02:04:09 -08:00
Omar Sandoval
adeeca927b type: add TypeFactory.from_type_name() 2018-03-07 00:31:00 -08:00
Omar Sandoval
f71d2a8fd9 type: add read() to type classes
For reading a value out of memory.
2018-03-06 01:22:14 -08:00
Omar Sandoval
84e0910342 type: remove all DWARF-specific code from type classes 2018-03-06 00:42:03 -08:00
Omar Sandoval
1717c060cd type: further improve type handling
Make specific type classes which are separate from the type name
classes.
2018-03-03 02:14:09 -08:00
Omar Sandoval
ec75400cc0 type: improve type handling
Add a parser for C type names and push the type logic out of the
CoredumpObject class.
2018-02-24 19:37:51 -08:00
Omar Sandoval
97e604c05c Rewrite in Cython
The lldwarf/drgn.dwarf split wasn't working out too well, and moving all
of drgn.dwarf into lldwarf (by rewriting it into C) would be way too
much work. Instead, use Cython, which results in a parser which is just
as fast but with much cleaner code overall. It also turns out lldwarf
wasn't doing GC right, so the switch also fixed that.
2017-08-28 21:16:43 -07:00
Omar Sandoval
682fd172a4 cli/probe: start implementing variable fetching
Resolving parameters, variables with function scope, and global
variables should work. This is just the variable resolution, no fetching
yet, but a bunch of refactors snuck in here so committing it all now.
2017-08-27 23:56:14 -07:00
Omar Sandoval
e6a58f533a Store CU and parent in DIE
Back-references from the DIE to the CU and the parent DIE will make it
much easier to implement several features.
2017-08-27 11:35:38 -07:00
Omar Sandoval
64f66f747f lldwarf: get rid of explicit offset members
The parsing library shouldn't really care about keeping track of these.
Instead, add __dict__ and getattr()/setattr() to all of the lldwarf
objects so higher layers can store the offset if they want.

DwarfDie is special in two ways:

1. We want to store an offset for the DIE so we know where to parse
   sibling and children entries.
2. For some attributes, we need to store an offset so we know where to
   find them later.

Both of these are changed to be relative to the CU rather than the
buffer.
2017-08-27 10:53:04 -07:00
Omar Sandoval
72b9af2b82 Add address range table parsing 2017-08-25 23:24:38 -07:00
Omar Sandoval
1fc2b6e89b Initial commit
I wrote all of this code a few months back and am just now getting
around to committing it. The low-level DWARF parsing library is pretty
solid, although it only implements a subset of DWARF so far. The CLI and
higher-level interface are experimental.
2017-08-24 22:46:16 -07:00