Commit graph

79 commits

Author SHA1 Message Date
Chih-Hung Hsieh
770032ddfa Fix/suppress bionic google-explicit-constructor warnings
* Add explicit to conversion constructors/operators

Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: Id1ad0327c1b8c6f094bcbb3ae599bc1f716b3f2f
2019-01-02 11:04:05 -08:00
Christopher Ferris
b233fab925 Fix handling of libs with a ro map and a rx map.
When the linker was changed so that it put a read-only map and
read-execute map, this code incorrectly computed the relative pc and
offset. Modify to look for the actual start map in this case.

Also, change the load_base name to load_bias.

Bug: 120613266

Test: Dumped logcat while dumping backtraces.

Change-Id: I6628694c5222ea34d63217af3d138707d4900004
2018-12-18 17:45:46 -08:00
Chih-hung Hsieh
b3fe0136d8 Merge "Revert "Disable lld, libc_malloc_debug failed to boot."" 2018-11-08 04:59:14 +00:00
Chih-hung Hsieh
56794421fc Revert "Disable lld, libc_malloc_debug failed to boot."
This reverts commit 0e87940961.

Reason for revert: This should have been fixed.
Bug: 78118944

Change-Id: I796ff2420ec3682dd54a059175a8428868b75c23
2018-11-07 23:49:37 +00:00
Elliott Hughes
5e62b34c0d Clean up bionic_macros.h a bit.
Use <android-base/macros.h> instead where possible, and move the bionic
macros out of the way of the libbase ones. Yes, there are folks who manage
to end up with both included at once (thanks OpenGL!), and cleaning that
up doesn't seem nearly as practical as just making this change.

Bug: N/A
Test: builds
Change-Id: I23fc544f39d5addf81dc61471771a5438778895b
2018-10-25 11:00:00 -07:00
Christopher Ferris
6774cc5b99 Add new parameter for creation of MapInfo object.
Bug: 109657296

Test: Unit tests pass.
Change-Id: Ie33b50234fa9ba2c5107c3eb0da36a466bba1589
2018-10-04 08:41:10 -07:00
Christopher Ferris
ad935c8139 Add more descriptive text around app starting.
Test: NA
Change-Id: If3bcf060b11ec08835863236b0a1408aebe43355
2018-08-16 17:57:23 -07:00
Christopher Ferris
0dc784431b Add new malloc benchmarks.
This runs through the trace of the allocations in a sql benchmark app
executed in the benchmark thread.

Add one benchmark with decay time set to 0 and another with decay time
set to 1.

Include a script that can generate a header file that can be used to
regenerate the data.

Bug: 112317428

Test: Builds, ran unit tests, ran benchmarks.
Change-Id: I62e287cc06b74b74bcc5a4bbee71b0fac0a196fd
2018-08-14 16:01:58 -07:00
Yi Kong
32bc0fcf69 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-08-02 18:09:44 -07:00
Christopher Ferris
97b4747102 Disable malloc debug intercepts when exiting.
There is a hang when enabling leak_track since the dumping of the
leak data can wind up doing an allocation.

Add new system unit test to make sure this doesn't happen again.

Bug: 111146059

Test: Test program that leaks does not hang forever.
Test: Unit tests pass.
Change-Id: Icf99be58ba5db98ee124a471b957a086045f5870
2018-07-11 15:23:00 -07:00
Christopher Ferris
2e1a40a203 Change heap dump format slightly.
Bump the version from v1.1 to v1.2 and add a build fingerprint line.

Update the heap dump documentation to match the new format and reflect
what made it in P and what made it in Q.

Update the unit tests for this change.

Add -O0 to unit test code to make it easier to debug.

Add an external function that can be used by the framework code
so that there is only one way to dump the heap.

Bug: 110095681

Test: Ran unit tests.
Test: Did a dump of a real process and verified fingerprint.
Test: Did a dump of a process without malloc debug enabled.
Change-Id: I769a476cbeaf4c85c5d75bd6d6385f0e3add948c
Merged-In: I769a476cbeaf4c85c5d75bd6d6385f0e3add948c
(cherry picked from commit c84a2a2601)
2018-06-15 12:29:13 -07:00
Christopher Ferris
1d52a7b1be Add an example of how to use multiple options.
Test: NA
Change-Id: I67b6c2f8eb8ad8ead98969e69990f540ecd9a770
2018-06-01 13:42:25 -07:00
Christopher Ferris
770cbb35cf Point to online documentation.
Test: Unit tests pass.
Change-Id: Ibbdc260bfdf6a6daf091c4a49cdf03e51f6ca6cf
2018-05-25 13:28:05 -07:00
Elliott Hughes
149671875d Link to native_heapdump_viewer.py.
Bug: N/A
Test: N/A
Change-Id: I1e448f30922d948513ebb65abc25c474ffbd5a24
2018-05-24 18:44:31 -07:00
Christopher Ferris
93bdd6ae3a Add support for using the new unwinder.
This adds a new option backtrace_full, when it is set, then it will use
libunwindstack.

