Commit graph

283 commits

Author SHA1 Message Date
Christopher Ferris
be788d891d Allow multiple threads sharing a map to unwind.
Add a mutex in MapInfo, and a mutex in Elf. Lock the creation of an Elf
file using the MapInfo mutex, and lock when calling Step, GetFunctionName,
or GetSoname since they can modify information in the object. It might
be beneficial to use a fine grained lock in the future.

Change the Maps object to contain a vector of MapInfo pointers rather
than the total objects. This avoids copying this data around.

Add a test to libbacktrace to verify that sharing a map while doing
unwinds in different threads works.

Add concurrency tests in libunwindstack to verify the locking works.

Add always inline to the RegsGetLocal arm and aarch64 functions. I had
a case where clang did not inline the code, so make sure this is specified.

Bug: 68813077

Test: New unit tests to cover the case. Passes all unit tests.
Test: Ran a monkey test while dumping bugreports and verified that
Test: no crashes in libunwind.
Test: Remove the locking and verified that all of the concurrenty tests fail.
Change-Id: I769e728c676f6bdae9e64ce4cdc03b6749beae03
2017-11-28 15:20:38 -08:00
Christopher Ferris
c56a499422 Only skip frames for local unwinds.
When doing a remote unwind, and there is a crash in the unwind stack
code or in libbacktrace, the old version would skip those frames.
This makes debugging crashes in those libraries a bit difficult.

Bug: 68820611

Test: Ran unit tests.
Test: kill -3 a zygote process and verify no frames in
Test: libunwindstack.so/libbacktrace.so.
Test: Forced a crash in libunwindstack.so and verified the tombstone
Test: contains the full crash.
Change-Id: I297e5b3775c87c0dddf57ebb423bd72ba1baf193
2017-11-02 16:22:52 -07:00
Christopher Ferris
086baf981d Switch libbacktrace new unwinder.
Update the backtrace leak tests to share a map since this is the most
common way it will be used, and it runs much faster.

Remove the CreateNew functions, and references to them.

Remove benchmarks of CreateNew functions.

Test: Builds, ran new unit tests, ran art tests.

Change-Id: I4a25a412f1a74c6d43aebbebbf32ead20ead8f94
2017-10-30 13:37:50 -07:00
Josh Gao
e22701ee8a libbacktrace: remove exit time destructors.
If libbacktrace is statically linked into a library that interposes
libc, exit-time destructors can lead to a segfault upon exit if static
variables are used after their destruction.

Remove the one use of a static variable (with inconsequential
performance impact of less than 1us per backtrace), and enable
-Wexit-time-destructors to ensure this stays fixed in the future.

Test: mma
Change-Id: Icdaf1cf1c1f166cf501d9ecd1983c44e4305f7e9
2017-10-26 14:20:17 -07:00
Josh Gao
b9670bb437 libbacktrace: add benchmarks for Backtrace::Create, CreateNew.
Test: backtrace_benchmarks
Change-Id: I80ba5adb31d446314060edd00149f09e14e6815e
2017-10-26 14:20:16 -07:00
Josh Gao
3b094c169f libbacktrace: let the benchmark library decide iteration count.
Manually doing 1000 iterations of the benchmark doesn't seem to add any
significant amount of precision, and it makes the benchmark take
forever and obfuscates the results. Just let benchmark figure out the
time (with the option of using command line flags to increase the
number of iterations).

Test: backtrace_benchmarks64
Change-Id: I8de912c1b3c904755c8e2ac4175ff70176544ba3
2017-10-26 14:19:49 -07:00
Josh Gao
cd546c11d6 libbacktrace: correctly number frames when skipping.
Correct for the number of skipped frames when unwinding with
libunwindstack.

Test: backtrace_test32  --gtest_filter="unwind_frame_skip_*"
Change-Id: I9528977104fde3c4ec792a6db1ada24ed571b867
2017-10-26 14:19:49 -07:00
Christopher Ferris
3adedf9895 Merge "Add an interface for stopping in certain maps." 2017-10-25 19:18:21 +00:00
Christopher Ferris
1cb84cea2f Add an interface for stopping in certain maps.
Also, change the std::set parameters to std::vector. As jmgao points out,
a small std::set is not really the best choice for performance reasons.

Test: All unit tests pass, enabled the new unwinder and did a kill -3 on
Test: an android process.
Change-Id: I81227d7b79a9b7cf1d54fb0e3331d3cf4d4d3c4f
2017-10-24 15:45:59 -07:00
Christopher Ferris
5169c167c5 Remove PauseTiming/ResumeTiming calls.
These calls can only be used after the call to state.KeepRunning(),
which handles the start/stop itself.

