Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#2414 drcallstack: Add libunwind-based callstack walking #5154

Merged
merged 17 commits into from
Oct 13, 2021

Conversation

derekbruening
Copy link
Contributor

Adds a new extension "drcallstack" which provides callstack walking
facilities. This initial implementation adds a libunwind-based
implementation and targets only Linux for now.

Adds an interface to walk one step at a time over callstack frames.
The implementation converts the dr_mcontext_t into libunwind's context
structure and invokes the libunwind step API.

Getting libunwind to work requires several steps:

  • Ignore libpthread exports when importing any symbol that does not start with
    "pthread". Otherwise libunwind crashes using __errno_location from libpthread
    instead of from libc. We add a warning when a private libpthread is loaded
    to help diagnose any other potential problems (xref CRASH using libpthread in a client #956).

  • Have dl_iterate_phdr operate on app libraries instead of private libraries.
    This is done with a new flag and logic in the redirection code, with the
    flag set for libraries named "libunwind*".

A statically-linked libunwind is not supported.

Updates drwrap to set the mcontext pc field to simplify usage.

Adds a test and documentation.

Adds a sample client showing how to use this library.

Issue: #2414, #956

Adds a new extension "drcallstack" which provides callstack walking
facilities.  This initial implementation adds a libunwind-based
implementation and targets only Linux for now.

Adds an interface to walk one step at a time over callstack frames.
The implementation converts the dr_mcontext_t into libunwind's context
structure and invokes the libunwind step API.

Getting libunwind to work requires several steps:

+ Ignore libpthread exports when importing any symbol that does not start with
  "pthread".  Otherwise libunwind crashes using __errno_location from libpthread
  instead of from libc.  We add a warning when a private libpthread is loaded
  to help diagnose any other potential problems (xref #956).

+ Have dl_iterate_phdr operate on app libraries instead of private libraries.
  This is done with a new flag and logic in the redirection code, with the
  flag set for libraries named "libunwind*".

A statically-linked libunwind is not supported.

Updates drwrap to set the mcontext pc field to simplify usage.

Adds a test and documentation.

Adds a sample client showing how to use this library.

Issue: #2414, #956
…for CI but not cross-compile; fixes for ARM and AArch64 (gested natively on both now)
…ing; allow host-not-target to not have libunwind.h
@derekbruening
Copy link
Contributor Author

Hmm, it can't find the libunwind-dev:i386 package: though I was able to install that on my (debian-ish) laptop.

Also, we have a packaging problem: there is no libunwind-dev package for cross-compiling, but that's how we make our aarchxx packages. Bundling our own libunwind.h is a possibility; it's not a simple header though, with many macros and sub-headers and arch-specific content.

@derekbruening
Copy link
Contributor Author

Hmm, it can't find the libunwind-dev:i386 package: though I was able to install that on my (debian-ish) laptop.

Note that here I'm assuming libunwind:i386 is there and we just need the header.

Also, we have a packaging problem: there is no libunwind-dev package for cross-compiling, but that's how we make our aarchxx packages. Bundling our own libunwind.h is a possibility; it's not a simple header though, with many macros and sub-headers and arch-specific content.

Here we need the header and the actual library so we would need to package the library up. It has a favorable license for that so that is a possible solution. Unfortunately we want a shared library to get the right isolation; though maybe a static library linked into drcallstack would work out.

core/unix/loader.c Outdated Show resolved Hide resolved
ext/drcallstack/drcallstack.c Outdated Show resolved Hide resolved
ext/drcallstack/drcallstack.c Outdated Show resolved Hide resolved
ext/drcallstack/drcallstack.c Outdated Show resolved Hide resolved
ext/drcallstack/drcallstack.h Outdated Show resolved Hide resolved
ext/drcallstack/drcallstack.c Outdated Show resolved Hide resolved
ext/drcallstack/drcallstack.h Outdated Show resolved Hide resolved
ext/drwrap/drwrap.c Show resolved Hide resolved
ext/drcallstack/drcallstack.c Show resolved Hide resolved
ext/drcallstack/drcallstack.c Outdated Show resolved Hide resolved
fmoessbauer and others added 6 commits October 12, 2021 16:58
…5152)

This patch replaces the install(CODE) commands that generate
files on the fly.
Instead, the files are generated at configuration time and just copied
at install time. By that, install relocation via various strategies like
DESTDIR and CPack works correctly. Further, this gets rid of a lot of
complex escaping and makes the results more predictable.

When appending to cmake-generated files, we also ensure that the file
is cleared on a re-configuration run to avoid duplicates in the file.

This patch enables a user to install multiple DynamoRIO versions
simultaneously and to switch between them by using tools like xstow.
It also helps as a preparation to package DynamoRIO for Linux
distributions like Debian.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>

Issue: #5153
…iles; add drcallstack-test to list of works-on-QEMU
@derekbruening
Copy link
Contributor Author

Well this x86-32 is a nightmare: GA CI is using https://packages.microsoft.com/ubuntu/20.04/prod instead of http://us.archive.ubuntu.com/ubuntu, and the microsoft one doesn't have i386 packages! I tried installing the other standard repo but it gives weird dependency errors as though something is messed up in its dep engine...considering a hacky manual install.

@derekbruening
Copy link
Contributor Author

PTAL at the workflow changes especially. The 32-bit one is very frustrating that we have to go those lengths just to installed libunwind-dev:i386 on their setup (vanilla Ubuntu installs fine w/ the default repos).

.github/workflows/ci-aarchxx.yml Show resolved Hide resolved
suite/tests/CMakeLists.txt Show resolved Hide resolved
api/samples/callstack.cpp Outdated Show resolved Hide resolved
@derekbruening derekbruening merged commit 9f8d170 into master Oct 13, 2021
@derekbruening derekbruening deleted the i2414-libunwind branch October 13, 2021 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants