Commit graph

18 commits

Author SHA1 Message Date
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
Christopher Ferris
a8c397317d Clear dex pc to avoid duplicate frames.
Bug: 73228466

Test: Passes new unit tests, fails without change.
Change-Id: I3660bfd16cbf2d5cf96490ca7714bc5f97914884
2018-02-12 08:46:19 -08:00
Christopher Ferris
e762f1f193 Check that dex pc is in a valid map.
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
2018-02-06 15:00:04 -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
David Srbecky
f9006ec9b6 Fix symbol resolution within a dex file.
Fixes the ART 137-cfi test, currently failing on buildbot.

Test: testrunner.py -j40 --host --cdex-none -t 137 -b
Change-Id: I16a007b291702207bbd003fd1e78e8e5ced7cd68
2018-02-01 14:51:57 +00: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
2fcf4cf13e Add error propagation into Unwinder/Elf objects.
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
2018-01-24 17:50:46 -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
Christopher Ferris
02fdb569f6 Do not check arch for format check.
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
2017-12-08 15:44:14 -08: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
Christopher Ferris
c3d79f7c07 Fix incorrect usage of relative pcs.
When stepping, it's necessary to use both the unaltered relative pc
and the adjusted relative pc. If the adjusted pc is not used, the
wrong unwind information can be used.

Added new offline unit tests that take real data and verifies that it
unwinds properly.

Fix a bug in the map code that would not properly parse map data for
a 64 bit process when done in a 32 bit process.

Fix bug in eh_frame processing that didn't adjust the pc correctly.
Fix unit tests related to the pc adjustment.

Bug: 69475565

Test: Passes libbacktrace/libunwindstack unit tests.
Test: Run debuggerd -b on processes on a hikey.
Change-Id: Ic501a1c4549c5f61d2742a7105c42a960f2c892b
2017-11-29 16:10:08 -08:00
Christopher Ferris
fda7edd13e Move sp/pc not changing check into Unwinder.
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
2017-10-31 17:51:02 -07:00
Christopher Ferris
1cb84cea2f Add an interface for stopping in certain maps.
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
2017-10-24 15:45:59 -07:00
Christopher Ferris
e69f470933 Multiple bugfixes, small restructuring.
- 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
2017-10-20 11:15:32 -07:00
Christopher Ferris
c5a3baa5e3 Fix setting of map_offset in frame data.
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
2017-10-17 18:42:03 -07:00
Christopher Ferris
f6f691b63c Update the Unwinder object and add tests.
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
2017-10-04 14:40:14 -07:00
Christopher Ferris
b9de87f7ed Add a new unwind method on error.
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
2017-09-22 16:55:12 -07:00