Commit graph

231 commits

Author SHA1 Message Date
Florian Mayer
249c90ff17 Fix missing load bias.
There are binaries that have non-executable LOAD with p_offset=0.

E.g.,

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000400040 0x0000000000400040 0x0002a0 0x0002a0 R   0x8
  INTERP         0x0002e0 0x00000000004002e0 0x00000000004002e0 0x00001c 0x00001c R   0x1
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x0059e0 0x0059e0 R   0x1000
  LOAD           0x006000 0x0000000000406000 0x0000000000406000 0x10f2b05 0x10f2b05 R E 0x1000
  LOAD           0x10f9000 0x00000000014f9000 0x00000000014f9000 0x70f634 0x70f634 R   0x1000
  LOAD           0x1808f18 0x0000000001c09f18 0x0000000001c09f18 0x089fc8 0x0a7ab8 RW  0x1000
  DYNAMIC        0x1864ce0 0x0000000001c65ce0 0x0000000001c65ce0 0x000240 0x000240 RW  0x8
  NOTE           0x0002fc 0x00000000004002fc 0x00000000004002fc 0x000020 0x000020 R   0x4
  TLS            0x1808f18 0x0000000001c09f18 0x0000000001c09f18 0x000010 0x000010 R   0x8
  GNU_EH_FRAME   0x11abde8 0x00000000015abde8 0x00000000015abde8 0x14484c 0x14484c R   0x4
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
  GNU_RELRO      0x1808f18 0x0000000001c09f18 0x0000000001c09f18 0x05c0e8 0x05c0e8 R   0x1

Test: host libunwindstack_test passes.
Test: Modified unit tests and new offline test.

Change-Id: I3992f712be238c7d4109556580b5dcc71175fe19
2019-07-09 10:22:36 -07:00
Christopher Ferris
7e21eba5b7 Switch case to suite to follow new gtest naming.
Bug: 135528735

Test: All unit tests pass.
Change-Id: I1f3dc6fe381ec557b6b7bc5cb1c58d210efa63da
2019-06-20 16:18:57 -07:00
Christopher Ferris
d1d973be12 Fix potential race condition.
Found when I noticed that the unit tests segfaulted every once in a while.

Test: Ran all unit tests 1000 times. The crash usually happens before 100 runs.
Change-Id: I1c8d2e3637400dc80f273f3677f4c94b0dbeac9d
2019-06-19 18:51:31 -07:00
Casey Dahlin
6b95a0e999 Internalize subclasses of Memory
There are many subclasses of the Memory class and the overwhelming
majority of them don't need to be exposed externally. We move all of
them to internal headers except MemoryOfflineBuffer, which moves to a
separate header. This dramatically reduces the exposed API surface and
makes the code more modular.

Also, remove the Offline code from libbacktrace. It's not used any where.

Test: Unit tests pass, clean tree still builds
Change-Id: I55dacdf080daba0bfe65c1ad53a4b326bb482e83
2019-06-11 12:09:18 -07:00
Christopher Ferris
d49499d5c9 Set elf_start_offset for invalid elf maps.
Add new unit tests to cover this case.

Bug: 133495043

Test: New unit tests pass.
Change-Id: I9ded5732c3c40197ebfddee3dcacc4aa07541ac0
2019-06-10 18:39:38 -07:00
Christopher Ferris
a4bdb984f9 Display offsets for dex frames.
When adding a dex frame, no offset is ever printed even if the dex data
is coming from a non-zero offset map. Fixed so an offset is printed
in this case.

Previous the line looked like this:

  #17 pc 0000000000500d7a  /product/app/GoogleCamera/GoogleCamera.apk (com.google.android.libraries.camera.async.AndroidPriorityThread.run+10)

Now looks like:

  #17 pc 0000000000500d7a  /product/app/GoogleCamera/GoogleCamera.apk (offset 0x11d0000) (com.google.android.libraries.camera.async.AndroidPriorityThread.run+10)