Bug: 68170209

Test: Ran the benchmark and got reasonable results.
Change-Id: Ie12eb3a983f6fe60c85d6dfc90957eedc16b5526
2017-10-24 12:39:10 -07:00
Treehugger Robot
1c65e77e6d Merge changes I8f33830f,Icd2b891b,I8736ff5c,Iae6e342a
* changes:
  libunwindstack: add method to iterate across registers.
  libbacktrace: expose BacktraceMap's unwindstack::Memory.
  libunwindstack: expose UnwindStackMap::GetFunctionName.
  libbacktrace: expose libunwindstack Unwind routine.
2017-10-24 04:03:18 +00:00
Josh Gao
ebea0ef256 libbacktrace: expose BacktraceMap's unwindstack::Memory.
Test: mma
Change-Id: Icd2b891b121b90d55e3ac45037a59c24221a2496
2017-10-20 13:52:56 -07:00
Josh Gao
358de18b27 libunwindstack: expose UnwindStackMap::GetFunctionName.
Test: mma
Change-Id: I8736ff5c2ed7c5e64eb68df5f4eccfed614612c7
2017-10-20 13:52:56 -07:00
Josh Gao
45c4a56f1d libbacktrace: expose libunwindstack Unwind routine.
Test: backtrace_test32/64 on hikey960
Change-Id: Iae6e342a8ffd13b4d5f76b39dd434c827f7a4d9e
2017-10-20 13:52:56 -07:00
Christopher Ferris
9a6b3e39e5 Fix demangle of function names.
Also move the Backtrace::CreateNew function into the same place as ::Create
in preparation for the switch to the new unwinder as the base.

Test: Verify that names are demangled properly.
Change-Id: I6274cd43ea52210523e1e1ce23af5b22f62f4573
2017-10-18 19:20:12 -07:00
Treehugger Robot
22d2136d75 Merge "libbacktrace is not directly available to vendors" 2017-10-19 01:31:24 +00:00
Dan Willemsen
bdddcab3bd Use target.linux for all linux kernel based targets
Now in Android.bp files, target.linux applies to all targets running a
linux kernel (android, linux_glibc, linux_bionic). So common
flags/sources/etc can be combined instead of copying them to each
target.

Test: m
Change-Id: If7ad138ea1c540c160731f86b6ccc0daa5c69b83
2017-10-16 20:55:39 -07:00
Jiyong Park
b7d92c4b96 libbacktrace is not directly available to vendors
This lib becomes VNDK-SP just because libutils, which is VNDK-SP, is
depending on it. Since libutils provide android::CallStack class for
collecting and printing the callstack, there is no need for vendors to
use the internal libbacktrace library. Thus the lib is marked as
vendor_available: false.

Bug: 64730695
Test: build 2017 pixel device
Change-Id: I4ad91e3a6747bb0ae88d32cd26dfba32239c5b93
2017-10-16 11:35:02 +09:00
Christopher Ferris
9e6c11da18 Merge "Update the Unwinder object and add tests." 2017-10-05 20:46:01 +00:00
Christopher Ferris
f6f691b63c Update the Unwinder object and add tests.
Changes:
- Remove unused GetReturnAddressFromDefault function and tests.
- Modify the unwinder to stop when a pc/sp in a device map.
- Modify the unwinder to skip initial frames based on map names.
- Unit tests that exercise all of the paths in the unwinder code.
- Move the test Elf/ElfInterface objects into their own file.
- Update RegsFake to handle extra cases.
- Modify libbacktrace code to use this unwinder.

The new unwinder does not implement the ignore frame functionality since
this is not used very often and is better implemented using a skip frames
in named libraries functionality.

Test: Ran new unit tests, ran backtrace tests.
Change-Id: Ifd65e9acd66ac5e2d0e04bd32a9ad870b54610ff
2017-10-04 14:40:14 -07:00
Dan Willemsen
4852933707 Rename target.linux[_x86[_64]] to target.linux_glibc[_x86[_64]]
In the future, target.linux will apply to all targets running a linux kernel
(android, linux_glibc, linux_bionic). So move all current users to the specific
linux_glibc.

There will be another cleanup pass later that will move some instances back to
target.linux if the properties should be shared with target.android and
target.linux_bionic, but target.linux needs to be removed first.

