Commit Graph

268 Commits

Author SHA1 Message Date
Omar Sandoval
25e7a9d3b8 libdrgn/python: implement Program.__contains__ 2019-06-28 16:02:52 -07:00
Omar Sandoval
c0bc72b0ea libdrgn: use splay tree for memory reader
The current array-based memory reader has a bug in the following
scenario:

    prog.add_memory_segment(0xffff0000, 128, ...)
    # This should replace a subset of the first segment.
    prog.add_memory_segment(0xffff0020, 32, ...)
    # This moves the first segment back to the front of the array.
    prog.read(0xffff0000, 32)
    # This finds the first segment instead of the second segment.
    prog.read(0xffff0032, 32)

Fix it by using the newly-added splay tree. This also splits up the
virtual and physical memory segments into separate trees.
2019-05-24 17:48:08 -07:00
Omar Sandoval
9b563170f8 libdrgn: make load_debug_info() API saner
Rather than exposing the underlying open and load steps of DWARF index,
simplify it down to a single load step.
2019-05-13 15:04:27 -07:00
Omar Sandoval
ab58a5bff0 libdrgn: determine default size_t and ptrdiff_t more intelligently
Currently, size_t and ptrdiff_t default to typedefs of the default
unsigned long and long, respectively, regardless of what the program
actually defines unsigned long or long as. Instead, make them refer the
whatever integer type (long, long long, or int) is the same size as the
word size.
2019-05-10 15:14:03 -07:00
Omar Sandoval
baba1ff3f0 libdrgn: make program components pluggable
Currently, programs can be created for three main use-cases: core dumps,
the running kernel, and a running process. However, internally, the
program memory, types, and symbols are pluggable. Expose that as a
callback API, which makes it possible to use drgn in much more creative
ways.
2019-05-10 12:41:07 -07:00
Omar Sandoval
565e0343ef libdrgn: make symbol index pluggable with callbacks
The last piece of making the major program components pluggable.
2019-05-06 14:55:34 -07:00
Omar Sandoval
a98445c277 libdrgn: make type index pluggable with callbacks
Similar to "libdrgn: make memory reader pluggable with callbacks", we
want to support custom type indexes (imagine, e.g., using drgn to parse
a binary format). For now, this disables the dwarf index tests; we'll
have a better way to test them later, so let's not bother adding more
test scaffolding.
2019-05-06 14:55:34 -07:00
Omar Sandoval
77443cecd1 libdrgn: use NULL-terminated arrays for mock {type,symbol} index
This will simplify the next couple of changes.
2019-05-06 14:55:34 -07:00
Omar Sandoval
c2be52dff0 libdrgn: rename object index to symbol index
An "object index" doesn't actually index objects, but really "partial
objects" -- i.e., a type + address. "Symbol" is a better name for this.
2019-05-06 14:55:34 -07:00
Omar Sandoval
417a6f0d76 libdrgn: make memory reader pluggable with callbacks
I've been planning to make memory readers pluggable (in order to support
use cases like, e.g., reading a core file over the network), but the
C-style "inheritance" drgn uses internally is awkward as a library
interface; it's much easier to just register a callback. This change
effectively makes drgn_memory_reader a mapping from a memory range to an
arbitrary callback. As a bonus, this means that read callbacks can be
mixed and matched; a part of memory can be in a core file, another part
can be in the executable file, and another part could be filled from an
arbitrary buffer.
2019-05-06 14:55:34 -07:00
Omar Sandoval
3645ce78ea libdrgn: assume all pointers have same size in type index 2019-05-06 14:55:34 -07:00
Omar Sandoval
932b7857b5 libdrgn: expose primitive type concept to public interface
Previously known as c_type.
2019-05-06 14:55:34 -07:00
Omar Sandoval
7dbf8447b2 tests: test comparison between Type and other object 2019-05-06 14:55:34 -07:00
Omar Sandoval
7282c40a75 libdrgn: fix crash in drgn_object_slice()
We need to set the value after we've reinitialized the object, otherwise
drgn_object_deinit() may try to free a buffer that we've already
overwritten. This also adds a test which triggers the crash.
2019-04-24 17:57:36 -07:00
Omar Sandoval
97f5cf70c6 libdrgn: fix C array and function casting
Casting an array or function should first convert the array or function
into a pointer.
2019-04-12 16:40:12 -07:00
Omar Sandoval
1db8d11f84 libdrgn: allow void pointer arithmetic
This is a GCC extension, but it's used pretty often in practice.
2019-04-12 16:06:24 -07:00
Omar Sandoval
7719d76820 libdrgn: allow comparison of function pointers and incomplete arrays 2019-04-12 15:49:15 -07:00
Omar Sandoval
309dc82789 libdrgn: allow comparing any pointer types in C
There's a bug that we don't allow comparisons between void * and other
pointer types, so let's fix it by allowing all pointer comparisons
regardless of the referenced type. Although this isn't valid by the C
standard, GCC and Clang both allow it by default (with a warning).
2019-04-12 15:44:08 -07:00
Omar Sandoval
73090f6128 libdrgn: fix error message for cast to incomplete type
The errant type is the one we're trying to cast to, not the object's
type. This fixes an abort in drgn_error_incomplete_type().
2019-04-12 13:24:51 -07:00
Omar Sandoval
1b4aee1a55 libdrgn/python: add Program.pointer_type() 2019-04-11 23:35:10 -07:00
Omar Sandoval
435640faf6 Fix some linter errors 2019-04-11 15:51:20 -07:00
Omar Sandoval
321e2c210e libdrgn/python: format pointers in hex for Object.__repr__() 2019-04-05 10:36:54 -07:00
Omar Sandoval
0b72e180fa libdrgn: match partial paths for type/object lookups
The declaration file name of a DIE depends on the compilation directory,
which may not always be what the user expects. Instead, make the search
match as long as the full declaration file name ends with the given file
name. This is more convenient and more intuitive.
2019-04-02 14:12:11 -07:00
Omar Sandoval
a5fb8ed4c3 Add libelf/libdw wrappers to _drgn
If libelf or libdw are statically linked or not in the usual search
path, ctypes won't be able to find them. Add the required functions to
the wrappers in the libdrgn bindings so that we can easily find them.
2019-04-02 14:12:11 -07:00
Omar Sandoval
75c3679147 Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:

- It's too slow for some common use cases, like iterating over large
  data structures.
- It can't be reused in utilities written in other languages.

This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:

- Types are now represented by a single Type class rather than the messy
  polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
  functions.

The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.

Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-04-02 14:12:07 -07: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
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
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
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
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
f4bb55e359 type: support putting multiple array elements on the same line 2018-07-21 22:53:05 -07:00
Omar Sandoval
6f14d82024 memberdesignator: fix error message when missing ']' 2018-07-16 20:30:09 -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
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
45da5e8d35 tests: split DwarfTypeIndex tests out of TypeIndex tests 2018-07-15 18:07:36 -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
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
51aa35bc05 type: also format typedefs of anonymous enums 2018-07-11 22:34:01 -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
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
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
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
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
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
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
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
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
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
5e2d70f09e dwarfindex: add file name to DIE index entry key
A name and tag are not always enough to uniquely identify a type or
variable. For example, "struct workspace" in the Linux kernel can refer
to one of at least three types; fs/btrfs/{lzo,zlib,zstd}.c each have
their own struct workspace type. We can, however, also differentiate
DIEs on the file they were declared in.

The naive thing to do would be to include the file name as a string in
the hash table entry. However, that means we must allocate and
canonicalize each path in the line number program header and pay an
extra cache miss plus string comparison when adding a new entry.

We can get rid of the cache miss and string comparison if we instead map
the file name to a unique identifier. The foolproof way to do this would
be to create another big hash table of file names and use the hash table
entry index as the unique identifier. However, for this, we'd still need
to allocate and canoicalize each path as well as worry about another big
hash table.

Once we observe that we can get away with "almost certainly unique"
instead of "truly unique" identifiers, the next logical step is to just
use a hash of the file name as the identifier. With a 64-bit hash and
the ~50k files in the kernel, the probability of a collision is 1 in 10
billion. Even in the extremely unlikely event that there is a collision,
it only matters if the files with colliding names also have colliding
DIEs, which brings things pretty close to the realm of impossibility.

After this change, DwarfIndex.find() returns a list of DIEs matching the
name and tag. The callers will be updated to use the list in upcoming
changes.
2018-06-21 23:13:39 -07:00
Omar Sandoval
856892375a typeindex: handle pointer to const void in from_dwarf_type()
Like pointer types and function types, qualified void types don't have a
DW_AT_type.
2018-06-15 22:36:58 -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
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
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