Add new unit test for this case.

Bug: 134420076

Test: Wrote new unit test, and verified a non-zero offset for dex file
Test: data results in a frame with a non-zero offset.
Change-Id: I58c134fda4fad5456ca0f1723192667a1ca5d509
2019-06-04 12:07:05 -07:00
Christopher Ferris
98aaf4cf08 Ignore memory from elf on /memfd:
In ART, some of the maps are /memfd:/jit-cache and it triggers the warning
about unreadable elf files. Do not set the elf from memory not file
flag in this case.

Bug: 131909548

Test: New unit tests pass.
Test: No warnings dumping stacks with this change done.
Change-Id: Ifba5e65da609525ded75430da173c614f6e4801e
2019-05-03 11:13:17 -07:00
Christopher Ferris
4ae266ccbd Add indicator that an elf is memory backed.
Modify the unwinder library to indicate that at least one of the stack
frames contains an elf file that is unreadable.

Modify debuggerd to display a note about the unreadable frame and a possible
way to fix it.

Bug: 129769339

Test: New unit tests pass.
Test: Ran an app that crashes and has an unreadable file and verified the
Test: message is displayed. Then setenforce 0 and verify the message is
Test: not displayed.
Change-Id: Ibc4fe1d117e9b5840290454e90914ddc698d3cc2
2019-04-18 15:37:52 -07:00
Christopher Ferris
d11ed86d65 Fix pc/function name for signal handler frame.
This refactors the step function slightly to split it up into
distinct pieces since the code needs to handle a signal handler
versus normal step slightly differently.

Add a new error for an invalid elf.

Modify libbacktrace code to handle new error code.

Bug: 130302288

Test: libbacktrace/libunwindstack unit tests.
Change-Id: I3fb9b00c02d2cf2cc5911541bba0346c6f39b8e6
2019-04-12 17:23:18 -07:00
Treehugger Robot
b626177d63 Merge "Revert "Check for data races when reading JIT/DEX entries."" 2019-04-06 17:09:10 +00:00
David Srbecky
b9cc4fbb26 Revert "Check for data races when reading JIT/DEX entries."
This reverts commit 85b5fecec9.

Reason for revert: Breaks ART tests, reverting to investigate.

Change-Id: I1bb905407e87cbd4f832646651133a9caf6fcfc8
2019-04-05 18:23:32 +00:00
Christopher Ferris
1760b45709 Fix off by one reading build id.
Update unit tests and add new build id displaying in offline unwinds.

Bug: 129873279

Test: All unit tests pass.
Test: Verify that debuggerd displays build id properly.
Change-Id: I97f4a204842447a20c812f535a458155b937d5e1
2019-04-03 14:51:51 -07:00
David Srbecky
59c70a5b75 Merge "Check for data races when reading JIT/DEX entries." 2019-04-03 07:15:39 +00:00
Christopher Ferris
c312c9ac15 Add minimal support for Dwarf 5.
This is not full support for dwarf 5, this merely treats a Dwarf 5
version as Dwarf 4. There are new dwarf ops that are not supported yet,
but this minimally support should allow unwinding to work if those
ops are not present.

Bug: 127355724

Test: New Unit tests pass.
Change-Id: I35b24fbcb15a64acd49e1e0b6890dff4456ee6fd
2019-04-01 16:56:09 -07:00
Christopher Ferris
22d8e8e12f Remove sequential search from DwarfEhFrameWithHdr.
Since there has never been a time that a sequential search has been
necessary, simply remove the sequential code and allow the DwarfEhFrame
object to be used in that case. If this does come up regularly, I'm not
sure that it wouldn't be more performant to use the DwarfEhFrame object
regardless.

Bug: 129550015

Test: libunwindstack unit tests, libbacktrace unit tests.
Change-Id: I738e81accb9bc1e182168cddc9c0c22823e3369b
2019-03-29 14:08:37 -07:00
David Srbecky
85b5fecec9 Check for data races when reading JIT/DEX entries.
Update the entries only when the list is modified by the runtime.