Test: out/soong/build.ninja identical before/after
Change-Id: I72ef34689c60ce547cab2898e354b027e335f6a1
Exempt-From-Owner-Approval: build system cleanup
2017-10-02 10:44:29 -07:00
Dan Willemsen
1e45d533b3 Remove default libraries
libdl is part of system_shared_libs now. -ldl -lpthread -lm are now defaults
for host_ldlibs on Linux and Darwin. -lrt is a default for host_ldlibs on
Linux.

Test: m host
Change-Id: I0b3c147b00a8ab6ff289b85db55b88836c905f5c
Exempt-From-Owner-Approval: build system cleanup
2017-09-29 13:17:06 -07:00
Treehugger Robot
92c355cc4f Merge "Show the number of VMAs in the tombstone." 2017-09-26 21:01:20 +00:00
Elliott Hughes
868d39a82f Show the number of VMAs in the tombstone.
Tombstones (especially ones with lots of VMAs) are regularly truncated.
We can at least show the number of VMAs, though, for anyone interested
in knowing whether they got close to the default 64Ki limit.

Bug: http://b/66911122
Test: ran crasher, examined tombstone
Change-Id: I286db66f28f132307d573dbe5164efc969dc6ddc
2017-09-26 12:01:06 -07:00
Christopher Ferris
b9de87f7ed Add a new unwind method on error.
If a function crashes by jumping into unexecutable code, the old method
could not unwind through that. Add a fallback method to set the pc from
the default return address location.

In addition, add a new finished check for steps. This will provide a method
to indicate that this step is the last step. This prevents cases where
the fallback method might be triggered incorrectly.

Update the libbacktrace code to unwind using the new methodology.

Update the unwind tool to use the new unwind methodology.

Add a new option to crasher that calls through a null function.

Create a new object, Unwinder, that encapsulates the a basic unwind. For now,
libbacktrace will still use the custom code.

Added new unit tests to cover the new cases. Also add a test that
crashes calling a nullptr as a function, and then has call frames in
the signal stack.

Bug: 65842173

Test: Pass all unit tests, verify crasher dumps properly.
Change-Id: Ia18430ab107e9f7bdf0e14a9b74710b1280bd7f4
2017-09-22 16:55:12 -07:00
Josh Gao
b63a60fe83 libbacktrace: make Backtrace::FormatFrameData static.
Backtrace::FormatFrameData doesn't depend on anything from its
instance. Make it static so that callers that don't have a Backtrace*
available can format frames.

Test: mma
Change-Id: Id0ca93bbef19da488305374e58b25c7ca9d0e518
2017-09-06 17:02:26 -07:00
Christopher Ferris
5f118519fd Add a method to share the process memory object.
New function to create the process memory object. This allows for
a future where different remote process memory objects could be created
depending on the way remote memory can be created. Even different local
memory objects that access memory without doing any checks.

It also allows MemoryRange objects to share one single process memory object
and could help if the process memory object caches data.

Small changes to MapInfo::CreateMemory to when some errors are detected.
- Always check if the map is a device map, instead of only if the name
  is not empty.
- Check if a memory map is readable before creating the memory from process
  memory.

Bug: 23762183

Test: Ran unit tests, unwound on device using the new code.
Change-Id: I12a93c2dc19639689a528ec41c67bfac74d431b3
2017-09-05 14:30:22 -07:00
Christopher Ferris
458cc66b07 Update the tests.
- Change all load_base to load_bias in the test files.
- Add the test files to the backtrace_test.
- Add a function to get the path to the test libraries.
- Change aarch64 to arm64 for offline test code.
- Modify the offline tests so that they can be easily updated when
  unwinding on any arch for any other arch is possible.
- Add tests of CreateNew for remote debugging.

Test: Ran unit tests on host and angler.
Change-Id: Id6c5afe73aeb2ac22463dd81f061799fcb1c178b
2017-08-28 18:08:52 -07:00
Treehugger Robot
75a40988c0 Merge "libunwindstack: make machine type a property of Regs." 2017-08-26 00:02:46 +00:00
Josh Gao
0953ecd03a libunwindstack: make machine type a property of Regs.
There are no actual users of the machine type output parameter to
Regs::RemoteGet. The concrete implementations of Regs know what machine
type they represent anyway, so provide an accessor to query.

Test: treehugger
Test: libunwindstack tests on 32/64-bit host, hikey960
Change-Id: Ia25910531d36c41b2b6919f154cfa914aae63117
2017-08-25 14:48:09 -07:00
Christopher Ferris
df3e89be94 Merge "Speed up map creation." 2017-08-25 19:04:14 +00:00
Christopher Ferris
60521c7d52 Speed up map creation.
- Rewrite the Maps::Parse to use open, and a buffer on the stack.
- Rewrite the line parser away from sscanf. The current way sscanf
  is used does not catch many malformed lines. In addition, this
  new version improves performance by 50% over sscanf on sailfish.
