Commit graph

325 commits

Author SHA1 Message Date
Treehugger Robot
6c9bb058c5 Merge "Build adbd for recovery" 2018-05-25 05:58:01 +00:00
Christopher Ferris
3acf577759 Change tests to use a temporary dir for files.
Avoid using hard-coded paths for generated files. This can cause problems
if the tests are run in parallel.

Also fix a potential race condition in the unwind_through_unreadable_elf_remote
test.

Test: Ran tests in parallel and normally.
Change-Id: Ib42522de49499766a29bda5bfffe737b56715e3f
2018-05-24 16:48:16 -07:00
Jiyong Park
a0e75045e6 Build adbd for recovery
adbd (and its dependencies) are marked as recovery_available:true so
that recovery version of the binary is built separately from the one for
system partition. This allows us to stop copying the system version to
the recovery partition and also opens up the way to enable shared
libraries in the recovery partition. Then we can also build adbd as a
dynamic executable.

Bug: 79146551
Test: m -j adbd.recovery
Change-Id: Ib95614c7435f9d0afc02a0c7d5ae1a94e439e32a
2018-05-24 14:11:11 +09:00
Treehugger Robot
9f6f8bf0dc Merge "Mark as recovery_available: true" 2018-05-22 05:16:20 +00:00
Jiyong Park
612210c75b Mark as recovery_available: true
Libraries that are direct or indirect dependencies of modules installed
to recovery partition (e.g. toybox) are marked as recovery_available:
true. This allows a recovery variant of the lib is created when it is
depended by other recovery or recovery_available modules.

Bug: 67916654
Bug: 64960723
Test: m -j
Change-Id: Ie59155c08890e96ce1893fa3687afcf763d7aea3
2018-05-15 09:47:04 +09:00
Yabin Cui
3841accba8 libprocinfo: add functions reading process map file.
Add test and benchmark.
Also switch libbacktrace, libunwindstack, libmemunreachable
to use libprocinfo for map file reading.
The benchmark shows using libprocinfo speeds up map file reading
in libbacktrace and libunwindstack 18% - 36% on walleye.

Bug: http://b/79118393
Test: run procinfo_test.
Test: run libunwindstack_test.
Test: run libbacktrace_test.
Test: run memunreachable_test.

Change-Id: Icf281c352f4103fc8d4ba6732c5c07b943330ca1
2018-05-14 14:00:18 -07:00
Christopher Ferris
c5943fd3fa Merge "Remove unnecessary references to libunwind." 2018-05-03 23:05:51 +00:00
Christopher Ferris
8548d55b45 Remove unnecessary references to libunwind.
Bug: 79209464

Test: Builds.

Change-Id: I79f7b0123bc802e3e12d218e888c30dedf5204dc
2018-05-03 14:24:38 -07:00
Elliott Hughes
03d183aecc Tell the build system about APCT's requirements.
Bug: N/A
Test: N/A
Change-Id: I8a67e1ce5acc4142387878ba0bb542da0861e700
2018-05-03 10:06:45 -07:00
Elliott Hughes
40fdf3f4ab Add test_suites lines.
Bug: N/A
Test: builds
Change-Id: Ic5e2b9206bcfcb53c774989013b5db6aab462e42
2018-04-27 16:12:06 -07:00
Christopher Ferris
6633b0ca09 Add a MemoryOfflineBuffer object.
Use this for offline stack data so that it's not necessary to
copy any data around.

Add unit tests for the new object.

Bug: 77258731
Bug: 74354410

Test: Ran libunwindstack/libbacktrace unit tests.
Change-Id: I9b0f25d9520c96e64aedef5f295423c60ddb3488
2018-04-03 18:37:52 -07:00
Christopher Ferris
458f4e725d Method to avoid skipping frames for local unwinds.
In cases where there might be a crash in the unwind library itself,
we need a method to avoid skipping these frames or we won't be able
to see the actual crash.

Added unit test for this behavior.

Bug: 74121887

Test: Ran unit tests on host and target.
Change-Id: I45825020c174016af39dd8ffdc67acb72a24ad4d
2018-03-23 13:01:44 -07:00
Yabin Cui
d5b22c5f04 Support a map that represents gdb jit elf data.
Changes:
- Add a new flag to the libbacktrace and libunwindstack map data.
- Modify the unwinder to handle this map to use the raw pc when stepping.
- Add new unit tests for this case.