Check that the list wasn't concurrently modified when being read.

Bug: 124287208
Test: libunwindstack_test
Test: art/test.py -b --host -r -t 137-cfi
Change-Id: I87ba70322053a01b3d5be1fdf6310e1dc21bb084
2019-03-29 14:01:32 +00:00
Christopher Ferris
7813345faa Add BuildId to frame information.
Update debuggerd to print BuildId information by default.

Bug: 120975492

Test: New unit tests pass.
Test: debuggerd -b <PID> shows build id information.
Test: tombstones include build id information.
Change-Id: I019b031113d0b77385516223c63455b868924440
2019-03-26 08:04:40 -07:00
Christopher Ferris
02a6c448c3 Add support for displaying soname in an apk.
Changes:
- Change GetSoname to always returns a std::string.
- Added new unit tests for the soname printing.
- Modify the GetElf() function to save the same elf when we see rosegment
  linkers that split the read-only and read-write across a map. This
  avoids creating multiple elf objects for each map.
- Fixed a few offline unwind tests.

Bug: 29218999

Test: Unit tests pass.
Change-Id: Iad7c38b5c2957a8c5fd4ba94ebec335bafcad57d
2019-03-13 17:07:46 -07:00
Christopher Ferris
86f2d9d943 Fix missing offset for apk.
The elf_start_offset field in a map_info was not set in one path.

Added new offline test for this, and update a few unit tests.

Bug: 128442792

Test: New unit tests pass.
Change-Id: I2c6ac1b5271a99aa0e8c4b6342a5970199185112
2019-03-12 16:00:55 -07:00
Casey Dahlin
6e96f68cf3 Add missing override keyword
Fuchsia builds with Clang, and it's a bit pickier about always using
override when it's appropriate.

Test: None
2019-03-11 12:35:41 -07:00
Casey Dahlin
0e113851a5 Add unistd.h to includes in Regs.h
This is required to use pid_t, but by luck nobody noticed its absence
until the Fuchsia build.

Test: Code now builds inside Fuchsia
2019-03-08 15:04:48 -08:00
Florian Mayer
3d67d347f5 Fix copy / move behaviour of Maps object.
Currently, moving or copying a Maps object leads to double free of MapInfo.

Even moving a Maps object  did not prevent this, as after a move
the object only has to be in an "unspecified but valid state", which can
be the original state for a vector of raw pointers (but not for a vector
of unique_ptrs).

Changing to unique_ptrs is the most failsafe way to make sure we never
accidentally destruct MapInfo.

Test: atest libuwindstack_test
      Failed LocalUnwinderTest#unwind_after_dlopen which also fails at master.

Change-Id: Id1c9739b334da5c1ba532fd55366e115940a66d3
2019-03-05 13:05:36 +00:00
Martin Stjernholm
852b64e549 Fix libdexfile dependencies to avoid direct dependency on libdexfile_external.
It should be dlopen'ed lazily by libdexfile_support now.

Also change debuggerd_test to not link libunwindstack and its dependencies
statically - the static libs can overlap with the dynamic ones.

Test: mmma system/core/debuggerd/
Test: atest debuggerd_test
Test: mmma system/core/{libunwindstack,libbacktrace}, run host gtests (cannot get atest to work)
Bug: 124827589
Bug: 123186083
Change-Id: I9e7bf9bcbae499af4e1be4c9854bce441e2a7b55
2019-02-24 22:04:11 +00:00
Sandeep Patil
f31c70989b procinfo: Read inode number from /proc/<pid>/maps
Adjust all callbacks to include the inode number as well.

Fixes: 123532375
Test: libprocinfo_test
Test: libdmabufinfo_test
Test: libmeminfo_test

Change-Id: I71fd75d90d5ee44585011c5ae654a1dd7e185458
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-02-11 01:38:08 +00:00
Christopher Ferris
ce34d62351 Avoid signed extension of chars for build ids.
Added a unit test that fails before the change and passes afterwards.

