Commit graph

156 commits

Author SHA1 Message Date
Christopher Ferris
3f9582f432 Fix implicit fall through switch cases.
Bug: 116020901

Test: Builds with -Werror=implicit-fallthrough.
Change-Id: I401f37585dae6cbf8995389a8a189abc2e102987
2018-09-19 14:12:59 -07:00
Chih-Hung Hsieh
502f4864d6 Suppress implicit-fallthrough warnings.
Add FALLTHROUGH_INTENDED for clang compiler.

Bug: 112564944
Test: build with global -Wimplicit-fallthrough.
Change-Id: I40f8bbf94e207c9dd90921e9b762ba51abab5777
2018-09-17 16:50:11 +00:00
Florian Mayer
ec004eb1b3 Merge "Allow to get raw register data on all platforms." 2018-08-08 21:37:46 +00:00
Mathieu Chartier
c2277fc216 Move to using ClassAccessor
In preparation for removal of ClassDataItemAccessor.

Bug: 79758018
Test: make
Test: test/run-test --host 137
Test: out/host/linux-x86/nativetest/libunwindstack_test/libunwindstack_test

Change-Id: I61a20fe7200a0d669b84573d3853b55877922602
2018-08-08 11:04:15 -07:00
Florian Mayer
932247e900 Allow to get raw register data on all platforms.
No new test failures introduced.

atest libunwindstack_test on aosp_walleye-userdebug:

Without patch:
Total: 800, Passed: 781, Failed: 19
With patch:
Total: 800, Passed: 781, Failed: 19

Change-Id: I8853c3e1594799761b481464b75e2904b38c4830
2018-08-08 11:19:41 +01:00
Christopher Ferris
5acf069a7a Be permissive about badly formed elf files.
Here is the allowable issues with an elf file that will not result in an error:
- The program headers/section headers offset points to unreadable memory.
- Allow missing program header and/or section headers.
- Allow a symbol table section header to point to invalid symbol table values.

There is no real reason to require the elf file be perfect. Everything in
the code has sane defaults, so any missing information won't cause any
problems.

This gets rid of the warning that occurs any time an elf is loaded
from memory. In memory elf files never contain all of the section headers,
and do not contain the symbol table data.

Update tests to test these new cases.

Test: Builds and unit tests all pass.
Change-Id: Iaefe2cd6b6c965a01ed425a112d6afae339f3b78
2018-08-03 22:02:05 +00:00
Christopher Ferris
2786608743 Fix incorrect left shifts.
Bug: 112142060

Test: New unit tests pass.
Change-Id: I0c47b22582f0bf75ab503364a337c7de4de3ec43
2018-08-02 18:01:02 -07:00
David Srbecky
02d0f7962d Create lookup table of DEX symbols.
Create fast lookup table instead of iterating every single time.
This will create the cache as methods are searched for.

Test: 137-cfi
Change-Id: I4be190bb1a637fef5d385b993be6a7e2203a6814
2018-07-20 10:48:59 -07:00
Christopher Ferris
5afddb0637 Remove Memory::ReadField.
In almost all cases, it is faster to read the entire structure rather
than do multiple reads using ReadField. The only case where it would be
slower is if doing a remote unwind and ptrace is the only way to read. In
all other cases, it's a single system call. In the ptrace call, it will be
multiple calls. Given that it is unusual to be forced to use ptrace,
it's better to avoid it.

It also reduces the code complexity to do a single read, and avoids
issues where the code forgets to read the field it needs.

Test: Unit tests pass on host and target.
Change-Id: I7b3875b2c85d0d88115b1776e1be28521dc0b932
2018-07-12 12:45:31 -07:00
Elliott Hughes
38488907a0 Move libbacktrace off cutils.
There's still <cutils/atomic.h> in a test, but I don't understand why
that isn't just std::atomic.

Also add a shared tgkill wrapper to libbase.

Bug: N/A
Test: ran tests
Change-Id: Idd4baa1e1670a84b3a8f35803cc5ffe5aae008a6
2018-07-11 13:55:07 -07:00
Christopher Ferris
92acaac8c7 Refactor the DwarfSection classes.
Modify the code for the no header sections because it turns out that
it is not okay to assume that the fdes are non-overlapping. It's necessary
to read the fdes in order and match as you go.

Modify the code so that it only reads until it finds the given pc rather than
reading all of the cie/fde entries at once.

Rewrote the tests to verify the new behavior.

