This object is able to be easily used from other code and can be used
to replace the libbacktrace calls in other parts of the platform.
Also, demangle the function names when calling FormatFrame.
Bug: 120606663
Test: Unit tests pass, debuggerd using this code directly passes unit
Test: tests.
Change-Id: Ifd8cf9bdd89174c1736810711d20e9f37f29b1bf
Also remove some tests for implementation details in the libdexfile API that
are now covered by unit tests there (http://r.android.com/867370).
Test: mmma system/core/{libunwindstack,libbacktrace} and run host gtests
Bug: 119632407
Change-Id: Ie731bb929a564de56ce1c78385da12a43d0954ff
Test: m
Test: mmma system/core/{libunwindstack,libbacktrace} and run host gtests
Bug: 119632407
Bug: 120978655
Change-Id: I919586ab503be3617e8a0604dfe48db331e7af94
The CHECK(encoding != DW_EH_PE_aligned) can trip given the right
arguments. This check isn't necessary, since the code will return
false in that case.
Add new unit test that tries all values to make sure no CHECK fires.
Bug: 120968571
Test: Passes new unit test, and passes fuzzing that failed before.
Change-Id: I062bcd18508c75cd3a4ca9dd12f922e25aafda8a
This reverts commit 444e23d2fc.
The rest of the topic doesn't need to be reverted.
Reason for revert: Breaks renderscript on marlin and sailfish.
Test: Manual repro of http://b/121110092#comment1 on reported branch
Test: "atest CtsRenderscriptTestCases" on that branch
Test: mmma system/core/{libunwindstack,libbacktrace}, run host gtests
Test: Make image, flash, and reboot device.
Bug: 121110092, 119632407
Change-Id: If1976b19ce386c95bc5bd4fd6d523745c167de18
The linker was modified so that a shared library has a read-only
map, then a read-execute map to represent the whole shared library.
When backtraces are created, then the offsets are set incorrectly
for backtraces. For example, all backtraces wind up with an offset now,
and a shared library loaded out of an apk shows the wrong offset.
Changes:
- Fix the FormatFrame function which was putting the offset before the
map name.
- Refactor the Maps and MapInfo classes to keep track of the previous map
instead of all maps. This was the only map that was ever needed.
- Modify the unwind_for_offline tool to capture both the read-only and
read-execute map when using the read-only segment option.
Bug: 120981155
Test: Updated unit tests pass.
Test: Unwinds on device don't show the offsets everywhere any more.
Change-Id: I75b3727221be9c20316dfdcd7a1c6d242d7ce948
Pages in .data.rel.ro are always dirty. Move whatever we can to
.rodata so that we reduce memory pressure.
The size of rodata, text, and data.rel.ro sections of linker64 on
cuttlefish before/after this change:
rodata: 0x170e4 -> 0x17964 (+2176 bytes)
text: 0xec919 -> 0xec919 (no change)
data.rel.ro: 0x9cf0 -> 0x98f0 (-1024 bytes)
Test: Boot cuttlefish
Change-Id: Ib2fd2bb0afb50208d441731d8c31bc8f287272c3
If the first frame of an unwind is a totally invalid pc that's not in
any map, a speculative frame is added. Rather than deleting this frame
if no more unwinding is possible, leave it. This fixes a case where
the only frame you get is an invalid one, but the speculative frame
winds up in a shared library or somewhere else and gets removed.
Bug: 120505086
Test: New unit tests to catch this case pass.
Test: Verified original crashing program now emits two backtrace lines.
Change-Id: I088dff21c057386dcdaeb3fc2578b24322683bd0
When a shared library is loaded directly from an apk, the new way the
linker splits a shared library into a read-only and execute segment
broke unwinding. Modify the code to handle this case.
Other changes:
- Modify the algorithm for finding read-only map entries. Before, the code
would search the entire map for the closest offset. Now it simply looks
at the previous map. I did this because the old code was too lenient and
might still work even if the linker changes. I want this to break if the
linker behavior changes so that I can analyze the change.
- Update the tools to use PTRACE_SEIZE instead of PTRACE_ATTACH since
PTRACE_ATTACH doesn't work in all cases.
- Small refactor of the GetFileMemory function.
- Add new unit test cases and new offline unwind test cases.
Bug: 120618231
Test: Ran new unit tests, ran original failing test.
Change-Id: I4bade55cf33220d52f1d5e9b0cbbbcc8419669d4
This will be used by heapprofd to allow us to correlate build ids with
memory leaks in libraries and binaries.
Test: m
Test: host libunwindstack_test
Test: run unwind_info against my phone's libc.so (32/64) and compare
to readelf Build ID output.
Bug: 120186412
Change-Id: I3cefd6cce9a8733509bf35b7175eb0f967783477
Remove unit test that is not needed any more.
Slightly reorganize the code around the changed check.
Bug: 77958880
Test: Ran backtrace tests with new linker options.
Test: Ran libunwindstack unit tests.
Change-Id: Ie95707323fb51616a093cafb83e0343fa24e7e61
To avoid a case where a malicious app might try and trick the system to
create an elf and register object that mismatches, always verify that they
are the same arch.
Test: Ran unit tests.
Change-Id: I66978e9e02f8e4f396856912e7019528ead4838e
Every real call always sets the value to true to init the gnu_debugdata
interface, so remove this parameter.
Test: Builds, unit tests pass.
Change-Id: I07fb3adbbd5b65b51c0dc7608561e820a5095051
If multiple threads are unwinding at the same time, new maps that contain
the global variables for dex files and jit information are created. This
leads to threads creating more new maps that then get searched, then
more maps, then more searching until virtual address space exhaustion.
Fix this so that we only search maps that have a corresponding rw map that
could contain the global memory.
Small refactor to combine the code to search for global variables into
one class that both classes inherit from.
Modify unit tests for the new pattern checking.
Bug: 117761427
Test: Ran unit tests for libunwindstack/libbacktrace/simpleperf.
Test: Ran art 004-ThreadStress that used to fail.
Change-Id: I837ca6b9d0383100079de090bc7d019598e0cdfe
When adding a frame with a dex pc, two frames will be added total. However,
if there is only enough room for a single frame, two get added any way.
Only add a single frame in this case, and add a unit test for this case.
Test: Passes unit tests.
Change-Id: If320584b126967a042c623d8fdf3f51dbc1c2251
The function should have returned a bool, so now it does.
Also use a different lighter weight function for validating the elf
in one place that didn't need to keep the max size value.
Test: Unit tests pass.
Change-Id: Ibde674e608091ba04abf22fad2fdc4dbdb2c6e73
The new linker base map is read-only, but the global handling code
for jit and dex information assumed the base map was a read-execute
one. Relax that requirement to search read-only maps.
Adjust the unit tests for this case.
Bug: 117293117
Test: Passes unit tests.
Test: Passes art cfi tests with and without llvm linker.
Change-Id: I31a765d51847d0b8d778ace9cbaa29f42073f4d9
The rosegment linker option results in two maps containing the elf data
existing. One is an execute map where the code lives, and the other is the
read-only segment which contains the elf header information. If the file
backing a shared library in memory is not readable, then the new code
will attempt to find the read-only map that has the same name as the
current execute segment, and that is at offest zero in the file.
Add new unit tests for this functionality.
Add the missing MapInfoCreateMemoryTest.cpp to the list of tests.
Bug: 109657296
Test: Pass new unit tests.
Test: All unit libbacktrace/libunwindstack tests pass with rosegment enabled.
Change-Id: If8f69e4a067d77b3f2a7c31e2e5cd989a0702a8c
Add FALLTHROUGH_INTENDED for clang compiler.
Bug: 112564944
Test: build with global -Wimplicit-fallthrough.
Change-Id: I40f8bbf94e207c9dd90921e9b762ba51abab5777
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
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
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
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
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
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
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
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
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
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