Commit graph

269 commits

Author SHA1 Message Date
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
Brian Carlstrom
6d1da7c607 Fix spelling error in warning
Test: m -j32 -k
Bug: 36450628
Change-Id: I0f6463f3de3dcf45f396c7f406f8c1d6b79bf7f9
2017-03-23 11:29:57 -07:00
Christopher Ferris
f5e568e653 Do not access device maps.
It's possible that a device map has memory controlled by a single entry
device driver. Thus, you can deadlock if a process is touching that
device memory and we try to unwind it and also touch that device memory.
Simply skip any attempts to step through, or get function names from
device memory maps.

Bug: 36130325

Test: Ran new unit tests, ran bionic unit tests, ran art ThreadStress.
Change-Id: Ibc62d7ec8106c619ee08968f05e04aea55d7cbfa
2017-03-22 14:55:05 -07:00
Christopher Ferris
82f3bbdc25 Allow calling GetFunctionName before unwinding.
Some extra initialization needs to occur before calling the local/remote
GetFunctioneName.

Also, cleanup the test code a bit:

- Make all local functions static.
- Create a common function to create and finish remote processes.
- Remove unused function.
- Fix the formatting a bit by making it match clang format.

Test: Ran the unit tests.
Change-Id: I998bed1378d582df59fdf9263df6f208db5d795a
2017-03-21 14:21:49 -07:00
Dan Willemsen
e0cd1e043d Enable more modules on linux_bionic builds
Bug: 31559095
Test: Enable host bionic, run soong
Change-Id: Ib4ebd909322cf464b6a40040e4b60ece7d905b6f
2017-03-15 15:44:00 -07:00
Christopher Ferris
f161e00289 Merge "Restore errno in signal handlers." 2017-03-13 20:50:20 +00:00
Christopher Ferris
a78d9a293c Add a 2 width option of clang format.
Make the default the 4 tab space version.

Add a link to the 2 space version for libbacktrace.

The only other difference between the 4 space and 2 space tab version
is that the 2 space tab version allows short functions on a single line.
This is for things like constructors, short destructors, or accessor
functions. I believe this is closer to the Google C++ style guide.

Bug: 36046320

Test: NA
Change-Id: Ida08db18902eeb101f42869dd5590182529d54ef
2017-03-10 13:01:39 -08:00
Christopher Ferris
10ab87f646 Restore errno in signal handlers.
There was a problem where errno could be set in a signal handler
and cause bugs if other system calls were interrupted.

There isn't strong evidence this is causing any issues, but add this
proactively.

Bug: 31448909

Test: Ran the backtrace unit tests, backtraces few random processes,
Test: forced the ANR path for some zygote based processes.
Test: Ran the art ThreadStress test a few times.
Change-Id: I5abc9e330a5e86cea7015e2362f66044c6bc37d0
2017-03-10 10:13:48 -08:00
Yabin Cui
26369a3a01 libbacktraceoffline: make it thread-safe.
Make libbacktraceoffline thread-safe by protecting the global variable with
a lock. So it can be used in a multi-thread environment, like by
simpleperf inplace sampling.

Bug: http://b/30974760
Test: no
Change-Id: I4699bf15dfa69ac75faeb4e79a73fb3af0f08dfc
2017-02-13 10:35:06 -08:00
Yabin Cui
c4a480e423 libbacktraceoffline: choose correct debug section for a given address.
1. In /system/lib/libart.so, the ranges of functions covered by .eh_frame
and .ARM.exidx overlap with each other. Currently, we don't check .eh_frame
if the address is in the ranges of functions covered by .ARM.exidx. It leads
to a wrong unwinding result. So change the logic to first try .eh_frame and
.debug_frame, if it fails, then try .ARM.exidx.
2. Add test for Item 1.

Bug: http://b/35251937
Test: run backtrace_test.

Change-Id: Ic412705617c300bc69b4ece178cc2e1bb3eb765b
2017-02-10 17:51:16 -08:00
Mark Salyzyn
30f991f251 liblog: use log/log.h when utilizing ALOG macros
Test: compile
Bug: 30465923
Change-Id: Id6d76510819ebd88c3f5003d00d73a0dbe85e943
2017-01-11 09:31:15 -08:00
Colin Cross
d233c2752b Remove obsolete mentions of LLVM_HOST_BUILD_MK
The libbacktrace common flags don't need the flags from
LLVM_HOST_BUILD_MK, they are added directly to libbacktrace_offline.
The -fno-omit-frame-pointer is unnecessary, as we no longer import
flags only used to build LLVM into everything that depends on LLVM.
Removing -Wno-extern-c-compat doesn't cause any warnings.

Test: mma -j
Change-Id: Ia01380e8572c3d84268843291a54ec8c932a327f
2016-12-17 13:34:05 -08:00
Colin Cross
da9bd5902f Convert the rest of libbacktrace to Android.bp
See build/soong/README.md for more information.

Reapplies I61c49fb62fdeafb66db25b8f97621239b8fd6e75 after fixing
an unused parameter warning on mips builds.

Test: mma -j
Test: backtrace_test
Change-Id: I6dc353a274cafcdb05ee866b41c3c2731612941c
2016-12-15 12:57:47 -08:00
Colin Cross
06d314917f Fix unused parameter warning for mips builds
libbacktrace_offline was inheriting -Wno-unused-parameter from llvm's
makefiles.  Fix an unused parameter warning when compiling for an
unsupported architecture, and return false since *value wasn't
written.

Test: lunch aosp_mips-eng && mma -j
Change-Id: I7df990f01e1025ca17ec3717107df56d2349f3cb
2016-12-15 12:57:45 -08:00
Colin Cross
ced030892d Revert "Convert the rest of libbacktrace to Android.bp"
This reverts commit 9a3603622f.

Broke the mips build with an unused parameter warning

Change-Id: If36964ea189b58a9825de8904f1cf49010548b59
2016-12-15 20:44:30 +00:00