Modify the dump to file data to dump the extra information from libunwindstack.
Along with the new dump file format, change the version to v1.1.
Updated document for new format of file data.

Add unit tests for the new functionality.

Bug: 74361929

Test: Ran unit tests.
Change-Id: I40fff795f5346bba7b9d7fde2e04f269ff4eb7f1
2018-05-24 08:44:53 -07:00
Christopher Ferris
c151bc3078 Fix nullptr dereference during sort.
Add new unit test that will crash without this fix.

Bug: 78900050

Test: Ran unit tests.
Change-Id: I73e1b89e965a7b399822c3a6f25cbc70d2d355e2
2018-05-01 14:49:15 -07:00
Chih-Hung Hsieh
0e87940961 Disable lld, libc_malloc_debug failed to boot.
* Linker rules for lld do not work with libunwind_llvm yet.

Bug: 78118944
Test: make checkbuild and boot
Change-Id: I0eda2409d9f365029f70f4255edffbeae49cb6d2
2018-04-16 10:50:52 -07:00
Elliott Hughes
5ad142157d Point to the NDK wrap.sh docs.
Bug: N/A
Test: N/A
Change-Id: Ic4c12a2ae43a6d733a23dcd2c901c2b6478eee97
2018-04-06 15:13:14 -07:00
Elliott Hughes
7dc7d2b7f2 Stop claiming that malloc debug is only usable on rooted devices.
Bug: N/A
Test: N/A
Change-Id: Ie9d753e7c2b6cc06e1c8e562970a000858f1072e
2018-04-06 14:44:49 -07:00
Christopher Ferris
4da2503d70 Refactor malloc debug.
Changes
- Refactor the code so that only guards require creating a special header
  for every pointer allocated.
- Store only a single copy of every backtrace. This saves memory so that
  turning on the backtrace option doesn't result in 10X memory usage.
- Added new option track_allocs that only verifies pointers are valid for
  free/malloc_usable_size/realloc.
- Remove suffix from test names.
- Add the TRACK_ALLOCS options to all guard options.
- Add new option verify_pointers that is a lightweight way to verify
  pointers that are passed to allocation routines.
- Do auto-formatting of the code.
- Updated documentation for all of these changes.

Bug: 74361929

Test: Ran unit tests.
Test: Ran libmemunreachable unit tests.
Test: Ran an app with backtrace enabled.

Change-Id: I3246c48ae4f9811f64622d90d0a9b4d9d818702c
2018-04-02 18:59:23 -07:00
Elliott Hughes
cbc80ba9d8 Switch the rest of our internal headers to #pragma once.
We've been using #pragma once for new internal files, but let's be more bold.

Bug: N/A
Test: builds
Change-Id: I7e2ee2730043bd884f9571cdbd8b524043030c07
2018-02-13 14:27:17 -08:00
Christopher Ferris
cae21a9b53 Add aligned_alloc to libc.
Bug: 72969374

Test: Bionic unit tests pass.
Test: Malloc debug unit tests pass.
Change-Id: I235985bbc638855d94249c97c98f14ab2924bda0
(cherry picked from commit d69ee59594)
2018-02-07 06:57:14 -08:00
Elliott Hughes
d50a1de565 Run bpfmt manually.
Bug: N/A
Test: builds
Change-Id: I0cf145c3b699ac8ef170a63366832f63a9cc1a91
2018-02-05 17:30:57 -08:00
Elliott Hughes
733c1e4221 Avoid trademarks.
API levels are generally more useful anyway.

Bug: N/A
Test: N/A
Change-Id: Ie7bd69c3d0223c9bc8ed52c871b1d2d34373e2d0
2018-02-05 13:29:33 -08:00
Elliott Hughes
3e235911c9 Add struct sigaction64 and sigaction64.
Bug: http://b/72493232
Test: ran tests
Change-Id: I47b0560a30aa33a9b1f1978dfb7f84d2e3d389b8
2018-02-01 14:45:15 -08:00
Treehugger Robot
e5fbd983cb Merge "Address a bunch of clang-tidy complaints." 2018-01-20 18:15:12 +00:00
Elliott Hughes
5cec377f49 Address a bunch of clang-tidy complaints.
There were a bunch more unreasonable/incorrect ones, but these ones
seemed legit. Nothing very interesting, though.

