Rename Memory::Read to ReadFully to match its semantics with that of
android::base. ReadPartially will be renamed to Read in a follow up
commit, kept intentionally separate so that there aren't any callers
accidentally switched from ReadFully to Read.
Test: treehugger
Change-Id: I7d845ac5244c3025d92c8512e960e5d0d1da05af
Add a way to read while allowing for partial reads.
Test: new tests added to libunwindstack_test, ran 32/64 on hikey960, sailfish
Test: ran unwind on hikey960/sailfish
Change-Id: I8b11d9230fcd3122148ef3f980863ac1404ad70a
In this case, if the .eh_frame_hdr doesn't exist, we would crash.
Bug: 68813077
Test: Pass new unit tests, verified that without the fix, the unit test
Test: would crash.
Change-Id: I4f1365a76fe5c2fb69fa106a1ef15889c14e7611
Static executables only have a .eh_frame section and no .eh_frame_hdr
section. Add support for this by rearranging the class hierarchy and
creating a DwarfEhFrameWithHdr class and a DwarfEhFrame class to handle
the different cases.
Add new unit tests for DwarfEhFrame and for the new functionality.
Bug: 68820189
Test: Passes new unit tests, unwinds static executables.
Change-Id: I63d7cb8c52a686e96579a2266e18c0d06bbb6e63
If an entry is found in .eh_frame_hdr, but it's not properly in .eh_frame,
then the code would crash. The assumption that the header always points
to valid fde data is not guaranteed.
Bug: 68813077
Test: Passes new unit test that crashed before the change.
Change-Id: I914d9bda0d442cd232e2a056ae490301a8850105
Remove this check from the DwarfSection class.
Rather than have every step function make the check, doing it at the
top level avoids having every function do the same check.
Bug: 68167269
Test: New unit tests, ran debuggerd -b on processes.
Change-Id: I23b7c799faaf26c93c1b72848df18c78de6c42fb
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
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
Bug: 68047085
Test: Ran new unit tests, verified new unwinder does not show an
Test: extra pc zero frame for arm 32 bit processes.
Change-Id: Ic6532e56fbb786a8b7d41638abae777c2d0f1d59
Add a function to iterate over Regs with a human-friendly name and the
value of the register, to make it easy to string-format registers.
Test: mma
Change-Id: I8f33830fa79b245b5030b7bc9bc3c1c7ced80c75
- Move the load bias stored out of ElfInterface into Elf. For the compressed
sections, the load bias was not the same as the data from the uncompressed
section.
- Move the initialization of the compressed section into Init. It was too easy
to forget to call the init of the compressed section.
- Do not automatically add in load bias to the pc before calling ElfInterface
code. Do all of the pc manipulations in the Elf object.
- Change the interface GetFunctionName code to pass in the load_bias instead
of modifying the pc inside the code.
- Modify the Step function to pass in the elf offset, not add it to the pc.
It is necessary to have two different relative values when executing the
Step: a pc that is relative to the beginning of the elf for the reading data
the actual instructions when trying to determine if this is in a signal
frame, and a pc that is relative to the map for finding the appropriate
unwind information.
- Add a feature to Unwinder so that an unwind can be stopped if it ends up
in map that has a specified suffix. This is so that the ART unwinding
code doesn't require skipping the compressed section. Instead, stop at
if trying to unwind through a known suffix code that means the code is
in java code. This is important because the compressed section data is
not only used by the jave compiled code, so that will continue to work.
- Fix tests for restructuring, add new tests for new functionality.
Test: Ran art test 137-cfi using new unwinder as default.
Test: Ran new unit tests.
Change-Id: I42e658c64c5e14f698ba34944a3043afac967884
The old code set the map_offset from elf_offset, but it should have used
offset. Without this change, frame data is not properly shown for shared
libraries in an apk.
Add new unit test to verify that map_offset is set properly.
Test: Ran new unit tests.
Change-Id: I2fe5abda23a5de51c8fcf9361ba9350b80446f15
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
There will be a second linux host config (linux_bionic), so move this to
apply to all supported host configs instead of just linux_glibc.
Test: out/soong/build.ninja is the same before/after
Change-Id: Id8db10e0a3db889736070eea16f387785c913179
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
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
libunwindstack_test:UnwindTest.* are all failing, but at least this
builds.
Test: Enable host bionic; m
Test: out/soong/host/linux_bionic-x86/nativetest64/libdemangle_test/libdemangle_test
Test: out/soong/host/linux_bionic-x86/nativetest64/libunwindstack_test/libunwindstack_test
Change-Id: Ie6c774ecb4d7a467b5ea7ae977833e9cba178f2d
- Rewrite some of the UnwindTest tests to properly wait for the process
to be ready.
- Add a TestScopedPidReaper to make sure that fork process get killed even
if the test fails. Add this to all tests that fail.
- Create a quiesce function to be used by all of the tests that will
wait after attaching to a process.
Bug: 65287279
Test: Ran unit tests on hikey960 board and on host repeatedly.
Change-Id: I57084120396f34d8dfb852f3d814bef2056f1b54
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
As a VNDK-SP module, Android.bp must have 'vndk' tag as well as
'vendor_available: true'.
The 'vndk' tag for VNDK-SP module is formated as below:
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: 64395154
Bug: 63866913
Test: build with BOARD_VNDK_VERSION=current
Merged-In: Idb4757988d1799ffcd3341343fcc4dac34bf7ef3
Change-Id: Idb4757988d1799ffcd3341343fcc4dac34bf7ef3
(cherry picked from commit 14d540a156)
- Add a method to get the max size of an elf file by reading the
section header offset + size. This will properly map an elf
file embedded into an apk, instead of just mapping in what is done
by the dynamic linker. It does assume that the section headers are
at the end of the elf file.
- Add new tests for the above functionality.
- Update the unwind_symbols tool to take an address for finding a
function instead of dumping the entire symbol table.
Bug: 23762183
Test: Unit tests pass, unwind through the camera process and verify
Test: the GoogleCamera.apk shows some function names.
Change-Id: I00c021680fe1d43b60d652bf91bbf6667d9617be
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
- 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
- The pc read from the eh frame binary table of pc/fde offset is off by 4.
I verified that on arm/arm64/x86/x86_64 the pc in this table matches
the fde pc_start value. I did this by adding an error if this occurred
and ran unwind_info over everything in system/lib, system/lib64, system/bin.
- Fixed unit tests for the above change.
- Fix a small bug in the processing encoded values. The high
bit of the encoding should be masked off, but I wasn't doing that. That
meant during processing of the fde, I was incorrectly returning
an error because the encoded value was unknown.
- Added a new test for this encoding change.
Bug: 23762183
Test: Build and all unit tests pass. Also, see above comments.
Change-Id: If074a410a1726392274cd72c64470ca0be48e0db
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)
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
The StepIfSignalHandler code reads from the process memory object, which
is currently the slowest way to read memory. Change the code to read from
the elf memory object which will almost always be a memory mapped file and
should be really fast.
Also, move the tests for StepIfSignalHandler to its own file.
Bug: 23762183
Test: Unit tests pass.
Change-Id: I1100b50554e5ef736a87babd484f3f34e9071caa
- Add the StepIfSignalHandler function to the Regs object that checks
if the code is in a signal handler.
- Add tests for new code, also add a test that unwinds through a signal
handler.
- Slight modification to Elf to fail if a bad machine type is encountered.
Add tests for this.
Bug: 23762183
Test: Ran unit tests.
Change-Id: Idafa1105d00b91a9343d7464ac9ed1cb95830963
- Add namespace unwindstack everywhere so that it's easier for other
code to use the library.
- Move some of the header files into include/unwindstack so that they
can be exposed.
- Modify the headers so that only a limited number need to be exposed.
- Update the tools to use the new headers.
- Add a GetLoadBias() call on the Elf object. This prevents the need
to get the interface object out of the Elf object.
- Move the GetRelPc() call out of the Reg class, to the Elf class. It's
not always the case that a Reg object will be around when you want to
get a relative pc. The tests for this moved to ElfTest.cpp.
Bug: 23762183
Test: Unit tests pass.
Change-Id: Iac609dac1dd90ed83d1a1e24ff2579c96c023bc3
- Cleanup the blueprint file a bit.
- Fix the formatting in DwarfMemoryTest.cpp.
- Fix the misnamed test MemoryBuffer.cpp to MemoryBufferTest.cpp.
- Add a function to find the location of the test files so it's not
necessary to run the test in the same directory as the test files.
Bug: 23762183
Test: Builds and unit tests pass.
Change-Id: I5666972bd01f14b8ee47c518f1840f8aeb7fd08b
- Fixes a few bugs in untested functionality.
- Add tests for the way the register handling code is used.
- Fix a few tests that were not reaping child processes.
Bug: 23762183
Test: Ran unit tests on host (32 bit and 64 bit).
Test: Ran unit tests on angler (32 bit and 64 bit).
Change-Id: I573d6617b4f1561f6e8494d7213c52086d112d97
- Modify the tests to share some code for the generation of the elf data.
- Move the gnu_debugdata files into a separate directory.
- Add tests for GetElf().
- Move the CreateMemory() tests and the GetElf() tests into separate files.
Bug: 23762183
Test: New unit tests pass.
Change-Id: Ie3380296bb49753c2ac8801cfa11f93d6ff7121d
- Use the CHECK macro everywhere that assert was used.
- Remove the _debug version of the tests and leave the CHECK macro so
it's always checking in the code.
Bug: 23762183
Test: Ran unit tests.
Change-Id: Ie705eedae393d0e95bb9d99f852687a11881aef1
Update the unwind_info tool to dump all of the sections.
Bug: 23762183
Test: Passes new unit tests.
Change-Id: I8b223bc208a1a2ef06ed333e6d96943c8f273681
Add the code to parse the Elf section headers.
Add the plumbing through of all the symbol handling code.
Add tests for all of this new functionality.
Bug: 23762183
Test: Pass new unit tests.
Change-Id: Ie2d90cbb3d7653c53251dbcf34d9e5d241278377
Fix a couple of memory leaks in tests.
Fix a potential case that length could be zero.
Bug: 23762183
Test: Ran unit tests, then ran valgrind on unit tests and verified no leaks.
Change-Id: I5f7602aa0204db0488a8e305250658cdb6e977d0