Commit Graph

974 Commits

Author SHA1 Message Date
Omar Sandoval
faad25d7b2 libdrgn: debug_info: fix address of objects with size zero
The stack trace variable work introduced a regression that causes
objects with size zero to always be marked absent even if they have an
address. This matters because GCC sometimes seems to omit the complete
array type for arrays declared without a length, so an array variable
can end up with an incomplete array type. I saw this with the
"swapper_spaces" variable in mm/swap_state.c from the Linux kernel.

Make sure to use the address of an empty piece if the variable is also
empty.

Fixes: ffcb9ccb19 ("libdrgn: debug_info: implement creating objects from DWARF location descriptions")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-07 15:46:22 -07:00
Omar Sandoval
f7fe93e573 cli: show elfutils version in use
drgn depends heavily on libelf and libdw, so it's useful to know what
version we're using. Add drgn._elfutils_version and use that in the CLI
and in the test cases where we currently check the libdw version.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-07 11:10:50 -07:00
Omar Sandoval
6357cea46b drgn 0.0.12
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-07 01:13:28 -07:00
Omar Sandoval
dbe1d4539b scripts: only build manylinux wheels for CPython.
The manylinux image apparently added a PyPy interpreter, which drgn
doesn't support.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-07 01:10:59 -07:00
Omar Sandoval
bc85767e5f libdrgn: support looking up parameters and variables in stack traces
After all of the preparatory work, the last two missing pieces are a way
to find a variable by name in the list of scopes that we saved while
unwinding, and a way to find the containing scopes of an inlined
function. With that, we can finally look up parameters and variables in
stack traces.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
38573cfdde libdrgn: stack_trace: pretty print frames and add frames for inline functions
If we want to access a parameter or local variable in an inlined
function, then we need a stack frame for that function. It's also much
more useful to see inlined functions in the stack trace in general. So,
when we've unwound the registers for a stack frame, walk the debugging
information to find all of the (possibly inlined) functions at the
program counter, and add a drgn stack frame for each of those.

Also add StackFrame.name and StackFrame.is_inline so that we can
distinguish inline frames. Also add StackFrame.source() to get the
filename and line and column numbers. Finally, add the source code
location to pretty-printed stack traces and add pretty-printing for
individual stack frames that includes extra information.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
0e113ecc8d libdrgn: debug_info: add drgn_find_die_ancestors()
This will be used for finding the ancestors of the abstract instance
root corresponding to a concrete inlined instance root for variable
lookups in inlined functions.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
d8d4157346 libdrgn: debug_info: add drgn_debug_info_module_find_dwarf_scopes()
This will be used for finding functions, inlined functions, and blocks
containing a PC for stack unwinding and variable lookups.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
b6d810b344 libdrgn: debug_info: add DWARF DIE iterator
We have a couple of upcoming use cases for iterating through all of the
DIEs in a module: searching for scopes and searching for a DIE's
ancestors. Add a DIE iterator interface to abstract away the details of
walking DIEs and allows us to efficiently track ancestors.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
ffcb9ccb19 libdrgn: debug_info: implement creating objects from DWARF location descriptions
Add support for evaluating a DWARF location description and translating
it into a drgn object. In this commit, this is just used for global
variables, but an upcoming commit will wire this up to stack traces for
parameters and local variables.

There are a few locations that drgn's object model can't represent yet.
DW_OP_piece/DW_OP_bit_piece can describe objects that are only partially
known or partially in memory; we approximate these where we can. We
don't have a good way to support DW_OP_implicit_pointer at all yet.