Bug: 68998033
Bug: 110235461

Test: Ran libbacktrace/libunwindstack unit tests.
Test: Unwind the mediaserver process on a walleye and verify it
Test: unwinds properly.

Change-Id: I7bb59d1db72c13fa34caa9735ec34c1a60e20ed2
2018-06-27 14:52:21 -07:00
Christopher Ferris
f882a38864 Fix ARM program header values used for exidx.
Before, I was using p_vaddr to get the offset into the elf file where
the exidx frame starts. I changed that to use p_offset since this already
has the load bias offset in it and some elf files do not set p_vaddr
properly.

Also, use p_filesz instead of p_memsz, since again, some elf files do
not set p_memsz to the same as p_filesz.

Bug: 110704153

Test: All libbacktrace/libunwindstack unit tests pass.
Test: Randomly unwind process on a walleye.
Test: Verified that this properly dumps and unwinds the shared
Test: library that sets p_vaddr and p_memsz differently.
Change-Id: Ic7b1e5d07439f4636fa02cd884a8727a5737372b
2018-06-22 16:48:02 -07:00
Christopher Ferris
4cc36d2b43 Fix handling of load bias values.
It turns out that for the dwarf information, if a FDE indicates it's pc
relative, then pc has to be incremented by the load bias. If not, then
it should not be incremented.

Previously, the code always subtracted load bias values from pcs, and assumed
that all fdes were incremented by load bias values. The new code actually
reads the fdes and adjusted the pcs in the fde and in the eh frame hdr so
that load bias values are already handled properly.

In addition, add dumping of arm exidx values in unwind_reg_info. This allowed
verifying that the debug frame in those elf files was being handled properly.

Added a new unit test that only has a debug frame that has a non-zero load
bias and has fde entries that do not have pc relative encoding.

Fix a couple of other small bugs.

Bug: 109824792

Test: All libbacktrace/libunwindstack unit tests pass.
Test: Ran ART 137-cfi test and 004-ThreadStress.
Test: Verify that displaying the fde start and end pc actually match the
Test: real data for fde that have pc relative set, and that don't.
Test: Verified that the unwind information for arm exidx matches the
Test: debug frame data.

Change-Id: I707555286b5cb05df9f25489e8c5ede753cfe0fb
2018-06-11 18:53:55 -07:00
Elliott Hughes
f6d7594d7f Try to fix LocalUnwinderTest.unwind_after_dlopen in APCT.
Failure:

  system/core/libunwindstack/tests/LocalUnwinderTest.cpp:181: Failure
  Value of: handle != nullptr
  Actual: false
  Expected: true

Bug: N/A
Test: N/A
Change-Id: I89b3228d51961f7bf952dd01f12f4ee61a97fe91
2018-06-06 10:48:41 -07:00
Treehugger Robot
6c9bb058c5 Merge "Build adbd for recovery" 2018-05-25 05:58:01 +00: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
Christopher Ferris
ca9a54b2c0 Add a specialized LocalUnwinder object.
This object is for doing many local unwinds across different threads
at any point during a program's execution.

Also add LocalUpdatableMaps that will re-read the maps data under certain
circumstances.

This first version does not support jit or dex pc data.

Bug: 74361929

Test: Ran unit tests.
Change-Id: I790662366d3fed677f31b3288182950c494de9ad
2018-05-23 20:02:30 -07:00
Treehugger Robot
2ed14f3923 Merge "Libunwindstack: Add -O0 to tools defaults on host" 2018-05-23 19:37:01 +00:00
Christopher Ferris
5e516cad93 Fix error messages handling.
Test: Builds.
Change-Id: I083ee4a51047e97e2ead78f40c82a21198f2b361
2018-05-21 13:26:58 -07:00
Andreas Gampe
8ccbe4258e Libunwindstack: Add -O0 to tools defaults on host
Extend the debug support from the host library to host tools.

Test: mmma system/core/libunwindstack
Change-Id: Ib6ea5f021d6b8139c545eaa2e6b1675befa4d3bd
2018-05-21 08:24:20 -07:00
Christopher Ferris
239425b9fa Fix bug when doing signal handler lookup.
The new lld linker uses all non-zero offset executable maps. There was
a bug when trying to find if the stack is in a signal handler that caused
the code to read the wrong place in the elf. Fixed by not adding the elf
offset to the relative pc.

Also fixed the unwind_for_offline tool to dump multiple stacks if necessary.