Bug: N/A
Test: ran tests, benchmarks
Change-Id: If66971194d4a7b4bf6d0251bedb88e8cdc88a76f
2018-01-19 15:56:12 -08:00
Denis Hsu
1a8106ec1a malloc debug: reset FreeTrackData mutex after fork
Lock the FreeTrackData mutex during fork and reset it in the child.
Ensures that the FreeTrackData is consistent when forking from a
multi-threaded process, and that the mutex is in a defined state
in the child.

Test: 89hours MTBF test
Change-Id: I5e5892832a733ea85727ec65abc7094d95a725ef
2018-01-16 17:43:53 +08:00
Mikhail Naganov
5a1a9533fe Fix typo in README.md for malloc_debug
The examples on malloc options were erroneously
specifying to use 'guards' as an option to enable
both front and rear guards, whereas the correct
option name is 'guard.'

Change-Id: I7118a832b6b308a7c312787f276bb87c1244986e
2018-01-03 08:52:56 -08:00
Elliott Hughes
cabc77f917 Always wrap waitpid in TEMP_FAILURE_RETRY.
Strictly not needed in the WNOHANG case, but it's probably best to have
every waitpid wrapped for future copy & pasters.

Bug: https://issuetracker.google.com/69525592
Test: ran tests
Change-Id: I013b0a52d2753e3d32638e9b84c79af7327fb405
2017-11-28 12:55:19 -08:00
Dan Albert
a613d0df5c Add a legacy inline for mmap64.
While this was never an inline, this function alone has caused most of
the bug reports related to _FILE_OFFSET_BITS=64. Providing an inline
for it should allow a lot more code to build with _FILE_OFFSET_BITS=64
when targeting pre-L.

Test: make checkbuild
Test: built trivial cc_binary for LP32 against API 14 with
      _FILE_OFFSET_BITS=64 set
Bug: lots
Change-Id: I8479d34af4da358c11423bee43d45b59e9d4143e
2017-10-05 23:41:47 -07:00
Christopher Ferris
602b88ccdd Provide method to dump backtrace heap data.
For non-zygote spawned processes, we might want to dump the backtrace
data. Provide a method to send a signal to a process and then dump the
data to a file.

Adds a method to dump the backtrace data on exit.

Update documentation and explain format of heap dump data.

Test: Ran unit tests, enabled new options and used them.
Change-Id: Ie2fa706694160731afe02c1382b037d06df1d069
2017-09-05 15:57:00 -07:00
Elliott Hughes
644275abe0 Improve debug malloc docs slightly for app developers.
Bug: http://b/63098430
Test: N/A
Change-Id: Icde92f5e8b01b5f918cbfdc470b947bd56bb35c6
2017-08-15 23:17:35 -07:00
Christopher Ferris
a625ee2063 Use libdemangle for function names.
Bug: 62141808

Test: Ran unit tests, ran malloc debug with leaks and verified functions
Test: are demangled.
Change-Id: I1900632e9a55bb818b1aabc798224ff3eebc1fca
2017-06-02 10:10:24 -07:00
Christopher Ferris
c0352bbd5f Add offset to backtrace_string printing.
The libmemunreachable code uses backtrace_string to print out the backtrace
information. However, when the offset of the map that a frame is in is
non-zero, no information is printed. This means that when a frame comes from
a shared library loaded from an apk, it's impossible to tell which
shared library the frame is really coming from.

Add the offset display when it's non-zero. This means this can now be fed
to development/scripts/stack to decode the frame.

Bug: 37276041

Test: Ran dumpsys meminfo --unreachable on an app that leaks from a
Test: shared library and verified the offset output is present.
Change-Id: I61d34ae3f617622d354cc099eff520a64782b6e2
2017-05-25 18:38:45 -07:00
Christopher Ferris
4c65669ab7 Update malloc debug documentation.
Test: NA
Change-Id: I8ab73bfc28c7a673efb5b0cec6067989153f092a
2017-05-25 17:23:08 -07:00
Christopher Ferris
2b0f2a4855 Fix missing function export.
Bug: 36401135

Test: Actually enable debug malloc and verify it loads properly.
Test: Ran unit tests.
Change-Id: I9df1699b06bb14c5df2c3cab35dc2eb0819033f1
2017-05-19 13:47:16 -07:00
Christopher Ferris
a1c0d2fd4c Add support for modifying decay timer.
Add the mallopt function, and only a single option so far.

Bug: 36401135

