Commit graph

13 commits

Author SHA1 Message Date
Christopher Ferris
a09c4a6ff2 Fix offsets when shared lib split across maps.
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
2018-12-18 11:22:14 -08:00
Florian Mayer
3f1f2e07ab Add missing includes.
Test: Builds.
Change-Id: Ia8b79154902503cdd774dc3b4523466123b4324c
2018-12-06 10:09:20 -08:00
Christopher Ferris
9d5712c123 Implement support for linker rosegment option.
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
2018-10-03 20:48:45 -07: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
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
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
e7b6624c3f Fix issues in libunwindstack.
- Add a load_bias field in MapInfo so that it can be loaded offline,
  and also so it can be cached.
- Add an Add function to the Maps class so that it's possible to manually
  create a map.
- Remove the OfflineMaps class since I haven't found a reason for this to
  exist.
- Add a pointer to the gnu debugdata compressed section in the interface
  itself and modify the step path to try eh_frame, then debug_frame, then
  gnu_debugdata. This way arm can add exidx as the last step behind
  gnu_debugdata. Add an offline test to verify the order of unwind.
- Fix x86_64_ucontext_t since it was a different size on 32 bit and 64 bit
  systems.

Test: Pass new unit tests.
Change-Id: I978b70d6c244bd307c62a29886d24c1a8cb2af23
2017-12-15 11:17:45 -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
be788d891d Allow multiple threads sharing a map to unwind.
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
2017-11-28 15:20:38 -08:00
Christopher Ferris
60521c7d52 Speed up map creation.
- 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
2017-08-23 15:43:39 -07:00
Christopher Ferris
d226a51409 Make the library usable as a library.
- 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
2017-07-14 12:20:23 -07:00
Christopher Ferris
051792fed4 Fix some memory leaks, potential errors.
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
2017-06-19 16:20:33 -07:00
Christopher Ferris
09385e7db5 Implement maps parsing.
The MapsOffline code is still in development so I'm not testing it very
thoroughly yet.

Bug: 23762183

Test: All unit tests pass.
Change-Id: I77aeac62940cd95c489ee221afe02349bfe39671
2017-04-06 15:01:02 -07:00