Bug: http://b/73127105
Test: Run simpleperf to unwind through jit symfiles.
Test: Run new unit tests.
Test: Run 137-cfi test on host.
Change-Id: I10bc0410680accc6d35fe51e9f1098911f667e01
2018-03-21 17:23:54 -07:00
Christopher Ferris
432981b905 Modify the offline handling interface.
- Add a new function Backtrace::UnwindOffline that takes the stack data.
- Modify BacktraceMap::CreateOffline so it doesn't take the stack data.
  This makes it easier to reuse the map object created this way.

Reusing the map object increases simpleperf speed (unwinds per second) by 50%.

Test: backtrace_test libunwindstack_test
Change-Id: I90cfbae9e50d95d8a0e3cd394b33ba36d65d45f7
2018-02-23 09:14:06 -08:00
Christopher Ferris
e4b3a6aaa4 Add ability to skip function name resolution.
Bug: 73558129

Test: New unit tests pass.
Change-Id: I3a6b17d2590aacb367ab3e3a51cc85be73ad64eb
2018-02-20 17:10:23 -08:00
Elliott Hughes
dc699a269f bpfmt.
Bug: N/A
Test: builds
Change-Id: I89ad00e1c4c7e0767bc80a7ac7935a4d55e090ac
2018-02-16 17:58:14 -08:00
Christopher Tate
6983112f59 Fix darwin build
Darwin needs libbase too.

Test: 'm'
Change-Id: I9d50face92b7d5a4399dbcebd39d4062477b3a2c
2018-02-16 14:54:36 -08:00
Elliott Hughes
e1415a5c3b Include the map name when dumping memory around a register.
Bug: http://b/19590178
Test: ran tests, ran crasher
Change-Id: Ib9afa34c860d8732ef1943eb4decd0b7c8fb55fd
2018-02-15 16:28:50 -08:00
Christopher Ferris
7747b60faa Load dex files from ART-specific data structure.
Fixes cdex which was recently changed to have shared data section,
which means the DEX PC cannot be used to find the right symbol,
as the bytecode is no longer within the dex file, and in-fact,
we might have to scan multiple dex files to find the method.

Bug: 72520014
Test: testrunner.py --host --cdex-none -t 137
Test: testrunner.py --host --cdex-fast -t 137
Test: All unit tests pass.
Change-Id: I80265d05ad69dd9cefbe3f8a75e4cd349002af5e
2018-02-02 15:03:00 -08:00
Christopher Ferris
d70ea5ea85 Move dex pc frame creation into libunwindstack.
Test: Compiles, all unit tests pass.
Test: Ran 137-cfi art test in interpreter and verified interpreter
Test: frames still show up.

Change-Id: Icea90194986faa733a873e8cf467fc2513eb5573
2018-01-31 14:19:42 -08:00
Christopher Ferris
c8bec5aa91 Use new unwinder for offline in libbacktrace.
libbbacktrace changes:
- Completely rewrite the BacktraceOffline class to use the new unwinder.
- Modify the test data to save ucontext_t data instead of unw_context data.
- Convert the previous tests from unw_context data to ucontext_t data.

Bug: 65682279

Test: New unit tests pass in libunwindstack.
Test: All offline tests continue to pass.
Change-Id: I540345c304b20199d46deeb0349a0638a0f3ab2f
2018-01-29 10:41:11 -08:00
Christopher Ferris
8fe5836c02 Fix frame numbering regression.
Test: All unit tests now pass.
Change-Id: I280dfbbed3f835c826788b80ff4abb22bea7dc59
2018-01-26 14:26:13 -08:00
David Srbecky
645f8bbc6f Emit the frame for DEX PC before the frame for native PC.
This results in more natural backtrace.

Test: ART's 137-cfi test

Change-Id: Ic472db2733a330f8dbc722887809273b77d9dfb5
2018-01-25 14:09:43 +00:00
Christopher Ferris
0b06a590d9 Add extra frame when dex_pc is non-zero.
Use the art dex file library to read the dex data.

Add unit tests for the UnwindDexFile code.

Bug: 72070049

Test: All unit tests continue to pass.
Test: Dumped the backtrace of the 137-cfi test while running in interpreter
Test: mode and verified that the stack trace is correct. Did this on host
Test: and for arm/arm64.