Test: Built and booted bullhead.
Test: Ran jemalloc unit tests.
Test: Ran bionic unit tests.
Test: Ran a test that allocated and free'd a large piece of memory,
Test: and verified that after changing the parameter, the PSS
Test: sticks around (decay timer set to 1), the PSS is purged (decay
Test: timer set to 0).
Change-Id: I6927929b0c539c1023d34772d9e26bb6a8a45877
2017-05-15 16:59:16 -07:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Christopher Ferris
2b2b25b878 Refactor Config from a struct to a class.
This should make it easier to add new options, and to add options that
are complex. For example, I want to modify the behavior of
record_allocs_file so that it also enables record_allocs to a default
state.

Test: All unit tests pass.
Test: Enable the backtrace option and restart.
Change-Id: Idf5cdeed06ade3bc2c8ae39d228734bf65209b4f
2017-04-06 15:30:42 -07:00
Christopher Ferris
426b00a29b Fix the way malloc debug returns info.
When I rewrote malloc debug, I accidentally thought that each
value returned in the info buffer contained the number of backtrace
frames in the backtrace. This was incorrect, it should have been
the total number of allocations with the same backtrace.

This is a temporary fix that sets that value to 1. The better fix is
to de-dupe backtraces and then return all allocations of the same size
with the same backtrace.

I updated the documents to describe this.

Bug: 31854476

Test: Unit tests pass.
Change-Id: Idf9efaa3d363923b5d7543d90dc7c65a0ed553d9
2017-03-09 13:47:37 -08:00
Vijay Venkatraman
191d2f3c99 Removed include log\logger.h from log_fake.cpp
Test: Compile malloc_debug_unit_tests
Change-Id: I635687016570ba52c571435b87d8e89f7f04d609
2017-01-23 18:56:53 -08:00
Tamas Berghammer
ac81fe8657 Enable malloc debug using environment variables
Previously malloc debug can be enabled only using global settings
accessible to the root user only. This CL adds a new option to enable
it using environment variables making it possible to use it with pure
native (shell) applications on production builds (from shell user) and
prepares it for using it from logwrapper on production devices.

Remove the old environment variable and property since they are not
necessary.

Test: Enable malloc debug using environment variable and verify
Test: that it only affects the commands launched from the shell.
Test: Enable malloc debug using the property variable and verify
Test: that it affects all commands.
Test: Run all unit tests in 32 bit and 64 bit.
Change-Id: Iecb75a3471552f619f196ad550c5f41fcd9ce8e5
2016-11-17 13:13:27 -08:00
Christopher Ferris
a19bc2d4ed Fix uninitialized variable usage.
If the dladdr call fails, then info.dli_fname will be unitialized.
Make sure that this can't happen.

Bug: 32907235

Test: Enabled malloc debug on an angler and verified that function names
Test: still work.
Change-Id: I738e66d9f37bce07bc4c10f1f9bac11fbfdae2c7
2016-11-16 10:55:20 -08:00
Christopher Ferris
ac66d16a52 Update documentation.
Fix the incorrect mention of when the zygote flag is set on a size.

Add information about how to use am dumpheap -n to dump the native
heap to a file.

Test: Documentation only change.

Change-Id: I82e810ee7ffffcf7506fb6fd9bcfdfb0465a48be
2016-09-28 14:54:06 -07:00
Tamas Berghammer
4bef28161f Fix unittests broken by 545808a
Change-Id: I590af5958e4dcb772b710be965ed6c99cd1d9234
2016-09-07 16:12:02 +01:00
Tamas Berghammer
545808a608 Fix a typo in the debug malloc usage info
Change-Id: I010fdc6c228a5f64edfef1c267cde7a2eef5190b
2016-08-26 12:34:16 +01:00
Colin Cross
baa4899d38 Convert malloc_debug from Android.mk to Android.bp
Change-Id: I60ad376d222a92a29263c2804dcd1bd0d3c383d0
2016-07-14 09:07:56 -07:00
Christopher Ferris
7bd01783a8 Add the record alloc option.
This option adds the ability to record all of the allocation requests
and dump them to a file when a signal is sent to the process.

Included in this change, redo the option processing to add a new
string option.

Bug: 27747898

Change-Id: Ida043362e38b5eb1d459c99db9c2581015dab366
2016-07-08 14:05:17 -07:00
Christopher Ferris
eab4803290 Update documentation for malloc debug.
Add a new document that describes the previous version of malloc debug.

Add a small update to the current documentation to indicate it only
applies to N and later.

Change-Id: Ief74c253ba79018777aa688bde7f5b35319fa4d4
2016-05-25 13:34:54 -07:00