- Add a lot of unit tests for the parser to make sure there are
  no problems. In addition, add a special line that was not rejected
  with the previous version of the code.
- Add new accessor to get the map at a particular index.
- Add a backtrace benchmark for map creation for both new and old.

This cl results in ~5% speedup and makes the new unwinder map creation
about the same for 64 bit. It's still a bit slower, but not by much.
On 32 bit, we are still about 5% slower than the old creation method,
though.

Bug: 23762183

Test: libunwindstack unit tests pass. Ran the new benchmarks.
Change-Id: Id4431e539f400984e6fad62153fdf4152d518322
2017-08-23 15:43:39 -07:00
Justin Yun
9ca92458e2 Mark the modules as VNDK-SP in Android.bp
As a VNDK-SP module, Android.bp must have 'vndk' tag as well as
'vendor_available: true'.

The 'vndk' tag for VNDK-SP formated as follows:
vndk: {
    enabled: true,
    support_system_process: true,
},

VNDK-SP modules will be installed both in system/lib(64) as normal
and in system/lib(64)/vndk-sp as a vendor variant.

Bug: 63866913
Test: build and boot with BOARD_VNDK_VERSION=current
Merged-In: I51fe0859f63ad58b7b91909e7d7d4206443228cd
Change-Id: I51fe0859f63ad58b7b91909e7d7d4206443228cd
(cherry picked from commit aeb68e86e4)
2017-08-23 17:56:13 +09:00
Christopher Ferris
04fdec0bbf Add demangling of function name.
Bug: 23762183

Test: Builds, unit tests pass.
Change-Id: Id49248a27d822db0f3837bfc0c20d004c55315fc
2017-08-11 15:17:46 -07:00
Christopher Ferris
3b4b075fea Small clean ups
- Remove redundant map_info checks.
- Initialize fde_count_ to zero.

Bug: 23762183

Contributed-By: Ivan Maidanski <i.maidanski@samsung.com>

Test: Builds, run backtrace_test modifying CreateNew to Create and vice-versa.
Change-Id: I6e9cdfa99734f8cc2d9915cc32c66a1455e79f1b
2017-08-09 14:22:12 -07:00
Christopher Ferris
6f3981c181 Add support for the new unwind method.
Also add a comment to the GetElf function to indicate that it never returns
nullptr.

Also needed to add this library to the a million and one places that the vndk
has hard-coded this data.

Bug: 23762183

Test: Built, nothing uses the new code.
Test: However, I did run backtrace_test using this code, and all tests pass.
Change-Id: Ib270665dcb7a7607075e36d88be76dbde6e2faa8
(cherry picked from commit dc4104b720)
2017-08-03 10:15:44 -07:00
Christopher Ferris
0d2cac9ea8 Merge "Revert "Add support for the new unwind method."" 2017-08-02 01:49:03 +00:00
Christopher Ferris
bd625efbca Revert "Add support for the new unwind method."
This reverts commit 5b460d13a4.

Reason for revert: Strange sailfish boot problem.

Change-Id: Ibde9375405cca4343c262335647dac120aab4d73
2017-08-02 01:47:31 +00:00
Christopher Ferris
9ccf627e78 Merge "Add support for the new unwind method." 2017-08-01 23:22:42 +00:00
Chih-Hung Hsieh
85244e8bc2 Fix misc-macro-parentheses warnings in system/core.
Add NOLINT comment to work around clang-tidy
error in checking macro arguments used in
type expressions.

Bug: 28705665
Test: make with WITH_TIDY=1 WITH_TIDY_CHECKS=-*,misc-macro-* \
      WITH_TIDY_FLAGS=-header-filter=system/core/.*

Change-Id: I7619978c1804e151a11a8b0477e80076bcf21cab
2017-08-01 22:12:57 +00:00
Christopher Ferris
5b460d13a4 Add support for the new unwind method.
Also add a comment to the GetElf function to indicate that it never returns
nullptr.

Bug: 23762183

Test: Built, nothing uses the new code.
Test: However, I did run backtrace_test using this code, and all tests pass.

Change-Id: I252b9c2497e2d3d94347dd6e506170bf50cbfe16
2017-07-31 13:00:35 -07:00
Christopher Ferris
96722b0fa4 Cleanup the libbacktrace interface a bit.
- Change the field name load_base to load_bias (which is what it really is).
- Add a rel_pc field so that callers do not need to compute it themselves.
- Remove the BacktraceMap::GetRelativePc() since nobody should need to
  compute this themselves.