Change-Id: Ia6f343318c5dd6968a954015a7d59fdf101575b0
2018-01-23 13:17:48 -08:00
Christopher Ferris
2486d5a10d Fix null ptr dereference if jit debug not enabled.
Test: No crash when a jit debug object is not instantiated.
Change-Id: Ic4350a10258459ead7c5679ceb84372f1084f0ad
2018-01-22 17:37:59 -08:00
Christopher Ferris
e20b4a48fe Merge "Change all uintptr_t to uint64_t in API." 2018-01-19 23:30:33 +00:00
Christopher Ferris
7937a36c8e Change all uintptr_t to uint64_t in API.
In order to support the offline unwinding properly, get rid of the
usage of non-fixed type uintptr_t from all API calls.

In addition, completely remove the old local and remote unwinding code
that used libunwind.

The next step will be to move the offline unwinding to the new unwinder.

Bug: 65682279

Test: Ran unit tests for libbacktrace/debuggerd.
Test: Ran debuggerd -b on a few arm and arm64 processes.
Test: Ran crasher and crasher64 and verified tombstones look correct.
Change-Id: Ib0c6cee3ad6785a102b74908a3d8e5e93e5c6b33
2018-01-18 17:26:20 -08:00
Christopher Ferris
98984b41da Add support for getting a dex pc.
Changes:
- Change the register type from int16_t to uint32_t for the location data
  and the Eval processing. This is because the special dex pc is > 65535.
- Add the ability for Dwarf register location information to point to a
  register that is itself a Dwarf location register.
- Add dex_pc to the frame information.
- Modify the unwind tool to print the dex pc if non-zero.

This does not implement the printing of the dex information in anything
but the unwind tool. It's not the final form of this printing.

Bug: 72070049

Test: Ran new unit tests.
Test: Dumped stack while in interpreter running 137-cfi art test and
Test: verified dex pc is set to non-zero.
Change-Id: I6ce8a6b577fb4f92abacbd433b1f68977e272542
2018-01-17 19:18:00 -08:00
Christopher Ferris
150db124f3 Add ability to read jit gdb data.
Changes:
- New JitDebug class to handle all of the jit gdb interface.
- Add unit tests for all, along with new offline test using debug data.
- Add new Memory type called MemoryOfflineParts that has multiple
  MemoryOffline objects to support the offline test.
- Update the tools to use the JitDebug object.
- Modify libbacktrace to use the JitDebug, but only looking in libart.so
  and libartd.so.
- Change the Format32Bits to Is32Bit since it's more accurate and I use
  it in a different context where original name didn't make sense.
- Add a new function to find global variables in an elf file
  (GetGlobalVariable).
- Add a new function to determine if a pc is valid for this elf (IsValidPc).

Bug: 68396769

Test: Ran new unit tests. Added new offline test that uses jit debug data.
Test: Ran art test that generates jit data and verified a crash unwinds
Test: through the jit data.
Change-Id: I6e7ee2f5bab2242028a06feece156dff21c0a974
2018-01-12 11:18:42 -08:00
Yabin Cui
9879137720 libBacktraceOffline: improve unwinding callchains.
1. Extend MAX_BACKTRACE_FRAMES to 256, as we can have callchains
   with length near 256 when recording Android applications.

2. .eh_frame and .ARM.exidx doesn't know how to unwind from instructions
   setting up or destroying stack frames. It can lead to wrong callchains,
   which may contain pcs outside executable mapping areas. Stop unwinding
   once this is detected.

3. Some CIE entries in .eh_frame/.debug_frame suggest unwinder reading
   personality routine from memory. However, that is not available in
   offline unwinding, and leads to ACCESS_MEM_FAILED error. Work around
   this by returning all zero data when failed to read data for some
   addresses.

4. Some libraries have empty .eh_frame_hdr but valid .eh_frame.
   Work around this by building eh_frame_hdr manually.

5. Prefer to use .debug_frame than .eh_frame. Because the former
   can unwind instructions setting up and destroying stack frames.

Bug: http://b/69383534
Test: run backtrace_test.
Test: run simpleperf on some apps.

Change-Id: I62dddda3865dd567c6be150ce5527dc2d3516256
2017-12-18 18:20:44 -08:00
Yabin Cui
f88082811a libbacktrace: export offline unwinding failures.
This is to help debugging different offline unwiding failures.