Added new offline unit test that would have failed with the old code.

Bug: 79936827

Test: Ran unit tests and libbacktrace unit tests.
Test: Dumped backtraces of system pids.
Test: Ran 137-cfi art test.
Change-Id: Iaca8c18c2a314902e64c3f72831234297e8dcb1b
2018-05-17 18:58:42 -07: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
Sen Jiang
2ef03e0f01 Match LZMA SDK 18.05 API.
Test: libunwindstack_test
Change-Id: Ie1c9c91fb4f3585a7543df55a71abf64f8fc6dff
2018-05-04 13:12:36 -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
Josh Gao
2f37a15472 libunwindstack: add Regs::Clone.
Add a way to copy a Regs object.

Bug: http://b/77296294
Test: libunwindstack_test
Change-Id: I28aff510aa3e1b677d5ae46dc3bfe7652817ce52
2018-04-20 13:23:20 -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
95a524460a Merge "Cache DWARF location rules for a given pc." 2018-03-29 14:47:35 +00:00
David Srbecky
3386ebade2 Cache DWARF location rules for a given pc.
Decoding the DWARF opcodes is expensive so make sure we cache it.

This speeds unwinding in simpleperf by over a factor of 3x.

Add unit tests for this new behavior.

Bug: 77258731

Test: libbacktrace/libunwindstack unit tests on host and target.
Test: Ran debuggerd -b on various processes on target.
Change-Id: Ia516c0fa5d3e5f76746190bb4b6fdf49fd1c9388
2018-03-29 14:47:13 +00:00
Christopher Ferris
6dbc28ece3 Fix null pointer dereference in RegsArm.
Fix RegsArm::GetPcAdjustment to check for an invalid elf before trying
to read memory.
Modify the tests for this so it crashes without this change.

Also modify the GetPcAdjustment for all different architectures so
that unless the relative pc is too small, it will return the minimum
amount that should be adjusted. This is to handle cases where we still
want to adjust the pc but it's in an invalid elf. Mostly this is for
handling cases when the pc is in jit gdb debug code so that we use the
right unwind information.

Bug: 77233204

Test: Passes unit tests for libbacktrace/libunwindstack.
Change-Id: Id73609adaf3b80a583584441de228156fec3afa7
2018-03-28 17:21:01 -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
b22451f178 Merge "Always set the sp reg to the cfa for DWARF." 2018-03-19 17:48:59 +00:00
David Srbecky
e8d1b75c0c Merge "Don't include map name if the consumer doesn't want names." 2018-03-19 11:23:10 +00:00
David Srbecky
e62f4c4d4c Don't include map name if the consumer doesn't want names.
Simpleperf doesn't need the name, so avoid the string copies.

This seems to speed up simpleperf by around 20%.

Test: backtrace_test libunwindstack_test
Change-Id: Iba064c7078f7e5ecfc9d8539ba09c14495a52158
2018-03-19 11:20:00 +00:00
Yabin Cui
11e96fe48a Always set the sp reg to the cfa for DWARF.
There are a few places where it is assumed that this register is
set to the cfa value when interpreting DWARF information.

Add a testcase for unwinding art_quick_osr_stub on ARM.

Bug: 73954823

Test: Ran libunwindstack/libbacktrace unit tests.
Test: Random debuggerd -b of process on a hikey.
Test: Ran the 137 art test on host.
Change-Id: Ida6ccdc38c3cfeea6b57fe861a0cc127b150b790
2018-03-16 23:38:07 -07:00
Christopher Ferris
704ec9adba Handle ARM thumb function symbols.
ARM thumb functions will have the zero bit set to one, which can cause
function name lookups to fail.

Add an ARM special GetFunctionName that handles this condition.

Fix a couple of the function offsets in unit tests.

Bug: 74844137

Test: Ran unit tests.
Test: Ran debuggerd -b on processes on a bullhead device.
Change-Id: Ibd407db34eaaa641f91fdb4f589c44a0dcc0216a
2018-03-15 15:14:18 -07:00
David Srbecky
ff9b1db67c Merge "Remove libunwindstack_dex" 2018-03-13 11:31:22 +00:00
David Srbecky
18121dc4d0 Remove libunwindstack_dex
Thanks to David Sehr's recent work the isolation is no longer needed.