Bug: 23762183

Test: Compiles and unit tests pass (debuggerd, libbacktrace).
Change-Id: I2cb579767120adf08c407a58f3c487ee3f2b45fc
2017-07-19 15:36:32 -07:00
Andreas Gampe
8f0947c11f Backtrace: Add libziparchive dependency
Bug: 37342627
Test: m
Change-Id: I2b4155bd11b315ff49eb9a69549e1ab3678d0b28
2017-07-04 12:03:52 -07:00
Christopher Ferris
7d0aea91c9 Use demangle for function names.
Bug: 62141808

Test: Ran unit tests, ran debuggerd -b on android processes.
Change-Id: I40f341bcb2b35dd0a020d245d6b6f2ed2df65481
2017-06-02 10:10:24 -07:00
Christopher Ferris
f30a810bce Use async safe logging in signal handlers.
Test: Boot on bullhead.
Test: Ran the libbacktrace tests on bullhead.
Test: Added a temporary log message in the signal handler, and ran the
Test: backtrace tests.
Change-Id: I0a6888c9f311af2c8cc7fbb4929315911bd2bb3c
2017-05-04 17:15:17 -07:00
Steven Moreland
4ad9d5155b libutils: export libbacktrace headers
This is used in CallStack.h.

Test: m -j libutils
Test: links
Test: trying to compile with BOARD_VNDK_VERSION := current
Bug: 33241851
Change-Id: I076c9551d356824d6e69b82349b890369bc7eea3
Merged-In: If7258e7b38000a72fd520f725030fb0038f90167
2017-04-28 09:42:50 +09:00
Steven Moreland
bb11af88e2 libbacktrace: make vendor_available
By setting vendor_available, the following may become true:

* a prebuilt library from this release may be used at runtime by
  in a later releasse (by vendor code compiled against this release).
  so this library shouldn't depend on runtime state that may change
  in the future.
* this library may be loaded twice into a single process (potentially
  an old version and a newer version). The symbols will be isolated
  using linker namespaces, but this may break assumptions about 1
  library in 1 process (your singletons will run twice).

Background:

This means that these modules may be built and installed twice --
once for the system partition and once for the vendor partition. The
system version will build just like today, and will be used by the
framework components on /system. The vendor version will build
against a reduced set of exports and libraries -- similar to, but
separate from, the NDK. This means that all your dependencies must
also mark vendor_available.

At runtime, /system binaries will load libraries from /system/lib*,
while /vendor binaries will load libraries from /vendor/lib*. There
are some exceptions in both directions -- bionic(libc,etc) and liblog
are always loaded from /system. And SP-HALs (OpenGL, etc) may load
/vendor code into /system processes, but the dependencies of those
libraries will load from /vendor until it reaches a library that's
always on /system. In the SP-HAL case, if both framework and vendor
libraries depend on a library of the same name, both versions will be
loaded, but they will be isolated from each other.

It's possible to compile differently -- reducing your source files,
exporting different include directories, etc. For details see:

https://android-review.googlesource.com/368372

None of this is enabled unless the device opts into the system/vendor
split with BOARD_VNDK_VERSION := current.

Bug: 33241851
Test: build and flash internal marlin
Test: m -j libbacktrace
Test: build with BOARD_VNDK_VERSION := current
(cherry picked from commit 4c0e956c76)
Merged-In: Idab4880e011416ebc40b225205c30fb5ed8661db
Change-Id: Idab4880e011416ebc40b225205c30fb5ed8661db
2017-04-19 10:32:43 -07:00
Vijay Venkatraman
8f2c28d572 Moved include/backtrace to libbacktrace/include
Export libbacktrace_headers

Bug: 33241851
Test: Build sailfish
Change-Id: Iba310ffc21d17ba542bed954a960ab305037061c
2017-04-11 11:22:43 -07:00
Christopher Ferris
d13099e66c Merge "Test unwinding through a signal handler." 2017-03-24 17:22:25 +00:00
Christopher Ferris
5ea2c1f20a Test unwinding through a signal handler.
Also make backtrace_testlib.c C++.

Bug: 34468756
Test: Ran new unit test on host x86, host x86_64, angler (32 bit, 64 bit),
Test: fugu.
Change-Id: Ia810f596c2df56cd56e8ab17e6c19be0c48d737f
2017-03-23 16:16:02 -07:00