Commit graph

211 commits

Author SHA1 Message Date
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
Martin Stjernholm
cacf5bf6bc Revert "Use libdexfile external API in libunwindstack."
This reverts commit 444e23d2fc.

The rest of the topic doesn't need to be reverted.

Reason for revert: Breaks renderscript on marlin and sailfish.

Test: Manual repro of http://b/121110092#comment1 on reported branch
Test: "atest CtsRenderscriptTestCases" on that branch
Test: mmma system/core/{libunwindstack,libbacktrace}, run host gtests
Test: Make image, flash, and reboot device.
Bug: 121110092, 119632407
Change-Id: If1976b19ce386c95bc5bd4fd6d523745c167de18
2018-12-19 00:11:04 +00:00
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
Vic Yang
80aba5494a Move DwarfCfaInfo::kTable from data.rel.ro to rodata
Pages in .data.rel.ro are always dirty.  Move whatever we can to
.rodata so that we reduce memory pressure.

The size of rodata, text, and data.rel.ro  sections of linker64 on
cuttlefish before/after this change:
  rodata: 0x170e4 -> 0x17964 (+2176 bytes)
  text: 0xec919 -> 0xec919 (no change)
  data.rel.ro: 0x9cf0 -> 0x98f0 (-1024 bytes)

Test: Boot cuttlefish
Change-Id: Ib2fd2bb0afb50208d441731d8c31bc8f287272c3
2018-12-14 06:03:09 -08:00
Martin Stjernholm
1d6969ccb9 Merge "Use libdexfile external API in libunwindstack." 2018-12-14 13:36:30 +00:00
Christopher Ferris
065f156195 Do not remove speculative frames in all cases.
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
2018-12-13 10:41:08 -08:00
Martin Stjernholm
444e23d2fc Use libdexfile external API in libunwindstack.
Test: mmma system/core/{libunwindstack,libbacktrace}, run host gtests
Test: Make image, flash, and reboot device.
Bug: 119632407
Change-Id: I370f089a1b20ba432e136818b4325d46f99df708
2018-12-13 17:58:23 +00:00
Christopher Ferris
583ce2deff Merge "Fix handling of ro segments for embedded libs." 2018-12-13 03:18:58 +00:00
Christopher Ferris
01040b10b2 Fix handling of ro segments for embedded libs.
When a shared library is loaded directly from an apk, the new way the
linker splits a shared library into a read-only and execute segment
broke unwinding. Modify the code to handle this case.

Other changes:
- Modify the algorithm for finding read-only map entries. Before, the code
  would search the entire map for the closest offset. Now it simply looks
  at the previous map. I did this because the old code was too lenient and
  might still work even if the linker changes. I want this to break if the
  linker behavior changes so that I can analyze the change.
- Update the tools to use PTRACE_SEIZE instead of PTRACE_ATTACH since
  PTRACE_ATTACH doesn't work in all cases.
- Small refactor of the GetFileMemory function.
- Add new unit test cases and new offline unwind test cases.

Bug: 120618231

Test: Ran new unit tests, ran original failing test.
Change-Id: I4bade55cf33220d52f1d5e9b0cbbbcc8419669d4
2018-12-11 19:16:29 -08:00
Chih-Hung Hsieh
1b7b7979af Fix performance-for-range-copy warnings
Bug: 30413223
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance*
Change-Id: I3ad102f2b0f971266d57488a3bd57d312f7ee3e6
2018-12-11 10:51:13 -08:00
Florian Mayer
3f1f2e07ab Add missing includes.
Test: Builds.
Change-Id: Ia8b79154902503cdd774dc3b4523466123b4324c
2018-12-06 10:09:20 -08:00
Florian Mayer
a5913bdd07 Merge "Read .note.gnu.build-id." 2018-12-06 10:57:26 +00:00
Florian Mayer
da459e56f7 Read .note.gnu.build-id.
This will be used by heapprofd to allow us to correlate build ids with
memory leaks in libraries and binaries.

Test: m
Test: host libunwindstack_test
Test: run unwind_info against my phone's libc.so (32/64) and compare
      to readelf Build ID output.

Bug: 120186412

Change-Id: I3cefd6cce9a8733509bf35b7175eb0f967783477
2018-12-05 14:13:30 +00:00
Christopher Ferris
ef6401091f Add support for caching small reads.
Add benchmarking to verify this is faster.

Test: Ran unit tests.
Change-Id: I1487114331f4581ec2368e56c4f18c6e3e6bcc7d
2018-11-28 13:04:58 -08:00
Christopher Ferris
5565906732 Remove overly restrictive check for memory.
Remove unit test that is not needed any more.

Slightly reorganize the code around the changed check.

Bug: 77958880

Test: Ran backtrace tests with new linker options.
Test: Ran libunwindstack unit tests.
Change-Id: Ie95707323fb51616a093cafb83e0343fa24e7e61
2018-11-15 14:06:26 -08:00
Mark Salyzyn
9f1cf25332 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I4f7ad84743e974b4b4d1d7256088f6c8b749a237
2018-11-14 09:35:34 -08:00
Christopher Ferris
4568f4bc0f Verify that the elf matches the expected arch.
To avoid a case where a malicious app might try and trick the system to
create an elf and register object that mismatches, always verify that they
are the same arch.

Test: Ran unit tests.
Change-Id: I66978e9e02f8e4f396856912e7019528ead4838e
2018-10-29 18:08:09 -07:00
Treehugger Robot
551efd11f7 Merge "Fix off by one error." 2018-10-24 00:52:15 +00:00
Christopher Ferris
e8c4ecf49e Always init gnu_debugdata interface if it exists.
Every real call always sets the value to true to init the gnu_debugdata
interface, so remove this parameter.

Test: Builds, unit tests pass.
Change-Id: I07fb3adbbd5b65b51c0dc7608561e820a5095051
2018-10-23 12:13:54 -07:00
Florian Mayer
9c36a99ebc Fix off by one error.
Change-Id: I18a2d177f3212626b7091150f42dfe151e47570e
2018-10-23 18:10:41 +01:00
Christopher Ferris
56d0e07d70 Fix which maps to search for globals.
If multiple threads are unwinding at the same time, new maps that contain
the global variables for dex files and jit information are created. This
leads to threads creating more new maps that then get searched, then
more maps, then more searching until virtual address space exhaustion.

Fix this so that we only search maps that have a corresponding rw map that
could contain the global memory.

Small refactor to combine the code to search for global variables into
one class that both classes inherit from.

Modify unit tests for the new pattern checking.

Bug: 117761427

Test: Ran unit tests for libunwindstack/libbacktrace/simpleperf.
Test: Ran art 004-ThreadStress that used to fail.
Change-Id: I837ca6b9d0383100079de090bc7d019598e0cdfe
2018-10-17 14:23:10 -07:00