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
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
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 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 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
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
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
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
Add new unit tests for dex pc being non-zero.
Bug: 73004673
Test: Ran unit tests.
Test: Ran art 137-cfi test on host for interpreter.
Change-Id: I09bbf96d0ed65fc1e5896e4ab2bc67867e3b7fdb
The backtrace offline code uses these error codes to diagnose errors.
In addtion, I've had cases where seeing these errors would help diagnose
failures.
This also allows us to add a few features to indicate why an unwind
terminated (such as max frames exceeded).
Bug: 65682279
Test: Updated unit tests pass.
Change-Id: If82b5092698e8a194016d670efff1320f9b44d50
This patch requires v3.18 kernel or above, because v3.10 kernel
has a bug (as of 8/1/2017) in the ptrace(GETREGSET) function for mips
and mips64.
Change-Id: I004c1fa190193eebe1c84440b366289122a6bd8a
Signed-off-by: Douglas Leung <douglas.leung@mips.com>
Signed-off-by: Dejan Jovicevic <dejan.jovicevic@mips.com>
Use a generic check if the address is 32 bits when using the default
formating of a backtrace line instead of an arch check.
Test: New unit tests pass.
Change-Id: Id609abc037d7b437a02d52763aa91fbefe5f4d5b
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
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
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
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
- 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