Bug: 120606663

Test: All unit tests pass.
Change-Id: I054c7eac0c55abc3babe1d48a041f5819ad9db81
2019-01-30 12:09:11 -08:00
Christopher Ferris
f835ba6b66 Merge "Fix bug in unwind_info display of exidx frame." 2019-01-29 23:13:07 +00:00
Treehugger Robot
9f5e9978c2 Merge "Allow to move frames out of Unwinder." 2019-01-29 19:23:23 +00:00
Christopher Ferris
7010ecb50d Fix bug in unwind_info display of exidx frame.
The rosegment changed the load segments and broke the unwind_info printing
of unwind information for the arm exidx frame.

Test: Fixed and verified by dumping the arm exidx frame.
Change-Id: I7270175e4dcb7fee2b96a16d168880ebd09f19b1
2019-01-28 14:51:19 -08:00
Florian Mayer
1c993b76bf Allow to move frames out of Unwinder.
This saves a copy for every unwind we do in heapprofd.

Change-Id: Ife7aa1ce68831729d96ccd4c3e54ca531f98b6bc
2019-01-28 17:11:07 +00:00
Christopher Ferris
49047d711b Merge "Add GetPrintableBuildID()." 2019-01-26 07:03:35 +00:00
Christopher Ferris
ed7ca8bb14 Merge "Add a few leak check tests." 2019-01-26 06:45:39 +00:00
Christopher Ferris
b1c9c20eb2 Add GetPrintableBuildID().
The GetBuildID() function returns the raw build id data, so add a function
to get the printable hex version of the data.

Bug: 120606663

Test: New unit tests pass.
Change-Id: Ia5aefc97457efb08bbd30ea96cbb2d47ae59f954
2019-01-25 14:31:37 -08:00
Christopher Ferris
e1f7a63a4d Add a few leak check tests.
These tests are meant to replace the leak check tests from libbacktrace.

Bug: 120606663

Test: Ran tests on host and target.
Change-Id: I928b199304afc36b4bac78e9a2cd688b6f2910b9
2019-01-25 12:35:19 -08:00
Treehugger Robot
8306597e8f Merge "Fix crash in libunwindstack." 2019-01-25 04:29:30 +00:00
Florian Mayer
c479e4e789 Fix crash in libunwindstack.
Bug: 122657596

Test: New unit test that crashes without this change.
Change-Id: I5d978530a833345def94a58805d7ee93b23382bb
2019-01-24 16:29:36 -08:00
Vic Yang
cc8009ff04 libunwindstack: Move DwarfOp callback table to rodata section
There are currently two copies of DwarfOp callback tables in
data.rel.ro section, and that is 16KB of dirty memory per process on a
64-bit platform.

To reduce memory usage, we introduce a layer of indirection so that
all instances of DwarfOp can share a single callback table.  We also
get rid of the pointers for op names in the callback table so that the
entire table can be placed in rodata section.

Test result shows 1MB saving on cuttlefish, and 750KB saving on a Go
device (32-bit ARM).

Bug: 112073665
Test: Boot on cuttlefish and a Go device.
Change-Id: Idf90a513f37534ab1ef30d5742a9d3ea779f3661
2019-01-24 11:11:15 -08:00
Christopher Ferris
4aec66e810 Fix memory leak in UnwinderFromPid object.
Actually make the destructor virtual so that objects in
UnwinderFromPid get freed.

Also, explicitly make the DexFiles and JitDebug destructors virtual.

Bug: 123099840