Bug: http://b/69383534
Test: run backtrace_test.
Change-Id: I5ed4837027a9f17d032925e97e9f5927161444b3
2017-12-15 13:29:53 -08:00
Yabin Cui
0ca49b09ad libBacktraceOffline: try both .debug_frame and .ARM.exidx on arm.
Currently, libBacktraceOffline doesn't try .ARM.exidx if a function
appears in .debug_frame. This make it can't unwind through functions
appear in both .debug_frame and .ARM.exidx, but having dwarf instructions
not accepted by libunwind.
This patch fixes this by trying first .debug_frame then .ARM.exidx on arm.

Bug: http://b/69383534
Test: run libbacktrace_test on arm.

Change-Id: Ib95dd56d5cc123a20948e880b51b28ddc04b4a6e
2017-12-10 18:00:35 -08:00
Christopher Ferris
88b48f7b18 Make sure at least XX maps are created.
Rather than expect exactly one set of maps, make sure there are at
least XX number of maps.

Test: Ran the 32 bit and 64 bit variants of the benchmarks.
Change-Id: I34184eab3810e92e7f246aa810ddb18fab443c9a
2017-12-08 12:48:46 -08:00
Christopher Ferris
70f7d47f3c Merge "Add method to detect remote read function to use." 2017-12-08 20:09:34 +00:00
Christopher Ferris
e328673a30 Add method to detect remote read function to use.
The process_vm_read function is much faster than ptrace, but sometimes
that will not work on a remote process. Modify the libunwindstack
MemoryRemote object to figure out which one it can use.

Wrote new unit test to verify this checking behavior.

Modify libbacktrace so that the read from libunwind is used instead of
using the default ptrace calls.

Add some benchmarks to libbacktrace to compare the two different methods.

Test: Ran unit tests libbacktrace/libunwindstack/debuggerd.
Test: Ran debuggerd -b <SYSTEM_SERVER_PID>
Test: Ran debuggerd -b <MEDIACODEC PID>
Test: Ran debuggerd -b <RANDOM_PID>
Test: Used crasher to create tombstones and verified stack data is
Test: dumped properly.
Change-Id: If75ca238289532dd8e1de430d569cabb2523380a
2017-12-07 19:00:00 -08:00
Elliott Hughes
3289b9c928 Merge "Add OWNERS." 2017-12-07 23:21:26 +00:00
Elliott Hughes
693d63f9cf Add OWNERS.
Bug: N/A
Test: N/A
Change-Id: Ie785058c0f5eb9b4086c98ccba6e63e3ed411b65
2017-12-07 13:30:03 -08:00
Christopher Ferris
a7e2a12d38 Merge "Split arch data into separate files." 2017-12-07 02:35:35 +00:00
Yabin Cui
d7edcc9bc4 Merge "libBacktraceOffline: fix using debug frame with load bias." 2017-12-07 00:25:20 +00:00
Christopher Ferris
d06001d6e0 Split arch data into separate files.
Add an ArchEnum to express the arch of the Elf objects and Reg objects.

Split out the regs code into per arch pieces and generic parts.
Also, split out the header files for each arch.

Do not break out the test code yet, there isn't enough and it doesn't
help to maintain the tests.

Test: libunwindstack/libbacktrace/debuggerd unit tests pass.
Test: Running debuggerd -b <PIDS> yields valid data on bullhead.
Change-Id: If61f6c730c9ff2249f986b41de8c4d62f7158325
2017-12-06 16:01:40 -08:00
Yabin Cui
4a26eaf1f1 libBacktraceOffline: fix using debug frame with load bias.
Bug: http://b/69383534
Test: run backtrace_test.
Change-Id: I295d9dc8f3e5b628f179b2eaeac21fa93de130b0
2017-12-06 11:27:06 -08:00
Christopher Ferris
b7de5f5429 Demand read load bias for a map.
Add a static GetLoadBias method to the Elf object that only reads just
enough to get the load bias.

Add a method to MapInfo that gets the load bias. First attempt to get
it if the elf object already exists. If no elf object was created, use
the new static method to get the load bias.

In BacktraceMap, add a custom iterator so that when code dereferences
a map element, that's when the load bias will be retrieved if it hasn't
already been set.

Bug: 69871050

Test: New unit tests, verify tombstones have non-zero load bias values for
Test: libraries with a non-zero load bias.
Change-Id: I125f4abc827589957fce2f0df24b0f25d037d732
2017-12-05 13:12:47 -08:00
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