This also adds test cases for DWARF expressions, which we couldn't
easily test before.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
8335450ecb libdrgn: debug_info: implement DW_OP_fbreg
Implement looking up location descriptions and evaluating DW_OP_fbreg.
This isn't actually used yet since CFI expressions don't have a current
function DIE, but it will be used for parameters/local variables in
stack traces.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
d5b68455b8 libdrgn: debug_info: save .debug_loc
.debug_loc will be used for variable resolution.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
e105be6c18 libdrgn: debug_info: add helper to cache module section
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
dcda688c9a libdrgn: debug_info: parenthesize PUSH() macro argument
It doesn't make a difference anywhere it's currently used, but let's do
it just in case that changes in the future.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
5fc879ef3e libdrgn: debug_info: limit number of DWARF expression operations executed
A malformed DWARF expression can easily get us into an infinite loop.
Avoid this by capping the number of operations that we'll execute.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-05 16:18:51 -07:00
Omar Sandoval
0e3054a0ba libdrgn: make addresses wrap around when reading memory
Define that addresses for memory reads wrap around after the maximum
address rather than the current unpredictable behavior. This is done by:

1. Reworking drgn_memory_reader to work with an inclusive address range
   so that a segment can contain UINT64_MAX. drgn_memory_reader remains
   agnostic to the maximum address and requires that address ranges do
   not overflow a uint64_t.
2. Adding the overflow/wrap-around logic to
   drgn_program_add_memory_segment() and drgn_program_read_memory().
3. Changing direct uses of drgn_memory_reader_reader() to
   drgn_program_read_memory() now that they are no longer equivalent.