Test: Ran UnwindTest.local_from_pid thousands of times.
Change-Id: I8bf11c0eb3587fa82f5f14f4723ea5c91da0fd46
2019-01-23 09:49:28 -08:00
Christopher Ferris
a5e0d695fa Merge "Fix flaky signal tests." 2019-01-23 17:39:09 +00:00
Florian Mayer
33d4bb3d88 Remove unused jit_debug unique_ptr.
Change-Id: I39ed4fdd5695fefff235b6c40d83d9780fc5b75b
2019-01-22 15:56:34 +00:00
Christopher Ferris
bc6a7e51e4 Fix flaky signal tests.
The signal tests that send a SIGUSR1 signal to a remote process, can
lead to a case where the code winds up in a location for which the
unwind information is not 100% accurate. This happens near the
end of the atomic functions which manipulate the stack right before
returning, but do not have separate cfi instructions for those last
few instructions.

Add a new test type for the from_context test that will wait explicitly
for the global g_finish and not piggy back on the remote test type.

Bug: 122902885

Test: Ran flaky tests 1000 times without failure on a taimen.
Change-Id: I7d0c9b016e3a3a2c0c0949cf74af11d7785a008c
2019-01-18 17:39:50 -08:00
Christopher Ferris
bf373edc3c Add caching of build id in MapInfo object.
Change the GetBuildID function to return a std::string.
Added benchmark to check how long it takes to get the build id from
a file versus an elf object.
Added a way to get an elf without passing in a valid process_memory and
added tests for this.

Test: New unit tests.
Change-Id: I3029019767e0181c758d611fe635bc1bf72d6e8e
2019-01-17 20:14:00 -08:00
Christopher Ferris
eb0772ff4a Add support for UnwinderFromPid object.
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
2019-01-16 15:13:25 -08:00
Christopher Ferris
cadacdf474 Fix usage of Read instead of ReadFully.
Found by inspection.

Test: Builds and unit tests passes.
Change-Id: I10b63534ae0a3bff9ce56e821c542fa69c15822d
2019-01-15 19:10:49 -08:00
Martin Stjernholm
2677b802bf Remove dependency on libdexfile internal header.
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
2019-01-11 21:05:50 +00:00
Martin Stjernholm
b49289b43a Some minor updates in the libdexfile external API.
Test: m
Test: mmma system/core/{libunwindstack,libbacktrace} and run host gtests
Bug: 119632407
Bug: 120978655
Change-Id: I919586ab503be3617e8a0604dfe48db331e7af94
2019-01-09 23:25:25 +00:00
Christopher Ferris
d76bd4c8d0 Merge "Remove CHECK in AdjustEncodedValue." 2019-01-08 16:47:06 +00:00
Treehugger Robot
a7d2ffa821 Merge "Move DwarfCfaInfo::kTable from data.rel.ro to rodata" 2018-12-21 12:58:26 +00:00
Christopher Ferris
a39aaf91eb Remove CHECK in AdjustEncodedValue.
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
2018-12-20 08:40:58 -08:00
Martin Stjernholm
bb4f2b440a Revert^2 "Use libdexfile external API in libunwindstack."
This reverts commit cacf5bf6bc.

Reason for revert: Re-apply with proper fix for VNDK visibility on marlin and sailfish.

Test: Manual repro of http://b/121110092#comment1 on reported branch
Test: atest CtsRenderscriptTestCases
Test: mmma system/core/{libunwindstack,libbacktrace}, run host gtests
Test: Make image, flash, and reboot device.
Test: Forrest cts/art/gce-all: https://android-build.googleplex.com/builds/forrest/run/L00300000240828791
Test: Forrest cts/bionic/gce-all: https://android-build.googleplex.com/builds/forrest/run/L05600000240682947 (shows 27/2958 failed, but it doesn't pass on Blackbox either: http://screen/xbjioEf6UgR)
Test: Forrest cts/renderscript/gce-all: https://android-build.googleplex.com/builds/forrest/run/L66200000240680523
Bug: 119632407
Change-Id: I601aa97eac8127e30d753405f8bc1fc4ae7f849f
2018-12-19 21:04:35 +00:00
Treehugger Robot
1baa19b1a6 Merge "Fix offsets when shared lib split across maps." 2018-12-19 17:11:53 +00:00