Commit Graph

73 Commits

Author SHA1 Message Date
Omar Sandoval
4a67d34fcb libdrgn: dwarf_info: expand unknown DWARF expression opcode
Include the opcode name if known, and add the bug report link like we do
for unknown relocation types. This might give us some idea of how to
prioritize #321.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-09-28 11:56:11 -07:00
Omar Sandoval
da83513d18 libdrgn: use if instead of switch for dw_foo_str
Some constant types (e.g. DW_OP) have duplicate values for vendor
specific extensions, so generating the dw_foo_str function for them
results in "duplicate case value" compiler errors. Use if statements
instead and use the first match. This doesn't change code generated for
dw_tag_str with either GCC or Clang.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-09-28 10:39:40 -07:00
Omar Sandoval
26ec38fcf0 Fix lint errors
Fixes: 4a2734bc74 ("Update scripts/gen_tests_elf_py.py to not use libdrgn/include/elf.h")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-08-24 16:41:13 -07:00
Omar Sandoval
4a2734bc74 Update scripts/gen_tests_elf_py.py to not use libdrgn/include/elf.h
libdrgn/include/elf.h no longer has the definitions that the script
needs. Update it to use the system elf.h and update tests/elf.py with one
new definition. Also make scripts/gen_elf_compat.py read elf.h in the
same way.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-08-24 14:20:55 -07:00
Omar Sandoval
3d07cb1682 libdrgn: wrap system elf.h instead of vendoring
In commit e5bc41f16c ("libdrgn: add latest elf.h and dwarf.h to
support elfutils 0.165"), we copied elf.h from glibc 2.33 into libdrgn.
This causes a build failure on Fedora Rawhide:

/usr/include/gelf.h:86:9: error: unknown type name 'Elf64_Relr'
   86 | typedef Elf64_Relr Gelf_Relr;

This is because an elfutils patch added to Rawhide
(https://sourceware.org/pipermail/elfutils-devel/2023q3/006337.html)
adds a typedef for a type that we don't have in our old copy of elf.h.

The reason that we have a copy in the first place is that we use some
definitions that aren't in older versions of glibc. Instead of copying
elf.h, wrap it using #include_next and add the definitions we need.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-08-24 13:27:38 -07:00
Omar Sandoval
7c3ac80a1b Update libkdumpfile in manylinux wheels to 0.5.2
And update --with-lzo to --with-lzo2, which was actually renamed back in
0.5.0.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-08-24 11:10:15 -07:00
Omar Sandoval
f14624baac Update elfutils in manylinux wheels to 0.189
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-27 09:53:21 -07:00
Omar Sandoval
104a14781d tests: test compressed debug sections
Test both .zdebug_* sections and SHF_COMPRESSED .debug_* sections.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-20 13:45:04 -07:00
Omar Sandoval
fc3ea4184a libdrgn: use new include-what-you-use exported declarations and fix warnings
include-what-you-use/include-what-you-use#1164 fixed
include-what-you-use/include-what-you-use#971 so that we can export
forward declarations instead of hacking around it. I can't reproduce the
issue with BINARY_OP_SIGNED_2C anymore either, so we can remove that
hack, too. Also fix any other warnings.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-05-24 00:25:25 -07:00
Stephen Brennan
9113c1ba51 scripts: Allow building just one Python release
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2023-01-30 12:20:15 -08:00
Omar Sandoval
5dd03eead9 Build manylinux2014 wheels instead of manylinux2010
manylinux2010 has been EOL since August 2022; see pypa/manylinux#1281.
In particular, the manylinux2010 image wasn't updated with Python 3.11.
Update scripts/build_dist.sh to use manylinux2014 and drop some CentOS 6
workarounds from scripts/build_manylinux_in_docker.sh.

If someone really wants manylinux2010, we can probably build both, but
none of the popular packages I checked (NumPy, SciPy, cryptography,
charset-normalizer) do this.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 20:10:36 -08:00
Omar Sandoval
69d3ce5ced Update libkdumpfile in manylinux wheels to 0.5.0
And make sure that it's built with zstd support.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 20:08:55 -08:00
Omar Sandoval
134393f5f0 Update elfutils in manylinux wheels to 0.188
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-01-05 19:44:24 -08:00
Omar Sandoval
4031093848 Add some missing copyright/license notices
I wanted to make REUSE pass, but I'm not sure what to do about trivial
files. REUSE suggests using CC0, but Fedora no longer allows CC0. I'll
punt that until later. For now, let's add notices to some code files.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-01 17:14:02 -07:00
Omar Sandoval
87b7292aa5 Relicense drgn from GPLv3+ to LGPLv2.1+
drgn is currently licensed as GPLv3+. Part of the long term vision for
drgn is that other projects can use it as a library providing
programmatic interfaces for debugger functionality. A more permissive
license is better suited to this goal. We decided on LGPLv2.1+ as a good
balance between software freedom and permissiveness.

All contributors not employed by Meta were contacted via email and
consented to the license change. The only exception was the author of
commit c4fbf7e589 ("libdrgn: fix for compilation error"), who did not
respond. That commit reverted a single line of code to one originally
written by me in commit 640b1c011d ("libdrgn: embed DWARF index in
DWARF info cache").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-01 17:05:16 -07:00
Omar Sandoval
d465071651 libdrgn: replace copies of elfutils headers with generated files
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-01 15:41:53 -07:00
Omar Sandoval
42e7d474d1 drgn.helpers.linux.mm: add compound page helpers
I had these helpers lying around from a couple of bugs related to
compound pages that I debugged.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-09-09 15:54:43 -07:00
Omar Sandoval
d14f751475 drgn.helpers.linux.mm: add simple PageFlag() getters
There are a bunch of page flag getters in the kernel like
PageUptodate(), PageLocked(), etc., that kernel developers are
accustomed to using. Most of them are simple bit tests. Let's add
helpers for all of those. These are generated from
include/linux/page-flags.h in the Linux kernel source tree as of Linux
v6.0-rc1.

More complicated getters that need to do more than a simple flag check
(e.g., PageCompound()) will need to be added manually.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-08-18 15:50:15 -07:00
Omar Sandoval
c47dd9952e Update elfutils in manylinux wheels to 0.187
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-07-25 16:52:24 -07:00
Omar Sandoval
b300021ba3 scripts/build_dists.sh: use docker run --pull always instead of docker pull
This way we only need to invoke docker (and sudo, if running with
DOCKER="sudo docker") once.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 01:23:01 -08:00
Omar Sandoval
6418ad1403 Run tests when building manylinux wheels
This will catch issues like the one fixed in commit 549cd7facc ("Add
tests/sample.core.zst to sdist").

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-03 01:20:03 -08:00
Omar Sandoval
24609a3a2e libdrgn: add autoconf option to enable compiler warnings
This adds an --enable-compiler-warnings flag that:

* Defines a canonical list of warnings that we enforce. For now, this is
  -Wall -Wformat-overflow=2 -Wformat-truncation=2, but we can add to it
  going forward.
* Enables warnings by default.
* Allows erroring on warnings. We recommend that developers use this and
  use it for the CI.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-03-01 15:38:05 -08:00
Kevin Svetlitski
e6306853d2 Make iwyu.py respect the CFLAGS environment variable
Previously iwyu.py overwrote the value of the `CFLAGS` environment
variable regardless of whether it was already set. This was very
frustrating when trying to set custom `CFLAGS` to be used in the
generation of compile_commands.json, so the script now only sets
`CFLAGS` if it is not already present in the environment.

Signed-off-by: Kevin Svetlitski <svetlitski@fb.com>
2022-02-25 11:33:30 -08:00
Kevin Svetlitski
9add9529eb Ensure compile_commands.json contains -Wall
This minor change is a quality of life improvement ensuring developers
receive more warnings and diagnostics in their editors.

Signed-off-by: Kevin Svetlitski <svetlitski@fb.com>
2021-12-17 12:08:22 -08:00
Omar Sandoval
ad23378977 Update elfutils and libkdumpfile in manylinux wheels
Use the latest version of elfutils (0.186) and libkdumpfile (0.4.1). We
can drop the elfutils patch since 0.186 has the fix (and we have our own
workaround), but we need a new patch to build libkdumpfile.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-12-08 15:13:09 -08:00
Omar Sandoval
2c6e36847f Remove some include-what-you-use workarounds
include-what-you-use 0.17 fixed a couple of issues we were working
around with a mapping file.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-12-06 01:51:54 -08:00
Omar Sandoval
c0d8709b45 Update copyright headers to Meta
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-21 15:59:44 -08:00
Omar Sandoval
07d00b7b11 tests: add tests for ELF symbols
Add some scaffolding to generate ELF files with symbol tables and use it
to test symbol lookups and Elf_Sym -> drgn.Symbol translation.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-19 17:04:20 -08:00
Omar Sandoval
c84d7e8c15 tests: generate ELF constants from elf.h
Generalize generate_dwarf_constants.py for ELF and replace tests/elf.py
with the generated version.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-19 17:02:32 -08:00
Omar Sandoval
d1745755f1 Fix some include-what-you-use warnings
Also:

* Rename struct string to struct nstring and move it to its own header.
* Fix scripts/iwyu.py, which was broken by commit 5541fad063 ("Fix
  some flake8 errors").
* Add workarounds for a few outstanding include-what-you-use issues.

There is still a false positive for
include-what-you-use/include-what-you-use#970, but hopefully that is
fixed soon.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-11-10 15:09:29 -08:00
Omar Sandoval
9c54083830 libdrgn: pp: make PP_CAT not variadic
The overloaded version is slower to compile, and we don't actually need
it. We can add a variadic version if we need to in the future. Also add
the script used to generate the macros.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-10-29 18:38:49 -07:00
Omar Sandoval
861c61eda0 Update elfutils in manylinux wheels
Use the latest version of elfutils (0.185) and apply the fix "libdwfl:
fix potential NULL pointer dereference when reading link map" since that
hasn't been released yet and is needed to avoid crashing when debugging
userspace core dumps.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-08-12 11:53:22 -07:00
Omar Sandoval
5541fad063 Fix some flake8 errors
Mainly unused imports, unused variables, unnecessary f-strings, and
regex literals missing the r prefix. I'm not adding it to the CI linter
because it's too noisy, though.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-08-11 14:52:44 -07:00
Omar Sandoval
87809f7692 libdrgn: dwarf_index: improve file path hashing for deduplication
We currently don't include the compilation directory when hashing file
names for deduplication. This can cause us to incorrectly deduplicate a
definition if, for example, two libraries have a definition with the
same name in files with the same name. Fix this by hashing the full file
path including the compilation directory.

This also requires reworking our strategy for path normalization to
better handle ".." components, since directories may end up outside of
the compilation directory. The new strategy keeps a linked list of
hashes (now FNV-1a instead of SipHash) for each parent directory. This
is actually more efficient than the previous approach, offsetting the
cost of the extra hash computations for the compilation directory. It
also correctly handles file names in the line number program header
which consist of multiple components.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-06-25 18:03:01 -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
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
a4b9d68a8c Use GPL-3.0-or-later license identifier instead of GPL-3.0+
Apparently the latter is deprecated and the former is preferred.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-04-03 01:10:35 -07:00
Omar Sandoval
e5bc41f16c libdrgn: add latest elf.h and dwarf.h to support elfutils 0.165
The oldest LTS version of Ubuntu, 16.04, has elfutils 0.165. This
version is missing some ELF and DWARF definitions used by drgn. Add
copies of elf.h from glibc 2.33 and dwarf.h and elfutils/known-dwarf.h
from elfutils 0.183 to get the latest definitions and drop the minimum
required version of elfutils further to 0.165.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-03-21 23:18:39 -07:00
Omar Sandoval
4c5c5f3842 Remove bundled version of elfutils
We currently bundle a version of elfutils with patches to export
additional stack tracing functionality. This has a few drawbacks:

- Most of drgn's build time is actually building elfutils.
- Distributions don't like packages that bundle verions of other
  packages.
- elfutils, and thus drgn, can't be built with clang.

Now that we've replaced the elfutils DWARF unwinder with our own, we
don't need the patches, so we can drop the bundled elfutils and fix
these issues.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-03-16 00:52:09 -07:00
Omar Sandoval
b5ed892481 Fix some include-what-you-use warnings and update for Bear 3
Bear 3 changed the CLI arguments, so update scripts/iwyu.py for it and
clean up some new warnings.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-02-26 16:05:49 -08:00
Omar Sandoval
9fda010789 Track byte order in scalar types instead of objects
Currently, reference objects and buffer value objects have a byte order.
However, this doesn't always make sense for a couple of reasons:

- Byte order is only meaningful for scalars. What does it mean for a
  struct to be big endian? A struct doesn't have a most or least
  significant byte; its scalar members do.
- The DWARF specification allows either types or variables to have a
  byte order (DW_AT_endianity). The only producer I could find that uses
  this is GCC for the scalar_storage_order type attribute, and it only
  uses it for base types, not variables. GDB only seems to use to check
  it for base types, as well.

So, remove the byte order from objects, and move it to integer, boolean,
floating-point, and pointer types. This model makes more sense, and it
means that we can get the binary representation of any object now.

The only downside is that we can no longer support a bit offset for
non-scalars, but as far as I can tell, nothing needs that.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2021-02-19 21:41:29 -08:00
Omar Sandoval
286c09844e Clean up #includes with include-what-you-use
I recently hit a couple of CI failures caused by relying on transitive
includes that weren't always present. include-what-you-use is a
Clang-based tool that helps with this. It's a bit finicky and noisy, so
this adds scripts/iwyu.py to make running it more convenient (but not
reliable enough to automate it in Travis).

This cleans up all reasonable include-what-you-use warnings and
reorganizes a few header files.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-09-23 16:29:42 -07:00
Omar Sandoval
d40526d85d scripts: add Python include header path to cscope
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-25 18:07:31 -07:00
Omar Sandoval
4e770fb18a Format imports with isort
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-08-20 16:55:07 -07:00
Omar Sandoval
8b264f8823 Update copyright headers to Facebook and add missing headers
drgn was originally my side project, but for awhile now it's also been
my work project. Update the copyright headers to reflect this, and add a
copyright header to various files that were missing it.
2020-05-15 15:13:02 -07:00
Omar Sandoval
36d350bf93 Add scripts/cscope.sh
For generating the cscope index from the proper files.
2020-04-27 17:07:15 -07:00
Omar Sandoval
dabfe19719 Rewrite virtual machine testing setup
The current implementation of vmtest has a few issues:

1. Building drgn for each kernel version on Travis is slow, mostly
   because they don't all run in parallel.
2. For local, incremental testing, recreating the filesystem image and
   rebuilding drgn is slow, and syncing the code to the filesystem image
   is brittle.
3. The filesystem image is the only communication channel, and reading
   the exit status from the filesystem image is awkward and fragile.
4. Creating and accessing the filesystem image requires root.

This reworks vmtest to use the build on the host via VirtFS with a
simple agent on the guest that can execute arbitrary commands and return
the exit status. This has a few more moving parts but is faster and
saner overall.
2020-04-02 17:35:24 -07:00
Omar Sandoval
739fe5686d vmtest: move to top-level directory 2020-03-27 17:13:44 -07:00
Omar Sandoval
fe42a71116 Add DW_LANG to generated dwarf.py
While we're here, make generate_dwarf_constants.py use the bundled
dwarf.h, generate code that black is happy with, and use the keyword
list from the standard library.
2020-02-26 19:55:42 -08:00
Omar Sandoval
71ce81ecbf travis.yml: add 5.6 to vmtest kernels and remove 5.3
v5.6-rc1 was released today, and 5.3 was recently EOL'd. (It might be
worthwhile to continue testing EOL kernels, but for now I don't want
Travis runs to take forever).
2020-02-10 12:43:25 -08:00