(For some platforms, a fault might be more appropriate than wrapping
around, but this is a step in the right direction.)

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-03 17:49:29 -07:00
Omar Sandoval
e5ff1ea7ac libdrgn: program: use preset platform in drgn_program_set_core_dump()
If the program already had a platform set, we should its callbacks
instead of the ones from the ELF file's platform.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-03 17:04:28 -07:00
Omar Sandoval
dd0885bacd CI: install correct version of libomp
actions/virtual-environments@15a610677b
changed the default version of Clang from 10 to 11, but `apt-get install
libomp-dev` still installs libomp-10-dev. Ideally, the correct version
of libomp would already be pre-installed (see
actions/virtual-environments#3506), but for now make sure we install the
correct version.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-01 17:52:00 -07:00
Omar Sandoval
43b90ffb1b libdrgn: debug_info: add missing stack size check for DW_OP_deref
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-23 13:14:28 -07:00
Omar Sandoval
ad37c79cba libdrgn: python: add documentation and type annotation for Program.__contains__()
drgn.Program has supported the "in" operator since commit 25e7a9d3b8
("libdrgn/python: implement Program.__contains__"), but it's
undocumented and unannotated. Add a type annotation with a docstring
along with a METH_COEXIST method.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-12 16:26:56 -07:00
Omar Sandoval
179b33c76f python: fix comment in execscript()
The runpy.run_code() function mentioned in the comment doesn't exist;
execscript() is based on runpy.run_path().

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-11 00:33:25 -07:00
Omar Sandoval
e7865e2b09 setup.py: add 5.13 to vmtest kernels
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-10 11:15:46 -07:00
Omar Sandoval
68fae425b6 vmtest: manage: get mainline releases from mainline linux repository
I incorrectly assumed that the stable repo would have the mainline tags
soon after they were released, but this is not the case. We also need to
check the mainline repo for tags and fetch them from the mainline repo.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-10 10:55:06 -07:00
Omar Sandoval
92fd967a3a libdrgn: print uint8_t as hex with PRIx8 format, not x
In practice, they're probably always the same, but PRIx8 is more
correct.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-07 15:34:30 -07:00
Omar Sandoval
6a8d335a1f Add scripts to build manylinux2010 wheels
One nice side effect of commit e0921c5bdb ("libdrgn: don't use OpenMP
tasking") is that drgn now works with older versions of libgomp that
don't implement taskloop, including version 4.4 in manylinux2010. So, we
can finally build manylinux2010 wheels. These scripts are based on
scripts from Stephen Brennan, with some cleanups and updates for changes
in drgn's build requirements.

Closes #69.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-07 09:50:13 -07:00
Omar Sandoval
fcb46d5ab8 Revert "CI: temporarily disable Clang"
This reverts commit 1cc3868955. The
previous commit (hopefully) works around the libomp bugs that caused
Clang builds to fail.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-06 16:56:42 -07:00
Omar Sandoval
e0921c5bdb libdrgn: don't use OpenMP tasking
libomp (at least in LLVM 9 and 10) seems to have buggy OpenMP tasking
support. See commit 1cc3868955 ("CI: temporarily disable Clang") for
one example. OpenMP tasks aren't buying us much; they simplify DWARF
index updates in some places but complicate it in others. Let's ditch
tasks and go back to building an array of CUs to index similar to what
we did before commit f83bb7c71b ("libdrgn: move debugging information
tracking into drgn_debug_info"). There is no significant performance
difference.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-06 16:56:02 -07:00
Omar Sandoval
1cc3868955 CI: temporarily disable Clang
Clang tests are hitting this assertion in libomp (libomp5-10
1:10.0.0-4ubuntu1):

  Assertion failure at kmp_tasking.cpp(501): taskdata->td_flags.tasktype == 1.
  OMP: Error #13: Assertion failure at kmp_tasking.cpp(501).
  OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and operating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see https://bugs.llvm.org/.

Disable Clang builds until we figure out what's going on.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-06 01:43:46 -07:00
Omar Sandoval
47ab6142d5 vmtest: fix vmtest.vm -k
The argument to download_kernels() is an iterable of kernels, but we're
passing it a single kernel string.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-06 01:35:27 -07:00
Omar Sandoval
abeea40b8a vmtest: fix cleanup of temporary directory on Python < 3.8
In Python before 3.8, tempfile.TemporaryDirectory.cleanup() fails when
the directory doesn't exist. Since we rename the temporary download
directory to its final name, this always fails. Switch to using
tempfile.mkdtemp() directly instead.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 13:48:35 -07:00
Omar Sandoval
a15de13a7c vmtest: handle exceptions when downloading in thread
Otherwise, an exception causes setup.py test -K to hang.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 13:19:44 -07:00
Omar Sandoval
a1dc80bc38 CI: reenable vmtest
Now that the vmtest kernels have a new home on GitHub, reenable vmtest
for the CI workflow.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 01:15:40 -07:00
Omar Sandoval
47c8e0e53e vmtest: fix vmtest kernel build command
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 00:34:11 -07:00
Omar Sandoval
ebca2d2f8a CI: add action to build vmtest kernels weekly
The previous commit mentioned this action but forgot to add it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 00:30:34 -07:00
Omar Sandoval
841a3dae88 Move vmtest assets to GitHub releases
As noted by commit 738261290f ("CI: temporarily disable vmtest"),
vmtest was generating too much traffic to the Dropbox shared folder that
hosted vmtest kernels. Instead, we can store kernel packages as GitHub
release assets. Update the code for downloading and uploading vmtest
assets, and also add a scheduled GitHub action to build new kernels
every Monday so I don't have to remember to do it manually.

This also drops vmtest support for 5.6-5.9, which now fail to build with
newer binutils due to the issue fixed in Linux kernel commit
1d489151e9f9 ("objtool: Don't fail on missing symbol table").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-05 00:28:56 -07:00
Omar Sandoval
8f7e524b6b docs: update links to main branch
The master branch was renamed to main. GitHub redirects links to the old
branch, but we might as well update them explicitly.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-04 17:25:33 -07:00
Omar Sandoval
cf371594f3 tests: run a few test cases with DW_FORM_indirect
Pick a few DWARF parsing test cases that exercise the interesting cases
for DW_FORM_indirect and run them with and without DW_FORM_indirect. We
only test DW_FORM_indirect if libdw is new enough to support it.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-04 16:56:54 -07:00
Jay Kamat
95646b47c9 libdrgn: dwarf_index: add support for DW_FORM_indirect
First, add instructions for DW_FORM_indirect. Then, we can call the
function to convert a form to an instruction whenever we see an indirect
instruction.

Note that without elfutils commit d63b26b8d21f ("libdw: handle
DW_FORM_indirect when reading attributes") (queued for elfutils
0.184), DW_FORM_indirect will cause errors later when parsing with
libdw.

Signed-off-by: Jay Kamat <jaygkamat@gmail.com>
2021-05-04 16:56:54 -07:00
Omar Sandoval
609a1cafc6 libdrgn: dwarf_index: check for attribute forms more strictly
Rather than silently ignoring attributes whose form we don't recognize,
return an error. This way, we won't mysteriously skip indexing DIEs.
While we're doing this, split the form -> instruction mapping to its own
functions.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-05-04 16:56:54 -07:00
Omar Sandoval
85c367bf79 Reformat empty docstrings
Black 21.4b2 now replaces empty docstrings with a docstring containing a
single space. Apply that formatting.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-30 17:06:47 -07:00
Omar Sandoval
037a510ff2 Fix drgn.FaultError type annotations
FaultError() also takes an error message.

Fixes: 80c9fb35ff ("Add type hint stubs and generate documentation from them")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-30 17:03:16 -07:00
Omar Sandoval
2ad52cb5f4 libdrgn: add option to time load_debug_info example program
I often use examples/load_debug_info to benchmark loading/DWARF
indexing, so add a -T option that prints the time it takes to load debug
info.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-23 09:29:44 -07:00
Omar Sandoval
2d40d6e146 libdrgn: add configure~ to .gitignore
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-23 09:18:16 -07:00
Jay Kamat
c108f9a24c tests: add basic tests for type units
Signed-off-by: Jay Kamat <jaygkamat@gmail.com>
2021-04-23 02:37:31 -07:00
Jay Kamat
6be21f674a libdrgn: follow DW_AT_signature when parsing DWARF types
When using type units, skeleton declarations are made instead of
concrete ones. However, these declarations have signature tags attached
that point to the type unit with the definition, so we can simply follow
the signature to get the concrete type.

Signed-off-by: Jay Kamat <jaygkamat@gmail.com>
2021-04-23 02:37:31 -07:00
Jay Kamat
9dabec1264 libdrgn: add support for parsing type units
Adds support for parsing of type units as enabled by
-fdebug-types-section. If a module has both a debug info section and
type unit section, both are read.

Signed-off-by: Jay Kamat <jaygkamat@gmail.com>
2021-04-23 02:37:31 -07:00
Omar Sandoval
33300d426e libdrgn: debug_info: don't overwrite Dwarf_Die passed to drgn_type_from_dwarf_internal()
If the DIE passed to drgn_type_from_dwarf_internal() is a declaration,
then we overwrite it with dwarf_offdie(). As far as I can tell, this
doesn't break anything at the moment, but it's sketchy to overwrite an
input parameter and may cause issues in the future. Use a temporary DIE
on the stack in this case instead.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-23 02:37:31 -07:00
Omar Sandoval
155ec92ef2 libdrgn: fix reading 32-bit float object values on big-endian
Closes #99.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-22 09:45:41 -07:00
Omar Sandoval
6b79b21ab5 tests: fix test depending on repr(enum.Flag) format
CPython commit b775106d940e ("bpo-40066: Enum: modify `repr()` and
`str()` (GH-22392)") changed repr(enum.Flag) from, e.g.,
<Qualifiers.VOLATILE|CONST: 3> to Qualifiers.CONST|Qualifiers.VOLATILE.
Fix tests.test_type.TestType.test_qualifiers to not assume the format.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-22 01:17:22 -07:00
Omar Sandoval
0e2703dd4e libdrgn: python: use _PyDict_GetItemIdWithError()
CPython commit fb5db7ec5862 ("bpo-42006: Stop using PyDict_GetItem,
PyDict_GetItemString and _PyDict_GetItemId. (GH-22648)") (in v3.10)
removed _PyDict_GetItemId() because it suppresses errors. Use
_PyDict_GetItemIdWithError() instead (which we should've been using
anyways).

Closes #101.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-22 01:17:22 -07:00