Bug: 72216369
Test: backtrace_test
Test: libunwindstack_test
Test: testrunner.py -t 137
Change-Id: I0f430e0c18bdbc83c5584a2461ebbcc7eeb91313
2018-03-12 20:13:21 +00:00
David Srbecky
3692f25199 Don't implicitly dereference DW_CFA_def_cfa_expression.
The specification isn't entirely clear. Follow the gdb interpretation.

Bug: 73954823
Test: libunwindstack_test
Change-Id: If72717f54eed84e442f43af19e615143a9796b68
2018-03-08 14:44:11 -08:00
Christopher Ferris
81744ac69f Remove leftover commented out code.
Test: Compiles.
Change-Id: Icf1cf1640e76450d5327395eb94dbd87d2faac36
2018-03-06 11:24:55 -08:00
David Srbecky
8fbdbba9f5 Merge "Adjust DEX file reading to follow layout changes in ART." 2018-02-23 17:53:23 +00:00
Christopher Ferris
a2ec50bf57 Change the GetAdjustedRelPc to GetPcAdjustment.
This cleans up a bit of the Unwinder code to make it clear what's
going on.

Modify the offline unit tests to verify the pc and sp to make sure
that those values get computed correctly.

Test: Passes unit tests.
Test: Passes 137-cfi art tests.
Change-Id: I0787a1d77b8726d3defd08f31c7476f6798f8d0d
2018-02-21 20:16:39 -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
Treehugger Robot
0609e8d231 Merge "bpfmt." 2018-02-20 02:02:59 +00:00
Elliott Hughes
dc699a269f bpfmt.
Bug: N/A
Test: builds
Change-Id: I89ad00e1c4c7e0767bc80a7ac7935a4d55e090ac
2018-02-16 17:58:14 -08:00
Christopher Ferris
d9575b668b Modify elf cache to handle elf_offsets properly.
Bug: 73498823

Test: All unit tests pass.
Test: Simpleperf run that previously failed, passes now.
Change-Id: Iff3a1f2f641a46ab9a0326579af3649f0c76fc65
2018-02-16 14:52:38 -08:00
David Srbecky
4015ef411a Adjust DEX file reading to follow layout changes in ART.
I have changed the root DEX debug descriptor in ART to more
closely follow the JIT debug descriptor. Add the appropriate
offsets to correctly fetch the linked list head for DEX files.

Test: testrunner.py -t 137
Test: libunwindstack_test
Change-Id: I90402befc88fec42658f7330d51ee79756a7f872
2018-02-16 14:54:49 +00:00
Christopher Ferris
beae42bc7f Fix soname reading code.
The dynamic section contained an address, not an offset into the elf
file to indicate where the soname exists. Changed to use the strtab
entries in the section headers to map this address to the actual offset.

Refactor the soname test a bit to make it easier to verify the code.

Bug: 73499044

Test: Passes new unit tests.
Test: Ran unwind_info on the failing shared elf and verified the soinfo
Test: is correct.
Change-Id: I16ba148389bcb9aadd3566fb442dac27f89fe894
2018-02-15 17:57:13 -08:00
David Sehr
3a26c27252 Move libdexfile out of runtime
Move the files out of runtime, leaving unfortunate dependences still
there on runtime/base (for the moment).  Also separates the build logic
into two Android.bp files.

Bug: 22322814
Test: make -j 50 test-art-host
Change-Id: I54b06f035034e7564480cd5d4c33c4f62785682d
2018-02-14 17:42:59 +00:00
Christopher Ferris
559c7f2092 Implement new DEX PC lookup scheme.
GDB wasn't handling the old one gracefully.

- Create a RegsInfo structure that can be used to properly eval expression
  data.
- Remove the versions on Dwarf ops. It doesn't work the in the real world
  and doesn't add useful information.
- Fix dex pc frame number bug.

Test: testrunner.py -j40 --host --cdex-fast -t 137
Test: libunwindstack_test
Test: All unit tests pass.
Change-Id: Iac4fea651b81cb6087fd237a9a5027a352a49245
2018-02-13 16:45:38 -08:00
Christopher Ferris
e4df5f5ab5 Fix computation of pc.
Fix the case where a non-zero load bias or a non-zero elf offset causes
the pc to be set incorrectly.

Add unit tests for these cases.

Bug: 73172903

Test: Ran unit tests.
Test: Ran the unit tests from the simpleperf CL that detected the failure.
Change-Id: Id8802c00b34c66875edd4926a20c5fccd2bb7d72
2018-02-12 14:06:13 -08:00